12 |
|
|
13 |
use IO::Socket::INET; |
use IO::Socket::INET; |
14 |
|
|
15 |
my $meteor_server = '192.168.1.13:4671'; |
my $debug = 0; |
16 |
|
|
17 |
|
my $tags_data; |
18 |
|
my $tags_security; |
19 |
|
my $visible_tags; |
20 |
|
|
21 |
|
my $meteor_server; # = '192.168.1.13:4671'; |
22 |
my $meteor_fh; |
my $meteor_fh; |
23 |
|
|
24 |
sub meteor { |
sub meteor { |
63 |
my ($client,$path) = @_; |
my ($client,$path) = @_; |
64 |
|
|
65 |
$path = "www/$path"; |
$path = "www/$path"; |
66 |
|
$path .= 'rfid.html' if $path =~ m{/$}; |
67 |
|
|
68 |
return unless -e $path; |
return unless -e $path; |
69 |
|
|
85 |
$client->autoflush(1); |
$client->autoflush(1); |
86 |
my $request = <$client>; |
my $request = <$client>; |
87 |
|
|
88 |
warn "<< $request\n"; |
warn "WEB << $request\n" if $debug; |
89 |
|
|
90 |
if ($request =~ m{^GET (/.*) HTTP/1.[01]}) { |
if ($request =~ m{^GET (/.*) HTTP/1.[01]}) { |
91 |
my $method = $1; |
my $method = $1; |
95 |
my ($n,$v) = split(/=/, $p, 2); |
my ($n,$v) = split(/=/, $p, 2); |
96 |
$param->{$n} = $v; |
$param->{$n} = $v; |
97 |
} |
} |
98 |
warn "<< param: ",dump( $param ); |
warn "WEB << param: ",dump( $param ) if $debug; |
99 |
} |
} |
100 |
if ( my $path = static( $client,$1 ) ) { |
if ( my $path = static( $client,$1 ) ) { |
101 |
warn ">> $path"; |
warn "WEB >> $path" if $debug; |
102 |
} elsif ( $method =~ m{/scan} ) { |
} elsif ( $method =~ m{/scan} ) { |
103 |
my $tags = scan_for_tags(); |
my $tags = scan_for_tags(); |
104 |
my $json = {}; |
my $json = { time => time() }; |
105 |
map { |
map { |
106 |
my $d = decode_tag($_); |
my $d = decode_tag($_); |
107 |
$d->{sid} = $_; |
$d->{sid} = $_; |
108 |
|
$d->{security} = $tags_security->{$_}; |
109 |
push @{ $json->{tags} }, $d; |
push @{ $json->{tags} }, $d; |
110 |
} keys %$tags; |
} keys %$tags; |
111 |
print $client "HTTP/1.0 200 OK\r\nContent-Type: application/x-javascript\r\n\r\n", |
print $client "HTTP/1.0 200 OK\r\nContent-Type: application/x-javascript\r\n\r\n", |
137 |
sub _log { _message('log',@_) }; |
sub _log { _message('log',@_) }; |
138 |
sub diag { _message('diag',@_) }; |
sub diag { _message('diag',@_) }; |
139 |
|
|
|
my $debug = 0; |
|
|
|
|
140 |
my $device = "/dev/ttyUSB0"; |
my $device = "/dev/ttyUSB0"; |
141 |
my $baudrate = "19200"; |
my $baudrate = "19200"; |
142 |
my $databits = "8"; |
my $databits = "8"; |
211 |
|
|
212 |
=cut |
=cut |
213 |
|
|
|
my $tags_data; |
|
|
my $visible_tags; |
|
|
|
|
214 |
my $item_type = { |
my $item_type = { |
215 |
1 => 'Book', |
1 => 'Book', |
216 |
6 => 'CD/CD ROM', |
6 => 'CD/CD ROM', |
312 |
$visible_tags = {}; |
$visible_tags = {}; |
313 |
|
|
314 |
foreach my $tag ( @tags ) { |
foreach my $tag ( @tags ) { |
315 |
|
$visible_tags->{$tag}++; |
316 |
if ( ! defined $last_visible_tags->{$tag} ) { |
if ( ! defined $last_visible_tags->{$tag} ) { |
317 |
if ( defined $tags_data->{$tag} ) { |
if ( defined $tags_data->{$tag} ) { |
318 |
# meteor( 'in-range', $tag ); |
# meteor( 'in-range', $tag ); |
320 |
meteor( 'read', $tag ); |
meteor( 'read', $tag ); |
321 |
read_tag( $tag ); |
read_tag( $tag ); |
322 |
} |
} |
|
$visible_tags->{$tag}++; |
|
323 |
} else { |
} else { |
324 |
warn "## using cached data for $tag" if $debug; |
warn "## using cached data for $tag" if $debug; |
325 |
} |
} |
435 |
( $from_tag, $security ) = ( substr($rest,0,8), substr($rest,8,1) ); |
( $from_tag, $security ) = ( substr($rest,0,8), substr($rest,8,1) ); |
436 |
die "security from other tag: ",as_hex( $from_tag ) if $from_tag ne str2bytes( $tag ); |
die "security from other tag: ",as_hex( $from_tag ) if $from_tag ne str2bytes( $tag ); |
437 |
$security = as_hex( $security ); |
$security = as_hex( $security ); |
438 |
|
$tags_security->{$tag} = $security; |
439 |
warn "# SECURITY $tag = $security\n"; |
warn "# SECURITY $tag = $security\n"; |
440 |
} |
} |
441 |
); |
); |
661 |
warn "## DISPATCH payload to with rest", dump( $payload, $to, $rest ) if $debug; |
warn "## DISPATCH payload to with rest", dump( $payload, $to, $rest ) if $debug; |
662 |
$dispatch->{ $to }->( $rest ); |
$dispatch->{ $to }->( $rest ); |
663 |
} else { |
} else { |
664 |
print "NO DISPATCH for ",dump( $full ),"\n"; |
print "NO DISPATCH for ",as_hex( $full ),"\n"; |
665 |
} |
} |
666 |
|
|
667 |
return $data; |
return $data; |