--- 3m-810.pl 2008/10/02 21:20:10 15 +++ 3m-810.pl 2008/10/02 22:53:57 16 @@ -104,26 +104,40 @@ die "wrong length $tl for $nr tags: ",dump( $tags ) if $tl =! $nr * 8; my @tags; - push @tags, substr($tags, $_ * 8, 8) foreach ( 0 .. $nr - 1 ); + push @tags, uc(unpack('H16', substr($tags, $_ * 8, 8))) foreach ( 0 .. $nr - 1 ); warn "## tags ",as_hex($tags), " [$tl] = ",dump( $tags ) if $debug; - print "seen $nr tags: ", join(',', map { unpack('H16', $_) } @tags ) , "\n"; + print "seen $nr tags: ", join(',', @tags ) , "\n"; + + # XXX read first tag + read_tag( @tags ); + } ) } ) foreach ( 1 .. 100 ); -cmd( 'D6 00 0D 02 E00401003123AA26 00 03 1CC4', 'read offset: 0 blocks: 3' ); +my $read_cached; + +sub read_tag { + my ( $tag ) = @_; -# D6 00 1F 02 00 E00401003123AA26 03 00 00 04 11 00 01 01 00 30 30 30 30 02 00 30 30 30 30 E5F4 -warn "D6 00 1F 02 00 E00401003123AA26 03 00 00 04 11 00 01 01 00 31 32 33 34 02 00 35 36 37 38 531F\n"; + print "read_tag $tag\n"; + return if $read_cached->{ $tag }++; -cmd( 'D6 00 0D 02 E00401003123AA26 03 04 3970', 'read offset: 3 blocks: 4' ); + cmd( "D6 00 0D 02 $tag 00 03 1CC4", 'read offset: 0 blocks: 3' ); -# D6 00 25 02 00 E00401003123AA26 04 03 00 30 30 00 00 04 00 00 00 00 00 -# 05 00 00 00 00 00 06 00 00 00 00 00 B9BA -warn "D6 00 25 02 00 E00401003123AA26 04 03 00 39 30 31 32 04 00 33 34 35 36 - 05 00 00 00 00 00 06 00 00 00 00 00 524B\n"; -warn "D6 00 0F FE 00 00 05 01 E00401003123AA26 941A ##### ready?\n"; + # D6 00 1F 02 00 $tag 03 00 00 04 11 00 01 01 00 30 30 30 30 02 00 30 30 30 30 E5F4 + warn "?? D6 00 1F 02 00 $tag 03 00 00 04 11 00 01 01 00 31 32 33 34 02 00 35 36 37 38 531F\n"; +if (0) { + cmd( "D6 00 0D 02 $tag 03 04 3970", 'read offset: 3 blocks: 4' ); + + # D6 00 25 02 00 $tag 04 03 00 30 30 00 00 04 00 00 00 00 00 + # $tag 05 00 00 00 00 00 06 00 00 00 00 00 B9BA + warn "?? D6 00 25 02 00 $tag 04 03 00 39 30 31 32 04 00 ....\n"; +} + warn "?? D6 00 0F FE 00 00 05 01 $tag 941A ##### ready?\n"; + +} for ( 1 .. 3 ) { @@ -241,9 +255,15 @@ my $xor = crcccitt( substr($bytes,1) ); # skip D6 warn "## checksum ",dump( $bytes, $xor, $checksum ) if $debug; + my $len = ord(substr($bytes,2,1)); + my $len_real = length($bytes); + print "length wrong: $len_real != $len\n" if $len_real != $len; + if ( defined $checksum && $xor ne $checksum ) { print "checksum doesn't match: ", as_hex($xor), " != ", as_hex($checksum), " data: ", as_hex($bytes), "\n"; + return $bytes . $xor; } + return $bytes . $checksum; } sub readchunk { @@ -291,6 +311,9 @@ my ( $cmd, $cmd_desc, $expect, $expect_desc, $coderef ) = @_; my $bytes = str2bytes( $cmd ); + # fix checksum if needed + $bytes = checksum( substr( $bytes, 0, -2 ), substr( $bytes, -2, 2 ) ); + warn ">> ", as_hex( $bytes ), "\t## $cmd_desc\n"; $assert->{send} = $cmd; writechunk( $bytes );