first draft of mon-functioning SIP2 selfcheck
[Biblio-RFID.git] / scripts / program.pl
index 443e475..755a5ea 100755 (executable)
@@ -11,24 +11,33 @@ use Biblio::RFID::RFID501;
 
 my $reader;
 my $afi;
+my $debug = 0;
+my $hash;
 
 GetOptions(
        'reader=s', => \$reader,
        'afi=i',    => \$afi,
+       'debug+',   => \$debug,
+       'set=i'         => \$hash->{set},
+       'total=i',      => \$hash->{total},
+       'type=i',       => \$hash->{type},
+       'branch=i',     => \$hash->{branch},
+       'library=i'     => \$hash->{library},
 ) || die $!;
 
 my ( $sid, $content ) =  @ARGV;
-die "usage: $0 [--reader regex_filter] [--afi 214] E0_RFID_SID [barcode]\n" unless $sid && ( $content | $afi );
-
-my @rfid = Biblio::RFID::Reader->available( $reader );
-
-foreach my $rfid ( @rfid ) {
-       my $visible = $rfid->scan;
-       foreach my $tag ( keys %$visible ) {
-               next unless $tag eq $sid;
-               warn "PROGRAM $tag with $content\n";
-               $rfid->write_blocks( $tag => Biblio::RFID::RFID501->from_hash({ content => $content }) );
-               $rfid->write_afi(    $tag => chr($afi) ) if $afi;
-       }
+die "usage: $0 [--reader regex_filter] [--afi 214] [--type 1] E0_RFID_SID [barcode]\n" unless $sid && ( $content | $afi );
+
+$hash->{content} = $content if defined $content;
+
+my $rfid = Biblio::RFID::Reader->new( $reader );
+$Biblio::RFID::debug = $debug;
+
+foreach my $tag ( $rfid->tags ) {
+       warn "visible $tag\n";
+       next unless $tag eq $sid;
+       warn "PROGRAM $tag with $content\n";
+       $rfid->write_blocks( $tag => Biblio::RFID::RFID501->from_hash($hash) );
+       $rfid->write_afi(    $tag => chr($afi) ) if $afi;
 }