Jalcock501 has asked for the wisdom of the Perl Monks concerning the following question:

Hi Guys

I am trying to write a script that reads in a constant stream of HEX lines and writes them out to screen in a (sort of) ascii table

_______________________ 0CFFE000|00|00|00|00|00|00|00|00| ----------------------- 18FEF501|00|00|00|00|00|00|00|00| ----------------------- IDENTIER| 8 sets of HEX bits | -----------------------
As it is streaming data I need to keep the identifier static and just update the bits as they come in. The data comes through like this:
12345678:123 0CFFE000 00 00 00 00 00 00 00 00 87654321:321 18FEF501 00 FF 32 C4 FF 00 00 00 43215678:132 0C11FF00 FF FF FF FF FF FF FF FF 12348765:312 18FFE100 23 E0 C1 0E FF 00 AC 00 43218765:112 00000000 01 FF FF FF FF FF FF FF 12345678:123 0CFFE000 01 00 00 00 00 00 00 00 87654321:321 18FEF501 00 00 00 00 00 00 00 00 43215678:132 0C11FF00 00 00 00 00 00 00 00 00 12348765:312 18FFE100 00 00 00 00 00 00 00 00 43218765:112 00000000 00 00 00 00 00 00 00 00 12345678:123 0CFFE000 00 00 00 00 00 00 00 00

Unfortuantely I have no idea how to handle constant data input. Would someone mind helping as I cannot find examples online either

Thanks

Jim

Replies are listed 'Best First'.
Re: Perl and Can Bus
by Corion (Patriarch) on Dec 12, 2014 at 14:48 UTC

    If you want to output the bytes received for 0CFFE000 and 18FEF501 onto a fixed screen position, the following could help. It's a very simplicistic approach:

    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 the table for my $id (sort keys %last_value) { print "$id\t$last_value{ $id }\n"; }; } else { warn "Ignoring unknown line:"; warn $_; }; };

    If you want something fancier than the flickering screen, you'll have to look at Curses (or NCurses).

      Hi Carion

      Thanks you have really helped

      I also need to count the amont of times an $id has been read and the elapse time between the messages, I'm not sure how to count entries in a hash, and I am trying to use the Time::Elapse module but if I doTime::Elapse->lapse($last_value{$id} = $payload); I get this output
      0C11FF00 00:00:00.002815 [00:00:00.000049 [00 00 00 00 00 00 00 00]] but I only want 0C11FF00 00:00:00.000049 [ 00 00 00 00 00 00 00 00]
      If I try to but the Time::Elapse anywhere else it errors or am I missing some control character to wrap around the $id

        You will have to show some code that reproduces the problem.

Re: Perl and Can Bus
by BrowserUk (Patriarch) on Dec 12, 2014 at 14:12 UTC
    Unfortuantely I have no idea how to handle constant data input.

    What is the source of the data stream?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      ./receivetest a pcan linux driver script
        ./receivetest a pcan linux driver script

        So that's an executable you have to run and it writes the data stream to stdout?


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Perl and Can Bus
by karlgoethebier (Abbot) on Dec 12, 2014 at 14:22 UTC

    You mean CAN bus?

    Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

      Yes CAN bus, the script to to take the output of the received CAN signals and write a report to screen that doesn't just stream down the page

        Thank you Jalcock501. I didn't know about Can bus until today.

        Update: Fixed some typos.

        Regards, Karl

        «The Crux of the Biscuit is the Apostrophe»