Printer Job Language Technical Reference Manual
[safeq] / terminal-server.pl
index 6a1c94b..5d425ec 100755 (executable)
@@ -25,6 +25,7 @@ my $prices = {
        BW => 0.0, # just paper cost
        COLOR => 3.99, # FIXME
        DUPLEX => -0.05,
+       COPY => 0, # no additional price other than paper
 };
 
 
@@ -65,7 +66,7 @@ while(1) {
                        $line =~ s/[\r\n]+$//;
                        warn "<< $line\n";
                } else {
-                       warn "<< [NULL] connected: ",dump($client_socket), $client_socket->connected;
+                       warn "<< NULL ", $client_socket->connected ? '' : 'NOT ', "connected";
                }
 
                return $line;
@@ -89,6 +90,7 @@ while(1) {
        while ($client_socket->connected) {
 
                my $line = client_line;
+               last if ! defined $line;
 
                if ( $line =~ m/^\.SQ ([\d\.]+) (\S+)/ ) {
                        my ($version,$serial) = ($1,$2);
@@ -125,18 +127,18 @@ while(1) {
                        $total_charged += $charge;
                        $total_pages++;
                        client_send ".CREDIT ".credit;
-                       client_send ".COPY 1"; # I verified that you are allowed to copy 1 page?
+                       client_send ".COPY $total_pages"; # page copied
                        client_send ".NOP";
 
                } elsif ( $line =~ m/\.ACTION LIST/ ) {
 
                        client_send "2"; # nr of items in list
-                       #            status: 0/3
+                       #            status: 0 - pendng/3 - printed
                        #            | pages
                        #            | | title
                        #            | | |                   queue
                        client_send "3|1|Koha online catalog|XWC7232";
-                       client_send "3|1|Koha online catalog|XWC5225";
+                       client_send "0|1|Koha online catalog|XWC5225";
                        # FIXME
 
                } elsif ( $line =~ m/\.ACTION PRINT (ALL|\d+)/ ) {
@@ -192,8 +194,11 @@ while(1) {
                        # interface on terminal device will be unresponsive
                        $next_nop_t = time() + 5; # NOP every 5s?
                } elsif ( $line =~ m/^\.END/ ) {
-                       client_send  ".DONE BLK WAIT";
-                       $client_socket->close;
+                       client_send ".DONE BLK WAIT";
+                       client_send ".NOP";
+                       my $nr_jobs = 0; # FIXME
+                       client_send ".DONE $total_pages ".credit($total_charged);
+#                      $client_socket->close;
                } elsif (defined $line) {
                        warn "UNKNOWN: ",dump($line);
                        print "Response>";
@@ -201,7 +206,7 @@ while(1) {
                        chomp $r;
                        client_send $r;
                } else {
-                       warn "NULL line, connected ", $client_socket->connected;
+                       warn "NULL line ", $client_socket->connected ? '' : 'NOT ', "connected";
                }
        }
        warn "# return to accept";