implement RFID::Serial->scan and test it
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 26 Jul 2010 22:11:46 +0000 (00:11 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 26 Jul 2010 22:11:46 +0000 (00:11 +0200)
lib/RFID/Serial.pm
t/10-3M-810.t
t/20-CPR-M02.t

index d23642c..e9435f6 100644 (file)
@@ -32,6 +32,7 @@ Perhaps a little code snippet.
     my $rfid = RFID::Serial->new(
                device => '/dev/ttyUSB0', # with fallback to RFID_DEVICE
        );
+       my $visible = $rfid->scan;
 
 =head1 SUBROUTINES/METHODS
 
@@ -74,6 +75,28 @@ sub port {
 
 }
 
+=head2 scan
+
+  my $visible = $rfid->scan;
+
+Returns hash with keys which match tag UID and values with blocks
+
+=cut
+
+sub scan {
+       my $self = shift;
+
+       warn "# scan tags in reader range\n";
+       my @tags = $self->inventory;
+
+       my $visible;
+       # FIXME this is naive implementation which just discards other tags
+       $visible->{$_} = $self->read_blocks( $_ )->{$_} foreach @tags;
+
+       return $visible;
+}
+
+
 =head1 MANDATORY IMPLEMENTATIONS
 
 Each reader must implement following hooks as sub-classes.
index 7a737a7..ae2e961 100755 (executable)
@@ -15,3 +15,7 @@ ok( my @tags = $o->inventory, 'inventory' );
 diag dump @tags;
 
 ok( my $blocks = $o->read_blocks( $_ ), "read_blocks $_" ) foreach @tags;
+
+ok( my $visible = $o->scan, 'scan' );
+diag dump $visible;
+
index 54c4a5d..fe4663d 100755 (executable)
@@ -15,3 +15,6 @@ ok( my @tags = $o->inventory, 'inventory' );
 
 ok( my $blocks = $o->read_blocks( $_ ), "read_blocks $_" ) foreach @tags;
 
+ok( my $visible = $o->scan, 'scan' );
+diag dump $visible;
+