From 1ec657b0297d8fabe81c645ae70ba7c38b23ecd4 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Fri, 28 Jun 2019 21:20:22 +0200 Subject: [PATCH] b3603: nicer output --- psu.pl | 47 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/psu.pl b/psu.pl index 3c2be90..7ac4aa7 100755 --- a/psu.pl +++ b/psu.pl @@ -32,12 +32,15 @@ $ob->write( shift(@commands) . "\n" ); my $got = ''; my $s; +my $show_response = $debug; + while ( 1 ) { my ($count_in, $string_in) = $ob->read($InBytes); print "<< $count_in << ",dump($string_in),"\n" if $debug && $count_in > 0; $got .= $string_in; if ( $got =~ m/(OK|E!)\r\n/ ) { - warn "# got = ",dump( $got ) if $debug; + warn "# got = ",dump( $got ) if $show_response; + $show_response = $debug; my $new; foreach ( split(/[\r\n]+/,$got) ) { my ($k,$v) = split(/:\s+/,$_,2); @@ -48,20 +51,54 @@ while ( 1 ) { $s->{$k} = $v; } } - warn "# new = ",dump( $new ); + warn "# new = ",dump( $new ) if $debug; + + print join("", map { + my $n = $_; + if ( my $v = $s->{$n} ) { + $v =~ s/(\d+) (\d+)$/$1/; # strip adc + "$n $v" . ( exists $new->{$n} ? '*' : ' ' ); + } else { '?' }; + } qw( +VIN +VSET +VOUT +CSET +COUT +OUTPUT +CONSTANT + ) ), "\n"; + + $got = ''; if ( @commands ) { $ob->write( shift(@commands) . "\n" ); } else { - print ">> "; alarm(1); my $c; eval { local $SIG{ALRM} = sub { die }; $c = ; + chomp $c; + alarm(0); + if ( length($c) == 0 ) { + print ">> "; + $c = ; + chomp $c; + } + $show_response = 1; }; - $c ||= "status\n"; - $ob->write( $c ); + + + if ( $c eq '?' ) { + print dump($s); + $c = ''; + } + + # always emit something to keep update working + $c ||= "status"; + warn ">> ",dump($c) if $debug; + $ob->write( "$c\n" ); } } } -- 2.20.1