--- 3m-810.pl 2009/06/23 14:59:53 48 +++ 3m-810.pl 2009/06/26 11:46:45 56 @@ -12,7 +12,13 @@ use IO::Socket::INET; -my $meteor_server = '192.168.1.13:4671'; +my $debug = 0; + +my $tags_data; +my $tags_security; +my $visible_tags; + +my $meteor_server; # = '192.168.1.13:4671'; my $meteor_fh; sub meteor { @@ -57,6 +63,7 @@ my ($client,$path) = @_; $path = "www/$path"; + $path .= 'rfid.html' if $path =~ m{/$}; return unless -e $path; @@ -78,7 +85,7 @@ $client->autoflush(1); my $request = <$client>; - warn "<< $request\n"; + warn "WEB << $request\n" if $debug; if ($request =~ m{^GET (/.*) HTTP/1.[01]}) { my $method = $1; @@ -88,16 +95,17 @@ my ($n,$v) = split(/=/, $p, 2); $param->{$n} = $v; } - warn "<< param: ",dump( $param ); + warn "WEB << param: ",dump( $param ) if $debug; } if ( my $path = static( $client,$1 ) ) { - warn ">> $path"; + warn "WEB >> $path" if $debug; } elsif ( $method =~ m{/scan} ) { my $tags = scan_for_tags(); - my $json = {}; + my $json = { time => time() }; map { my $d = decode_tag($_); $d->{sid} = $_; + $d->{security} = $tags_security->{$_}; push @{ $json->{tags} }, $d; } keys %$tags; print $client "HTTP/1.0 200 OK\r\nContent-Type: application/x-javascript\r\n\r\n", @@ -129,8 +137,6 @@ sub _log { _message('log',@_) }; sub diag { _message('diag',@_) }; -my $debug = 0; - my $device = "/dev/ttyUSB0"; my $baudrate = "19200"; my $databits = "8"; @@ -205,9 +211,6 @@ =cut -my $tags_data; -my $visible_tags; - my $item_type = { 1 => 'Book', 6 => 'CD/CD ROM', @@ -309,6 +312,7 @@ $visible_tags = {}; foreach my $tag ( @tags ) { + $visible_tags->{$tag}++; if ( ! defined $last_visible_tags->{$tag} ) { if ( defined $tags_data->{$tag} ) { # meteor( 'in-range', $tag ); @@ -316,7 +320,6 @@ meteor( 'read', $tag ); read_tag( $tag ); } - $visible_tags->{$tag}++; } else { warn "## using cached data for $tag" if $debug; } @@ -432,6 +435,7 @@ ( $from_tag, $security ) = ( substr($rest,0,8), substr($rest,8,1) ); die "security from other tag: ",as_hex( $from_tag ) if $from_tag ne str2bytes( $tag ); $security = as_hex( $security ); + $tags_security->{$tag} = $security; warn "# SECURITY $tag = $security\n"; } ); @@ -657,7 +661,7 @@ warn "## DISPATCH payload to with rest", dump( $payload, $to, $rest ) if $debug; $dispatch->{ $to }->( $rest ); } else { - print "NO DISPATCH for ",dump( $full ),"\n"; + print "NO DISPATCH for ",as_hex( $full ),"\n"; } return $data;