??? 11/07/06 00:39 Modified: 11/07/06 00:41 Read: times |
#127468 - Done, definitively. Responding to: ???'s previous message |
A couple of things first:
- there are some 20h characters which I believe were 00h but went wrong during capturing (Hyperterminal); so for checksumming I put them back to 00h - there are 2 types of checksums, I guess it is different for PC->8051 and 8051->PC (although privately Russ told otherwise, I believe both directions are present in the given sample). First checksum: - clear 2 byte-wide registers - omit the leading 16h - from the first byte (length) subtract 1 - repeat for all bytes in body: - add byte to first register, ignore overflows - add first register to second register, ignore overflows - done. Second checksum: - clear 2 byte-wide registers - omit the leading 16h - repeat for all bytes in body: - add byte to first register, ignore overflows - add first register to second register, ignore overflows - subtract from zero both first and second register and place it back into first register - done. Some quasi C code from the C hater (please note that I deliberately abuse the non-checking property of C) - quasi because it is nasty, but I tried on PC and it works. #include <stdio.h> #include <stdlib.h> #include <string.h> unsigned char cs1, cs2; void csum(unsigned char c) { cs1 += c; cs2 += cs1; } int main(int argc,char *argv[]) { cs1 = cs2 = 0; csum(0x09-1); csum(0x10); csum(0x47); csum(0x4c); csum(0x41); csum(0x57); csum(0x01); csum(0x11); printf("Checksum type 1 of packet 16 09 10 47 4C 41 57 01 11 (55 F2) is %x %x.\n", (unsigned int) cs1, (unsigned int) cs2); cs1 = cs2 = 0; csum(0x09); csum(0x10); csum(0x47); csum(0x54); csum(0x50); csum(0x57); csum(0x01); csum(0x30); cs1 = 512 - cs1 - cs2; printf("Checksum type 2 of packet 16 09 10 47 54 50 57 01 30 (F7 7D) is %x %x.\n", (unsigned int) cs1, (unsigned int) cs2); return 0; } Jan Waclawek PS. Oh yes. It is not visible from these samples, but in the body of the data, the 16h would be doubled, but the second 16h not influencing the checksum. |
Topic | Author | Date |
A Real Contest!!! | 01/01/70 00:00 | |
Owww cannot we just assume that... | 01/01/70 00:00 | |
can you make it easier? | 01/01/70 00:00 | |
OP Update #1 | 01/01/70 00:00 | |
Done. | 01/01/70 00:00 | |
In C ? | 01/01/70 00:00 | |
For the $1... | 01/01/70 00:00 | |
duh beaten to it, | 01/01/70 00:00 | |
The contest is not over!!! | 01/01/70 00:00 | |
How much for ... | 01/01/70 00:00 | |
No C? How about this ... | 01/01/70 00:00 | |
Done, definitively. | 01/01/70 00:00 | |
Congratulations! | 01/01/70 00:00 | |
We have a winner! Jan\'s the man! | 01/01/70 00:00 | |
Christmas drinks at jan's place | 01/01/70 00:00 |