From: Maps Date: Thu, 20 Nov 2014 22:35:26 +0000 (+0100) Subject: very pleasing progress with back-end tools X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=a52825fd5ea4000e543f0eb75d07b2af83b308dd;p=labtools.git very pleasing progress with back-end tools --- diff --git a/peltier_controller/webGUI/index.pl b/peltier_controller/webGUI/index.pl index 65be60e..ee664c4 100755 --- a/peltier_controller/webGUI/index.pl +++ b/peltier_controller/webGUI/index.pl @@ -39,6 +39,7 @@ sub new { appName => "peltierControl", tty => "/dev/ttyACM1", baudrate => 115200, + columnNames => ["temp","pid","setpoint"] }; # put tons of default values here (if you wish); $self = { @@ -55,7 +56,7 @@ sub main { my $isHttpReq = $ENV{HTTP_USER_AGENT}; - print header('text/plain') if $isHttpReq; + print header('text/html') if $isHttpReq; my $self = shift; # receive CGI query @@ -157,8 +158,21 @@ sub die_test { } +sub clear { + my $self = shift; + + my $ttyID = $self->{tty}; + $ttyID =~ s/^.*\///; + my $shm_manager = shm_manager->new(shmName => $self->{appName}."-".$ttyID ); + + $shm_manager->deleteShm(); +} + sub log_test { my $self = shift; + my %options = @_; + + daemonize() if $options{daemonize}; my $ttyID = $self->{tty}; $ttyID =~ s/^.*\///; @@ -174,11 +188,33 @@ sub log_test { serial_communication => $serial_communication ); - $logging_tool->set_column_names(["temp","pid","setpoint"]); + $logging_tool->set_columnNames($self->{columnNames}); $logging_tool->main(verbose => 1); +} + +sub plot_test { + my $self = shift; + + my $ttyID = $self->{tty}; + $ttyID =~ s/^.*\///; + my $shm_manager = shm_manager->new(shmName => $self->{appName}."-".$ttyID ); + + my $plotting_tool = plotting_tool->new( + columnNames => $self->{columnNames}, + dataFile => $shm_manager->{dataFile} + ); + + my $plotFile = $plotting_tool->plot(); + + $plotFile =~ s%/dev/%%; + + print qq%%; + exit; + + } ################################################## @@ -201,6 +237,13 @@ sub daemonize { } + +################################################## +## misc ## +################################################## + + + sub CGI_parameters { # for each item on the list, get the # designated parameter from the CGI query and diff --git a/peltier_controller/webGUI/logging_tool.pm b/peltier_controller/webGUI/logging_tool.pm index 8d27720..c67d419 100644 --- a/peltier_controller/webGUI/logging_tool.pm +++ b/peltier_controller/webGUI/logging_tool.pm @@ -10,7 +10,7 @@ sub new { my $class = shift; my %options = @_; my $self = { - column_names => ["x","y","z"], + columnNames => ["x","y","z"], delay => 2, %options }; @@ -25,9 +25,9 @@ sub new { -sub set_column_names { +sub set_columnNames { my $self = shift; - $self->{column_names} = shift; + $self->{columnNames} = shift; # as argument I expect a ref to an array } @@ -56,7 +56,7 @@ sub main { unless(-e $dataFile){ open(LOG,"> ".$dataFile); - print LOG "#time\t#".join("\t#",@{$self->{column_names}})."\n"; + print LOG "#time\t#".join("\t#",@{$self->{columnNames}})."\n"; close(LOG); } @@ -71,7 +71,7 @@ sub main { $now = sprintf "%02d.%02d.%02d_%02d:%02d:%02d",(localtime)[3],((localtime)[4] +1),((localtime)[5] -100),(localtime)[2],(localtime)[1],(localtime)[0]; print LOG "$now\t"; print "$now\t" if $verbose; - for my $column_name (@{$self->{column_names}}) { + for my $column_name (@{$self->{columnNames}}) { print LOG $data->{$column_name}."\t"; print $data->{$column_name}."\t" if $verbose; } @@ -81,12 +81,18 @@ sub main { for(my $i=0; $i<$self->{delay};$i++){ - last LOGLOOP if($shmHash->{die}); #die when you are told to + exit if not($shm_manager->existShm()); + last LOGLOOP if($shmHash->{die}); + #die when you are told to sleep 1; } } + $shmHash = $shm_manager->readShm(); + delete $shmHash->{die}; + $shm_manager->writeShm($shmHash); + } diff --git a/peltier_controller/webGUI/plotting_tool.pm b/peltier_controller/webGUI/plotting_tool.pm index d34fdcb..e439636 100644 --- a/peltier_controller/webGUI/plotting_tool.pm +++ b/peltier_controller/webGUI/plotting_tool.pm @@ -10,13 +10,15 @@ sub new { my $class = shift; my %options = @_; my $self = { - plotfile => "/dev/null", - datafile => "/dev/null", last_n => "40", - title => "Temperature", + title => "plot title", %options }; + + die "plotting tool needs to be given a dataFile" unless(defined($self->{dataFile})); + die "plotting tool needs to be given a list containing colum names" unless(defined($self->{columnNames})); + $self->{plotFile} = $self->{dataFile}.".gif"; bless($self, $class); } @@ -26,8 +28,8 @@ sub plot { my $self = shift; my %options = @_; - my $plotfile = $self->{plotfile}; - my $datafile = $self->{datafile}; + my $plotFile = $self->{plotFile}; + my $dataFile = $self->{dataFile}; my $last_n = $self->{last_n}; my $title = $self->{title}; @@ -48,7 +50,7 @@ set style line 12 lc rgb '#808080' lt 0 lw 1 set grid back ls 12 set terminal gif size 800,600 -set output "$plotfile" +set output "$plotFile" set title "$title" set xdata time set timefmt "\%d.\%m.\%Y_\%H:\%M:\%S" @@ -56,12 +58,22 @@ set format x " \%H:\%M" set xtics rotate set ylabel "temperature in °C" set yrange [-20:30] -plot "< tail -$last_n $datafile" using 1:2 title "p" w linespoints EOF - close(GNUPLOT); - - + my $i=2; + for my $columnName ( @{$self->{columnNames}} ){ + if($i == 2) { + print GNUPLOT "plot "; + } else { + print GNUPLOT " , "; + } + print GNUPLOT qq%"< tail -$last_n $dataFile" using 1:$i title "$columnName" w linespoints%; + $i++; + } + print GNUPLOT "\n"; + close(GNUPLOT); + return $self->{plotFile}; } +