8 |
use Carp qw/confess/; |
use Carp qw/confess/; |
9 |
use Getopt::Long; |
use Getopt::Long; |
10 |
|
|
11 |
|
use IO::Socket::INET; |
12 |
|
|
13 |
|
my $meteor = IO::Socket::INET->new( '192.168.1.13:4671' ) || die "can't connect to meteor: $!"; |
14 |
|
|
15 |
|
sub meteor { |
16 |
|
my ( $item, $html ) = @_; |
17 |
|
warn ">> meteor $item $html\n"; |
18 |
|
print $meteor "ADDMESSAGE test $item|" . localtime() . "<br>$html\n"; |
19 |
|
} |
20 |
|
|
21 |
my $debug = 0; |
my $debug = 0; |
22 |
|
|
23 |
my $device = "/dev/ttyUSB0"; |
my $device = "/dev/ttyUSB0"; |
82 |
|
|
83 |
=cut |
=cut |
84 |
|
|
85 |
|
my $tags_data; |
86 |
|
my $visible_tags; |
87 |
|
|
88 |
my $port=new Device::SerialPort($device) || die "can't open serial port $device: $!\n"; |
my $port=new Device::SerialPort($device) || die "can't open serial port $device: $!\n"; |
89 |
warn "using $device $handshake $baudrate $databits $parity $stopbits" if $debug; |
warn "using $device $handshake $baudrate $databits $parity $stopbits" if $debug; |
90 |
$handshake=$port->handshake($handshake); |
$handshake=$port->handshake($handshake); |
108 |
|
|
109 |
cmd( 'D5 00 05 04 00 11 8C66', 'hw version', |
cmd( 'D5 00 05 04 00 11 8C66', 'hw version', |
110 |
'D5 00 09 04 00 11 0A 05 00 02 7250', sub { |
'D5 00 09 04 00 11 0A 05 00 02 7250', sub { |
111 |
print "hardware version ", join('.', unpack('CCCC', skip_assert(3) )), "\n"; |
my $hw_ver = join('.', unpack('CCCC', skip_assert(3) )); |
112 |
|
print "hardware version $hw_ver\n"; |
113 |
|
meteor( -1, "Found reader $hw_ver" ); |
114 |
}); |
}); |
115 |
|
|
116 |
cmd( 'D6 00 0C 13 04 01 00 02 00 03 00 04 00 AAF2','FIXME: stats?', |
cmd( 'D6 00 0C 13 04 01 00 02 00 03 00 04 00 AAF2','FIXME: stats?', |
126 |
if ( ! $nr ) { |
if ( ! $nr ) { |
127 |
print "no tags in range\n"; |
print "no tags in range\n"; |
128 |
update_visible_tags(); |
update_visible_tags(); |
129 |
|
meteor( -1, "No tags in range" ); |
130 |
} else { |
} else { |
131 |
|
|
132 |
my $tags = substr( $rest, 1 ); |
my $tags = substr( $rest, 1 ); |
141 |
|
|
142 |
update_visible_tags( @tags ); |
update_visible_tags( @tags ); |
143 |
|
|
144 |
|
my $html = join('', map { "<li><tt>$_</tt>" } @tags); |
145 |
|
meteor( 0, "Tags:<ul>$html</ul>" ); |
146 |
} |
} |
147 |
} |
} |
148 |
) foreach ( 1 .. 100 ); |
) foreach ( 1 .. 1000 ); |
149 |
|
|
150 |
|
|
151 |
|
|
|
my $tags_data; |
|
|
my $visible_tags; |
|
|
|
|
152 |
sub update_visible_tags { |
sub update_visible_tags { |
153 |
my @tags = @_; |
my @tags = @_; |
154 |
|
|
166 |
} |
} |
167 |
|
|
168 |
foreach my $tag ( keys %$last_visible_tags ) { |
foreach my $tag ( keys %$last_visible_tags ) { |
169 |
print "removed tag $tag with data ",dump( delete $tags_data->{$tag} ),"\n"; |
my $data = delete $tags_data->{$tag}; |
170 |
|
print "removed tag $tag with data ",dump( $data ),"\n"; |
171 |
} |
} |
172 |
|
|
173 |
warn "## update_visible_tags(",dump( @tags ),") = ",dump( $visible_tags )," removed: ",dump( $last_visible_tags ), " data: ",dump( $tags_data ) if $debug; |
warn "## update_visible_tags(",dump( @tags ),") = ",dump( $visible_tags )," removed: ",dump( $last_visible_tags ), " data: ",dump( $tags_data ) if $debug; |
220 |
} |
} |
221 |
warn "?? D6 00 0F FE 00 00 05 01 $tag 941A ##### ready?\n"; |
warn "?? D6 00 0F FE 00 00 05 01 $tag 941A ##### ready?\n"; |
222 |
|
|
223 |
|
my $item = unpack('H*', substr($tag,-8) ) % 100000; |
224 |
|
meteor( $item, "Loading $item" ); |
225 |
|
|
226 |
} |
} |
227 |
|
|
228 |
exit; |
exit; |