--- 3m-810.pl 2008/10/03 08:53:57 17 +++ 3m-810.pl 2008/10/03 12:31:58 18 @@ -124,10 +124,29 @@ print "read_tag $tag\n"; return if $read_cached->{ $tag }++; - cmd( "D6 00 0D 02 $tag 00 03 1CC4", 'read offset: 0 blocks: 3' ); + cmd( "D6 00 0D 02 $tag 00 03 1CC4", 'read $tag offset: 0 blocks: 3', + "D6 00 0F FE 00 00 05 01 $tag 941A", "$tag ready?", sub { +dispatch( "D6 00 1F 02 00 $tag ", sub { # 03 00 00 04 11 00 01 01 00 31 32 33 34 02 00 35 36 37 38 531F\n"; + my $rest = shift || die "no rest?"; + warn "## DATA ", dump( $rest ) if $debug; + my $blocks = ord(substr($rest,0,1)); + my @data; + foreach my $nr ( 0 .. $blocks - 1 ) { + my $block = substr( $rest, 1 + $nr * 6, 6 ); + warn "## block ",as_hex( $block ) if $debug; + my $ord = unpack('v',substr( $block, 0, 2 )); + die "got block $ord, expected block $nr from ",dump( $block ) if $ord != $nr; + my $data = substr( $block, 2 ); + die "data payload should be 4 bytes" if length($data) != 4; + warn sprintf "## tag %08s %02d %s |%-4s|\n", $tag, $ord, as_hex( $data ), $data; + $data[ $ord ] = $data; + } + $read_cached->{ $tag } = join('', @data); + print "DATA $tag ",dump( $read_cached->{ $tag } ), "\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' ); @@ -169,7 +188,7 @@ { my $str=shift; my $count = $port->write($str); - print "#> ", as_hex( $str ), "\t[$count]\n"; + print "#> ", as_hex( $str ), "\t[$count]" if $debug; } sub as_hex {