7 use Time::HiRes qw(time);
8 use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK O_RDONLY);
10 our $PACKET_SIZE = 9; # 9 bytes + 0x05
13 my ($class, $args) = @_;
15 my $filename = $args->{filename}
16 or die "filename not specified";
18 my $parser = $args->{parser}
19 or die "parser not specified";
23 if ($filename eq '-') {
24 open($fh, '<&=STDIN');
25 my $flags = fcntl($fh, F_GETFL, 0);
26 fcntl($fh, F_SETFL, $flags | O_NONBLOCK);
28 system 'stty', '-F', $filename, '115200', 'raw';
30 die "stty died with code $? (no permissions?)";
33 sysopen($fh, $filename, O_RDONLY|O_NONBLOCK)
34 or die "Can't open $filename: $!";
38 filename => $filename,
48 sub fh { return shift->{fh}; }
54 my $bytes_read = sysread $self->fh, $data, $PACKET_SIZE;
55 die "Read error on $self->{filename}: $!"
60 my @bytes = unpack("C*", $data);
62 $self->{parser}->add_data($now, @bytes);