[time-nuts] Oncore Checksums

Chris Kuethe chris.kuethe at gmail.com
Thu Apr 17 21:29:50 EDT 2008


int
oncore_checksum(char *buf, int len){
	unsigned char a, b;
	int i;

	a = buf[len-3];
	b = '\0';
	for(i = 2; i < len - 3; i++)
		b ^= buf[i];
	if (a == b)
		return 0;
	return 1;
}


On Thu, Apr 17, 2008 at 6:26 PM, Matthew Smith <matt at smiffytech.com> wrote:
> Hi Folks
>
>  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.)
>
>  Cheers
>
>  M
>
>  --
>  Matthew Smith
>  Smiffytech - Technology Consulting & Web Application Development
>  Business: http://www.smiffytech.com/
>  Personal: http://www.smiffysplace.com/
>  LinkedIn: http://www.linkedin.com/in/smiffy
>
>
>  #!/usr/bin/perl -w
>
>  # Oncore message fixer-upper.
>
>  use strict;
>
>  # Count number of arguments.
>  my $argc=@ARGV;
>
>  # Check that we have one argument
>  # and that it begins with @@
>  if ($argc!=1 || $ARGV[0]!~/^\@\@/)
>  {
>    print "Usage: $0 \@\@[message]\n";
>    exit;
>  }
>
>  # Set $instring to be the given
>  # argument, strip of the initial
>  # @@.
>  my $instring=$ARGV[0];
>  $instring=~s/^\@\@//;
>
>  # Start $outstring with the hex
>  # representation of @@.
>  my $outstring='0x40 0x40 ';
>
>
>  # Convert each character to hex and
>  # do checksum stuff.
>  my ($cs,$last);
>  for (my $i=0; $i<length($instring); $i++)
>  {
>    my $thischar=ord(substr($instring,$i));
>    $outstring.=sprintf("0x%x ",$thischar);
>
>    # Handle the checksum bit.
>    if ($i==1)
>    {
>      # If we're on the 2nd character,
>      # XOR this character with the last.
>      $cs=$last^$thischar;
>    }
>    elsif ($i>1)
>    {
>      # If we're past the 2nd character,
>      # XOR this character with the
>      # previous checksum.
>      $cs=$cs^$thischar;
>    }
>
>    $last=$thischar;
>  }
>
>  # Convert the (decimal) checksum to
>  # hex.
>  $outstring.=sprintf("0x%x ",$cs);
>
>  # Finish off $outstring with the hex
>  # representation of <CR><LF>.
>  $outstring.='0x0d 0x0a';
>
>  # Return $outstring.
>  print "$outstring\n";
>
>
>  _______________________________________________
>  time-nuts mailing list -- time-nuts at febo.com
>  To unsubscribe, go to https://www.febo.com/cgi-bin/mailman/listinfo/time-nuts
>  and follow the instructions there.
>



-- 
GDB has a 'break' feature; why doesn't it have 'fix' too?



More information about the time-nuts mailing list