6 use Data::Dump qw(dump);
9 use RFID::Biblio::Reader;
10 use RFID::Biblio::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;
35 my $persistant_path = '/tmp/programmed.storable';
38 if ( -e $persistant_path ) {
39 $programmed = retrieve($persistant_path);
40 warn "# loaded ", scalar keys %$programmed, " programmed cards\n";
41 foreach my $tag ( keys %$programmed ) {
42 $numbers->{ $programmed->{$tag} } = $tag;
48 warn "# reading tab-delimited input: number login\@domain name surname\n";
51 my @a = split(/\t/,$_);
52 die "invalid: @a in line $_" if $a[0] !~ m/\d{12}/ && $a[1] !~ m/\@/;
53 push @queue, [ @a ] if ! $numbers->{ $a[0] };
56 print "# queue ", dump @queue;
58 my $rfid = RFID::Biblio::Reader->new( $reader );
59 $RFID::Biblio::debug = $debug;
65 , uc unpack('H2', $rfid->afi($tag))
67 , dump( RFID::Biblio::RFID501->to_hash( $rfid->blocks($tag) ) )
73 my @t = localtime(time);
74 return sprintf "%04d-%02d-%02dT%02d:%02d:%02d", $t[5]+1900,$t[4]+1,$t[3],$t[2],$t[1],$t[0];
79 my $log_path = "$log_print/" . iso_date . ".txt";
80 die "$log_path exists" if -e $log_path;
81 open(my $log, '>', $log_path) || die "$log_path: $!";
83 while ( $rfid->tags ) {
84 print "ERROR: remove all tags from output printer tray\n";
91 my @visible = $rfid->tags(
94 print localtime()." enter ", eval { tag($tag) };
97 if ( ! $programmed->{$tag} ) {
98 my $card = shift @queue;
99 my $number = $card->[0];
100 print "PROGRAM $tag $number\n";
101 $rfid->write_blocks( $tag => RFID::Biblio::RFID501->from_hash({ content => $number }) );
102 $rfid->write_afi( $tag => chr($afi) );
104 $programmed->{$tag} = $number;
105 store $programmed, $persistant_path;
107 print $log iso_date, ",$tag,$number\n";
114 print_card if $programmed->{$tag};
118 warn localtime()." visible: ",join(' ',@visible),"\n";
126 print "QUEUE EMPTY - printing finished\n";
128 print "$log_path ", -s $log_path, " bytes created\n";
132 my @data = @{$queue[0]};
133 print "XXX print_card @data\n";
137 my $p = Printer::EVOLIS::Parallel->new( '/dev/usb/lp0' );
138 print "insert card ", $p->command( 'Si' ),$/;
140 print "eject card ", $p->command( 'Ser' ),$/;
144 system "$evolis_dir/scripts/inkscape-render.pl", "$evolis_dir/card/ffzg-2010.svg", @data;
146 system "$evolis_dir/scripts/evolis-driver.pl out/$nr.front.pbm out/$nr.back.pbm > /dev/usb/lp0";