added emulator and improve server to interoperate
authorDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 21 Feb 2019 15:31:26 +0000 (16:31 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 21 Feb 2019 15:31:41 +0000 (16:31 +0100)
terminal-emulator.pl [new file with mode: 0755]
terminal-server.pl

diff --git a/terminal-emulator.pl b/terminal-emulator.pl
new file mode 100755 (executable)
index 0000000..9a4b485
--- /dev/null
@@ -0,0 +1,69 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+
+use Data::Dump qw(dump);
+
+use IO::Socket::INET;
+
+my $ip   = shift @ARGV || '127.0.0.1';
+my $port = shift @ARGV || 4096;
+
+my $socket = IO::Socket::INET->new(
+       PeerAddr => $ip,
+       PeerPort => $port,
+       Proto => 'tcp',
+) or die "ERROR $ip:$port - $!";
+
+warn "# connected to $ip:$port\n";
+
+my @send_receive = grep { /^.+$/ } split(/\n/, q{
+.SQ 3.2.9 SQPR8463332F62E
+.SQ OK
+
+.CFG gd lang=HR
+.CFG OK %s
+
+.SERVER LIST
+.ERROR NO-ENTERPRISE
+
+.CARD E009000000009999
+.CARD OK Ime Prezime (nobody@example.com)
+
+.ACTION
+.ACTION CMENUS0
+
+.NOP
+.NOP 
+
+
+.NOP
+.NOP 
+
+.NOP
+.NOP 
+
+.NOP
+.NOP 
+
+.NOP
+.NOP
+
+.END 
+});
+
+#warn "# send_receive=",dump( \@send_receive );
+
+while ( @send_receive ) {
+       my $send   = shift @send_receive;
+       my $expect = shift @send_receive;
+       warn ">> $send\n";
+       print $socket "$send\r\n";
+       my $got = <$socket>;
+       $got =~ s/[\r\n]+$//;
+warn dump($send,$expect,$got);
+       warn "<< $got\n";
+       die "ERROR expected [$expect] got [$got]" if $expect ne $got;
+}
+
+$socket->close();
index ca2fd57..3598ce2 100755 (executable)
@@ -2,6 +2,8 @@
 use warnings;
 use strict;
 
+use Data::Dump qw(dump);
+
 use IO::Socket::INET;
 
 $| = 1;
@@ -32,7 +34,8 @@ while(1) {
 
        while ($client_socket->connected) {
                my $line = <$client_socket>;
-               chomp $line;
+               $line =~ s/[\r\n]+$//;
+
                warn "<< $line\n";
 
                if ( $line =~ m/^\.SQ ([\d\.]+) (\S+)/ ) {
@@ -42,16 +45,16 @@ while(1) {
                } elsif ( $line =~ m/\.SERVER LIST/ ) {
                        client_send  ".ERROR NO-ENTERPRISE";
                } elsif ( $line =~ m/\.CARD (\S+)/ ) {
-                       client_send  ".CARD OK pero peric (pero\@example.com)";
+                       client_send  ".CARD OK Ime Prezime (nobody\@example.com)";
                } elsif ( $line =~ m/\.ACTION$/ ) {
-                       client_send  ".ACTION CMENUS2";
+                       client_send  ".ACTION CMENUS0"; # FIXME can be CMENUS2
                } elsif ( $line =~ m/\.ACTION COPY/ ) {
                        client_send  ".ACTION COPY";
                        client_send  ".COPY Mozete kopirati (pero)";
                } elsif ( $line =~ m/(\.NOP)/ ) {
                        client_send  "$1";
                } else {
-                       die "unknown: $line";
+                       die "UNKNOWN: ",dump($line);
                }
        }
 }