simplify serial dump format
authorDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 1 Mar 2017 12:21:34 +0000 (13:21 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 1 Mar 2017 12:21:34 +0000 (13:21 +0100)
serial.pl

index 63372d0..dd409e5 100755 (executable)
--- a/serial.pl
+++ b/serial.pl
@@ -7,11 +7,13 @@ use Time::HiRes qw(time);
 
 my $read_len = 255;
 
+my $path = shift @ARGV || '/dev/serial/by-path/platform-20980000.usb-usb-0:1.3.1:1.0-port0';
+
 $|=1;
 
-my $s = new Device::SerialPort( '/dev/ttyUSB0' ) || die $!;
+my $s = new Device::SerialPort( $path ) || die $!;
 $s->baudrate(2400);
-$s->databits(8);
+$s->databits(8); # 7
 $s->parity('none');
 $s->stopbits(1);
 $s->handshake('none');
@@ -22,6 +24,9 @@ $s->read_const_time(3);
 
 my $t = time();
 
+my $sym;
+my $chr = 'A';
+
 while (1) {
        my ($len, $string) = $s->read($read_len);
        my $ts = time();
@@ -29,8 +34,15 @@ while (1) {
        if ( $len > 0 ) {
                my $hex = unpack('H*',$string);
                $hex =~ s/(..)/$1 /g;
+=for later
+               my $ascii;
+               foreach ( split(/ /, $hex) ) {
+                       if ( ! exists $sym->{$_} ) {
+                               $chr++;
+                       $ascii 
+=cut
                #printf "%s %2d  %s\n", time(), $len, $hex;
-               printf "%8.4f %0.4f %2d  %s\n", $ts, $ts - $t, $len, $hex;
+               printf "%8.4f %6.2f %2d  %s\n", $ts, $ts - $t, $len, $hex;
                $t = time();
        }
 }