From 932883ea61826723d57f912fae6fa3938393f286 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Fri, 27 Jan 2012 21:24:46 +0100 Subject: [PATCH] correct crc calculation and escaping --- qcdm.pl | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/qcdm.pl b/qcdm.pl index 472e4b1..21a1673 100755 --- a/qcdm.pl +++ b/qcdm.pl @@ -46,7 +46,7 @@ my @crc_table = ( sub crc { my $crc = 0xffff; foreach my $byte ( split(//, join('',@_)) ) { - $crc = ($crc >> 8) ^ $crc_table[ ($crc ^ $byte) & 0xff ]; + $crc = ($crc >> 8) ^ $crc_table[ ($crc ^ ord($byte)) & 0xff ]; } return $crc ^ 0xffff; } @@ -121,8 +121,8 @@ sub diag { my $crc = pack('v', crc($data) ); -# $data =~ s/\x7d/\x7d\x5d/; -# $data =~ s/\x7e/\x7d\x5e/; + $data =~ s/\x7d/\x7d\x5d/gs; + $data =~ s/\x7e/\x7d\x5e/gs; my $out = $data . $crc . "\x7e"; @@ -139,20 +139,22 @@ sub block_read { my $ret = $port->read(1); while ( my $c = $port->input ) { - print STDERR "<<< ",dump($ret . $c), $/; + print STDERR "<<< ",as_hex($ret . $c), $/; $ret .= $c; # last if $c =~ m/^OK\r/; } + $ret =~ s/\x7d\x5d/\x7d/gs; + $ret =~ s/\x7d\x5e/\x7e/gs; return $ret; } diag 'GET_VERSION'; -$port->close || die "can't close port $!"; +diag 'GET_SERIAL_NUMBER'; -while ( block_read() ) { - warn "# more"; -} +diag 'EXTENDED_BUILD_ID'; + +$port->close || die "can't close port $!"; warn "## $device closed\n"; -- 2.20.1