14 |
|
|
15 |
use IO::Socket::INET; |
use IO::Socket::INET; |
16 |
|
|
17 |
my $debug = 2; |
my $debug = 0; |
18 |
|
|
19 |
my $tags_data; |
my $tags_data; |
20 |
my $tags_security; |
my $tags_security; |
287 |
return pack('v', $crc); |
return pack('v', $crc); |
288 |
} |
} |
289 |
|
|
290 |
|
sub cpr_psst_wait { |
291 |
|
# Protocol Start Synchronization Time (PSST): 5ms < data timeout 12 ms |
292 |
|
Time::HiRes::sleep 0.005; |
293 |
|
} |
294 |
|
|
295 |
sub cpr { |
sub cpr { |
296 |
my ( $hex, $description ) = shift; |
my ( $hex, $description, $coderef ) = @_; |
297 |
my $bytes = str2bytes($hex); |
my $bytes = str2bytes($hex); |
298 |
my $len = pack( 'c', length( $bytes ) + 3 ); |
my $len = pack( 'c', length( $bytes ) + 3 ); |
299 |
my $send = $len . $bytes; |
my $send = $len . $bytes; |
300 |
my $checksum = cpr_m02_checksum($send); |
my $checksum = cpr_m02_checksum($send); |
301 |
$send .= $checksum; |
$send .= $checksum; |
302 |
|
|
303 |
warn ">> ", as_hex( $send ), "[$description]\n"; |
warn ">> ", as_hex( $send ), "\t\t[$description]\n"; |
304 |
$port->write( $send ); |
$port->write( $send ); |
305 |
|
|
306 |
|
cpr_psst_wait; |
307 |
|
|
308 |
my $r_len = $port->read(1); |
my $r_len = $port->read(1); |
309 |
|
|
310 |
while ( ! $r_len ) { |
while ( ! $r_len ) { |
311 |
warn "# wait for response length 0.050\n"; |
warn "# wait for response length 5ms\n"; |
312 |
Time::HiRes::sleep 0.050; |
cpr_psst_wait; |
313 |
$r_len = $port->read(1); |
$r_len = $port->read(1); |
314 |
} |
} |
315 |
|
|
316 |
warn "<< response len: ", as_hex($r_len), "\n"; |
my $data_len = ord($r_len) - 1; |
317 |
$r_len = ord($r_len) - 1; |
my $data = $port->read( $data_len ); |
318 |
my $data = $port->read( $r_len ); |
warn "<< ", as_hex( $r_len . $data ),"\n"; |
319 |
warn "<< ", as_hex( $data ); |
|
320 |
|
cpr_psst_wait; |
321 |
|
|
322 |
|
$coderef->( $data ) if $coderef; |
323 |
|
|
|
Time::HiRes::sleep 0.050; |
|
324 |
} |
} |
325 |
|
|
326 |
#cpr( 'FF 52 00', 'detect boud rate' ); |
# FF = COM-ADDR any |
327 |
|
|
328 |
#cpr( '00 65', 'software version' ); |
cpr( 'FF 52 00', 'Boud Rate Detection' ); |
329 |
|
|
330 |
cpr( 'FF 65', 'get ? info' ); |
cpr( 'FF 65', 'Get Software Version' ); |
331 |
|
|
332 |
cpr( 'FF 69 00', 'get reader info' ); |
cpr( 'FF 66 00', 'Get Reader Info - General hard and firware' ); |
333 |
|
|
334 |
cpr( 'FF B0 01 00', '?' ); |
cpr( 'FF 69', 'RF Reset' ); |
335 |
|
|
336 |
|
|
337 |
|
sub cpr_read { |
338 |
|
my $uid = shift; |
339 |
|
my $hex_uid = as_hex($uid); |
340 |
|
|
341 |
|
cpr( "FF B0 23 01 $hex_uid 00 04", "Read Multiple Blocks $hex_uid" ); |
342 |
|
# cpr( "FF B0 2B 01 $hex_uid", "Get System Information $hex_uid" ); |
343 |
|
} |
344 |
|
|
345 |
cpr( 'FF 69', '?' ); |
|
346 |
|
my $inventory; |
347 |
|
|
348 |
|
while(1) { |
349 |
|
|
350 |
|
cpr( 'FF B0 01 00', 'ISO - Inventory', sub { |
351 |
|
my $data = shift; |
352 |
|
my $data_sets = ord(substr($data,3,1)); |
353 |
|
$data = substr($data,4); |
354 |
|
foreach ( 1 .. $data_sets ) { |
355 |
|
my $tr_type = substr($data,0,1); |
356 |
|
die "FIXME only TR-TYPE=3 ISO 15693 supported" unless $tr_type eq "\x03"; |
357 |
|
my $dsfid = substr($data,1,1); |
358 |
|
my $uid = substr($data,2,8); |
359 |
|
$inventory->{$uid}++; |
360 |
|
$data = substr($data,10); |
361 |
|
warn "# TAG $_ ",as_hex( $tr_type, $dsfid, $uid ),$/; |
362 |
|
|
363 |
|
cpr_read( $uid ); |
364 |
|
} |
365 |
|
warn "inventory: ",dump($inventory); |
366 |
|
}); |
367 |
|
|
368 |
|
} |
369 |
|
|
370 |
#cpr( '', '?' ); |
#cpr( '', '?' ); |
371 |
|
|