Avisaro Online Documentation - Wiki
Impressum Kontakt Sitemap

CRC Computation

The CRC value of the packet commands can ether be ignored (0x00, 0x00) or used. This is the method the CRC is calculated for the packet commands:

(Note: This example is written for "little endian" machines - such as a PC or many microcontroller.)

#define INIT_CRC 0xffff

const UINT16 crc_tab[16] =
{
  0x0000, 0x1081, 0x2102, 0x3183,
  0x4204, 0x5285, 0x6306, 0x7387,
  0x8408, 0x9489, 0xA50A, 0xB58B,
  0xC60C, 0xD68D, 0xE70E, 0xF78F
};

// crc_update as macro
#define CRC_UPDATE(crc, d)\
{\
  crc = (crc >> 4) ^ crc_tab[(crc ^ d) & 0x000f];\
  crc = (crc >> 4) ^ crc_tab[(crc ^ (d >> 4)) & 0x000f];\
}

---------------------------------------------------

1. crc initialisieren:
UINT16 crc = INIT_CRC;

2. dann für alle bytes:
CRC_UPDATE (crc, byte[n]);
 
3. das Ergebnis bitweise invertieren. Fertig.
crc = ~crc;