--- 3m-810.pl 2009/04/08 14:48:22 33 +++ 3m-810.pl 2009/06/01 13:09:41 37 @@ -19,16 +19,23 @@ push @a, scalar localtime() if $a[0] =~ m{^info}; if ( ! defined $meteor_fh ) { - warn "# open connection to $meteor_server"; - $meteor_fh = IO::Socket::INET->new( - PeerAddr => $meteor_server, - Timeout => 1, - ) || warn "can't connect to meteor $meteor_server: $!"; # FIXME warn => die for production - $meteor_fh = 0; # don't try again + if ( $meteor_fh = + IO::Socket::INET->new( + PeerAddr => $meteor_server, + Timeout => 1, + ) + ) { + warn "# meteor connected to $meteor_server"; + } else { + warn "can't connect to meteor $meteor_server: $!"; + $meteor_fh = 0; + } } - warn ">> meteor ",dump( @a ); - print $meteor_fh "ADDMESSAGE test ",join('|',@a),"\n" if $meteor_fh; + if ( $meteor_fh ) { + warn ">> meteor ",dump( @a ); + print $meteor_fh "ADDMESSAGE test ",join('|',@a),"\n" + } } my $debug = 0; @@ -41,6 +48,7 @@ my $handshake = "none"; my $program_path = './program/'; +my $secure_path = './secure/'; my $response = { 'd500090400110a0500027250' => 'version?', @@ -207,6 +215,10 @@ meteor( 'write', $tag ); write_tag( $tag ); } + if ( -e "$secure_path/$tag" ) { + meteor( 'secure', $tag ); + secure_tag( $tag ); + } } foreach my $tag ( keys %$last_visible_tags ) { @@ -288,7 +300,7 @@ my $total = ( $set_item & 0x0f ); my $branch = $br_lib >> 20; my $library = $br_lib & 0x000fffff; - print "TAG $tag [$u1] set: $set/$total [$u2] type: $type '$content' branch: $branch library: $library custom: $custom security: $security\n"; + print "TAG $tag [$u1] set: $set/$total [$u2] type: $type '$content' library: $library branch: $branch custom: $custom security: $security\n"; } @@ -303,12 +315,12 @@ my $hex_data = unpack('H*', $data) . ' 00' x ( 16 - length($data) ); - print "write_tag $tag = $data ",dump( $hex_data ); + print "write_tag $tag = ",dump( $data ), " == $hex_data\n"; 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! + "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(); @@ -319,6 +331,24 @@ delete $tags_data->{$tag}; # force re-read of tag } +sub secure_tag { + my ($tag) = @_; + + my $path = "$secure_path/$tag"; + my $data = substr(read_file( $path ),0,2); + + cmd( + "d6 00 0c 09 $tag $data 1234", "secure $tag -> $data", + "d6 00 0c 09 00 $tag 1234", sub { assert() }, + ); + + my $to = $path; + $to .= '.' . time(); + + rename $path, $to; + print ">> $to\n"; +} + exit; for ( 1 .. 3 ) {