X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=scripts%2Fprogram.pl;h=565bb2a178b0fa2648f354e2a2e1a3b75b130d1f;hb=201b8a9ac971a3039f101ed0bbb87a6ceec78f91;hp=122a81a35c138038968a48794a7dc78cf1c2bac7;hpb=85d5a59bbac6392a0b691774cdc6f580be3ec100;p=Biblio-RFID.git diff --git a/scripts/program.pl b/scripts/program.pl index 122a81a..565bb2a 100755 --- a/scripts/program.pl +++ b/scripts/program.pl @@ -6,29 +6,54 @@ use strict; use Data::Dump qw(dump); use Getopt::Long; use lib 'lib'; -use RFID::Biblio::Readers; -use RFID::Biblio::RFID501; +use Biblio::RFID::Reader; +use Biblio::RFID::RFID501; my $reader; -my $afi; +my $afi = 0x00; +my $debug = 0; +my $hash; +my $blank; 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}, + '3mblank' => \$blank->{blank_3m}, + 'blank' => \$blank->{blank}, ) || die $!; my ( $sid, $content ) = @ARGV; -die "usage: $0 [--reader regex_filter] [--afi 214] E0_RFID_SID [barcode]\n" unless $sid && ( $content | $afi ); +if ( $sid =~ m/.+,.+/ && ! defined $content ) { + ( $sid, $content ) = split(/,/, $sid); +} + +die "usage: $0 [--reader regex_filter] [--afi 214] [--type 1] E0_RFID_SID [barcode]\n" unless $sid && ( $content || $afi || $blank ); -my @rfid = RFID::Biblio::Readers->available( $reader ); +$hash->{content} = $content if defined $content; -foreach my $rfid ( @rfid ) { - my $visible = $rfid->scan; - foreach my $tag ( keys %$visible ) { - next unless $tag eq $sid; +my $rfid = Biblio::RFID::Reader->new( $reader ); +$Biblio::RFID::debug = $debug; + +foreach my $tag ( $rfid->tags, $sid ) { + warn "visible $tag\n"; + next unless $tag eq $sid; + if ( grep { defined $_ } values %$blank ) { + my $type = ( grep { $blank->{$_} } keys %$blank )[0]; + warn "BLANK $type $tag\n"; + $rfid->write_blocks( $tag => Biblio::RFID::RFID501->$type ); + } elsif ( $content ) { warn "PROGRAM $tag with $content\n"; - $rfid->write_blocks( $tag => RFID::Biblio::RFID501->from_hash({ content => $content }) ); - $rfid->write_afi( $tag => chr($afi) ) if $afi; + $rfid->write_blocks( $tag => Biblio::RFID::RFID501->from_hash($hash) ); + } + if ( $afi ) { + warn "AFI $tag with $afi\n"; + $rfid->write_afi( $tag => chr($afi) ); } }