4ca1e4820ad4a530043cb75438ad1a6d274302f3
[Printer-EVOLIS.git] / scripts / evolis-command.pl
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use Data::Dump qw(dump);
7 use Time::HiRes;
8 use Getopt::Long;
9 use Term::ReadLine;
10 use lib 'lib';
11 use Printer::EVOLIS::Parallel;
12
13 my $port = '/dev/usb/lp0';
14 my $debug = 0;
15
16 GetOptions(
17         'debug+' => \$debug,
18         'port=s' => \$port,
19 ) || die $!;
20
21 warn "# port $port debug $debug\n";
22
23 my $parallel = Printer::EVOLIS::Parallel->new( $port );
24 $Printer::EVOLIS::Parallel::debug = $debug;
25 sub cmd { $parallel->command( "\e$_[0]\r" ) }
26
27 my $term = Term::ReadLine->new('EVOLIS');
28 my $OUT = $term->OUT || \*STDOUT;
29
30 #select($OUT); $|=1;
31
32
33
34 my @help;
35 {
36         open(my $fh, '<', 'docs/commands.txt');
37         @help = <$fh>;
38         warn "# help for ", $#help + 1, " comands, grep with /search_string\n";
39 }
40
41 print $OUT "Printer model ", cmd('Rtp'),"\n";
42 print $OUT "Printer s/no  ", cmd('Rsn'),"\n";
43 print $OUT "Kit head no   ", cmd('Rkn'),"\n";
44 print $OUT "Firmware      ", cmd('Rfv'),"\n";
45 print $OUT "Mac address   ", cmd('Rmac'),"\n";
46 print $OUT "IP address    ", cmd('Rip'),"\n";
47
48 while ( defined ( $_ = $term->readline('command> ')) ) {
49         chomp;
50
51         if ( m{^/(.*)} ) {
52                 print $OUT $_ foreach grep { m{$1}i } @help;
53                 next;
54         }
55
56         my $send = "\e$_\r";
57
58         my $response = $parallel->command( $send );
59
60         $term->addhistory($_) if $response;
61
62         print $OUT "<answer ",dump($response),"\n";
63
64 }
65