]> jspc29.x-matter.uni-frankfurt.de Git - daqtools.git/commitdiff
First working version which reads at least temperatures from the padiwa...
authorAndreas Neiser <neiser@kph.uni-mainz.de>
Tue, 20 May 2014 16:11:15 +0000 (18:11 +0200)
committerAndreas Neiser <neiser@kph.uni-mainz.de>
Wed, 21 May 2014 13:30:09 +0000 (15:30 +0200)
web/htdocs/padiwa/padiwa.pl [new file with mode: 0755]
xml-db/get.pl

diff --git a/web/htdocs/padiwa/padiwa.pl b/web/htdocs/padiwa/padiwa.pl
new file mode 100755 (executable)
index 0000000..5c87ef4
--- /dev/null
@@ -0,0 +1,41 @@
+#!/usr/bin/perl
+if ($ENV{'SERVER_SOFTWARE'} =~ /HTTPi/i) {
+  print "HTTP/1.0 200 OK\n";
+  print "Content-type: text/html\r\n\r\n";
+  }
+else {
+  use lib '..';
+  use if (!($ENV{'SERVER_SOFTWARE'} =~ /HTTPi/i)), apacheEnv;
+  print "Content-type: text/html\n\n";
+  }
+
+use CGI ':standard';
+use XML::LibXML;
+use POSIX;
+use CGI::Carp qw(fatalsToBrowser);
+
+use lib qw|../commands htdocs/commands|;
+use xmlpage;
+
+my $page;
+
+$page->{title} = "Padiwa";
+$page->{link}  = "../";
+
+
+my @setup;
+$setup[0]->{name}    = "AnyReg";
+$setup[0]->{cmd}     = "Padiwa-0xfe48:0..3-Status";
+$setup[0]->{period}  = -1;
+$setup[0]->{generic} = 1;
+$setup[0]->{rate}    = 1;
+
+
+xmlpage::initPage(\@setup,$page);
+
+
+1;
+
+
index 5c3a95d8b55cf6262635b127a6a96c160e342a6e..2f6fdaf6a222fa264bd6020cfa7788a7f3b0e631 100755 (executable)
@@ -2,7 +2,7 @@
 use HADES::TrbNet;
 use Storable qw(lock_store lock_retrieve);
 use feature "switch";
-use Time::HiRes qw( time );
+use Time::HiRes qw( time usleep );
 use CGI::Carp qw(fatalsToBrowser);
 
 use if (!defined $ENV{'QUERY_STRING'}), warnings;
@@ -13,7 +13,7 @@ use if (!defined $ENV{'QUERY_STRING'}), Data::TreeDumper;
 use if (!defined $ENV{'QUERY_STRING'}), Getopt::Long;
 
 # use Data::TreeDumper;
-#use Data::Dumper;
+use Data::Dumper;
 my ($db,$data,$once,$slice);
 my $help = 0;
 my $verbose = 0;
@@ -141,7 +141,7 @@ foreach my $req (@request) {
       if @spi_chains==0;
   }
   elsif($db->{'§EntityType'} eq 'SpiEntity') {
-    # no spi range supplied, just use 0 by default
+    # no spi range supplied, just use chain 0 by default
     @spi_chains = (0);
   }
 
@@ -337,7 +337,9 @@ sub register_read {
     when ("TrbNetEntity")  {
       $o =  convert_keys_to_hex(trb_register_read($netaddr, $regaddr));
     }
-    when ("SpiEntity") { $o = { "$netaddr:1" => [1,2,3] }; }
+    when ("SpiEntity") {
+      $o = spi_register_read($netaddr, $regaddr);
+    }
     default {die "EntityType not recognized";}
   }
   return $o;
@@ -368,6 +370,37 @@ sub convert_keys_to_hex {
   return \%h;
 }
 
+sub spi_register_read {
+  # inspired by the simple padiwa.pl
+  my ($netaddr, $regaddr) = @_;
+  $o = {};
+  foreach my $chain (@spi_chains) {
+    # in $cmd, the lower 16 bits are the payload
+    # the upper 16 bits control:
+    # 31..24: select (something like an address)
+    # 23..20: command read=0x0, write=0x8
+    # 19..16: channel/register (something like an address)
+
+    # the lower 4 bits directly map:
+    my $cmd = $regaddr & 0xF;
+    # the next 8 bits need to be shifted
+    $cmd |= (($regaddr >> 4) & 0xFF) << 8;
+    # shift it to the upper 16 bits finally
+    $cmd <<= 16;
+
+    my $c = [$cmd,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1<<$chain,1];
+    trb_register_write_mem($netaddr,0xd400,0,$c,scalar @{$c});
+    usleep(1000);
+    my $res = trb_register_read($netaddr,0xd412);
+    foreach my $board (keys %$res) {
+      my $b = sprintf('%04x:%d', $board, $chain);
+      $o->{$b} = $res->{$board};
+    }
+  }
+
+  return $o;
+}
+
   
 sub generateoutput {
   my ($obj,$name,$slice,$once) = @_;