--- 3m-810.pl 2009/04/06 12:36:22 28 +++ 3m-810.pl 2009/04/06 13:18:55 30 @@ -7,6 +7,7 @@ use Data::Dump qw/dump/; use Carp qw/confess/; use Getopt::Long; +use File::Slurp; use IO::Socket::INET; @@ -39,6 +40,8 @@ my $stopbits = "1"; my $handshake = "none"; +my $program_path = './program/'; + my $response = { 'd500090400110a0500027250' => 'version?', 'd60007fe00000500c97b' => 'no tag in range', @@ -182,6 +185,11 @@ warn "## using cached data for $tag" if $debug; } delete $last_visible_tags->{$tag}; # leave just missing tags + + if ( -e "$program_path/$tag" ) { + meteor( 'write', $tag ); + write_tag( $tag ); + } } foreach my $tag ( keys %$last_visible_tags ) { @@ -243,6 +251,33 @@ } +sub write_tag { + my ($tag) = @_; + + my $path = "$program_path/$tag"; + + my $data = read_file( $path ); + + $data = substr($data,0,16); + + my $hex_data = unpack('H*', $data) . ' 00' x ( 16 - length($data) ); + + print "write_tag $tag = $data ",dump( $hex_data ); + + cmd( + "D6 00 26 04 $tag 00 06 00 04 11 00 01 $hex_data 00 00 00 00 FD3B", "write $tag", + "D6 00 0D 04 00 $tag 06 AFB1", sub { assert() }, + ) foreach ( 1 .. 3 ); # XXX 3M software does this three times! + + my $to = $path; + $to .= '.' . time(); + + rename $path, $to; + print ">> $to\n"; + + delete $tags_data->{$tag}; # force re-read of tag +} + exit; for ( 1 .. 3 ) {