6 use Data::Dump qw(dump);
9 use Biblio::RFID::Reader;
10 use Biblio::RFID::RFID501;
13 my $evolis_dir = '/home/dpavlin/klin/Printer-EVOLIS'; # FIXME
14 use lib '/home/dpavlin/klin/Printer-EVOLIS/lib';
15 use Printer::EVOLIS::Parallel;
23 my $log_print = 'log.print';
24 mkdir $log_print unless -d $log_print;
28 'reader=s', => \$reader,
33 die "Usage: $0 print.txt\n" unless @ARGV;
37 foreach my $log_path ( glob( "$log_print/*.txt" ) ) {
38 warn "# loading $log_path";
39 open( my $in, '<', $log_path ) || die $!;
42 my ( $date, $sid, $nr ) = split(/,/,$_,3);
43 $programmed->{ $sid } = $nr;
44 $numbers->{ $nr } = $sid;
48 warn "# ", scalar keys %$numbers, " programmed cards found\n";
52 warn "# reading tab-delimited input: number login\@domain name surname\n";
55 my @a = split(/\t/,$_);
56 die "invalid: @a in line $_" if $a[0] !~ m/\d{12}/ && $a[1] !~ m/\@/;
57 push @queue, [ @a ] if ! $numbers->{ $a[0] };
61 @queue = sort { $a->[0] <=> $b->[0] } @queue;
63 print "# queue ", dump @queue;
65 my $rfid = Biblio::RFID::Reader->new( $reader );
66 $Biblio::RFID::debug = $debug;
72 , uc unpack('H2', $rfid->afi($tag))
74 , dump( Biblio::RFID::RFID501->to_hash( $rfid->blocks($tag) ) )
80 my @t = localtime(time);
81 return sprintf "%04d-%02d-%02dT%02d:%02d:%02d", $t[5]+1900,$t[4]+1,$t[3],$t[2],$t[1],$t[0];
86 my $log_path = "$log_print/" . iso_date . ".txt";
87 die "$log_path exists" if -e $log_path;
88 open(my $log, '>', $log_path) || die "$log_path: $!";
90 while ( $rfid->tags ) {
91 print "ERROR: remove all tags from output printer tray\n";
98 my @visible = $rfid->tags(
101 print localtime()." enter ", eval { tag($tag) };
104 if ( ! $programmed->{$tag} ) {
105 my $card = shift @queue;
106 my $number = $card->[0];
107 print "PROGRAM $tag $number\n";
111 $rfid->write_blocks( $tag => Biblio::RFID::RFID501->from_hash({ content => $number }) );
112 $rfid->write_afi( $tag => chr($afi) ) if $afi;
115 warn "RETRY PROGRAM $tag $number\n";
119 print $log iso_date, ",$tag,$number\n";
120 $programmed->{$tag} = $number;
128 print_card if $programmed->{$tag};
132 warn localtime()." visible: ",join(' ',@visible),"\n";
140 $counters->{$_} = $p->command("Rco;$_") foreach ( qw/p c a m n l b e f i k s/ );
147 print "QUEUE EMPTY - printing finished\n";
149 print "$log_path ", -s $log_path, " bytes created\n";
153 my @data = @{$queue[0]};
155 print "PRINT @data\n";
157 my $p = Printer::EVOLIS::Parallel->new( '/dev/usb/lp0' );
159 my $before = _counters $p;
163 print "insert card ", $p->command( 'Si' ),$/;
165 print "eject card ", $p->command( 'Ser' ),$/;
169 system "$evolis_dir/scripts/inkscape-render.pl", "$evolis_dir/card/ffzg-2010.svg", @data;
170 system "$evolis_dir/scripts/evolis-driver.pl out/$nr.front.pbm out/$nr.back.pbm > /dev/usb/lp0";
174 my $after = _counters $p;
176 if ( $before->{p} = $after->{p} - 2 ) {
177 print "OK printerd card $nr\n";
179 die "ERROR printing card $nr\n";
182 warn "# counters ", dump( $before, $after );