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);
$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 = <STDIN>;
+ chomp $c;
+ alarm(0);
+ if ( length($c) == 0 ) {
+ print ">> ";
+ $c = <STDIN>;
+ 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" );
}
}
}