--- 3m-810.pl 2009/03/28 03:47:10 23 +++ 3m-810.pl 2009/04/01 16:59:09 26 @@ -10,12 +10,21 @@ use IO::Socket::INET; -my $meteor = IO::Socket::INET->new( '192.168.1.13:4671' ) || die "can't connect to meteor: $!"; +my $meteor_server = '192.168.1.13:4671'; +my $meteor_fh; sub meteor { - my ( $item, $html ) = @_; - warn ">> meteor $item $html\n"; - print $meteor "ADDMESSAGE test $item|" . localtime() . "
$html\n"; + my @a = @_; + push @a, scalar localtime() if $a[0] =~ m{^info}; + + if ( ! defined $meteor_fh ) { + $meteor_fh = IO::Socket::INET->new( $meteor_server ) + || warn "can't connect to meteor $meteor_server: $!"; # FIXME warn => die for production + $meteor_fh = 0; # don't try again + } + + warn ">> meteor ",dump( @a ); + print $meteor_fh "ADDMESSAGE test ",join('|',@a),"\n" if $meteor_fh; } my $debug = 0; @@ -47,6 +56,7 @@ 'parity=s' => \$parity, 'stopbits=i' => \$stopbits, 'handshake=s' => \$handshake, + 'meteor=s' => \$meteor_server, ) or die $!; my $verbose = $debug > 0 ? $debug-- : 0; @@ -110,7 +120,7 @@ 'D5 00 09 04 00 11 0A 05 00 02 7250', sub { my $hw_ver = join('.', unpack('CCCC', skip_assert(3) )); print "hardware version $hw_ver\n"; - meteor( -1, "Found reader $hw_ver" ); + meteor( 'info', "Found reader hardware $hw_ver" ); }); cmd( 'D6 00 0C 13 04 01 00 02 00 03 00 04 00 AAF2','FIXME: stats?', @@ -126,7 +136,8 @@ if ( ! $nr ) { print "no tags in range\n"; update_visible_tags(); - meteor( -1, "No tags in range" ); + meteor( 'info-none-in-range' ); + $tags_data = {}; } else { my $tags = substr( $rest, 1 ); @@ -139,13 +150,13 @@ warn "## tags ",as_hex($tags), " [$tl] = ",dump( $tags ) if $debug; print "$nr tags in range: ", join(',', @tags ) , "\n"; - update_visible_tags( @tags ); + meteor( 'info-in-range', join(' ',@tags)); - my $html = join('', map { "
  • $_" } @tags); - meteor( 0, "Tags:" ); + update_visible_tags( @tags ); } } -) foreach ( 1 .. 1000 ); +) while(1); +#) foreach ( 1 .. 100 ); @@ -157,7 +168,12 @@ foreach my $tag ( @tags ) { if ( ! defined $last_visible_tags->{$tag} ) { - read_tag( $tag ); + if ( defined $tags_data->{$tag} ) { +# meteor( 'in-range', $tag ); + } else { + meteor( 'read', $tag ); + read_tag( $tag ); + } $visible_tags->{$tag}++; } else { warn "## using cached data for $tag" if $debug; @@ -168,6 +184,7 @@ foreach my $tag ( keys %$last_visible_tags ) { my $data = delete $tags_data->{$tag}; print "removed tag $tag with data ",dump( $data ),"\n"; + meteor( 'removed', $tag ); } warn "## update_visible_tags(",dump( @tags ),") = ",dump( $visible_tags )," removed: ",dump( $last_visible_tags ), " data: ",dump( $tags_data ) if $debug; @@ -179,8 +196,6 @@ confess "no tag?" unless $tag; - return if defined $tags_data->{$tag}; - print "read_tag $tag\n"; cmd( @@ -220,9 +235,6 @@ } warn "?? D6 00 0F FE 00 00 05 01 $tag 941A ##### ready?\n"; - my $item = unpack('H*', substr($tag,-8) ) % 100000; - meteor( $item, "Loading $item" ); - } exit;