test on real device, scanning somewhat work other things don't yet
[safeq] / terminal-emulator.pl
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4
5 use Data::Dump qw(dump);
6
7 use IO::Socket::INET;
8
9 my $ip   = shift @ARGV || '127.0.0.1';
10 my $port = shift @ARGV || 4096;
11
12 my $socket = IO::Socket::INET->new(
13         PeerAddr => $ip,
14         PeerPort => $port,
15         Proto => 'tcp',
16 ) or die "ERROR $ip:$port - $!";
17
18 warn "# connected to $ip:$port\n";
19
20 my @send_receive = grep { /^.+$/ } split(/\n/, q{
21 .SQ 3.2.9 SQPR8463332F62E
22 .SQ OK
23
24 .CFG gd lang=HR
25 .CFG OK %s
26
27 .SERVER LIST
28 .ERROR NO-ENTERPRISE
29
30 .CARD E009000000009999
31 .CARD OK Ime Prezime (nobody@example.com)
32
33 .ACTION
34 .ACTION CMENUS0
35
36 .NOP
37 .NOP
38
39 .NOP
40 .NOP
41
42 .NOP
43 .NOP
44
45 .NOP
46 .NOP
47
48 .NOP
49 .NOP
50
51 .END
52 });
53
54 #warn "# send_receive=",dump( \@send_receive );
55
56 while ( @send_receive ) {
57         my $send   = shift @send_receive;
58         my $expect = shift @send_receive;
59         warn ">> $send\n";
60         print $socket "$send\r\n";
61         my $got = <$socket>;
62         $got =~ s/[\r\n]+$//;
63 warn "# send/expect/got ",dump($send,$expect,$got);
64         warn "<< $got\n";
65         if ( $expect ne $got ) {
66                 warn "ERROR expected [$expect] got [$got]\n";
67                 print "Response>";
68                 my $r = <STDIN>; chomp $r;
69                 print $socket "$r\r\n";
70         }
71
72 }
73
74 $socket->close();