--- 3m-810.pl 2008/10/01 18:46:03 14 +++ 3m-810.pl 2008/10/02 21:20:10 15 @@ -39,6 +39,8 @@ L +L + =head1 AUTHOR Dobrica Pavlinusic L @@ -219,12 +221,25 @@ } } +use Digest::CRC; + +sub crcccitt { + my $bytes = shift; + my $crc = Digest::CRC->new( + # midified CCITT to xor with 0xffff instead of 0x0000 + width => 16, init => 0xffff, xorout => 0xffff, refout => 0, poly => 0x1021, refin => 0, + ) or die $!; + $crc->add( $bytes ); + pack('n', $crc->digest); +} + # my $checksum = checksum( $bytes ); # my $checksum = checksum( $bytes, $original_checksum ); sub checksum { my ( $bytes, $checksum ) = @_; - my $xor = $checksum; # FIXME + my $xor = crcccitt( substr($bytes,1) ); # skip D6 + warn "## checksum ",dump( $bytes, $xor, $checksum ) if $debug; if ( defined $checksum && $xor ne $checksum ) { print "checksum doesn't match: ", as_hex($xor), " != ", as_hex($checksum), " data: ", as_hex($bytes), "\n";