From a3bc64c0112dc4f6530a3c8d746beabb32b66816 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Thu, 11 Dec 2014 20:17:55 +0100 Subject: [PATCH] better output, more commands --- dialog.pl | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/dialog.pl b/dialog.pl index 8f50b5e..dbab70b 100755 --- a/dialog.pl +++ b/dialog.pl @@ -12,24 +12,44 @@ $port->parity('none'); $port->stopbits(1); $port->handshake('none'); -# disable timeouts -$port->read_char_time(500); -$port->read_const_time(1000); +$port->read_char_time(1000); +$port->read_const_time(3000); + +sub as_hex { + my @out; + foreach my $str ( @_ ) { + my $hex = uc unpack( 'H*', $str ); + $hex =~ s/(..)/$1 /g if length( $str ) > 2; + $hex =~ s/\s+$//; + push @out, $hex; + } + return join(' | ', @out); +} -sub v { - my ($hex,$desc) = @_; +sub hex2bytes { my $bytes; - $bytes .= pack('C', hex('0x' . $_)) foreach split(/\s+/,$hex); + $bytes .= pack('C', hex('0x' . $_)) foreach split(/\s+/,join(' ',@_)); + return $bytes; +} + +sub v { + my ($hex,$expect,$desc) = @_; + my $bytes = hex2bytes( $hex ); warn "# $desc\n"; - warn ">> $hex ",dump( $bytes ); + warn ">> ",as_hex( $bytes ); $port->write( $bytes ); - my $len = $port->read(1); - warn "<< len: ",ord($len); - my $data = $port->read(ord($len) - 1); - warn "<< ",dump($data); + my $data = $port->read(1); + warn "<< len: ",ord($data); + $data .= $port->read(ord($data) - 1); + warn "<< ",as_hex($data); + warn "?? $expect\n" if $expect; } -v '07 02 00 00 00 04 C4', "hardware version"; +#v '07 02 00 00 00 04 C4', "hardware version"; + +#v '07 0A 00 00 00 04 44', 'software version'; + +v '07 00 01 00 06 0E EA', 'temperatures'; -- 2.20.1