microsecond time resultion and delay from last transmission
authorDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 14 Oct 2016 12:31:51 +0000 (14:31 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 14 Oct 2016 12:31:51 +0000 (14:31 +0200)
serial.pl

index 6620593..63372d0 100755 (executable)
--- a/serial.pl
+++ b/serial.pl
@@ -3,6 +3,9 @@ use warnings;
 use strict;
 use Device::SerialPort;
 use Data::Dump qw(dump);
+use Time::HiRes qw(time);
+
+my $read_len = 255;
 
 $|=1;
 
@@ -17,13 +20,18 @@ $s->read_const_time(3);
 
 #$s->write('o');
 
+my $t = time();
+
 while (1) {
-       my ($len, $string) = $s->read(255);
+       my ($len, $string) = $s->read($read_len);
+       my $ts = time();
 
        if ( $len > 0 ) {
                my $hex = unpack('H*',$string);
                $hex =~ s/(..)/$1 /g;
-               printf "%s %2d  %s\n", time(), $len, $hex;
+               #printf "%s %2d  %s\n", time(), $len, $hex;
+               printf "%8.4f %0.4f %2d  %s\n", $ts, $ts - $t, $len, $hex;
+               $t = time();
        }
 }