Re: [time-nuts] Oncore Checksums

2008-04-17 Thread Matthew Smith
Quoth Chris Kuethe at 2008-04-18 11:29...
> yeah, i should've mentioned, that's function i use to check the sum,
> not compute it. return b instead, or just patch the buffer inside the
> function:
Ah, thanks.  I suppose I should use that checksum checker in the Nixie 
clock I'm building.  I'm going to set the receiver up in polled mode, do 
the initial time set against the receiver then sanity-check the time 
every now and then.  It would probably make sense to check the data 
checksum before I go and set the clock with it.  Clock will get its 
'tick' from the 1PPS signal.

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

___
time-nuts mailing list -- time-nuts@febo.com
To unsubscribe, go to https://www.febo.com/cgi-bin/mailman/listinfo/time-nuts
and follow the instructions there.


Re: [time-nuts] Oncore Checksums

2008-04-17 Thread Chris Kuethe
On Thu, Apr 17, 2008 at 6:51 PM, Matthew Smith <[EMAIL PROTECTED]> wrote:
> Quoth Chris Kuethe at 2008-04-18 10:59...
>
> > 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;
>  > }
>
>  'Scuse me for being something of a C newbie, but does that not return
>  either a 1 or a 0, but not the checksum?
>
>  Otherwise, I can follow the logic.  Thanks.

yeah, i should've mentioned, that's function i use to check the sum,
not compute it. return b instead, or just patch the buffer inside the
function:

void
oncore_add_checksum(char *buf, int len){
unsigned char b;
int i;

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


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

___
time-nuts mailing list -- time-nuts@febo.com
To unsubscribe, go to https://www.febo.com/cgi-bin/mailman/listinfo/time-nuts
and follow the instructions there.


Re: [time-nuts] Oncore Checksums

2008-04-17 Thread Matthew Smith
Quoth Chris Kuethe at 2008-04-18 10:59...
> 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;
> }

'Scuse me for being something of a C newbie, but does that not return 
either a 1 or a 0, but not the checksum?

Otherwise, I can follow the logic.  Thanks.


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

___
time-nuts mailing list -- time-nuts@febo.com
To unsubscribe, go to https://www.febo.com/cgi-bin/mailman/listinfo/time-nuts
and follow the instructions there.


Re: [time-nuts] Oncore Checksums

2008-04-17 Thread Chris Kuethe
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 <[EMAIL PROTECTED]> 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 [EMAIL PROTECTED];
>
>  # Check that we have one argument
>  # and that it begins with @@
>  if ($argc!=1 || $ARGV[0]!~/[EMAIL PROTECTED]@/)
>  {
>print "Usage: $0 [EMAIL PROTECTED]@[message]\n";
>exit;
>  }
>
>  # Set $instring to be the given
>  # argument, strip of the initial
>  # @@.
>  my $instring=$ARGV[0];
>  $instring=~s/[EMAIL PROTECTED]@//;
>
>  # 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  {
>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 .
>  $outstring.='0x0d 0x0a';
>
>  # Return $outstring.
>  print "$outstring\n";
>
>
>  ___
>  time-nuts mailing list -- time-nuts@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?

___
time-nuts mailing list -- time-nuts@febo.com
To unsubscribe, go to https://www.febo.com/cgi-bin/mailman/listinfo/time-nuts
and follow the instructions there.