#!/usr/bin/perl -w use strict; use warnings; # Call the script using # perl mpxcrc.pl fileofinterest.log # reveng.exe must be in the same directory # http://reveng.sourceforge.net/ # Expects input file to look like: # #15 00 #09 f3 84 f3 84 f3 84 c2 #0a 00 00 f3 84 f3 84 7a #88 f3 84 f3 84 f3 84 68 #3b 01 #01 f6 8e f6 8e f6 8e b6 #02 00 00 f6 8e f6 8e 58 #80 f6 e1 f6 e1 f6 dc ff #etc... my $length=0; my $crctest=""; my $rfchannel; my $packet; my $lineno=0; foreach my $line (<>) { $lineno++; my $length=length($line); if ($length==7) { if ($crctest ne "") { my $poly; my $init; # Sometimes with the data provided there are multiple possible poly and init values. # We read them all until we find a poly equal to 0x31 we use this one as we assume it to be correct # (Assumed because it gets the most hits) # If there isn't a match on 0x31 we save the last guess open(REVENG,"./reveng.exe -w 8 -s ".$crctest." |") || die "Open reveng failed: $! \n"; while () { chomp; #print $rfchannel." ".$_."\n"; ($poly, $init) = (/^width=8 poly=0x(..) init=0x(..)/); last if ($poly eq "31") } close(REVENG); # Print results print "lineno=".($lineno-4).",rfchan=".$rfchannel.",poly=0x".$poly.",init=0x".$init."\n"; } $rfchannel = substr($line,0, 2); $packet=""; $crctest=""; } else # ($length != 7) { $packet = trim($line); $crctest.= $packet." "; } } exit; sub trim { my $s = shift; $s =~ s/\s+//g; return $s };