Checksum calculation – Welch Allyn SureTemp PlusModule - User Manual User Manual

Page 37

Advertising
background image

SureTemp Plus Module OEM Implementation

Communications Protocol

Welch Allyn OEM Technologies

Confidential 37

Checksum Calculation

The checksum is a single-byte summation of all the data, including the control characters
(preamble, command, type, byte count, data, and so on).

After computing the checksum, send the negative of the checksum.

When receiving a message, sum all of the characters (including the checksum) into an unsigned
8-bit variable. The resulting summation must be zero, since the checksum equals the negative
value of all the bytes (excluding the checksum).

The following code sample sends bytes over the link:

extern void response(unsigned short size, const void *data)

{

unsigned char cksum;

unsigned char *ptr, c;

/* Initialize checksum */

ptr = (unsigned char*) data;

cksum=0;

while (size- -)

{

c = *ptr;

put_byte(c);

/* Send data byte */

cksum += c;

/* Update checksum */

ptr++;

/* Bump pointer to next byte to send */

}

put_byte(-cksum);

/* Send the negative of the checksum */

}

Advertising