rename module to Biblio::RFID
[Biblio-RFID.git] / scripts / scan.pl
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use Data::Dump qw(dump);
7 use Getopt::Long;
8 use lib 'lib';
9 use Biblio::RFID::Reader;
10 use Biblio::RFID::RFID501;
11
12 my $loop = 0;
13 my $reader;
14 my $debug = 0;
15
16 GetOptions(
17         'loop!'     => \$loop,
18         'reader=s', => \$reader,
19         'debug+'    => \$debug,
20 ) || die $!;
21
22 my $rfid = Biblio::RFID::Reader->new( $reader );
23 $Biblio::RFID::debug = $debug;
24
25 sub tag {
26         my $tag = shift;
27         return $tag
28                 , " AFI: "
29                 , uc unpack('H2', $rfid->afi($tag))
30                 , " "
31                 , dump( Biblio::RFID::RFID501->to_hash( $rfid->blocks($tag) ) )
32                 , $/
33                 ;
34 }
35
36 do {
37         my @visible = $rfid->tags(
38                 enter => sub {
39                         my $tag = shift;
40                         print localtime()." enter ", tag($tag);
41
42                 },
43                 leave => sub {
44                         my $tag = shift;
45                         print localtime()." leave ", tag($tag);
46                 },
47         );
48
49         warn localtime()." visible: ",join(' ',@visible),"\n";
50
51 } while $loop;