added all RFID501 fields
[Biblio-RFID.git] / scripts / program.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 $reader;
13 my $afi;
14 my $debug = 0;
15 my $hash;
16
17 GetOptions(
18         'reader=s', => \$reader,
19         'afi=i',    => \$afi,
20         'debug+',   => \$debug,
21         'set=i'         => \$hash->{set},
22         'total=i',      => \$hash->{total},
23         'type=i',       => \$hash->{type},
24         'branch=i',     => \$hash->{branch},
25         'library=i'     => \$hash->{library},
26 ) || die $!;
27
28 my ( $sid, $content ) =  @ARGV;
29 die "usage: $0 [--reader regex_filter] [--afi 214] [--type 1] E0_RFID_SID [barcode]\n" unless $sid && ( $content | $afi );
30
31 $hash->{content} = $content if defined $content;
32
33 my $rfid = Biblio::RFID::Reader->new( $reader );
34 $Biblio::RFID::debug = $debug;
35
36 foreach my $tag ( $rfid->tags ) {
37         warn "visible $tag\n";
38         next unless $tag eq $sid;
39         warn "PROGRAM $tag with $content\n";
40         $rfid->write_blocks( $tag => Biblio::RFID::RFID501->from_hash($hash) );
41         $rfid->write_afi(    $tag => chr($afi) ) if $afi;
42 }
43