]> jspc29.x-matter.uni-frankfurt.de Git - daqtools.git/commitdiff
update pwrswitch tool for new firmware. Remove trbnet for easier usage.
authorJan Michel <j.michel@gsi.de>
Mon, 16 Mar 2020 12:46:22 +0000 (13:46 +0100)
committerJan Michel <j.michel@gsi.de>
Mon, 16 Mar 2020 12:46:22 +0000 (13:46 +0100)
tools/pwrswitch.pl

index 64655db7bd0975c7f4dab0decb56f9bed647b901..3402d8e3459f3dd7c5ad9a9f7b2ccd90784ee636 100755 (executable)
@@ -14,7 +14,7 @@ use Device::SerialPort;
 use feature 'state';
 use URI::Escape;
 use Data::Dumper;
-use HADES::TrbNet;
+use HADES::TrbNet;
 use Time::HiRes qw( usleep);
 use Getopt::Long;
 
@@ -56,17 +56,17 @@ sub Cmd {
       #print '.';
       }
     }
-  else {
-    trb_register_read_mem($ser_dev,0xd600,1,100); #clear memory
-    my @c = split('',$c."\n");
-    my @cmd =  map(ord, @c);
-    trb_register_write_mem($ser_dev,0xd600,1,\@cmd,scalar @cmd);
-    usleep(20000);
-    my $r = trb_register_read_mem($ser_dev,0xd600,1,5);
-    my $s = join('',map (chr($_ & 0xff),@{$r->{$ser_dev}}));
-    if ($s =~ /^\w[a-f0-9]{3}/) {return hex(substr($s,1,3));} 
-    if ($s =~ /^\w[a-f0-9]{2}/) {return hex(substr($s,1,2));}    
-    }
+  else {
+    trb_register_read_mem($ser_dev,0xd600,1,100); #clear memory
+    my @c = split('',$c."\n");
+    my @cmd =  map(ord, @c);
+    trb_register_write_mem($ser_dev,0xd600,1,\@cmd,scalar @cmd);
+    usleep(20000);
+    my $r = trb_register_read_mem($ser_dev,0xd600,1,5);
+    my $s = join('',map (chr($_ & 0xff),@{$r->{$ser_dev}}));
+    if ($s =~ /^\w[a-f0-9]{3}/) {return hex(substr($s,1,3));} 
+    if ($s =~ /^\w[a-f0-9]{2}/) {return hex(substr($s,1,2));}    
+    }
   return ;
   }
 
@@ -75,7 +75,7 @@ if ($help || (defined $ARGV[0] && $ARGV[0] =~ /help/)) {
   print "CHANNEL:   Channel number, hex or decimal\n";
   print "OPERATION: 1 (on), 0 (off), / (toggle), L (set limit)\n";
   print "VALUE:     A 10 Bit value, 3 hex digits or decimal\n";
-  print "If the DEVICE is an hex value, it is treated as a TrbNet address. Uart must be present and is assumed to be set at right baud rate\n";
+  print "If the DEVICE is an hex value, it is treated as a TrbNet address. Uart must be present and is assumed to be set at right baud rate\n";
   exit;
   }
 
@@ -160,9 +160,11 @@ if($args <= 1 || 1) {
     my $avg  = Cmd("D$n?");
     my $lim  = Cmd("L$n?");
 
+    if($curr > 0x800) {$curr = $curr - 0x1000;}
+    if($avg > 0x800) {$avg = $avg - 0x1000;}
     if(($s & 0xf0) == 0xe0) {printf(" $n\tERR\t\t (%3i)\n",$lim&0x3FF);}
     if(($s & 0xff) == 0x00) {printf(" $n\t---   \t\t (%3i)\n",$lim&0x3FF);}
-    if(($s & 0xff) == 0x01) {printf(" $n\t%3imA\t %3imA\t (%3i)\n",$curr&0x7ff,$avg&0x7ff,$lim&0x3FF);}
+    if(($s & 0xff) == 0x01) {printf(" $n\t%3imA\t %3imA\t (%3i)\n",$curr,$avg,$lim&0x3FF);}
     }
   
   }