]> jspc29.x-matter.uni-frankfurt.de Git - mvdsensorcontrol.git/commitdiff
added a scriptable command line tool to read n ADC values and get simple statistics/
authorwww@jspc55 <www@jspc55>
Thu, 13 Feb 2014 10:28:50 +0000 (11:28 +0100)
committerwww@jspc55 <www@jspc55>
Thu, 13 Feb 2014 10:28:50 +0000 (11:28 +0100)
Environment.pm
tools/HPlot.pm
tools/adcmon.pl
tools/adcread.pl [new file with mode: 0755]
tools/plotService.pl

index a8ceef8ee17d42c28e65437d321aa8758b23790b..5f808e3002363ccc89b545e64012817710e2c718 100644 (file)
@@ -25,6 +25,8 @@ use constant SHAREPATH        => JTAGROOTPATH."share/";             #path for ic
 use constant SETUPFILE        => SETUPDIR."testsetup.xml";
 use constant SHMSYMLINK       => JTAGROOTPATH."shm/";
 
+use constant XML_CBCTRL_ENTITY    => JTAGROOTPATH."../daqtools/xml-db/cache/CbController.entity";
+
 
 
 #Export variables that are used elsewhere
index 437f38258da157dfc253484f978565597a6b6391..6e2fabab8f625d1c88e7e4c40cc27b890158128b 100644 (file)
@@ -129,7 +129,20 @@ sub PlotInit {
 sub PlotDraw {
   my($name) = @_;
   if($p->{$name}->{run}>=1) {
-    plot_write($p->{$name}->{fh},"set out \"".$p->{$name}->{file}.".png\"");
+    plot_write($p->{$name}->{fh},"set out \"|cat >".
+      $p->{$name}->{file}.".png_tmp && mv ".
+      $p->{$name}->{file}.".png_tmp ".
+      $p->{$name}->{file}.".png ".
+      "\"");
+# #       this code makes gnuplot write a temp file first, and after its creation, moves the temp file
+#     plot_write($p->{$name}->{fh},"set out \"|base64 >".
+#       $p->{$name}->{file}.".png.base64_tmp && mv ".
+#       $p->{$name}->{file}.".png.base64_tmp ".
+#       $p->{$name}->{file}.".png.base64 ".
+#       "\"");
+#     plot_write($p->{$name}->{fh},"set out \"".
+#       $p->{$name}->{file}.".png".
+#       "\"");
     plot_write($p->{$name}->{fh},makeTimeString());
     plot_write($p->{$name}->{fh},"replot");
     }
index 1cd0e1082ea69ff9f155e4d39cf61a1cea22fadb..95a7e41b60eb4c2558e9fb850b56be6269fec63a 100755 (executable)
@@ -35,6 +35,7 @@ require Common;
 use FindBin;
 use lib "$FindBin::Bin/..";
 use Environment;
+use Time::HiRes;
 
 
 ##############
@@ -44,7 +45,7 @@ my $CBsPerFpga=2;
 my $ChipsPerCB=2;
 my $plotWidth=600;
 my $plotHeight=400;
-my $xmldbEntityFile = "../../daqtools/xml-db/cache/CbController.entity";
+my $xmldbEntityFile = XML_CBCTRL_ENTITY;
 
 ##############
 ## global variables
@@ -327,3 +328,19 @@ sub addpng {
   chomp $out;
   return $out;
   }
+
+sub addpng64 {
+  my ($file) = @_;
+#   delay if file does not yet exist
+  Time::HiRes::sleep(0.2) unless (-e $file);
+  return unless (-e $file);
+  my $out = "data:image/png;base64,";
+  open (my $fh, "<$file");
+  local $/;
+  my $bin = <$fh>;
+  $fh->close();
+  $/='\n';
+  $out .= $bin;
+  chomp $out;
+  return $out;
+  }
diff --git a/tools/adcread.pl b/tools/adcread.pl
new file mode 100755 (executable)
index 0000000..c032c3b
--- /dev/null
@@ -0,0 +1,157 @@
+#!/usr/bin/perl -w
+
+
+my $me = "adcread.pl";
+
+# my $verbose = 1;
+my $suicideTimeout = 5;
+
+
+
+use strict;
+use warnings;
+use POSIX;
+use Storable qw(lock_store lock_retrieve);
+use Data::Dumper;
+use Getopt::Long;
+use Time::HiRes;
+use HADES::TrbNet;
+use AccessXmlDb;
+use CGI ':standard';
+require Common;
+
+
+use FindBin;
+use lib "$FindBin::Bin/..";
+
+
+my $entityFile = "../../daqtools/xml-db/cache/CbController.entity";
+my $xmldb = AccessXmlDb->new( entityFile => $entityFile );
+
+my $isHttpReq = $ENV{HTTP_USER_AGENT};
+
+my $q = CGI->new;
+
+my $channel     = $q->param('channel');
+my $chip        = $q->param('chip');
+my $FPGA        = $q->param('FPGA');
+my $DAQOPSERVER = $q->param('DAQOPSERVER') || $ENV{'DAQOPSERVER'};
+my $n           = $q->param('n')           || 10;
+my $delay       = $q->param('delay')       || 5 ; #ms
+my $verbose     = $q->param('verbose')     || 0;
+
+print header('text/plain') if $isHttpReq;
+print_usage() unless ( defined($channel) && defined($chip) && defined($FPGA));
+
+
+# Getopt::Long::Configure(qw(gnu_getopt));
+# GetOptions(
+#            'chip=s' => \$chip,
+#            'channel=s' => \$channel,
+#            'FPGA=s' => \$FPGA,
+#            'delay=s' => \$delay,
+#            'DAQOPSERVER=s' => \$DAQOPSERVER,
+#            'n=s' => \$n
+#           );
+
+
+          
+$ENV{'DAQOPSERVER'} = $DAQOPSERVER;
+
+
+my $self = $xmldb->channelParm($chip,$channel);
+$self->{FPGA} = any2dec($FPGA);
+trb_init_ports() or die trb_strerror();
+
+
+my @vals;
+
+minMax();
+
+$delay /= 1000;
+
+for (my $i = 0; $i < $n; $i++){
+  Time::HiRes::sleep( $delay );
+  my $val=getVal();
+  print $val."\n" if $verbose;
+  push(@vals,$val);
+}
+
+my( $min, $max) = minMax();
+
+my $mean = average(\@vals);
+my $stdev = stdev(\@vals);
+print "unit = 1 ".$self->{unit}."\n" if $verbose;
+print "mean:\tstdev:\tmin:\tmax:\n" if $verbose; 
+print "$mean\t$stdev\t$min\t$max\n";
+
+
+
+sub getVal{
+  my $read = trb_register_read($self->{FPGA},$self->{address});
+  my $value = ($read->{$self->{FPGA}} & 0xFFFF ) * $self->{scale};
+  return $value;
+}
+
+sub minMax{
+#   read min and max 
+  my $read = trb_register_read($self->{FPGA},$self->{address}+0x30);
+  my $minmax = ($read->{$self->{FPGA}} ) ;
+  my $min = ($minmax & 0x0000FFFF) * $self->{scale}; # lower 16 bit
+  my $max = ($minmax >> 16       ) * $self->{scale};        # upper 16 bit
+  return ($min, $max);
+}
+
+sub print_usage{
+
+my $text = q%
+Usage (cmdline): adcread.pl FPGA=<address> chip=<number> channel=<channelName> [OPTIONS]
+Usage (CGI)    : adcread.pl?FPGA=<address>&chip=<number>&channel=<channelName>[&OPTIONS]
+
+Reads n (default=10) values from selected ConverterBoard(v2013) ADCs and prints out their
+mean and stdev, as well as the minimum and maximum value that the FPGA has seen during
+readout time (regardless of whether min and max have been sampled by this script).
+
+Results will have the following format:
+  <mean>\t<stdev>\t<min>\t<max>\n
+
+Options:
+  n           = <number>        sample <number> values
+  delay       = <ms>            delay between samples (default=5ms)
+  DAQOPSERVER = <host>:<port>   sets the DAQOPSERVER (server which hosts TRBnet daemon)
+                                if left out, will use DAQOPSERVER ENV variable
+  verbose     = <0|1>           if verbose=1 then script will print all sampled values
+                                as well as the channel unit and other debug data
+
+available ADC channels:
+
+  %.
+join("\n  ", @{$xmldb->channelList()})
+.q%
+
+Example:
+  cmdline: adcread.pl DAQOPSERVER=localhost:88 FPGA=0xd882 chip=0 channel=CurrentDigital
+  CGI    : adcread.pl?DAQOPSERVER=localhost:88&FPGA=0xd882&chip=0&channel=CurrentDigital
+%;
+
+
+
+  if ( $isHttpReq ){
+    print "you have called this script via CGI\n";
+  } else {
+    print "you have called this script via command line\n";
+  }
+  print $text;
+  exit;
+
+}
+
+
+sub text2html {
+
+my $text = shift;
+$text = escapeHTML($text);
+$text =~ s/\n/<br>/g;
+return $text;
+
+}
\ No newline at end of file
index 4e292432445c1d8f97e90fe24f2d37483530893a..8f40700be805bbe2e4fe6f79ab437bbcf4069b65 100755 (executable)
@@ -188,6 +188,10 @@ sub new {
   $plot->{output}  = HPlot::OUT_PNG;
   $plot->{titles}->[0] = $self->{requestString};
   $plot->{ylabel}  = $self->{unit};
+  $plot->{curves}  = 3;
+  $plot->{titles}->[1] = "min";
+  $plot->{titles}->[2] = "max";
+  
   ## uncomment for resizing y axis to full adc range
 #   $plot->{ymin}    = 0;
 #   $plot->{ymax}    = $self->{scale} * 65536;
@@ -203,8 +207,15 @@ sub sample {
 #   HPlot::PlotAdd($self->{requestString},rand());
   my $read = trb_register_read($self->{FPGA},$self->{address});
   my $value = ($read->{$self->{FPGA}} & 0xFFFF ) * $self->{scale};
+#   read min and max 
+  my $read = trb_register_read($self->{FPGA},$self->{address}+0x30);
+  my $minmax = ($read->{$self->{FPGA}} ) ;
+  my $min = ($minmax & 0x0000FFFF) * $self->{scale}; # lower 16 bit
+  my $max = ($minmax >> 16       ) * $self->{scale};        # upper 16 bit
 #   print $value."\n" if $myverbose;
-  HPlot::PlotAdd($self->{requestString},$value);
+  HPlot::PlotAdd($self->{requestString},$value,0);
+  HPlot::PlotAdd($self->{requestString},$min,1);
+  HPlot::PlotAdd($self->{requestString},$max,2);
 
 }
 sub draw {