rename module to Biblio::RFID in source
[Biblio-RFID.git] / scripts / scan.pl
index 44156a7..ec61fd5 100755 (executable)
@@ -6,28 +6,48 @@ use strict;
 use Data::Dump qw(dump);
 use Getopt::Long;
 use lib 'lib';
-use RFID::Biblio::Reader;
-use RFID::Biblio::RFID501;
+use Biblio::RFID::Reader;
+use Biblio::RFID::RFID501;
 
 my $loop = 0;
 my $reader;
+my $debug = 0;
 
 GetOptions(
        'loop!'     => \$loop,
        'reader=s', => \$reader,
+       'debug+'    => \$debug,
 ) || die $!;
 
-my $rfid = RFID::Biblio::Reader->new( $reader );
+my $rfid = Biblio::RFID::Reader->new( $reader );
+$Biblio::RFID::debug = $debug;
+
+sub tag {
+       my $tag = shift;
+       return $tag
+               , " AFI: "
+               , uc unpack('H2', $rfid->afi($tag))
+               , " "
+               , dump( Biblio::RFID::RFID501->to_hash( $rfid->blocks($tag) ) )
+               , $/
+               ;
+}
 
 do {
-       my @visible = $rfid->tags;
-       foreach my $tag ( @visible ) {
-               print $tag
-                       , " AFI: "
-                       , uc unpack('H2', $rfid->afi($tag))
-                       , " "
-                       , dump( RFID::Biblio::RFID501->to_hash( $rfid->blocks($tag) ) )
-                       , $/
-                       ;
-       }
+       my @visible = $rfid->tags(
+               enter => sub {
+                       my $tag = shift;
+                       print localtime()." enter ", tag($tag);
+
+               },
+               leave => sub {
+                       my $tag = shift;
+                       print localtime()." leave ", tag($tag);
+               },
+       );
+
+       warn localtime()." visible: ",join(' ',@visible),"\n";
+
+       sleep 1;
+
 } while $loop;