From d01ee4206dc7eaab0e8a5185c865969194bc74d6 Mon Sep 17 00:00:00 2001 From: Jan Michel Date: Mon, 16 Mar 2020 13:46:22 +0100 Subject: [PATCH] update pwrswitch tool for new firmware. Remove trbnet for easier usage. --- tools/pwrswitch.pl | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/tools/pwrswitch.pl b/tools/pwrswitch.pl index 64655db..3402d8e 100755 --- a/tools/pwrswitch.pl +++ b/tools/pwrswitch.pl @@ -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);} } } -- 2.43.0