From: www@jspc55 Date: Thu, 30 Jan 2014 18:34:57 +0000 (+0100) Subject: first version of adcmon working X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=9a04910b9de25997d8eaa17caf2f26ac5e49515a;p=mvdsensorcontrol.git first version of adcmon working --- diff --git a/layout/adcmon.css b/layout/adcmon.css new file mode 100644 index 0000000..e259f60 --- /dev/null +++ b/layout/adcmon.css @@ -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 index 0000000..959fef3 --- /dev/null +++ b/scripts/jquery.timer.js @@ -0,0 +1,111 @@ +/** + * jquery.timer.js + * + * Copyright (c) 2011 Jason Chavannes + * + * 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); diff --git a/tools/PlotScheduler.pm b/tools/PlotScheduler.pm index 42f0ef3..936e502 100644 --- a/tools/PlotScheduler.pm +++ b/tools/PlotScheduler.pm @@ -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; diff --git a/tools/adcmon.js b/tools/adcmon.js index 961674b..692d7fe 100644 --- a/tools/adcmon.js +++ b/tools/adcmon.js @@ -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); + } + }); + + +} diff --git a/tools/adcmon.pl b/tools/adcmon.pl index 05c425d..dc82882 100755 --- a/tools/adcmon.pl +++ b/tools/adcmon.pl @@ -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 ""; + print "$reqStr"; 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 ""; print ""; print ""; -print ""; +print ""; print ""; print ""; print ""; @@ -155,7 +171,8 @@ print ""; print ""; print ""; @@ -189,16 +214,25 @@ print "
DAQOPSERVER
FPGA"; 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 ""; 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 ""; 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 "
"; print ""; print ""; + print ""; +print ""; + + +print ""; +print ""; -print ""; -print ""; -print ""; +print ""; + print "
"; +print ""; +print "
"; print ""; print ""; +print ""; print ""; print ""; +print ""; print ""; print "
"; @@ -231,17 +265,21 @@ my $q = shift; -trb_init_ports() or die trb_strerror(); -print '
'; + +print '
'; print_selectors($q); print '
'; -print '
'; -print_plotArea($q); +print '
'; +# print "plotAreaBg"; +print '
'; + +print '
'; +# print "plotAreaFg"; print '
'; -print '
'; +print '
'; print_debugStuff($q); print '
'; @@ -249,11 +287,6 @@ print '
'; } -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); diff --git a/tools/plotService.pl b/tools/plotService.pl index a6afeaf..7258682 100755 --- a/tools/plotService.pl +++ b/tools/plotService.pl @@ -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