On 10/10/05 11:30, Karsten Hilbert <[EMAIL PROTECTED]> wrote: > On Mon, Oct 10, 2005 at 10:20:18PM +0100, Chris Ridd wrote: > >>> I suggest XORing the data with/without the control characters. >> >> That occurred to me too, but recall the result is 16-bits wide. No amount of >> XORing 8-bit values will produce a result with stuff in the top byte. >> >> I tried doing a 16-bit sum too. No luck. >> >> I'd expect the algorithm being used to be either very simple, or easily >> implemented in extremely cheap hardware (or both). But not as simple as >> addition or XORing :-) > > Well :-) > > Using XON/XOFF flow control requires the checksum to be sent > not as binary but rather as an ASCII interpretation of the > binary value. Usually what's done is converting an 8 bit > binary value into it's two byte hex representation, eg. > value 255 becomes "FF". > > That should help...
Ah ha! If I add together all the bytes into an unsigned 8-bit variable, then convert that to hex, the result matches the meter's checksum. In C: int verify_checksum(const unsigned char *s, const char *hex) { unsigned char calculated = 0; while (*s) { calculated += *s++; } unsigned char purported; purported = strtol(hex, NULL, 16); if (purported == calculated) return 1; return 0; } The bytes of 's' include the leading "1" and the trailing 0x03, e.g.: 120051010\x0918:56\x09XC0824-0109 133-113-04 \x0d\x03 Thanks for the major clue :-) Cheers, Chris ------------------------ Yahoo! Groups Sponsor --------------------~--> Most low income households are not online. Help bridge the digital divide today! http://us.click.yahoo.com/cd_AJB/QnQLAA/TtwFAA/W4wwlB/TM --------------------------------------------------------------------~-> Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/openhealth/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/