--- /dev/null
+
+$(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(","));
+ });
+
+});
+
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'},
{'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;
+ }