From: Jan Michel Date: Mon, 2 Jan 2023 11:48:08 +0000 (+0100) Subject: add MDC Power Distributor support to register access script X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=f406598dade751888b68384315b571ce62d41510;p=avr.git add MDC Power Distributor support to register access script --- diff --git a/atmega32u4/dcdc_mdc/mdc_powerboard.pl b/atmega32u4/dcdc_mdc/mdc_powerboard.pl index 24d5c10..92dd116 100755 --- a/atmega32u4/dcdc_mdc/mdc_powerboard.pl +++ b/atmega32u4/dcdc_mdc/mdc_powerboard.pl @@ -46,7 +46,7 @@ if ($help || (defined $ARGV[0] && $ARGV[0] =~ /help/)) { print "dcdc.pl -d DEVICE -b BOARD [-c CHANNEL] [-o OUTPUT] -r REGISTER [-v VALUE]\n"; print "DEVICE: Network address of device\n"; - print "BOARD: Board number in chain (0..3)\n"; + print "BOARD: Board number in chain (-1..3)\n"; print "CHANNEL: Channel number (0..3)\n"; print "OUTPUT: Output number in channel (0..1)\n"; print "REGISTER: Register to access (number or name)\n"; @@ -62,7 +62,7 @@ $SEL_value //= 0; $SEL_value &= 0xffff; $SEL_board //= 0; -$SEL_board &= 0xff; +$SEL_board = 0xff if $SEL_board == -1; $SEL_output = 0 unless defined $SEL_output && $SEL_output =~ /^\d$/; die "Group number too high (0..3)" if $SEL_output > 3; @@ -74,7 +74,7 @@ if(defined $registers->{$SEL_register}) {$SEL_register = $registers->{$SEL_regis $SEL_register //= -1; die "Undefined register" unless ($SEL_register >= 0 && $SEL_register <= 7); -my $port = IO::Socket::INET->new(PeerAddr => $device, PeerPort => 2323, Proto => "tcp", Type => SOCK_STREAM, Timeout => 1) +my $port = IO::Socket::INET->new(PeerAddr => $device, PeerPort => 2323, Proto => "tcp", Type => SOCK_STREAM, Timeout => 1, Blocking => 0) or die "Can't bind to $device: $@\n"; my $cmd = sprintf("%s%02x%01x%01x%01x%04x",$SEL_rw?'W':'R',$SEL_board,$SEL_output,$SEL_channel,$SEL_register,$SEL_value&0xFFFF); @@ -87,8 +87,8 @@ sub Cmd { print $port "$c"; my $x = ""; for my $i (0..10) { - $x .= <$port>; - if($x && ($x =~ /\n/ || $x =~ /\r/) ) { + $x .= <$port>//''; + if($x && (substr($x,-1) eq "\n" || substr($x,-1) eq "\r" || length($x)>=10) ) { chomp $x; return $x; } @@ -99,6 +99,7 @@ sub Cmd { sub PrintAnswerNice { my ($s) = @_; + $s //= ""; my $FSR = 0.002; #Full Sclae Range is set to +-4.096V; LSB Size is 2mV if (substr($s,0,1) ne 'A') {die 'not a correct Answer from DCDC board'} my $command = hex(substr($s,5,1)); @@ -134,8 +135,14 @@ sub PrintAnswerNice { printf "measured Current @ Input : %.3f Ampere (RAW: 0x%x)\n", ($calc) , ($answ); } if ($command == 4) { # Temperature - my $calc = ((($answ&0x7FF)*2-250)/9.5)+25; - printf "measured temperature : %.2f°C (RAW: 0x%x)\n", ($calc) , ($answ); + if($SEL_board < 255) { + my $calc = ((($answ&0x7FF)*2-250)/9.5)+25; + printf "measured temperature : %.2f°C (RAW: 0x%x)\n", ($calc) , ($answ); + } + else { + my $calc = $answ / 100.; + printf "measured temperature : %.2f°C (RAW: 0x%x)\n", ($calc) , ($answ); + } } if ($command == 5) { #Infos print "Firmware : ".($answ>>4)."\n";