9 |
use Getopt::Long; |
use Getopt::Long; |
10 |
use File::Slurp; |
use File::Slurp; |
11 |
use JSON; |
use JSON; |
12 |
|
use POSIX qw(strftime); |
13 |
|
use Time::HiRes; |
14 |
|
|
15 |
use IO::Socket::INET; |
use IO::Socket::INET; |
16 |
|
|
20 |
my $tags_security; |
my $tags_security; |
21 |
my $visible_tags; |
my $visible_tags; |
22 |
|
|
|
my $meteor_server; # = '192.168.1.13:4671'; |
|
|
my $meteor_fh; |
|
|
|
|
|
sub meteor { |
|
|
my @a = @_; |
|
|
push @a, scalar localtime() if $a[0] =~ m{^info}; |
|
|
|
|
|
if ( ! defined $meteor_fh ) { |
|
|
if ( $meteor_fh = |
|
|
IO::Socket::INET->new( |
|
|
PeerAddr => $meteor_server, |
|
|
Timeout => 1, |
|
|
) |
|
|
) { |
|
|
warn "# meteor connected to $meteor_server"; |
|
|
} else { |
|
|
warn "can't connect to meteor $meteor_server: $!"; |
|
|
$meteor_fh = 0; |
|
|
} |
|
|
} |
|
|
|
|
|
if ( $meteor_fh ) { |
|
|
warn ">> meteor ",dump( @a ); |
|
|
print $meteor_fh "ADDMESSAGE test ",join('|',@a),"\n" |
|
|
} |
|
|
} |
|
|
|
|
23 |
my $listen_port = 9000; # pick something not in use |
my $listen_port = 9000; # pick something not in use |
24 |
|
my $server_url = "http://localhost:$listen_port"; |
25 |
|
|
26 |
sub http_server { |
sub http_server { |
27 |
|
|
28 |
my $server = IO::Socket::INET->new( |
my $server = IO::Socket::INET->new( |
32 |
Reuse => 1 |
Reuse => 1 |
33 |
); |
); |
34 |
|
|
35 |
die "can't setup server" unless $server; |
die "can't setup server: $!" unless $server; |
36 |
|
|
37 |
print "Server $0 accepting clients at http://localhost:$listen_port/\n"; |
print "Server $0 ready at $server_url\n"; |
38 |
|
|
39 |
sub static { |
sub static { |
40 |
my ($client,$path) = @_; |
my ($client,$path) = @_; |
85 |
$d->{security} = $tags_security->{$_}; |
$d->{security} = $tags_security->{$_}; |
86 |
push @{ $json->{tags} }, $d; |
push @{ $json->{tags} }, $d; |
87 |
} keys %$tags; |
} keys %$tags; |
88 |
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/json\r\n\r\n", |
89 |
$param->{callback}, "(", to_json($json), ")\r\n"; |
$param->{callback}, "(", to_json($json), ")\r\n"; |
90 |
|
} elsif ( $method =~ m{/program} ) { |
91 |
|
|
92 |
|
my $status = 501; # Not implementd |
93 |
|
|
94 |
|
foreach my $p ( keys %$param ) { |
95 |
|
next unless $p =~ m/^(E[0-9A-F]{15})$/; |
96 |
|
my $tag = $1; |
97 |
|
my $content = "\x04\x11\x00\x01" . $param->{$p}; |
98 |
|
$content = "\x00" if $param->{$p} eq 'blank'; |
99 |
|
$status = 302; |
100 |
|
|
101 |
|
warn "PROGRAM $tag $content\n"; |
102 |
|
write_tag( $tag, $content ); |
103 |
|
secure_tag_with( $tag, $param->{$p} =~ /^130/ ? 'DA' : 'D7' ); |
104 |
|
} |
105 |
|
|
106 |
|
print $client "HTTP/1.0 $status $method\r\nLocation: $server_url\r\n\r\n"; |
107 |
|
|
108 |
|
} elsif ( $method =~ m{/secure(.js)} ) { |
109 |
|
|
110 |
|
my $json = $1; |
111 |
|
|
112 |
|
my $status = 501; # Not implementd |
113 |
|
|
114 |
|
foreach my $p ( keys %$param ) { |
115 |
|
next unless $p =~ m/^(E[0-9A-F]{15})$/; |
116 |
|
my $tag = $1; |
117 |
|
my $data = $param->{$p}; |
118 |
|
$status = 302; |
119 |
|
|
120 |
|
warn "SECURE $tag $data\n"; |
121 |
|
secure_tag_with( $tag, $data ); |
122 |
|
} |
123 |
|
|
124 |
|
if ( $json ) { |
125 |
|
print $client "HTTP/1.0 200 OK\r\nContent-Type: application/json\r\n\r\n", |
126 |
|
$param->{callback}, "({ ok: 1 })\r\n"; |
127 |
|
} else { |
128 |
|
print $client "HTTP/1.0 $status $method\r\nLocation: $server_url\r\n\r\n"; |
129 |
|
} |
130 |
|
|
131 |
} else { |
} else { |
132 |
print $client "HTTP/1.0 404 Unkown method\r\n"; |
print $client "HTTP/1.0 404 Unkown method\r\n\r\n"; |
133 |
} |
} |
134 |
} else { |
} else { |
135 |
print $client "HTTP/1.0 500 No method\r\n"; |
print $client "HTTP/1.0 500 No method\r\n\r\n"; |
136 |
} |
} |
137 |
close $client; |
close $client; |
138 |
} |
} |
156 |
sub diag { _message('diag',@_) }; |
sub diag { _message('diag',@_) }; |
157 |
|
|
158 |
my $device = "/dev/ttyUSB0"; |
my $device = "/dev/ttyUSB0"; |
159 |
my $baudrate = "19200"; |
my $baudrate = "38400"; |
160 |
my $databits = "8"; |
my $databits = "8"; |
161 |
my $parity = "none"; |
my $parity = "even"; |
162 |
my $stopbits = "1"; |
my $stopbits = "1"; |
163 |
my $handshake = "none"; |
my $handshake = "none"; |
164 |
|
|
169 |
my $http_server = 1; |
my $http_server = 1; |
170 |
|
|
171 |
# 3M defaults: 8,4 |
# 3M defaults: 8,4 |
172 |
my $max_rfid_block = 16; |
# cards 16, stickers: 8 |
173 |
|
my $max_rfid_block = 8; |
174 |
my $read_blocks = 8; |
my $read_blocks = 8; |
175 |
|
|
176 |
my $response = { |
my $response = { |
193 |
'parity=s' => \$parity, |
'parity=s' => \$parity, |
194 |
'stopbits=i' => \$stopbits, |
'stopbits=i' => \$stopbits, |
195 |
'handshake=s' => \$handshake, |
'handshake=s' => \$handshake, |
|
'meteor=s' => \$meteor_server, |
|
196 |
'http-server!' => \$http_server, |
'http-server!' => \$http_server, |
197 |
) or die $!; |
) or die $!; |
198 |
|
|
265 |
#$port->stty_inpck(1); |
#$port->stty_inpck(1); |
266 |
#$port->stty_istrip(1); |
#$port->stty_istrip(1); |
267 |
|
|
268 |
|
sub cpr_m02_checksum { |
269 |
|
my $data = shift; |
270 |
|
|
271 |
|
my $preset = 0xffff; |
272 |
|
my $polynom = 0x8408; |
273 |
|
|
274 |
|
my $crc = $preset; |
275 |
|
foreach my $i ( 0 .. length($data) - 1 ) { |
276 |
|
$crc ^= ord(substr($data,$i,1)); |
277 |
|
for my $j ( 0 .. 7 ) { |
278 |
|
if ( $crc & 0x0001 ) { |
279 |
|
$crc = ( $crc >> 1 ) ^ $polynom; |
280 |
|
} else { |
281 |
|
$crc = $crc >> 1; |
282 |
|
} |
283 |
|
} |
284 |
|
# warn sprintf('%d %04x', $i, $crc & 0xffff); |
285 |
|
} |
286 |
|
|
287 |
|
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 { |
296 |
|
my ( $hex, $description, $coderef ) = @_; |
297 |
|
my $bytes = str2bytes($hex); |
298 |
|
my $len = pack( 'c', length( $bytes ) + 3 ); |
299 |
|
my $send = $len . $bytes; |
300 |
|
my $checksum = cpr_m02_checksum($send); |
301 |
|
$send .= $checksum; |
302 |
|
|
303 |
|
warn ">> ", as_hex( $send ), "\t\t[$description]\n"; |
304 |
|
$port->write( $send ); |
305 |
|
|
306 |
|
cpr_psst_wait; |
307 |
|
|
308 |
|
my $r_len = $port->read(1); |
309 |
|
|
310 |
|
while ( ! $r_len ) { |
311 |
|
warn "# wait for response length 5ms\n"; |
312 |
|
cpr_psst_wait; |
313 |
|
$r_len = $port->read(1); |
314 |
|
} |
315 |
|
|
316 |
|
my $data_len = ord($r_len) - 1; |
317 |
|
my $data = $port->read( $data_len ); |
318 |
|
warn "<< ", as_hex( $r_len . $data ),"\n"; |
319 |
|
|
320 |
|
cpr_psst_wait; |
321 |
|
|
322 |
|
$coderef->( $data ) if $coderef; |
323 |
|
|
324 |
|
} |
325 |
|
|
326 |
|
# FF = COM-ADDR any |
327 |
|
|
328 |
|
cpr( 'FF 52 00', 'Boud Rate Detection' ); |
329 |
|
|
330 |
|
cpr( 'FF 65', 'Get Software Version' ); |
331 |
|
|
332 |
|
cpr( 'FF 66 00', 'Get Reader Info - General hard and firware' ); |
333 |
|
|
334 |
|
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 |
|
|
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( '', '?' ); |
371 |
|
|
372 |
|
exit; |
373 |
# initial hand-shake with device |
# initial hand-shake with device |
374 |
|
|
375 |
cmd( 'D5 00 05 04 00 11 8C66', 'hw version', |
cmd( 'D5 00 05 04 00 11 8C66', 'hw version', |
376 |
'D5 00 09 04 00 11 0A 05 00 02 7250', sub { |
'D5 00 09 04 00 11 0A 05 00 02 7250', sub { |
377 |
my $hw_ver = join('.', unpack('CCCC', skip_assert(3) )); |
my $hw_ver = join('.', unpack('CCCC', skip_assert(3) )); |
378 |
print "hardware version $hw_ver\n"; |
print "hardware version $hw_ver\n"; |
|
meteor( 'info', "Found reader hardware $hw_ver" ); |
|
379 |
}); |
}); |
380 |
|
|
381 |
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?', |
393 |
if ( ! $nr ) { |
if ( ! $nr ) { |
394 |
_log "no tags in range\n"; |
_log "no tags in range\n"; |
395 |
update_visible_tags(); |
update_visible_tags(); |
|
meteor( 'info-none-in-range' ); |
|
396 |
$tags_data = {}; |
$tags_data = {}; |
397 |
} else { |
} else { |
398 |
|
|
404 |
warn "## tags ",as_hex($tags), " [$tl] = ",dump( $tags ) if $debug; |
warn "## tags ",as_hex($tags), " [$tl] = ",dump( $tags ) if $debug; |
405 |
_log "$nr tags in range: ", join(',', @tags ) , "\n"; |
_log "$nr tags in range: ", join(',', @tags ) , "\n"; |
406 |
|
|
|
meteor( 'info-in-range', join(' ',@tags)); |
|
|
|
|
407 |
update_visible_tags( @tags ); |
update_visible_tags( @tags ); |
408 |
} |
} |
409 |
} |
} |
437 |
$visible_tags->{$tag}++; |
$visible_tags->{$tag}++; |
438 |
if ( ! defined $last_visible_tags->{$tag} ) { |
if ( ! defined $last_visible_tags->{$tag} ) { |
439 |
if ( defined $tags_data->{$tag} ) { |
if ( defined $tags_data->{$tag} ) { |
440 |
# meteor( 'in-range', $tag ); |
warn "$tag in range\n"; |
441 |
} else { |
} else { |
|
meteor( 'read', $tag ); |
|
442 |
read_tag( $tag ); |
read_tag( $tag ); |
443 |
} |
} |
444 |
} else { |
} else { |
447 |
delete $last_visible_tags->{$tag}; # leave just missing tags |
delete $last_visible_tags->{$tag}; # leave just missing tags |
448 |
|
|
449 |
if ( -e "$program_path/$tag" ) { |
if ( -e "$program_path/$tag" ) { |
|
meteor( 'write', $tag ); |
|
450 |
write_tag( $tag ); |
write_tag( $tag ); |
451 |
} |
} |
452 |
if ( -e "$secure_path/$tag" ) { |
if ( -e "$secure_path/$tag" ) { |
|
meteor( 'secure', $tag ); |
|
453 |
secure_tag( $tag ); |
secure_tag( $tag ); |
454 |
} |
} |
455 |
} |
} |
456 |
|
|
457 |
foreach my $tag ( keys %$last_visible_tags ) { |
foreach my $tag ( keys %$last_visible_tags ) { |
458 |
my $data = delete $tags_data->{$tag}; |
my $data = delete $tags_data->{$tag}; |
459 |
print "removed tag $tag with data ",dump( $data ),"\n"; |
warn "$tag removed ", dump($data), $/; |
|
meteor( 'removed', $tag ); |
|
460 |
} |
} |
461 |
|
|
462 |
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; |
494 |
return $last_block + 1; |
return $last_block + 1; |
495 |
} |
} |
496 |
|
|
497 |
|
my $saved_in_log; |
498 |
|
|
499 |
sub decode_tag { |
sub decode_tag { |
500 |
my $tag = shift; |
my $tag = shift; |
501 |
|
|
502 |
my $data = $tags_data->{$tag} || die "no data for $tag"; |
my $data = $tags_data->{$tag}; |
503 |
|
if ( ! $data ) { |
504 |
|
warn "no data for $tag\n"; |
505 |
|
return; |
506 |
|
} |
507 |
|
|
508 |
my ( $u1, $set_item, $u2, $type, $content, $br_lib, $custom ) = unpack('C4Z16Nl>',$data); |
my ( $u1, $set_item, $u2, $type, $content, $br_lib, $custom ) = unpack('C4Z16Nl>',$data); |
509 |
my $hash = { |
my $hash = { |
521 |
custom => $custom, |
custom => $custom, |
522 |
}; |
}; |
523 |
|
|
524 |
|
if ( ! $saved_in_log->{$tag}++ ) { |
525 |
|
open(my $log, '>>', 'rfid-log.txt'); |
526 |
|
print $log strftime( "%Y-%m-%d %H:%M:%S", localtime ), ",$tag,$content\n"; |
527 |
|
close($log); |
528 |
|
} |
529 |
|
|
530 |
return $hash; |
return $hash; |
531 |
} |
} |
532 |
|
|
533 |
|
sub forget_tag { |
534 |
|
my $tag = shift; |
535 |
|
delete $tags_data->{$tag}; |
536 |
|
delete $visible_tags->{$tag}; |
537 |
|
} |
538 |
|
|
539 |
sub read_tag { |
sub read_tag { |
540 |
my ( $tag ) = @_; |
my ( $tag ) = @_; |
541 |
|
|
548 |
while ( $start_block < $max_rfid_block ) { |
while ( $start_block < $max_rfid_block ) { |
549 |
|
|
550 |
cmd( |
cmd( |
551 |
sprintf( "D6 00 0D 02 $tag %02x %02x ffff", $start_block, $read_blocks ), |
sprintf( "D6 00 0D 02 $tag %02x %02x BEEF", $start_block, $read_blocks ), |
552 |
"read $tag offset: $start_block blocks: $read_blocks", |
"read $tag offset: $start_block blocks: $read_blocks", |
553 |
"D6 00 1F 02 00", sub { # $tag 03 00 00 04 11 00 01 01 00 31 32 33 34 02 00 35 36 37 38 531F\n"; |
"D6 00 1F 02 00", sub { # $tag 03 00 00 04 11 00 01 01 00 31 32 33 34 02 00 35 36 37 38 531F\n"; |
554 |
$start_block = read_tag_data( $start_block, @_ ); |
$start_block = read_tag_data( $start_block, @_ ); |
555 |
warn "# read tag upto $start_block\n"; |
warn "# read tag upto $start_block\n"; |
556 |
}, |
}, |
557 |
"D6 00 0F FE 00 00 05 01 $tag 941A", sub { |
"D6 00 0F FE 00 00 05 01 $tag BEEF", sub { |
558 |
print "FIXME: tag $tag ready? (expected block read instead)\n"; |
print "FIXME: tag $tag ready? (expected block read instead)\n"; |
559 |
}, |
}, |
560 |
|
"D6 00 0D 02 06 $tag", sub { |
561 |
|
my $rest = shift; |
562 |
|
print "ERROR reading $tag ", as_hex($rest), $/; |
563 |
|
forget_tag $tag; |
564 |
|
$start_block = $max_rfid_block; # XXX break out of while |
565 |
|
}, |
566 |
); |
); |
567 |
|
|
568 |
} |
} |
570 |
my $security; |
my $security; |
571 |
|
|
572 |
cmd( |
cmd( |
573 |
"D6 00 0B 0A $tag 1234", "check security $tag", |
"D6 00 0B 0A $tag BEEF", "check security $tag", |
574 |
"D6 00 0D 0A 00", sub { |
"D6 00 0D 0A 00", sub { |
575 |
my $rest = shift; |
my $rest = shift; |
576 |
my $from_tag; |
my $from_tag; |
579 |
$security = as_hex( $security ); |
$security = as_hex( $security ); |
580 |
$tags_security->{$tag} = $security; |
$tags_security->{$tag} = $security; |
581 |
warn "# SECURITY $tag = $security\n"; |
warn "# SECURITY $tag = $security\n"; |
582 |
} |
}, |
583 |
|
"D6 00 0C 0A 06", sub { |
584 |
|
my $rest = shift; |
585 |
|
warn "ERROR reading security from $rest\n"; |
586 |
|
forget_tag $tag; |
587 |
|
}, |
588 |
); |
); |
589 |
|
|
590 |
print "TAG $tag ", dump(decode_tag( $tag )); |
print "TAG $tag ", dump(decode_tag( $tag )); |
591 |
} |
} |
592 |
|
|
593 |
sub write_tag { |
sub write_tag { |
594 |
my ($tag) = @_; |
my ($tag,$data) = @_; |
595 |
|
|
596 |
my $path = "$program_path/$tag"; |
my $path = "$program_path/$tag"; |
597 |
|
$data = read_file( $path ) if -e $path; |
598 |
|
|
599 |
|
die "no data" unless $data; |
600 |
|
|
|
my $data = read_file( $path ); |
|
601 |
my $hex_data; |
my $hex_data; |
602 |
|
|
603 |
if ( $data =~ s{^hex\s+}{} ) { |
if ( $data =~ s{^hex\s+}{} ) { |
625 |
print "write_tag $tag = ",dump( $data ), " [$len/$blocks] == $hex_data\n"; |
print "write_tag $tag = ",dump( $data ), " [$len/$blocks] == $hex_data\n"; |
626 |
|
|
627 |
cmd( |
cmd( |
628 |
"d6 00 ff 04 $tag 00 $blocks 00 $hex_data ffff", "write $tag", |
"d6 00 ff 04 $tag 00 $blocks 00 $hex_data BEEF", "write $tag", |
629 |
"d6 00 0d 04 00 $tag $blocks afb1", sub { assert() }, |
"d6 00 0d 04 00 $tag $blocks BEEF", sub { assert() }, |
630 |
); # foreach ( 1 .. 3 ); # XXX 3m software does this three times! |
); # foreach ( 1 .. 3 ); # XXX 3m software does this three times! |
631 |
|
|
632 |
my $to = $path; |
my $to = $path; |
635 |
rename $path, $to; |
rename $path, $to; |
636 |
print ">> $to\n"; |
print ">> $to\n"; |
637 |
|
|
638 |
delete $tags_data->{$tag}; # force re-read of tag |
forget_tag $tag; |
639 |
|
} |
640 |
|
|
641 |
|
sub secure_tag_with { |
642 |
|
my ( $tag, $data ) = @_; |
643 |
|
|
644 |
|
cmd( |
645 |
|
"d6 00 0c 09 $tag $data BEEF", "secure $tag -> $data", |
646 |
|
"d6 00 0c 09 00 $tag BEEF", sub { assert() }, |
647 |
|
); |
648 |
|
|
649 |
|
forget_tag $tag; |
650 |
} |
} |
651 |
|
|
652 |
sub secure_tag { |
sub secure_tag { |
655 |
my $path = "$secure_path/$tag"; |
my $path = "$secure_path/$tag"; |
656 |
my $data = substr(read_file( $path ),0,2); |
my $data = substr(read_file( $path ),0,2); |
657 |
|
|
658 |
cmd( |
secure_tag_with( $tag, $data ); |
|
"d6 00 0c 09 $tag $data 1234", "secure $tag -> $data", |
|
|
"d6 00 0c 09 00 $tag 1234", sub { assert() }, |
|
|
); |
|
659 |
|
|
660 |
my $to = $path; |
my $to = $path; |
661 |
$to .= '.' . time(); |
$to .= '.' . time(); |
704 |
sub as_hex { |
sub as_hex { |
705 |
my @out; |
my @out; |
706 |
foreach my $str ( @_ ) { |
foreach my $str ( @_ ) { |
707 |
my $hex = unpack( 'H*', $str ); |
my $hex = uc unpack( 'H*', $str ); |
708 |
$hex =~ s/(..)/$1 /g if length( $str ) > 2; |
$hex =~ s/(..)/$1 /g if length( $str ) > 2; |
709 |
$hex =~ s/\s+$//; |
$hex =~ s/\s+$//; |
710 |
push @out, $hex; |
push @out, $hex; |
718 |
while ( length( $data ) < $len ) { |
while ( length( $data ) < $len ) { |
719 |
my ( $c, $b ) = $port->read(1); |
my ( $c, $b ) = $port->read(1); |
720 |
die "no bytes on port: $!" unless defined $b; |
die "no bytes on port: $!" unless defined $b; |
721 |
#warn "## got $c bytes: ", as_hex($b), "\n"; |
warn "## got $c bytes: ", as_hex($b), "\n"; |
722 |
|
last if $c == 0; |
723 |
$data .= $b; |
$data .= $b; |
724 |
} |
} |
725 |
$desc ||= '?'; |
$desc ||= '?'; |
777 |
warn "## checksum ",dump( $bytes, $xor, $checksum ) if $debug; |
warn "## checksum ",dump( $bytes, $xor, $checksum ) if $debug; |
778 |
|
|
779 |
if ( defined $checksum && $xor ne $checksum ) { |
if ( defined $checksum && $xor ne $checksum ) { |
780 |
print "checksum doesn't match: ", as_hex($xor), " != ", as_hex($checksum), " data: ", as_hex($bytes), "\n"; |
warn "checksum error: ", as_hex($xor), " != ", as_hex($checksum), " data: ", as_hex($bytes), "\n" if $checksum ne "\xBE\xEF"; |
781 |
return $bytes . $xor; |
return $bytes . $xor; |
782 |
} |
} |
783 |
return $bytes . $checksum; |
return $bytes . $checksum; |
819 |
warn "## DISPATCH payload to with rest", dump( $payload, $to, $rest ) if $debug; |
warn "## DISPATCH payload to with rest", dump( $payload, $to, $rest ) if $debug; |
820 |
$dispatch->{ $to }->( $rest ); |
$dispatch->{ $to }->( $rest ); |
821 |
} else { |
} else { |
822 |
print "NO DISPATCH for ",as_hex( $full ),"\n"; |
die "NO DISPATCH for ",as_hex( $full ),"\n"; |
823 |
} |
} |
824 |
|
|
825 |
return $data; |
return $data; |