X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=scripts%2Fprint.pl;h=3bb7721bcfb9631e45f9d83084b64524775683e5;hb=bb93f2432b71bed8fed19472e014efa3a2063b68;hp=e887a6c8bd7e534a3647549e00854fc7b1f2cd5d;hpb=ad54a9807183ba09ea54dcd94a8515e7f40b2fc0;p=Biblio-RFID.git diff --git a/scripts/print.pl b/scripts/print.pl index e887a6c..3bb7721 100755 --- a/scripts/print.pl +++ b/scripts/print.pl @@ -6,8 +6,8 @@ use strict; use Data::Dump qw(dump); use Getopt::Long; use lib 'lib'; -use RFID::Biblio::Reader; -use RFID::Biblio::RFID501; +use Biblio::RFID::Reader; +use Biblio::RFID::RFID501; use Storable; my $evolis_dir = '/home/dpavlin/klin/Printer-EVOLIS'; # FIXME @@ -32,17 +32,21 @@ GetOptions( die "Usage: $0 print.txt\n" unless @ARGV; -my $persistant_path = '/tmp/programmed.storable'; my $programmed; my $numbers; -if ( -e $persistant_path ) { - $programmed = retrieve($persistant_path); - warn "# loaded ", scalar keys %$programmed, " programmed cards\n"; - foreach my $tag ( keys %$programmed ) { - $numbers->{ $programmed->{$tag} } = $tag; +foreach my $log_path ( glob( "$log_print/*.txt" ) ) { + warn "# loading $log_path"; + open( my $in, '<', $log_path ) || die $!; + while(<$in>) { + chomp; + my ( $date, $sid, $nr ) = split(/,/,$_,3); + $programmed->{ $sid } = $nr; + $numbers->{ $nr } = $sid; } } +warn "# ", scalar keys %$numbers, " programmed cards found\n"; + my @queue; my @done; warn "# reading tab-delimited input: number login\@domain name surname\n"; @@ -53,10 +57,13 @@ while(<>) { push @queue, [ @a ] if ! $numbers->{ $a[0] }; } +# sort by card number +@queue = sort { $a->[0] <=> $b->[0] } @queue; + print "# queue ", dump @queue; -my $rfid = RFID::Biblio::Reader->new( $reader ); -$RFID::Biblio::debug = $debug; +my $rfid = Biblio::RFID::Reader->new( $reader ); +$Biblio::RFID::debug = $debug; sub tag { my $tag = shift; @@ -64,7 +71,7 @@ sub tag { , " AFI: " , uc unpack('H2', $rfid->afi($tag)) , " " - , dump( RFID::Biblio::RFID501->to_hash( $rfid->blocks($tag) ) ) + , dump( Biblio::RFID::RFID501->to_hash( $rfid->blocks($tag) ) ) , $/ ; } @@ -98,11 +105,10 @@ do { my $card = shift @queue; my $number = $card->[0]; print "PROGRAM $tag $number\n"; - $rfid->write_blocks( $tag => RFID::Biblio::RFID501->from_hash({ content => $number }) ); - $rfid->write_afi( $tag => chr($afi) ); + $rfid->write_blocks( $tag => Biblio::RFID::RFID501->from_hash({ content => $number }) ); + $rfid->write_afi( $tag => chr($afi) ) if $afi; $programmed->{$tag} = $number; - store $programmed, $persistant_path; print $log iso_date, ",$tag,$number\n"; } @@ -120,6 +126,13 @@ do { sleep 1; } while $loop; +sub _counters { + my $p = shift; + my $counters; + $counters->{$_} = $p->command("Rco;$_") foreach ( qw/p c a m n l b e f i k s/ ); + return $counters; +} + sub print_card { if ( ! @queue ) { @@ -130,11 +143,15 @@ sub print_card { } my @data = @{$queue[0]}; - print "XXX print_card @data\n"; + my $nr = $data[0]; + print "PRINT @data\n"; + + my $p = Printer::EVOLIS::Parallel->new( '/dev/usb/lp0' ); + + my $before = _counters $p; if ( $test ) { - my $p = Printer::EVOLIS::Parallel->new( '/dev/usb/lp0' ); print "insert card ", $p->command( 'Si' ),$/; sleep 1; print "eject card ", $p->command( 'Ser' ),$/; @@ -142,10 +159,19 @@ sub print_card { } else { system "$evolis_dir/scripts/inkscape-render.pl", "$evolis_dir/card/ffzg-2010.svg", @data; - my $nr = $data[0]; system "$evolis_dir/scripts/evolis-driver.pl out/$nr.front.pbm out/$nr.back.pbm > /dev/usb/lp0"; } + my $after = _counters $p; + + if ( $before->{p} = $after->{p} - 2 ) { + print "OK printerd card $nr\n"; + } else { + die "ERROR printing card $nr\n"; + } + + warn "# counters ", dump( $before, $after ); + }