[time-nuts] Oncore Checksums
matt at smiffytech.com
Thu Apr 17 21:26:37 EDT 2008
I've been reading various notes on the Oncore protocol that have been
suggested to me and have written a little bit of Perl that - I think -
will output the correct set of bytes that should be sent to a receiver
given a specific message.
If anyone is able to verify that I've got this right (or wrong), it
would be appreciated, especially the checksum bit.
The code below has been written to display all values as 0xnn for ease
of reading. Once I know this is working, I'll convert this to a more
machine-friendly format. (Possibly as an array of chars, as this is
heading for a microcontroller.)
Smiffytech - Technology Consulting & Web Application Development
# Oncore message fixer-upper.
# Count number of arguments.
# Check that we have one argument
# and that it begins with @@
if ($argc!=1 || $ARGV!~/^\@\@/)
print "Usage: $0 \@\@[message]\n";
# Set $instring to be the given
# argument, strip of the initial
# Start $outstring with the hex
# representation of @@.
my $outstring='0x40 0x40 ';
# Convert each character to hex and
# do checksum stuff.
for (my $i=0; $i<length($instring); $i++)
# Handle the checksum bit.
# If we're on the 2nd character,
# XOR this character with the last.
# If we're past the 2nd character,
# XOR this character with the
# previous checksum.
# Convert the (decimal) checksum to
# Finish off $outstring with the hex
# representation of <CR><LF>.
# Return $outstring.
More information about the time-nuts