From: www@jspc55 Date: Thu, 13 Feb 2014 10:28:50 +0000 (+0100) Subject: added a scriptable command line tool to read n ADC values and get simple statistics/ X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=b8ee340bc729e92055522be4552356c9e02b9d87;p=mvdsensorcontrol.git added a scriptable command line tool to read n ADC values and get simple statistics/ --- diff --git a/Environment.pm b/Environment.pm index a8ceef8..5f808e3 100644 --- a/Environment.pm +++ b/Environment.pm @@ -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 diff --git a/tools/HPlot.pm b/tools/HPlot.pm index 437f382..6e2faba 100644 --- a/tools/HPlot.pm +++ b/tools/HPlot.pm @@ -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"); } diff --git a/tools/adcmon.pl b/tools/adcmon.pl index 1cd0e10..95a7e41 100755 --- a/tools/adcmon.pl +++ b/tools/adcmon.pl @@ -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 index 0000000..c032c3b --- /dev/null +++ b/tools/adcread.pl @@ -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=
chip= channel= [OPTIONS] +Usage (CGI) : adcread.pl?FPGA=
&chip=&channel=[&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: + \t\t\t\n + +Options: + n = sample values + delay = delay between samples (default=5ms) + DAQOPSERVER = : 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/
/g; +return $text; + +} \ No newline at end of file diff --git a/tools/plotService.pl b/tools/plotService.pl index 4e29243..8f40700 100755 --- a/tools/plotService.pl +++ b/tools/plotService.pl @@ -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 {