]> jspc29.x-matter.uni-frankfurt.de Git - mvdsensorcontrol.git/commitdiff
updates on the plotting system
authorwww@jspc55 <www@jspc55>
Thu, 30 Jan 2014 14:11:01 +0000 (15:11 +0100)
committerwww@jspc55 <www@jspc55>
Thu, 30 Jan 2014 14:11:01 +0000 (15:11 +0100)
Environment.pm
tools/AccessXmlDb.pm
tools/PlotScheduler.pm
tools/adcmon.js [new file with mode: 0644]
tools/adcmon.pl
tools/plotService.pl

index d333e2c2ba78dc4e280b8830c2664753fffbdcd0..a8ceef8ee17d42c28e65437d321aa8758b23790b 100644 (file)
@@ -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/";
 
 
 
index 0b385b76e55890a11f1e3dd8c4fb7a6811b1f2d5..21d170d439384973fe6cade4f92ba628fcb47d72 100644 (file)
@@ -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
index c14398559f627d14912095dc19c1d428120baecd..42f0ef3326cc391eb0ba9f1e21e9004316987775 100644 (file)
@@ -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 (file)
index 0000000..961674b
--- /dev/null
@@ -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 <b>world!</b> (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(","));
+   });
+
+});
+
index ccec34425592ce1738404c2addd0059a07f8b8dd..05c425d3b510ca19d760656a6eda4f6cd0bba83f 100755 (executable)
@@ -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 "<p>usage:</p>";
+#   print "<p>adcmon?DAQOPSERVER=...&FPGA=...&CB=...&chip=...&channel=...</p>";
+#   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 "<br>";
-  print img {src => "../shm/DQ55_plots/".$plot.".png"};
+
+
+
+
+sub plot_request {
+
+  my $q= shift;
+  
+  
+  my @requestStrings = split(",",$q->param('requestStrings'));
+  
+#   print join("<br>",@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 "<img src='".addpng($ps->{plotDir}."/".$reqStr.".png")."'>";
+      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 "<table>";
+print "<tr>";
+print "<td>DAQOPSERVER</td>";
+print "<td><input type='text' id='input_DAQOPSERVER' value='".$daqopserver."'></td>";
+print "</tr>";
+print "<tr>";
+print "<td>FPGA</td>";
+print "<td>CB</td>";
+print "<td>chip</td>";
+print "</tr>";
+
+print "<tr>";
+print "<td>";
+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 "</td>";
+print "<td>";
+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 "</td>";
+print "<td>";
+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 "</td>";
+print "</tr>";
+
+print "</table>";
+
+print "<table>";
+print "<tr>";
+print "<td>";
+print "<button id='comm_ajax'>ajax!</button>";
+print "</td>"; 
+print "<td>";
+print "<button id='test_but'>test</button>";
+print "</td>";
+print "<td>";
+print "<input type='text' name='refresh(ms)' id='refreshInterval' value='1000'>";
+print "</td>";
+print "</tr>";
+
+print "</table>";
+
+
+
+
+print "<table id='checkboxTable'>";
+$xmldb = AccessXmlDb->new( entityFile => $entityFile );
+for my $element ( @{$xmldb->channelList()}) {
+  print "<tr>";
+  print "<td>";
+  print "$element";
+  print "</td>";
+  print "<td>";
+  print "<input type='checkbox' class='channelCheckbox' id='checkbox_"
+  .$FPGA."-".$CB."-".$chip."-".$element."'>";
+  print "</td>";
+  print "</tr>";
+}
+print "</table>";
+
+
 }
 
+sub page_body{
+
+init_html();
+my $q = shift;
+
+
+
+
+trb_init_ports() or die trb_strerror();
+
+print '<div id="selectors">';
+print_selectors($q);
+print '</div>';
+
+print '<div id="plotArea">';
+print_plotArea($q);
+print '</div>';
+
+print '<div id="debugStuff">';
+print_debugStuff($q);
+print '</div>';
+
+
+}
+
+
+sub print_plotArea{
+  my $q=shift;
+  print p "plot Area";
+  
+}
+
+sub print_debugStuff{
+
+my $q=shift();
+print "<p> debug stuff: </p>";
+table_hash($q);
+# print qq%<p id='placeholder'>placeholder</p>%;
+# 
+# print <<EOF
+# <p id="test1">This is a <b>bold</b> paragraph.</p>
+# <p id="test2">This is another <b>bold</b> paragraph.</p>
+# <button id="btn1">Show Old/New Text</button>
+# <button id="btn2">Show Old/New HTML</button>
+# EOF
+}
+
+sub table_hash{
+  my $q = shift;
+  
+  print '<table>';
+  for my $key ( $q->param()){
+    print '<tr>';
+    print '<td>'.$key.'</td><td>=></td><td>'.$q->param($key).'</td>';
+    print '</tr>';
+  }
+  print '</table>';
+}
+
+
+
 
 
 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;
+  }
index 0dd13eabc869f8b309018f03a8d4008efedd1b2b..a6afeaffd2ca1d1422f6cfb7a2e70eeaf28388fd 100755 (executable)
@@ -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);
 
 }