User manual
Automation Protocol Appendix C – CRC Generation
Miranda Technologies Ltd Page 271
Appendix C
CRC Generation
The following C example demonstrates simple codes to format and send
messages to an Imagestore. Imagestore status returns and acknowledges are
ignored.
// Note these codes bear no relation to the ASCII defined
codes with similar names.
#define STX0 0x002
#define STX1 0x003
#define ACK0 0x004
#define ACK1 0x005
#define NAK 0x007
char stx = STX0;
const UINT lstab[] =
{
0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0,
0x0280, 0xc241, 0xc601, 0x06c0, 0x0780, 0xc741,
0x0500, 0xc5c1, 0xc481, 0x0440
};
const UINT mstab[] =
{
0x0000, 0xcc01, 0xd801, 0x1400, 0xf001, 0x3c00,
0x2800, 0xe401, 0xa001, 0x6c00, 0x7800, 0xb401,
0x5000, 0x9c01, 0x8801, 0x4400
};
void do_crc(INT8 ch, UINT16 * crcptr)
{
UINT tmp;
tmp = *crcptr ^ ch;
*crcptr = mstab[(tmp>>4) & 0xf] ^ lstab[tmp&0xf]
^ ((*crcptr) >> 8);
}
// Send a single command to an Imagestore, using printf style
formatting.
void remote_send(char * format,...)
{
UINT16 rem_crc = 0;
INT ch;