From 64f08bdccf92464e3f43aa07dd517db955689ff1 Mon Sep 17 00:00:00 2001 From: "www@jspc55" Date: Thu, 30 Jan 2014 15:11:01 +0100 Subject: [PATCH] updates on the plotting system --- Environment.pm | 2 +- tools/AccessXmlDb.pm | 12 ++ tools/PlotScheduler.pm | 29 +++- tools/adcmon.js | 55 +++++++ tools/adcmon.pl | 331 +++++++++++++++++++++++++++++++++++------ tools/plotService.pl | 4 +- 6 files changed, 378 insertions(+), 55 deletions(-) create mode 100644 tools/adcmon.js diff --git a/Environment.pm b/Environment.pm index d333e2c..a8ceef8 100644 --- a/Environment.pm +++ b/Environment.pm @@ -23,7 +23,7 @@ use constant DUMPPATH => "/tmp/MAPS_PREV/"; #path for s use constant SHAREPATH => JTAGROOTPATH."share/"; #path for icons and misc stuff use constant SETUPFILE => SETUPDIR."testsetup.xml"; - +use constant SHMSYMLINK => JTAGROOTPATH."shm/"; diff --git a/tools/AccessXmlDb.pm b/tools/AccessXmlDb.pm index 0b385b7..21d170d 100644 --- a/tools/AccessXmlDb.pm +++ b/tools/AccessXmlDb.pm @@ -1,6 +1,7 @@ package AccessXmlDb; use Storable qw(lock_store lock_retrieve); +use Data::Dumper; sub new { my $class = shift; @@ -29,6 +30,16 @@ sub channelParm { return $parm; } +sub dumpEntity { # for debug + my $self = shift; + print Dumper $self->{entity}; +} + +sub channelList { + my $self = shift; + return $self->{entity}->{AdcSensor}->{children};# returns a reference to an array +} + # returns a hash ref to the following contents (example); # # $VAR1 = { @@ -46,4 +57,5 @@ sub channelParm { # 'start' => '0' # }; + 1; \ No newline at end of file diff --git a/tools/PlotScheduler.pm b/tools/PlotScheduler.pm index c143985..42f0ef3 100644 --- a/tools/PlotScheduler.pm +++ b/tools/PlotScheduler.pm @@ -10,7 +10,7 @@ use Data::Dumper; use Time::HiRes; -require Common; +# require Common; use FindBin; @@ -35,13 +35,22 @@ sub new { sub addRequest { + # either give it a complete requestString of type + # "$FPGA-$CB-$chip-$channel" + # or give it individual components + # to add a request to the scheduler my $self = shift; my %param = @_; - my $FPGA = $param{FPGA}; - my $CB = $param{CB}; - my $chip = $param{chip}; - my $channel = $param{channel}; - $self->{requests}->{"$FPGA-$CB-$chip-$channel"} = time(); + + my $requestString = $param{requestString}; + unless (defined ($requestString)){ + my $FPGA = $param{FPGA}; + my $CB = $param{CB}; + my $chip = $param{chip}; + my $channel = $param{channel}; + $requestString = "$FPGA-$CB-$chip-$channel"; + } + $self->{requests}->{$requestString} = time(); } sub enforceTimeout { @@ -73,6 +82,8 @@ sub retrieveRequests { sub storeRequests { my $self = shift; if ( -e $self->{shm} ){ + + # backing off stuff for( my $i = 0 ; $i < $self->{maxRepeats}; $i++){ if( lock_store($self->{requests},$self->{shm}) ) { last; @@ -80,6 +91,8 @@ sub storeRequests { Time::HiRes::sleep(rand()/10*$i/$self->{maxRepeats}); # if you don't get it step back } } + +# lock_store($self->{requests},$self->{shm}); } } @@ -128,7 +141,7 @@ sub startPlotService { if (-e $self->{shm}) { die "service already running!\n"; } else { - system("./plotService.pl --shm ".$self->{shm}.' >/dev/null &'); + system("./plotService.pl --shm ".$self->{shm}.' >/dev/null & disown'); for (my $i = 0; $i< $self->{startTimeout}*100; $i++){ if( -e $self->{shm} ) { return 1; @@ -136,7 +149,7 @@ sub startPlotService { Time::HiRes::sleep(0.01); } } - die "could not start Service\n"; + die "could not start Service (shm file=".$self->{shm}.")\n"; return 0; } } diff --git a/tools/adcmon.js b/tools/adcmon.js new file mode 100644 index 0000000..961674b --- /dev/null +++ b/tools/adcmon.js @@ -0,0 +1,55 @@ + +$(document).ready(function(){ + $("#btn1").click(function(){ + $("#test1").text(function(i,origText){ + return "Old text: " + origText + " New text: Hello world! (index: " + i + ")"; + }); + }); + + $("#btn2").click(function(){ + $("#test2").html(function(i,origText){ + return "Old html: " + origText + " New html: Hello world! (index: " + i + ")"; + }); + }); + + $("#comm_ajax").click(function(){ + var collector = []; + $(".channelCheckbox:checked").each(function(){ + var cb_id = $(this).attr('id'); + collector.push( cb_id.replace(/checkbox_/,"")); + }); + var requestStrings = collector.join(","); + var daqopserver = $("#input_DAQOPSERVER").val(); + $.ajax({ + url: "adcmon.pl", + cache: false, + dataType: "text", + data: { sub: 'plot_request', + requestStrings: requestStrings, + DAQOPSERVER: daqopserver}, + success: function(result) {$("#plotArea").html(result);} + }); + + + }); + var counter= 0; + + var timer = $.timer(function() { +// alert('This message was sent by a timer.'); + $("#refreshInterval").val(counter++); + }); + + timer.set({ time : 2000, autostart : true }); + + + $("#test_but").click(function(){ + var collector = []; + $(".channelCheckbox:checked").each(function(){ + var cb_id = $(this).attr('id'); + collector.push( cb_id.replace(/checkbox_/,"")); + }); + alert(collector.join(",")); + }); + +}); + diff --git a/tools/adcmon.pl b/tools/adcmon.pl index ccec344..05c425d 100755 --- a/tools/adcmon.pl +++ b/tools/adcmon.pl @@ -5,59 +5,289 @@ my $me = "adcmon.pl"; use strict; use warnings; -use XML::LibXML; use POSIX; use CGI ':standard'; use CGI::Carp qw(fatalsToBrowser); -use HTML::Entities; -use Widgets; -use Data::Dumper; +# use HTML::Entities; use PlotScheduler; +use MIME::Base64; +use Widgets; +use HADES::TrbNet; use AccessXmlDb; -use Storable qw(lock_store lock_retrieve); - -# use HPlot; +require Common; -# require Common; -# require xmlOperations; -# require xmlRendering; use FindBin; use lib "$FindBin::Bin/.."; use Environment; -$ENV{'DAQOPSERVER'} = "jspc55:88"; +# subs that are callable via http request +my $dispatch = { + table_hash => \&table_hash, + plot_request => \&plot_request +}; +my $q = CGI->new; + +# for accessing the xml-db stuff +my $entityFile = "../../daqtools/xml-db/cache/CbController.entity"; +my $xmldb; + + + +$ENV{'DAQOPSERVER'} = $q->param('DAQOPSERVER') if defined $q->param('DAQOPSERVER'); +my $FPGA = $q->param('FPGA'); +my $CB = $q->param('CB'); +my $chip = $q->param('chip'); +my $channel = $q->param('channel'); +my $daqopserver = $ENV{'DAQOPSERVER'}; + + + +print header; -init_html(); -my $ps = PlotScheduler->new( shm => "/dev/shm/DQ55" ); -# $ps->addRequest( FPGA => "0xd882", CB => "0", chip => "1", channel => "TEMP"); -# $ps->storeRequests(); -$ps->startPlotService() unless $ps->plotServiceRunning(); - -# while(1){ - $ps->retrieveRequests(); - $ps->addRequest( FPGA => "0xd882", CB => "0", chip => "0", channel => "CurrentDigital"); - $ps->addRequest( FPGA => "0xd882", CB => "0", chip => "0", channel => "CurrentAnalog"); - $ps->addRequest( FPGA => "0xd882", CB => "0", chip => "0", channel => "VoltageDigital"); - $ps->addRequest( FPGA => "0xd882", CB => "0", chip => "0", channel => "VoltageAnalog"); - $ps->listRequests(); - $ps->storeRequests(); -# sleep 1; +# unless (defined( $FPGA ) && defined( $CB ) && defined( $chip ) && defined( $channel ) && defined( $daqopserver )) { +# print "

usage:

"; +# print "

adcmon?DAQOPSERVER=...&FPGA=...&CB=...&chip=...&channel=...

"; +# exit; + +if ($q->param('sub')){ + my $subname = $q->param('sub'); + $dispatch->{$subname}->($q); # give the sub the query +} else { + page_body($q); +} +exit; # } -for my $plot ( keys $ps->{requests}) { - print "
"; - print img {src => "../shm/DQ55_plots/".$plot.".png"}; + + + + +sub plot_request { + + my $q= shift; + + + my @requestStrings = split(",",$q->param('requestStrings')); + +# print join("
",@requestStrings); + + return if (@requestStrings == 0); + + + $ENV{'DAQOPSERVER'} = $q->param('DAQOPSERVER') if defined $q->param('DAQOPSERVER'); + my $daqopserver = $ENV{'DAQOPSERVER'}; + +# unless (defined( $FPGA ) && defined( $CB ) && defined( $chip ) && defined( $channel ) && defined( $daqopserver )) { + unless (defined($daqopserver)){ + die "DAQOPSERVER undefined!"; + } + my $ps = PlotScheduler->new( shm => SHMSYMLINK."adcmon-$daqopserver" ); + # $ps->addRequest( FPGA => "0xd882", CB => "0", chip => "1", channel => "TEMP"); + # $ps->storeRequests(); + $ps->startPlotService() unless $ps->plotServiceRunning(); + + $ps->retrieveRequests(); +# $ps->addRequest( FPGA => $FPGA, CB => $CB, chip => $chip, channel => $channel); + for my $reqStr (@requestStrings){ + $ps->addRequest( requestString => $reqStr ); + } + # $ps->listRequests(); + $ps->storeRequests(); +# my $plotfile = $ps->{plotDir}."/$FPGA-$CB-$chip-$channel.png"; +# } +# system("echo 'blah'>".$ps->{plotDir}."/test.txt"); + for my $reqStr (@requestStrings){ + print ""; + print br; + } +} +# sub plot_request { +# +# my $q= shift; +# +# $ENV{'DAQOPSERVER'} = $q->param('DAQOPSERVER') if defined $q->param('DAQOPSERVER'); +# my $FPGA = $q->param('FPGA'); +# my $CB = $q->param('CB'); +# my $chip = $q->param('chip'); +# my $channel = $q->param('channel'); +# my $daqopserver = $ENV{'DAQOPSERVER'}; +# +# unless (defined( $FPGA ) && defined( $CB ) && defined( $chip ) && defined( $channel ) && defined( $daqopserver )) { +# +# my $ps = PlotScheduler->new( shm => SHMSYMLINK."adcmon-$daqopserver" ); +# # $ps->addRequest( FPGA => "0xd882", CB => "0", chip => "1", channel => "TEMP"); +# # $ps->storeRequests(); +# $ps->startPlotService() unless $ps->plotServiceRunning(); +# +# $ps->retrieveRequests(); +# $ps->addRequest( FPGA => $FPGA, CB => $CB, chip => $chip, channel => $channel); +# # $ps->listRequests(); +# $ps->storeRequests(); +# my $plotfile = $ps->{plotDir}."/$FPGA-$CB-$chip-$channel.png"; +# } +# } + + +sub print_selectors { + + + + +my $q=shift; + +print ""; +print ""; +print ""; +print ""; +print ""; +print ""; +print ""; +print ""; +print ""; +print ""; + +print ""; +print ""; +print ""; +print ""; +print ""; + +print "
DAQOPSERVER
FPGACBchip
"; +my $FPGA_selector = fileSelector->new( + id=>"FPGA_selector", + name=>"FPGA_selectionDropdown", + selected=>lc($q->param("FPGA")) +); +$FPGA_selector->add_item(value=>'...'); +for my $element (activeTRBs()) { + $FPGA_selector->add_item(value=>lc(any2hex($element))); +} +$FPGA_selector->print_html(); +print ""; +my $CB_selector = fileSelector->new( + id=>"CB_selector", + name=>"CB_selectionDropdown", + selected=>$q->param("CB") +); +$CB_selector->add_item(value=>'...'); +$CB_selector->add_item(value=>$q->param("CB")) if defined $q->param("CB"); +$CB_selector->print_html(); +print ""; +my $chip_selector = fileSelector->new( + id=>"chip_selector", + name=>"chip_selectionDropdown", + selected=>$q->param("chip") +); +$chip_selector->add_item(value=>'...'); +$chip_selector->add_item(value=>$q->param("chip")) if defined $q->param("chip"); +$chip_selector->print_html(); +print "
"; + +print ""; +print ""; +print ""; +print ""; +print ""; +print ""; + +print "
"; +print ""; +print ""; +print ""; +print ""; +print ""; +print "
"; + + + + +print ""; +$xmldb = AccessXmlDb->new( entityFile => $entityFile ); +for my $element ( @{$xmldb->channelList()}) { + print ""; + print ""; + print ""; + print ""; +} +print "
"; + print "$element"; + print ""; + print ""; + print "
"; + + } +sub page_body{ + +init_html(); +my $q = shift; + + + + +trb_init_ports() or die trb_strerror(); + +print '
'; +print_selectors($q); +print '
'; + +print '
'; +print_plotArea($q); +print '
'; + +print '
'; +print_debugStuff($q); +print '
'; + + +} + + +sub print_plotArea{ + my $q=shift; + print p "plot Area"; + +} + +sub print_debugStuff{ + +my $q=shift(); +print "

debug stuff:

"; +table_hash($q); +# print qq%

placeholder

%; +# +# print <This is a bold paragraph.

+#

This is another bold paragraph.

+# +# +# EOF +} + +sub table_hash{ + my $q = shift; + + print ''; + for my $key ( $q->param()){ + print ''; + print ''; + print ''; + } + print '
'.$key.'=>'.$q->param($key).'
'; +} + + + sub init_html{ - print header; print start_html( -title=>'ADC Monitor', -style=>[{'src'=>'../layout/styles.css'}, @@ -65,26 +295,39 @@ sub init_html{ {'src'=>'../layout/testgui.css'} ], -script=>[ - { -type => 'text/javascript', -src => './testgui.js'}, - { -type => 'text/javascript', -src => './hideAndShow.js'}, - { -type => 'text/javascript', -src => './getdata.js'}, - { -type => 'text/javascript', -src => './xmlOperations.js'} + { -type => 'text/javascript', -src => 'http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'}, + { -type => 'text/javascript', -src => './adcmon.js'}, + { -type => 'text/javascript', -src => '../scripts/jquery.timer.js'} ] +# # -script=>[ +# # { -type => 'text/javascript', -src => './testgui.js'}, +# # { -type => 'text/javascript', -src => './hideAndShow.js'}, +# # { -type => 'text/javascript', -src => './getdata.js'}, +# # { -type => 'text/javascript', -src => './xmlOperations.js'} +# # ] ); - +# print start_html(- } +sub activeTRBs { + # read microsecond counters, return list of active addresses + my $read = trb_register_read(0xFFFF,0x50); + return (keys %$read); +} +sub addpng { + my ($file) = @_; + my $out = "data:image/png;base64,"; + open (my $fh, "<$file"); - - - - - - - - - \ No newline at end of file + local $/; + my $bin = <$fh>; + $fh->close(); + $/='\n'; + $out .= encode_base64($bin); + chomp $out; + return $out; + } diff --git a/tools/plotService.pl b/tools/plotService.pl index 0dd13ea..a6afeaf 100755 --- a/tools/plotService.pl +++ b/tools/plotService.pl @@ -189,12 +189,12 @@ sub new { sub sample { my $self = shift; - my $myverbose=0; +# my $myverbose=0; # sample random number for debug # HPlot::PlotAdd($self->{requestString},rand()); my $read = trb_register_read($self->{FPGA},$self->{address}); my $value = ($read->{$self->{FPGA}} & 0xFFFF ) * $self->{scale}; - print $value."\n" if $myverbose; +# print $value."\n" if $myverbose; HPlot::PlotAdd($self->{requestString},$value); } -- 2.43.0