I have a script that reads CAN bus signals and displays them to screen but I need to add a signal counter and frequency.
So I need to count how many times has this $id appeared so far and how many milliseconds ago did was it added to the hash table.
#!/usr/bin/perl -w
use strict;
open my $can_bus, "./receivetest |"
or die "Couldn't read from CAN bus: $!";
my %last_value;
while (<$can_bus>) {
if( /^(........:...) (........) (.*)$/ )
{
my ($something, $id, $payload) = ($1,$2,$3);
$last_value{ $id } = $payload;
system('clear'); #clear screen
#Print Table
for my $id (sort keys %last_value) {
print "$id\t $last_value{ $id }\n";
}
}
else {
warn "ignore unknown line: ";
warn $_;
}
}
This is my code so far.