]> jspc29.x-matter.uni-frankfurt.de Git - mvdsensorcontrol.git/commitdiff
first version of adcmon working
authorwww@jspc55 <www@jspc55>
Thu, 30 Jan 2014 18:34:57 +0000 (19:34 +0100)
committerwww@jspc55 <www@jspc55>
Thu, 30 Jan 2014 18:34:57 +0000 (19:34 +0100)
layout/adcmon.css [new file with mode: 0644]
scripts/jquery.timer.js [new file with mode: 0644]
tools/PlotScheduler.pm
tools/adcmon.js
tools/adcmon.pl
tools/plotService.pl

diff --git a/layout/adcmon.css b/layout/adcmon.css
new file mode 100644 (file)
index 0000000..e259f60
--- /dev/null
@@ -0,0 +1,52 @@
+
+
+
+
+
+
+
+
+.plasticBox {
+   border-radius:5px;
+   background:#eef;
+   box-shadow: 0 0 10px 5px #fff,  0 0 4px 1px #78b inset;
+}
+
+.debugFeature {
+  visibility:collapse;
+}
+
+
+#selectors {
+   float:right;
+   position:absolute;
+   position:fixed;
+   top: 0px;
+   left: 640px;
+   width:280px;
+   padding:10px;
+   margin-top:30px;
+   margin-left:30px;
+
+   }
+   
+.plotArea {
+/*    float:left; */
+   position:absolute;
+/*    position:fixed; */
+/*    width:320px; */
+   left:0px;
+   top:0px;
+   min-width: 600px;
+   min-height: 400px;
+   padding:10px;
+   margin-top:30px;
+   margin-left:30px;
+
+   }
+   
+#plotAreaFg {
+   z-index: +1;
+}
+#plotAreaBg {
+}
\ No newline at end of file
diff --git a/scripts/jquery.timer.js b/scripts/jquery.timer.js
new file mode 100644 (file)
index 0000000..959fef3
--- /dev/null
@@ -0,0 +1,111 @@
+/**
+ * jquery.timer.js
+ *
+ * Copyright (c) 2011 Jason Chavannes <jason.chavannes@gmail.com>
+ *
+ * http://jchavannes.com/jquery-timer
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+;(function($) {
+        $.timer = function(func, time, autostart) {    
+                this.set = function(func, time, autostart) {
+                        this.init = true;
+                        if(typeof func == 'object') {
+                                var paramList = ['autostart', 'time'];
+                                for(var arg in paramList) {if(func[paramList[arg]] != undefined) {eval(paramList[arg] + " = func[paramList[arg]]");}};
+                                func = func.action;
+                        }
+                        if(typeof func == 'function') {this.action = func;}
+                        if(!isNaN(time)) {this.intervalTime = time;}
+                        if(autostart && !this.isActive) {
+                                this.isActive = true;
+                                this.setTimer();
+                        }
+                        return this;
+                };
+                this.once = function(time) {
+                        var timer = this;
+                        if(isNaN(time)) {time = 0;}
+                        window.setTimeout(function() {timer.action();}, time);
+                        return this;
+                };
+                this.play = function(reset) {
+                        if(!this.isActive) {
+                                if(reset) {this.setTimer();}
+                                else {this.setTimer(this.remaining);}
+                                this.isActive = true;
+                        }
+                        return this;
+                };
+                this.pause = function() {
+                        if(this.isActive) {
+                                this.isActive = false;
+                                this.remaining -= new Date() - this.last;
+                                this.clearTimer();
+                        }
+                        return this;
+                };
+                this.stop = function() {
+                        this.isActive = false;
+                        this.remaining = this.intervalTime;
+                        this.clearTimer();
+                        return this;
+                };
+                this.toggle = function(reset) {
+                        if(this.isActive) {this.pause();}
+                        else if(reset) {this.play(true);}
+                        else {this.play();}
+                        return this;
+                };
+                this.reset = function() {
+                        this.isActive = false;
+                        this.play(true);
+                        return this;
+                };
+                this.clearTimer = function() {
+                        window.clearTimeout(this.timeoutObject);
+                };
+                this.setTimer = function(time) {
+                        var timer = this;
+                        if(typeof this.action != 'function') {return;}
+                        if(isNaN(time)) {time = this.intervalTime;}
+                        this.remaining = time;
+                        this.last = new Date();
+                        this.clearTimer();
+                        this.timeoutObject = window.setTimeout(function() {timer.go();}, time);
+                };
+                this.go = function() {
+                        if(this.isActive) {
+                                this.action();
+                                this.setTimer();
+                        }
+                };
+               
+                if(this.init) {
+                        return new $.timer(func, time, autostart);
+                } else {
+                        this.set(func, time, autostart);
+                        return this;
+                }
+        };
+})(jQuery);
index 42f0ef3326cc391eb0ba9f1e21e9004316987775..936e5027e839e2ba6df2eb40ef1d8e65deba8244 100644 (file)
@@ -141,7 +141,7 @@ sub startPlotService {
   if (-e $self->{shm}) {
     die "service already running!\n";
   } else {
-    system("./plotService.pl --shm ".$self->{shm}.' >/dev/null & disown');
+    system("./plotService.pl --daemonize --shm ".$self->{shm});
     for (my $i = 0; $i< $self->{startTimeout}*100; $i++){
       if( -e $self->{shm} ) {
        return 1;
index 961674b5307c06f7fb66c1ca8677560e11a27bc9..692d7feeb9077c9ef1c45c4522fda17c4bc61668 100644 (file)
@@ -1,5 +1,7 @@
+var timer;
 
-$(document).ready(function(){
+function activateSelectorFunctions() {
+  
   $("#btn1").click(function(){
     $("#test1").text(function(i,origText){
       return "Old text: " + origText + " New text: Hello world! (index: " + i + ")"; 
@@ -13,34 +15,36 @@ $(document).ready(function(){
   });
   
   $("#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({
+    refreshPlots();
+  });
+   var counter= 0;
+   
+   $(".selectorsReloadTrigger").change(function(){
+     var DAQOPSERVER = $("#input_DAQOPSERVER").val();
+     var FPGA = $("#FPGA_selector :selected").val();
+     var CB = $("#CB_selector :selected").val();
+     var chip = $("#chip_selector :selected").val();
+     $.ajax({
         url:       "adcmon.pl",
         cache:     false,
+       async:     false,
         dataType:  "text",
-        data:      { sub: 'plot_request',
-         requestStrings: requestStrings,
-         DAQOPSERVER: daqopserver},
-        success:   function(result) {$("#plotArea").html(result);}
-    });
-    
-  
-  });
-   var counter= 0;
+        data:      {
+         sub        : "print_selectors",
+         DAQOPSERVER: DAQOPSERVER,
+         FPGA       : FPGA,
+         CB         : CB,
+         chip       : chip
+       },
+        success:   function(result) {
+         $("#selectors").html(result);
+         activateSelectorFunctions();
+       }
+     });
+   });
   
-    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 = [];
@@ -50,6 +54,68 @@ $(document).ready(function(){
       });
      alert(collector.join(","));
    });
+   
+   $("#startStopButton").click(function(){
+     if(timer.isActive){
+       timer.stop();
+       $(this).text("start");
+     } else {
+       $(this).text("stop");
+       timer.set({time:1000,autostart: true});
+     }
+     
+   }); 
+   
+}   
+
+$(document).ready(function(){
+  
+  
+  timer = $.timer(function() {
+    refreshPlots();
+  });
+  
+  activateSelectorFunctions();
 
 });
 
+var BgFg = true; // true when bg is being refreshed
+
+function refreshPlots(){
+     var collector = [];
+     var fadeSpeed = 200;
+     $(".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,
+       async:     false,
+        dataType:  "text",
+        data:      { sub: 'plot_request',
+         requestStrings: requestStrings,
+         DAQOPSERVER: DAQOPSERVER},
+        success:   function(result) {
+//       var tempScrollTop = $(window).scrollTop();
+         if(BgFg) {
+           
+           $("#plotAreaBg").html(result);
+           $("#plotAreaFg").fadeOut(fadeSpeed);
+           
+           BgFg = false;
+         }else{
+           
+           $("#plotAreaFg").html(result);
+           $("#plotAreaFg").fadeIn(fadeSpeed);
+           
+           BgFg = true;
+         }
+//       $(window).scrollTop(tempScrollTop);
+       }
+    });
+    
+  
+}
index 05c425d3b510ca19d760656a6eda4f6cd0bba83f..dc828827e0134cea1211c23661e13705cd53b692 100755 (executable)
@@ -17,15 +17,30 @@ use AccessXmlDb;
 require Common;
 
 
-
 use FindBin;
 use lib "$FindBin::Bin/..";
 use Environment;
 
+
+##############
+## preliminarily hardcoded constants
+##############
+my $CBsPerFpga=2;
+my $ChipsPerCB=2;
+
+
+
+
+
+
+
+
+
 # subs that are callable via http request
 my $dispatch = {
   table_hash => \&table_hash,
-  plot_request => \&plot_request
+  plot_request => \&plot_request,
+  print_selectors => \&print_selectors
 };
 
 my $q = CGI->new;
@@ -34,13 +49,11 @@ my $q = CGI->new;
 my $entityFile = "../../daqtools/xml-db/cache/CbController.entity";
 my $xmldb;
 
-
+my $plotWidth=600;
+my $plotHeight=400;
 
 $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'};
 
 
@@ -101,7 +114,7 @@ sub plot_request {
 #   }
 #     system("echo 'blah'>".$ps->{plotDir}."/test.txt");
     for my $reqStr (@requestStrings){
-      print "<img src='".addpng($ps->{plotDir}."/".$reqStr.".png")."'>";
+      print "<img alt='$reqStr' width='$plotWidth' height='$plotHeight' src='".addpng($ps->{plotDir}."/".$reqStr.".png")."'>";
       print br;
     }
 }
@@ -134,7 +147,10 @@ sub plot_request {
 
 sub print_selectors {
 
-
+my $FPGA = $q->param('FPGA');
+my $CB = $q->param('CB');
+my $chip = $q->param('chip');
+my $channel = $q->param('channel');
 
 
 my $q=shift;
@@ -142,7 +158,7 @@ my $q=shift;
 print "<table>";
 print "<tr>";
 print "<td>DAQOPSERVER</td>";
-print "<td><input type='text' id='input_DAQOPSERVER' value='".$daqopserver."'></td>";
+print "<td colspan=2><input type='text' class='selectorsReloadTrigger' id='input_DAQOPSERVER' value='".$daqopserver."'></td>";
 print "</tr>";
 print "<tr>";
 print "<td>FPGA</td>";
@@ -155,7 +171,8 @@ print "<td>";
 my $FPGA_selector = fileSelector->new(
   id=>"FPGA_selector",
   name=>"FPGA_selectionDropdown",
-  selected=>lc($q->param("FPGA"))
+  selected=>lc($q->param("FPGA")),
+  class=>"selectorsReloadTrigger"
 );
 $FPGA_selector->add_item(value=>'...');
 for my $element (activeTRBs()) {
@@ -167,20 +184,28 @@ print "<td>";
 my $CB_selector = fileSelector->new(
   id=>"CB_selector",
   name=>"CB_selectionDropdown",
-  selected=>$q->param("CB")
+  selected=>$q->param("CB"),
+  class=>"selectorsReloadTrigger"
 );
 $CB_selector->add_item(value=>'...');
-$CB_selector->add_item(value=>$q->param("CB")) if defined $q->param("CB");
+for( my $i = 0; $i < $CBsPerFpga; $i++){
+  $CB_selector->add_item(value=>$i);
+}
+# $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")
+  selected=>$q->param("chip"),
+  class=>"selectorsReloadTrigger"
 );
 $chip_selector->add_item(value=>'...');
-$chip_selector->add_item(value=>$q->param("chip")) if defined $q->param("chip");
+for( my $i = 0; $i < $ChipsPerCB; $i++){
+  $chip_selector->add_item(value=>$i);
+}
+# $chip_selector->add_item(value=>$q->param("chip")) if defined $q->param("chip");
 $chip_selector->print_html();
 print "</td>";
 print "</tr>";
@@ -189,16 +214,25 @@ print "</table>";
 
 print "<table>";
 print "<tr>";
+
 print "<td>";
+print "<button id='startStopButton'>start</button>";
+print "</td>";
+print "</tr>";
+
+
+print "<tr class='debugFeature'>";
+print "<td class='debugFeature'>";
 print "<button id='comm_ajax'>ajax!</button>";
 print "</td>"; 
-print "<td>";
+print "<td class='debugFeature'>";
 print "<button id='test_but'>test</button>";
 print "</td>";
-print "<td>";
+print "<td class='debugFeature'>";
 print "<input type='text' name='refresh(ms)' id='refreshInterval' value='1000'>";
 print "</td>";
-print "</tr>";
+print "<tr>";
+
 
 print "</table>";
 
@@ -231,17 +265,21 @@ my $q = shift;
 
 
 
-trb_init_ports() or die trb_strerror();
 
-print '<div id="selectors">';
+
+print '<div id="selectors" class="plasticBox">';
 print_selectors($q);
 print '</div>';
 
-print '<div id="plotArea">';
-print_plotArea($q);
+print '<div id="plotAreaBg" class="plasticBox plotArea">';
+# print "plotAreaBg";
+print '</div>';
+
+print '<div id="plotAreaFg" class="plotArea">';
+# print "plotAreaFg";
 print '</div>';
 
-print '<div id="debugStuff">';
+print '<div id="debugStuff" class="debugFeature">';
 print_debugStuff($q);
 print '</div>';
 
@@ -249,11 +287,6 @@ print '</div>';
 }
 
 
-sub print_plotArea{
-  my $q=shift;
-  print p "plot Area";
-  
-}
 
 sub print_debugStuff{
 
@@ -292,7 +325,7 @@ sub init_html{
   -title=>'ADC Monitor',
   -style=>[{'src'=>'../layout/styles.css'},
   {'src'=>'../layout/jtageditor_blue.css'},
-  {'src'=>'../layout/testgui.css'}
+  {'src'=>'../layout/adcmon.css'}
   ],
   -script=>[
   { -type => 'text/javascript', -src => 'http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'},
@@ -312,6 +345,10 @@ sub init_html{
 
 
 sub activeTRBs {
+
+#   trb_init_ports() or die trb_strerror();
+  trb_init_ports() or return ();
+  
   # read microsecond counters, return list of active addresses
   my $read = trb_register_read(0xFFFF,0x50);
   return (keys %$read);
index a6afeaffd2ca1d1422f6cfb7a2e70eeaf28388fd..7258682de29e3a35df862fe8f55c2097d5d41bf7 100755 (executable)
@@ -32,15 +32,17 @@ my $timeout = 5;
 my $suicideTimer = time();
 my $updateInterval = 1; #s
 my $updateTS = time();
+my $daemonize = 0;
 
 
 Getopt::Long::Configure(qw(gnu_getopt));
 GetOptions(
            'shm=s' => \$shm,
            'timeout=s' => \$timeout,
+           'daemonize' => \$daemonize
           );
 
-          
+daemonize() if $daemonize;
           
 PlotJob::initXmlDb("../../daqtools/xml-db/cache/CbController.entity");
 PlotJob::initTrbNet();
@@ -136,6 +138,19 @@ sub keepAlive {
   }
 }
 
+
+sub daemonize {
+# chdir '/' or die "Can't chdir to /: $!";
+open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
+open STDOUT, '>>/dev/null' or die "Can't write to /dev/null: $!";
+open STDERR, '>>/dev/null' or die "Can't write to /dev/null: $!";
+defined(my $pid = fork) or die "Can't fork: $!";
+exit if $pid;
+POSIX::setsid or die "Can't start a new session: $!";
+umask 0;
+}
+
+
 package PlotJob;
 
 use HPlot;
@@ -217,4 +232,6 @@ sub any2dec { # converts numeric expressions 0x, 0b or decimal to decimal
 
 
 
+
+
 1;
\ No newline at end of file