use XML::LibXML;
use POSIX;
use CGI ':standard';
-use Cwd;
use CGI::Carp qw(fatalsToBrowser);
use HTML::Entities;
require Common;
require xmlOperations;
-my $here = getcwd();
+
+##### 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 $q = CGI->new;
+
+
+unless($q->param()) {
+ #if called without arguments,
+ init_html();
+} else {
+ print header;
+ print start_html(
+ -title=>'testgui_debug',
+ -style=>{'src'=>'../layout/styles.css'},
+ -script=>{ -type => 'text/javascript',
+ -src => './testgui.js'},
+ );
+ #process the arguments
+ report_param();
+
+}
+
+
+
+
+
+
+
+
+
+##################################
+#### Subs
+##################################
+
+
+sub parse_quickEditMaskFile {
+ my $parser = XML::LibXML->new();
+ unless( -e $quickEditMaskFile) {
+ die "quickEditMaskFile $quickEditMaskFile does not exist!\n";
+ }
+ $quickEditMaskTree = $parser->parse_file($quickEditMaskFile);
+}
+
+sub print_quickEditArea {
+
+ 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("0.xml");
+ integrateAncestry();
+ print_registers(getConfigFile());
+
+
+}
+
+sub init_html{
+
print header;
print start_html(
-title=>'testgui',
--style=>{'src'=>'../layout/styles.css'}
+-style=>[{'src'=>'../layout/styles.css'},
+{'src'=>'../layout/jtageditor.css'}
+]
);
print h2("testgui");
print "</div>";
+
+print "<div id='quickEditArea'>";
+print_quickEditArea();
+print "</div>";
print end_html;
+
+}
+
+
+
+
+
+
+
+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_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 $xmltree->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 = $xmlfile . "//" . $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("$registerName","");'> X </td>
+EOF
+ }
+ if ( $xmlfile eq $specFile ) { # we are printing the Settings Tree
+
+ print <<EOF;
+<td class='button_move' onclick='copyDefaultRegister("$registerName");'> → </td>
+EOF
+ }
+
+ print "</tr>";
+
+ #print "<tr>";
+
+ print '<tr id="' . $flistid . '" background=dea>';
+ print '<td></td>';
+ print '<td class="fieldcontainer">';
+ print_fields( $xmlfile, $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 @fields = sort by_name $register->findnodes("./field");
+ print "<table class=\"fields\">";
+ for my $field (@fields) {
+
+ my $fieldName = $field->findvalue("./\@name");
+
+ # 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 $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("$registerName","$fieldName",this.value)' >
+</td>
+EOF
+
+ }
+
+ print '</td>';
+ if ( $xmlfile eq $specFile ) { # we are printing the Specifications tree
+ print <<EOF;
+<td class='button_move' onclick='saveSettings("$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("$registerName","$fieldName");'> 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>";
+
+}
+