Checksum for cash register packet
Posted on 2004-08-21
I have problem finding the right checksum for this packet.
Checksum is CRC-like type except for the table.
This is "Datecs" cash registers and the packet that is sent trough RS-232 from PC. For now, i'm looking for easy solution (not decompiling executive of the program that does the communication or disassemble the firmware to find it out).
Here it is:
#$0A R2;1; #$0D #$18 #$78 - This command is a "read" with subcommand 2 and article no. 1.
#$0A I0;1; #$0D #$5A #$51 - Don't remember what this command does, but it's using the same scheme
Here's the format:
"All bytes in the block are ASCII characters except the two control bytes CRC.
A sucessful transmission of a block from the ECR includes transmitting of:
- control character for beginning of a block BEG ( 0A HEX or ^J)
- data bytes
- control symbol for end of block END ( 0D HEX or ^M)
- 2 control bytes CRC."
So, i need the way to calculate last 2 numbers from the packet - in first case $1878 and in the second $5A51.
Here's the explanation of the manufacturers (very unclear) - looks like some CRC16, but it's not alike anything i ever see:
The two CRC bytes are calculated according to the formula x^15 + 1. In the calculation are included all data bytes plus the byte for block end. Every byte passes through the calculation register from teh MSB to LSB.
Three working bytes are used - S1, S0 and TR
S1 - Most significant byte from the CRC ( it is transmitted immediatelly after END)
S0 - Least significant byte from the CRC ( It is transmitted after S1)
TR - the current transmitted byte in the block.
The CRC is calculated as follows:
1. S1 and S0 are zeroed
2. TR is loaded with the current transmitted byte. The byte is transmitted.
3. Points 3.1 and 3.2 are executed 8 times:
3.1. S1, S0 and TR are shifted one bit to the left.
3.2. If the carry bit from S1 is 1, the MSB of S1 and LSB of S0 are inverted.
Points 2 and 3 are executed for all bytes, included in the calculation of the CRC - from the first byte after BEG up to and including byte END.
4. TR is loaded with 0 and point 3 is executed
5. TR is loaded with 0 and point 3 is executed
6. Byte S1 is transmitted
7. Byte S0 is transmitted