/[RFID]/3m-810.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /3m-810.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 14 by dpavlin, Sun Sep 28 22:15:29 2008 UTC revision 15 by dpavlin, Thu Oct 2 21:20:10 2008 UTC
# Line 39  L<Device::SerialPort(3)> Line 39  L<Device::SerialPort(3)>
39    
40  L<perl(1)>  L<perl(1)>
41    
42    L<http://stackoverflow.com/questions/149617/how-could-i-guess-a-checksum-algorithm>
43    
44  =head1 AUTHOR  =head1 AUTHOR
45    
46  Dobrica Pavlinusic <dpavlin@rot13.org> L<http://www.rot13.org/~dpavlin/>  Dobrica Pavlinusic <dpavlin@rot13.org> L<http://www.rot13.org/~dpavlin/>
# Line 219  sub dispatch { Line 221  sub dispatch {
221          }          }
222  }  }
223    
224    use Digest::CRC;
225    
226    sub crcccitt {
227            my $bytes = shift;
228            my $crc = Digest::CRC->new(
229                    # midified CCITT to xor with 0xffff instead of 0x0000
230                    width => 16, init => 0xffff, xorout => 0xffff, refout => 0, poly => 0x1021, refin => 0,
231            ) or die $!;
232            $crc->add( $bytes );
233            pack('n', $crc->digest);
234    }
235    
236  # my $checksum = checksum( $bytes );  # my $checksum = checksum( $bytes );
237  # my $checksum = checksum( $bytes, $original_checksum );  # my $checksum = checksum( $bytes, $original_checksum );
238  sub checksum {  sub checksum {
239          my ( $bytes, $checksum ) = @_;          my ( $bytes, $checksum ) = @_;
240    
241          my $xor = $checksum; # FIXME          my $xor = crcccitt( substr($bytes,1) ); # skip D6
242            warn "## checksum ",dump( $bytes, $xor, $checksum ) if $debug;
243    
244          if ( defined $checksum && $xor ne $checksum ) {          if ( defined $checksum && $xor ne $checksum ) {
245                  print "checksum doesn't match: ", as_hex($xor), " != ", as_hex($checksum), " data: ", as_hex($bytes), "\n";                  print "checksum doesn't match: ", as_hex($xor), " != ", as_hex($checksum), " data: ", as_hex($bytes), "\n";

Legend:
Removed from v.14  
changed lines
  Added in v.15

  ViewVC Help
Powered by ViewVC 1.1.26