X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;ds=sidebyside;f=lib%2FRFID%2FSerial%2F3M810.pm;h=41e125c403b9d947877d454347cb79e1730650f8;hb=7832e5544c3d3e1535e3f019c939947265a0a7ae;hp=5aaf78b338aaea2a1847321e00772f5d7b707a2f;hpb=b008963cecfd48e87939e7bff97ef1265988bf4d;p=Biblio-RFID.git diff --git a/lib/RFID/Serial/3M810.pm b/lib/RFID/Serial/3M810.pm index 5aaf78b..41e125c 100644 --- a/lib/RFID/Serial/3M810.pm +++ b/lib/RFID/Serial/3M810.pm @@ -106,11 +106,15 @@ cmd( )}); } -sub tag_hex { uc(unpack('H16', shift)) } +=head2 inventory + + my @tags = inventory; + +=cut sub inventory { - my $inventory; + my @tags; cmd( 'FE 00 05', 'scan for tags', sub { my $data = shift; @@ -125,14 +129,14 @@ cmd( 'FE 00 05', 'scan for tags', sub { die "wrong length $tl for $nr tags: ",dump( $tags ) if $tl =! $nr * 8; foreach ( 0 .. $nr - 1 ) { - my $tag = tag_hex substr($tags, $_ * 8, 8); - $invetory->{$tag} ||= read_tag($tag); + push @tags, tag_hex substr($tags, $_ * 8, 8); } } }); - return $invetory; + warn "# tags ",dump @tags; + return @tags; } @@ -151,18 +155,18 @@ sub _matched { } } -sub read_tag { +sub read_blocks { my $tag = shift || confess "no tag?"; - warn "# read $tag\n"; + $tag = shift if ref($tag); my $tag_blocks; my $start = 0; cmd( - sprintf( "02 $tag %02x %02x", $start, $blocks ) => "read $tag $start/$blocks", sub { + sprintf( "02 $tag %02x %02x", $start, $blocks ) => "read_blocks $tag $start/$blocks", sub { my $data = shift; if ( my $rest = _matched $data => '02 00' ) { - my $tag = tag_hex substr($rest,0,8); + my $tag = hex_tag substr($rest,0,8); my $blocks = ord(substr($rest,8,1)); warn "# response from $tag $blocks blocks ",as_hex substr($rest,9); foreach ( 1 .. $blocks ) { @@ -176,6 +180,8 @@ sub read_tag { warn "FIXME ready? ",as_hex $test; } elsif ( my $rest = _matched $data => '02 06' ) { warn "ERROR ",as_hex($rest); + } else { + die "FIXME unsuported ",as_hex($rest); } });