in reply to Re^3: How to use perl digest module to calculate CRC?
in thread How to use perl digest module to calculate CRC?

First, thx for your support!

The reason I need it:

I'm acting as a transmitter, and I need to calculate the CRC and then send it along with the message.

The CRC algorithem that I'm using is not standard.

P = 1EDC6F41

Init value = FFFFFFFF

The file that I'm working on is generated by an in-house script that we have.

The address should not be part of the CRC calc. Only the HEX bytes.

All the lines in the file should be considered as one message.

So what should I do prior to send the data into the digest::CRC?

Thx again :)

Guy

  • Comment on Re^4: How to use perl digest module to calculate CRC?

Replies are listed 'Best First'.
Re^5: How to use perl digest module to calculate CRC?
by BrowserUk (Patriarch) on Mar 21, 2013 at 14:35 UTC
    I'm acting as a transmitter, and I need to calculate the CRC and then send it along with the message.

    Okay. But you still need to ensure that you calculate it in the same way that the receiver does; which means you need the full parameterisation of the algorithm used.

    What you've supplied so far is not enough information:

    The CRC algorithem that I'm using is not standard. P = 1EDC6F41 Init value = FFFFFFFF

    Hm. Looks an awful lot like this.

    But without the full parameters, this is only guesswork:

    #! perl -slw use strict; use Digest::CRC; my $o = Digest::CRC->new( width => 32, init => 0xffffffff, poly => 0x1edc6f41, xorout => 0xffffffff, refout => 1, refin =>1, cont => 1 ); while( <DATA> ) { my( $addrr, @hexBytes ) = split; my $data = pack 'H*', join '', @hexBytes; $o->add( $data ); } print $o->hexdigest; __END__ @0000 FF FF FF 02 24 E0 02 26 A9 02 21 B0 02 21 53 02 @0010 21 6A 02 21 EE 02 21 F5 02 25 55 02 22 7B 02 23 @0090 D2 AF D2 B8 75 1F 01 12 0B B1 75 15 00 E5 0B 20

    Note: You'll probably need $o->digest rather than $o->hexdigest.

    NB: But the above will probably fail because it is just guesswork. Also, you'll need to retain the packed data for transmission.


    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.