added com2tcp windows binary i386
[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 = 0x00;
14 my $debug = 0;
15 my $hash;
16 my $blank;
17
18 GetOptions(
19         'reader=s', => \$reader,
20         'afi=i',    => \$afi,
21         'debug+',   => \$debug,
22         'set=i'         => \$hash->{set},
23         'total=i',      => \$hash->{total},
24         'type=i',       => \$hash->{type},
25         'branch=i',     => \$hash->{branch},
26         'library=i'     => \$hash->{library},
27         '3mblank'       => \$blank->{blank_3m},
28         'blank'         => \$blank->{blank},
29 ) || die $!;
30
31 my ( $sid, $content ) =  @ARGV;
32 if ( $sid =~ m/.+,.+/ && ! defined $content ) {
33         ( $sid, $content ) = split(/,/, $sid);
34 }
35
36 die "usage: $0 [--reader regex_filter] [--afi 214] [--type 1] E0_RFID_SID [barcode]\n" unless $sid && ( $content || $afi || $blank );
37
38 $hash->{content} = $content if defined $content;
39
40 my $rfid = Biblio::RFID::Reader->new( $reader );
41 $Biblio::RFID::debug = $debug;
42
43 foreach my $tag ( $rfid->tags, $sid ) {
44         warn "visible $tag\n";
45         next unless $tag eq $sid;
46         if ( grep { defined $_ } values %$blank ) {
47                 my $type = ( grep { $blank->{$_} } keys %$blank )[0];
48                 warn "BLANK $type $tag\n";
49                 $rfid->write_blocks( $tag => Biblio::RFID::RFID501->$type );
50         } elsif ( $content ) {
51                 warn "PROGRAM $tag with $content\n";
52                 $rfid->write_blocks( $tag => Biblio::RFID::RFID501->from_hash($hash) );
53         }
54         if ( $afi ) {
55                 warn "AFI $tag with $afi\n";
56                 $rfid->write_afi( $tag => chr($afi) );
57         }
58 }
59