From 6ba051911df1492e778d09920eef2d026a4b1534 Mon Sep 17 00:00:00 2001 From: Manuel Penschuck Date: Fri, 1 Nov 2013 21:06:02 +0100 Subject: [PATCH] Improved error messages Support for Cts AddOn Fix for bug, that causes firefox not to reload page in case of an error --- web/CtsPlugins/CtsMod10.pm | 4 +- web/CtsPlugins/CtsMod12.pm | 54 ++++++++++++++++ web/CtsPlugins/CtsModStatic.pm | 30 ++++++++- web/cts | 29 ++++++++- web/htdocs/cts.htm | 84 ++++++++++++++++++++---- web/htdocs/cts.pl | 32 ++++++++- web/htdocs/layout/base.css | 1 + web/htdocs/scripts/{base.js => cts.js} | 90 +++++++++++++++++++++++++- web/include/Cts.pm | 3 +- 9 files changed, 303 insertions(+), 24 deletions(-) create mode 100644 web/CtsPlugins/CtsMod12.pm rename web/htdocs/scripts/{base.js => cts.js} (89%) diff --git a/web/CtsPlugins/CtsMod10.pm b/web/CtsPlugins/CtsMod10.pm index 47e7ad2..43f7063 100755 --- a/web/CtsPlugins/CtsMod10.pm +++ b/web/CtsPlugins/CtsMod10.pm @@ -40,7 +40,9 @@ sub init { } for(my $i = 0; $i < $header->{'itc_len'}; $i++) { - $self->{'_cts'}->getProperties->{'itc_assignments'}[$i + $header->{'itc_base'}] = "Trigger Input $i"; + if ($self->{'_cts'}->getProperties->{'itc_assignments'}[$i + $header->{'itc_base'}] eq 'unconnected') { + $self->{'_cts'}->getProperties->{'itc_assignments'}[$i + $header->{'itc_base'}] = "Trigger Input $i"; + } } # properties diff --git a/web/CtsPlugins/CtsMod12.pm b/web/CtsPlugins/CtsMod12.pm new file mode 100644 index 0000000..7713b47 --- /dev/null +++ b/web/CtsPlugins/CtsMod12.pm @@ -0,0 +1,54 @@ +# Module: AddOn Input Multiplexer (Type 0x12) +package CtsMod12; + +@ISA = (CtsBaseModule); + +use warnings; +use strict; +use TrbRegister; + +sub moduleName {"AddOn Input Multiplexer"} + +sub init { + my $self = $_[0]; + my $address = $_[1]; + + my $trb = $self->{'_cts'}{'_trb'}; + + my $regs = $self->{'_registers'}; + my $prop = $self->{'_properties'}; + + my $header = $self->{'_cts'}{'_enum'}{0x12}->read(); + +# registers + for(my $i = 0; $i < $header->{'len'}; $i++) { + my $key = "trg_addon_config$i"; + + $regs->{$key} = new TrbRegister($address + 1 + $i, $trb, { + 'input' => {'lower' => 0, 'len' => 7, 'type' => 'enum', 'enum' => + { + 0 => 'jeclin[0]', 1 => 'jeclin[1]', 2 => 'jeclin[2]', 3 => 'jeclin[3]', + 4 => 'jin1[0]', 5 => 'jin1[1]', 6 => 'jin1[2]', 7 => 'jin1[3]', + 8 => 'jin2[0]', 9 => 'jin2[1]', 10 => 'jin2[2]', 11 => 'jin2[3]', + 12 => 'nimin1', 13 => 'nimin2' + } + } + }, { + 'accessmode' => "rw", + 'export' => 1, + 'monitor' => '1', + 'label' => "AddOn Multiplexer $i" + }); + } + + for(my $i = 0; $i < $header->{'itc_len'}; $i++) { + $self->{'_cts'}->getProperties->{'itc_assignments'}[$i + $header->{'itc_base'}] = "AddOn Multiplexer $i"; + } + +# properties + $prop->{"trg_addon_count"} = $header->{'len'}; + $prop->{"trg_addon_itc_base"} = $header->{'itc_base'}; + +} + +1; \ No newline at end of file diff --git a/web/CtsPlugins/CtsModStatic.pm b/web/CtsPlugins/CtsModStatic.pm index f8e7b32..5662620 100755 --- a/web/CtsPlugins/CtsModStatic.pm +++ b/web/CtsPlugins/CtsModStatic.pm @@ -23,6 +23,10 @@ sub init { my $trb = $self->{'_cts'}->{'_trb'}; my $debug_block = 0xa000; + + $prop->{'cts_clock_frq'} = 1e8; + $prop->{'trb_endpoint'} = $trb->getEndpoint; + $prop->{'trb_compiletime'} = $trb->read(0x40); $regs->{'cts_cnt_trg_asserted'} = TrbRegister->new(0x00 + $debug_block, $trb, {}, { 'accessmode' => "ro", @@ -156,10 +160,30 @@ sub init { 'monitor' => 1, 'export' => 1 }); + + if ($prop->{'trb_compiletime'} > 1366287468) { + eval { + # really ugly solution, but we currently have to read the register in order + # to verify its existing ... + $regs->{'cts_eventbuilder'} = TrbRegister->new(0x0d + $debug_block, $trb, { + 'mask' => {'lower' => 0, 'len' => 16,'type' => 'mask'}, + 'rr_interval' => {'lower' => 16, 'len' => 8, 'type' => 'uint'}, + 'cal_eb' => {'lower' => 24, 'len' => 4, 'type' => 'uint'}, + 'use_cal_eb' => {'lower' => 28, 'len' => 1, 'type' => 'bool'} + + }, { + 'accessmode' => "rw", + 'label' => "Event Builder Selection", + 'monitor' => 1, + 'export' => 1 + }); + $regs->{'cts_eventbuilder'}->read(); + 1; + } and do { + $prop->{'cts_eventbuilder_rr'} = 1; + } + } - $prop->{'cts_clock_frq'} = 1e8; - $prop->{'trb_endpoint'} = $trb->getEndpoint; - $prop->{'trb_compiletime'} = $trb->read(0x40); } 1; diff --git a/web/cts b/web/cts index c104f3d..7399974 100755 --- a/web/cts +++ b/web/cts @@ -3,8 +3,7 @@ # Debugging use warnings; use strict; - use Carp; - $SIG{ __DIE__ } = sub { Carp::confess( @_ ) }; + use lib "./include"; @@ -33,6 +32,30 @@ use lib "./include"; } } + our $endpoint; + use Carp; + $SIG{ __DIE__ } = sub { + my $error = $_[0]; + + if ($error =~ /unknown address/ and $error =~ /trb_register_read/ and $error =~ /0xa[012]/) { + printf("Endpoint (0x%04x) responded, but could not read CTS registers. Does the endpoint contain a CTS?\n" . + "If the CTS uses a different address, change the default endpoint address in\n" . + "htdocs/CtsConfig.pm, or use the --endpoint parameter when starting the CTS tool.", $endpoint); + + } elsif ($error =~ /no endpoint has been reached/) { + printf("Endpoint (0x%04x) not reached. Please ensure that \n" . + "(1) the correct DAQOPSERVER is used and\n" . + "(2) the CTS is configured to this address.\n" . + "If the CTS uses a different address, change the default endpoint address in\n" . + "htdocs/CtsConfig.pm, or use the --endpoint parameter when starting the CTS tool.", $endpoint); + } + + print "\n\n\n--------------------- More details error description ------------------------------\n"; + Carp::confess( @_ ); + + exit; + }; + use FileHandle; @@ -93,7 +116,7 @@ sub connectToCTS { } #################################################################################### -my $endpoint = CtsConfig->getDefaultEndpoint; +$endpoint = CtsConfig->getDefaultEndpoint; my $updateInterval = 1000; my $quiet = 0; diff --git a/web/htdocs/cts.htm b/web/htdocs/cts.htm index d126f26..bb77b23 100644 --- a/web/htdocs/cts.htm +++ b/web/htdocs/cts.htm @@ -5,7 +5,7 @@ - + @@ -154,6 +154,24 @@ + + @@ -276,6 +316,26 @@ Buffered Trigger (15:0) n/a + +   + + + TD FSM Limit (debug only): + + + + + + + RO FSM Limit (debug only): + + + + diff --git a/web/htdocs/cts.pl b/web/htdocs/cts.pl index d25697c..23872df 100755 --- a/web/htdocs/cts.pl +++ b/web/htdocs/cts.pl @@ -10,6 +10,34 @@ use CtsCommands; use File::Basename; +our $endpoint; +use Carp; +$SIG{ __DIE__ } = sub { + my $error = $_[0]; + + print 'HTTP/1.0 500 INTERNAL SERVER ERROR'; + print "\r\nContent-Type: text/html;\r\n\r\n"; + + print "
\r\n";
+
+   if ($error =~ /unknown address/ and $error =~ /trb_register_read/ and $error =~ /0xa[012]/) {
+      printf("Endpoint (0x%04x) responded, but could not read CTS registers. Does the endpoint contain a CTS?\n" . 
+      "If the CTS uses a different address, change the default endpoint address in\n" . 
+      "htdocs/CtsConfig.pm, or use the --endpoint parameter when starting the CTS tool.", $endpoint);
+      
+   } elsif ($error =~ /no endpoint has been reached/) {
+      printf("Endpoint (0x%04x) not reached. Please ensure that \n" . 
+      "(1) the correct DAQOPSERVER is used and\n" .
+      "(2) the CTS is configured to this address.\n" .
+      "If the CTS uses a different address, change the default endpoint address in\n" . 
+      "htdocs/CtsConfig.pm, or use the --endpoint parameter when starting the CTS tool.", $endpoint);
+   }
+   
+   print "\n\n\n--------------------- More details error description ------------------------------\n";
+   print $error;
+   
+   print "
\r\n"; +}; BEGIN { if (eval "require JSON::PP;") { @@ -41,7 +69,7 @@ sub printHeader { sub connectToCTS { my $trb; - my $endpoint = CtsConfig->getDefaultEndpoint; + $endpoint = CtsConfig->getDefaultEndpoint; my $cache = {'enumCache' => 0}; my $port = int $ENV{'SERVER_PORT'}; @@ -72,6 +100,8 @@ sub connectToCTS { my $cts = connectToCTS( ); +#print Dumper $cts; + my $query = $ENV{'QUERY_STRING'}; if ($query eq "init") { diff --git a/web/htdocs/layout/base.css b/web/htdocs/layout/base.css index 547ddec..5e8f197 100644 --- a/web/htdocs/layout/base.css +++ b/web/htdocs/layout/base.css @@ -241,4 +241,5 @@ text-align: right; } + .eventbuilder_rr {visibility: hidden;} \ No newline at end of file diff --git a/web/htdocs/scripts/base.js b/web/htdocs/scripts/cts.js similarity index 89% rename from web/htdocs/scripts/base.js rename to web/htdocs/scripts/cts.js index 69254b9..84a2dbe 100644 --- a/web/htdocs/scripts/base.js +++ b/web/htdocs/scripts/cts.js @@ -76,6 +76,7 @@ var CTS = new Class({ this.renderTriggerChannels(); this.renderTriggerInputs(); this.renderCoins(); + this.renderTriggerAddOnInputs(); this.renderRegularPulsers(); this.renderRandPulsers(); this.renderCTSDetails(); @@ -90,9 +91,11 @@ var CTS = new Class({ }); this.addEvent('dataUpdate', this.updateStatusIndicator.bind(this)); + //this.addEvent('dataUpdate', function() {$('eb_rr').set('disabled', !this.currentData. + + this.initEventBuilderRR(); this.initAutoCommit(); - this.initSliceTitle(); }, @@ -107,6 +110,7 @@ var CTS = new Class({ } }, + writeRegisters: function(values) { var arrValues = []; Object.each(values, function(v,r) {arrValues.push(r); arrValues.push(v)}); @@ -147,7 +151,11 @@ var CTS = new Class({ dup.removeClass('error').set('text', 'Update').setStyle('display', 'block'); // hard-reset. if request's timeout fails, this is the last resort ... - var manualTimeout = window.location.reload.delay(10000); + var manualTimeout = (function(e) { + if (console) + console.log(e.stack); + window.location.reload.delay(10000); + }).delay(10000, this, new Error()); new Request.JSON({ url: this.monitorPrefix + 'dump.js', @@ -194,6 +202,11 @@ var CTS = new Class({ }.bind(this) }).send(); }, + + initEventBuilderRR: function() { + if (!this.defs.properties.cts_eventbuilder_rr) return; + $$('.eventbuilder_rr').setStyle('visibility', 'visible'); + }, /** * This method handles all "autorate"-elements. It is registered @@ -358,7 +371,9 @@ var CTS = new Class({ * should not by called manually. */ renderTriggerInputs: function() { - for(var i=0; i < this.defs.properties.trg_input_count; i++) { + var num = this.defs.properties.trg_input_count; + num -= (this.defs.properties.trg_addon_count) ? this.defs.properties.trg_addon_count : 0; + for(var i=0; i < num; i++) { var reg = 'trg_input_config' + i; $('inputs-tab') .adopt( @@ -403,6 +418,74 @@ var CTS = new Class({ } }, +/** + * Creates all active elements of the AddOn Multiplexer Input Configuration + * section. It is called by the class' constructor and hence + * should not by called manually. + */ + renderTriggerAddOnInputs: function() { + if (!this.defs.properties.trg_addon_count) { + $('addon-board-expander').setStyle('display', 'none'); + return; + } + + var from = this.defs.properties.trg_input_count - this.defs.properties.trg_addon_count; + var to = this.defs.properties.trg_input_count; + + for(var i=from; i < to; i++) { + var reg = 'trg_input_config' + i; + var areg = 'trg_addon_config' + (i-from); + var en = this.defs.registers[areg]._defs.input.enum; + $('addon-board-tab') + .adopt( + new Element('tr', {'class': i%2?'':'alt', 'flashgroup': 'itc-' + (i + parseInt(this.defs.properties.trg_input_itc_base))}) + .adopt( + new Element('td', {'class': 'num', 'text': i}), + + new Element('td', {'class': 'source'}) + .adopt( + new Element('select', {'class': 'text autocommit autoupdate', 'slice': areg + '.input'}) + .adopt( + Object.values(en).map(function (r) { + return new Element('option', {'value': r, 'text': r}) + }) + ) + ), + + new Element('td', {'class': 'rate autorate', 'slice': 'trg_input_edge_cnt' + i + '.value', 'text': 'n/a', 'id': 'inp-rate' + i}), + + new Element('td', {'class': 'invert'}) + .adopt( + new Element('input', {'type': 'checkbox', 'class': 'autocommit autoupdate', 'slice': reg + '.invert'}) + ), + + new Element('td', {'class': 'delay'}) + .adopt([ + new Element('input', {'class': 'text autocommit autoupdate', 'slice': reg + '.delay', 'format': 'countToTime', 'interpret': 'timeToCount'}), + new Element('span', {'text': ' ns'}) + ]), + + new Element('td', {'class': 'spike'}) + .adopt([ + new Element('input', {'class': 'text autocommit autoupdate', 'slice': reg + '.spike_rej', 'format': 'countToTime', 'interpret': 'timeToCount'}), + new Element('span', {'text': ' ns'}) + ]), + + new Element('td', {'class': 'override'}) + .adopt( + new Element('select', {'class': 'text autocommit autoupdate', 'slice': reg + '.override'}) + .adopt([ + new Element('option', {'value': 'off', 'text': 'bypass'}), + new Element('option', {'value': 'to_low', 'text': '-> 0'}), + new Element('option', {'value': 'to_high', 'text': '-> 1'}), + ]) + ) + ) + ); + } + }, + + /** * Creates all active elements of the Trigger Channel Configuration * section. It is called by the class' constructor and hence @@ -670,6 +753,7 @@ var CTS = new Class({ }); function xhrFailure(xhr){ + console.log(xhr.responseText); var m = xhr.responseText.match(/
([\s\S]*)<\/pre>/im);
    if (m) alert("Server send error response:\n"+m[1].trim());
    else  alert("An unknown error while contacting the sever. Did you open this file locally? Did the connection or server crash?");
diff --git a/web/include/Cts.pm b/web/include/Cts.pm
index 22d2974..2a81688 100644
--- a/web/include/Cts.pm
+++ b/web/include/Cts.pm
@@ -34,7 +34,8 @@ sub new {
    
    $self->{'_enumCache'} =  $enumCache if ref $enumCache;
    
-   my $static = $self->_loadModule("Static") or die("Error while loading mandantory module >CtsModStatic<");
+   my $static = $self->_loadModule("Static") or exit; #die("Error while loading mandantory module >CtsModStatic<");
+ 
    $static->register();
    
    $self->_enumerateTriggerLogic();
-- 
2.43.0