-#!/usr/bin/perl -w
-#print "Content-type: text/html\n\n";
-
-
-my $me = "testgui.pl";
-
-use strict;
-use warnings;
-use XML::LibXML;
-use POSIX;
-use CGI ':standard';
-use CGI::Carp qw(fatalsToBrowser);
-use HTML::Entities;
-require Common;
-require xmlOperations;
-
-
-##### preliminary hardcoded stuff:
-
-our $setupDir = '../setup';
-our $confDir = '../config';
-our $specDir = '../specs';
-
-my $setupFileName = "testsetup.xml";
-my $setupFile = $setupDir."/".$setupFileName;
-
-# the file that tells me what fields should be printed in the quick edit area
-# for each sensor
-my $quickEditMaskFileName = "quickEditMask.xml";
-my $quickEditMaskFile = $confDir."/".$quickEditMaskFileName;
-
-
-#### globals:
-
-my $quickEditMaskTree;
-my $setupTree;
-my $sensorAreaId;
-my $quickEditAreaId;
-
-my %previewAreaIdHash;
-
-
-#######################
-
-my $q = CGI->new;
-
-
-
-unless($q->param()) {
- #if called without arguments,
- init_html();
-} else {
-#####################################
-######## process CGI request ########
-#####################################
- print header;
- #process the arguments
-
- if ($q->param('action') eq "print_quickEditArea") {
- my $configFileName = $q->param('configFile');
- my $destId = $q->param('destId');
- $quickEditAreaId = $destId;
- print_quickEditArea($configFileName);
- } elsif ($q->param('action') eq "showPlot") {
-
- my $sensorId = $q->param('sensorId');
- my $imgSrc = './preview/image_recalibrated_'.$sensorId.'.png';
- if (-e $imgSrc) {
- print img{src=>$imgSrc."?".rand(),title=>$sensorId};
- } else {
- print img{src=>"./preview/error.jpg",title=>$sensorId};
- }
- } else {
-
- print start_html(
- -title=>'testgui_debug',
- -style=>{'src'=>'../layout/styles.css'}
- );
- report_param();
-
- }
-
-}
-
-
-
-
-
-
-
-
-
-##################################
-#### Subs
-##################################
-
-sub parse_setupFile {
- my $parser = XML::LibXML->new();
- unless( -e $setupFile) {
- die "setup file $setupFile does not exist!\n";
- }
- $setupTree = $parser->parse_file($setupFile);
-}
-
-
-sub parse_quickEditMaskFile {
- my $parser = XML::LibXML->new();
- unless( -e $quickEditMaskFile) {
- die "quickEditMaskFile $quickEditMaskFile does not exist!\n";
- }
- $quickEditMaskTree = $parser->parse_file($quickEditMaskFile);
-}
-
-
-
-sub init_html{
-
-print header;
-print start_html(
--title=>'testgui',
--style=>[{'src'=>'../layout/styles.css'},
-{'src'=>'../layout/testgui.css'}
-],
--script=>[
-{ -type => 'text/javascript', -src => './testgui.js'},
-{ -type => 'text/javascript', -src => './getdata.js'},
-{ -type => 'text/javascript', -src => './xmlOperations.js'}
-]
-);
-
-# print h2("testgui");
-
-
-# print "<div>";
-#
-# print "<table>";
-# print "<tr><td>IVDREF1A</td><td>IVDREF1B</td></tr>";
-# print "<tr><td><input type='text' id='IVDREF1A'></td></tr>";
-# print "</table>";
-#
-#
-# print "</div>";
-
-
-
-
-# print "<div id='quickEditArea'>";
-# print_quickEditArea("0.xml");
-# print "</div>";
-print_setupStructure();
-print q%<input type='button' onClick='run(0.2)' value='run'>%;
-
-
-
-
-# pass a list of sensor Ids to the javascript side
-# more precisely: a hash consisting of $sensorId=>$previewAreaId
-# so the javascript knows which placeholders to fill with actual plots
-print "<script language='javascript'>\n";
-print "var previewAreaIdHash = new Object();\n";
-for my $sensorId (keys %previewAreaIdHash){
- print "previewAreaIdHash[\"$sensorId\"]=\"".$previewAreaIdHash{$sensorId}."\";\n";
-}
-print "</script>";
-# end of that story
-
-print "<input type='button' value='show/hide debug output' onclick='toggleVis(\"theConsole\")'>";
-print "<div id='theConsole'>[the \"console\"]</div>";
-
-print end_html;
-
-
-
-}
-
-
-
-
-sub print_setupStructure {
-
- unless(defined($setupTree)) {
- parse_setupFile();
- }
- my $setup = $setupTree->findnodes("/DetectorSetup")->shift();
- unless(defined($setup)) { die "did not find DetectorSetup node in setup file!\n";}
- my $setupDesc = $setup->findvalue("./description");
- my $setupName = $setup->findvalue("./\@name");
- print h2("Setup: $setupName");
- print "<p>description: $setupDesc</p>";
-
- my @controllers = $setup->findnodes("./controller");
- unless(scalar(@controllers) > 0) { die "no controllers in setup file!\n";}
- for my $controller (@controllers) {
- my $controllerName = $controller->findvalue("./\@name");
- my $controllerAddress = $controller->findvalue("./\@address");
- my $controllerId = $controller->findvalue("./\@id");
- print h3("Controller name:$controllerName id:$controllerId address:$controllerAddress");
-
- my @chains = $controller->findnodes("./chain");
- unless(scalar(@chains)>0) {die "no chains attached to controller $controllerName\n";}
-
- for my $chain (@chains) {
- my $chainName = $chain->findvalue("./\@name");
- my $chainId = $chain->findvalue("./\@id");
- print h4("Chain name:$chainName id:$chainId");
-
- my @sensors = $chain->findnodes("./sensor");
- unless(scalar(@sensors)>0) { die "no sensors attached to chain $chainName\n";}
- for my $sensor (@sensors) {
-
- my $sensorId = $sensor->findvalue("./\@id");
- my $sensorName = $sensor->findvalue("./\@name");
- my $sensorConfig = $sensor->findvalue("./\@config");
- my $sensorEnabled = $sensor->findvalue("./\@enabled");
- my $sensorSerial = $sensor->findvalue("./\@serial");
- my $sensorPosition = $sensor->findnodes("./position")->shift();
- my $sensorDescription = $sensor->findvalue("./description");
-
-# print h5("Sensor name:$sensorName id:$sensorId");
-# print "<p>description: $sensorDescription</p>";
- print_sensorArea($sensor);
- }
-
- }
-
- }
-
-}
-
-
-sub report_param {
- print br,br;
- print "action ".$q->param('action')." executed with following parameters:",br;
- my @params = $q->param();
- print "<table>";
- for (@params) {
- print "<tr><td>";
- print escapeHTML($_);
- print "</td><td>=</td><td>";
- print escapeHTML($q->param($_));
- print "</td>";
-
- }
- print "</table>";
-
-}
-
-
-#### html output subs ###########
-
-sub print_sensorArea {
-
- my $sensor = $_[0];
- # this is an xml object that contains the sensor node
- # from the setup file
- my $sensorId = $sensor->findvalue("./\@id");
- my $sensorName = $sensor->findvalue("./\@name");
- my $sensorConfig = $sensor->findvalue("./\@config");
- my $sensorEnabled = $sensor->findvalue("./\@enabled");
- my $sensorSerial = $sensor->findvalue("./\@serial");
- my $sensorPosition = $sensor->findnodes("./position")->shift();
- my $sensorDescription = $sensor->findvalue("./description");
-
-
- $sensorAreaId = $sensorId;
- print "<div class='sensorAreaDiv' id='".$sensorAreaId."'>";
- print "<table class='sensorAreaTable'>";
- print "<tr>";
- print "<td colspan=2 align='center' class='td_solid'>";
- print "<table><tr><td>$sensorName (id=$sensorId)</td></tr>";
- print "<tr><td>description: $sensorDescription</td></tr></table>";
- print "</td>";
- print "</tr>";
- print "<tr>";
- my $previewAreaId = "preview_".$sensorId;
- print "<td id='".$previewAreaId."' class='previewArea'> [not run yet!] </td>";
- $quickEditAreaId = "quickEdit_".$sensorId;
- print "<td id='".$quickEditAreaId."' class='quickEditArea td_solid'>";
- print_quickEditArea($sensorConfig);
- print "</td>";
- print "</tr>";
-# print "<tr>";
-# print "<td colspan=2 align='right'>";
-# my $command = "./prevImg.pl";
-# print q%<input type='button' onClick='getdata("%.$command.q%","%.$previewAreaId.q%","true")' value='run'>%;
-# print "</td>";
-# print "</tr>";
- print "</table>";
- print "</div>";
-
- $previewAreaIdHash{$sensorId}=$previewAreaId;
-}
-# description the block that is printed for each sensor,
-# containing the preview plot and the quick edit area
-
-
-sub print_quickEditArea {
-
- my $argumentConfigFile = $_[0];
-
- unless(defined($quickEditMaskTree)) {
- parse_quickEditMaskFile();
- }
-
-# print "<table>";
-# my @fields = $quickEditMaskTree->findnodes("/MAPS/register/field");
-# for my $field (@fields) {
-# print "<tr><td>";
-# print $field->findvalue("./\@name");
-# print "</td></tr>";
-#
-#
-# }
-# print "</table>";
-# print "print_registers();",br;
- parseConfigAndSpec($argumentConfigFile);
- integrateAncestry();
- print "<div align=center>".getConfigFileName()."</div>";
- print_registers(getConfigFile());
-
-
-}
-
-
-
-
-sub print_registers {
-
- my $configFile = getConfigFile();
- my $specFile = getSpecFile();
- my $configFileName = getConfigFileName();
- my $specFileName = getSpecFileName();
- my $configTree = getConfigTree();
- my $specTree = getSpecTree();
-
- my $xmlfile = $_[0];
- my $xmltree;
-# if ( $xmlfile eq $configFile ) {
-# $xmltree = $configTree;
-# }
-# elsif ( $xmlfile eq $specFile ) {
-# $xmltree = $specTree;
-# }
-# else {
-# die "xmlfile given to sub print_registers is unknown";
-# }
- my @registers = sort by_name $quickEditMaskTree->findnodes("/MAPS/register");
- print "<table class=\"registers\"";
- if ( $xmlfile eq $configFile ) {
- print "id='configFileRegisters'";
- }
- print ">";
- for my $register (@registers) {
-
- my $registerName = $register->findvalue("./\@name");
-
-# # if register not in the mask file, don't print!
-# unless( $quickEditMaskTree->findnodes("/MAPS/register[\@name='".
-# $registerName."']")) {
-# next;
-# }
-
- my $registerId = $register->findvalue("./\@id");
- my $registerSize = $register->findvalue("./\@size");
- my $registerDescr = prepare_text(
- $specTree->findvalue(
- "/MAPS/register[\@name='" . $registerName . "']/description"
- )
- || "n/a"
- );
-
- my $flistid = $configFile . "//" . $registerName;
-
- print "<tr>";
-
- print <<EOF;
-<td onClick='toggleVis("$flistid",this)' class='regheader'> + </td>
-EOF
- print "<td title=\"$registerDescr\">$registerName</td>";
-
- #print "<td>$registerId</td>";
-
-# if ( $xmlfile eq $configFile ) { # we are printing the Specifications Tree
-# print <<EOF;
-# <td class='button_move' onclick='deleteSettings("$configFileName","$registerName","");reloadQuickEditArea("$configFileName","$quickEditAreaId")'> X </td>
-# EOF
-# }
-
-
- print "</tr>";
-
- #print "<tr>";
-
- print '<tr id="' . $flistid . '" class="bitfield">';
- print '<td></td>';
- print '<td class="fieldcontainer">';
- print_fields( $configFile, $register );
- print "<td>";
- print "</tr>";
- }
- print "</table>";
-}
-
-sub print_fields {
-
- my $configFile = getConfigFile();
- my $specFile = getSpecFile();
- my $configFileName = getConfigFileName();
- my $specFileName = getSpecFileName();
- my $configTree = getConfigTree();
- my $specTree = getSpecTree();
-
- my $register = $_[1];
- my $xmlfile = $_[0];
- my $registerName = $register->findvalue("./\@name");
- my @maskFields = sort by_name $register->findnodes("./field");
- print "<table class=\"fields\">";
- for my $maskField (@maskFields) {
-
- my $fieldName = $maskField->findvalue("./\@name");
-
- my $field = $configTree->findnodes("/MAPS/register[\@name='".
- $registerName."']/field[\@name='".$fieldName."']")->shift();
-
-
- unless(defined($field)){
-
- my $specField = $specTree->findnodes("/MAPS/register[\@name='".
- $registerName."']/field[\@name='".$fieldName."']")->shift();
- $field=$register->addNewChild("","field");
- $field->setAttribute("name",$fieldName);
- $field->setAttribute("value",$specField->findvalue("./\@defaultValue"));
- $field->setAttribute( "isHeritageFrom", $specFileName );
- }
-
-
-
-
-# # if field not in the mask file, don't print!
-# unless( $quickEditMaskTree->findnodes("/MAPS/register[\@name='".
-# $registerName."']/field[\@name='".$fieldName."']")) {
-# next;
-# }
-
- my $isHeritageFrom = $field->findvalue("./\@isHeritageFrom") || "";
-# my $isHeritageFrom = "";
- my $readOnlyFlag = 0;
- my $fieldValue = $field->findvalue("./\@value");
- my $fieldSize =
- $specTree->findvalue( "/MAPS/register[\@name='"
- . $registerName
- . "']/field[\@name='"
- . $fieldName
- . "']/\@size" )
- || "n/a";
- my $fieldDescr = prepare_text(
- $specTree->findvalue(
- "/MAPS/register[\@name='"
- . $registerName
- . "']/field[\@name='"
- . $fieldName
- . "']/description"
- )
- || "n/a"
- );
-
- my $maxFieldVal = 2**$fieldSize;
- my $sizeInfo =
- sprintf(
- "Field contains %d bits, possible values: 0-%d (0x0-0x%x)\n\n",
- $fieldSize, $maxFieldVal, $maxFieldVal );
-
- $fieldDescr = $sizeInfo . $fieldDescr;
-
- unless ( $isHeritageFrom eq "" ) {
- $fieldDescr =
- "Field was inherited from $isHeritageFrom\n\n" . $fieldDescr;
- }
-
- my $fieldId = $xmlfile . "//" . $registerName . "/" . $fieldName;
- if ( $fieldValue eq "" ) {
- $fieldValue = $field->findvalue("./\@defaultValue");
- $readOnlyFlag = 1;
- }
-
- print "<tr class='fileLevel" . getFileLevel($isHeritageFrom) . "'>";
- print "<td width=120 title=\"$fieldDescr\"";
- print ">$fieldName</td>";
- print "<td> = </td>";
- if ($readOnlyFlag) {
- print <<EOF;
- <td width=120 align='right'>$fieldValue</td>
-EOF
- }
- else {
- print <<EOF;
-<td align='right'>
-<input type='text' align='right' value='$fieldValue' onchange='saveSettings("$configFileName","$registerName","$fieldName",this.value);reloadQuickEditArea("$configFileName","$quickEditAreaId")' >
-</td>
-EOF
-
- }
-
- print '</td>';
-# if ( $xmlfile eq $specFile ) { # we are printing the Specifications tree
-# print <<EOF;
-# <td class='button_move' onclick='saveSettings("$configFileName","$registerName","$fieldName","$fieldValue");'> → </td>
-# EOF
-# }
- if ( $xmlfile eq $configFile ) { # we are printing the Settings Tree
-
- if ( $isHeritageFrom eq "" )
- { # these are actual settings, not inherited!
- print <<EOF;
-<td class='button_move' onclick='deleteSettings("$configFileName","$registerName","$fieldName");reloadQuickEditArea("$configFileName","$quickEditAreaId")'> X </td>
-EOF
- }
- else {
- print "<td class='button_move_deac'> X </td>";
- }
- }
- print "</tr>";
- if ( ( any2dec($fieldValue) < 0 )
- or ( any2dec($fieldValue) > $maxFieldVal ) )
- {
- print
-"<tr class='fieldError'><td colspan = 4 align='center'>!!!Above value not in allowed range!!!</td></tr>"
- ; # just debug
- }
- }
- print "</table>";
-
-}