Can anyone help me with c++ code. I don't know much about CRC and the C++ sample is not making it easy for me.
I would like to send message from my application to a device using my serial port. The last two bytes of the message should have CRC (LSB) and CRC(MSB).
Sample CRC Calculation
//---------------------------------------------------------------------------
void UpdateCRC(unsigned short int *CRC, unsigned char x)
{
// This function uses the initial CRC value passed in the first
// argument, then modifies it using the single character passed
// as the second argument, according to a CRC-16 polynomial
// calculation used for HAI communication protocol.
// Arguments:
// CRC -- pointer to starting CRC value
// x -- new character to be processed
// Returns:
// The function does not return any values, but updates the variable
// pointed to by CRC
static int const Poly = 0xA001; // CRC-16 polynomial
int i;
bool flag;
*CRC ^= x;
for (i=0; i<8; i++)
{
flag = ((*CRC & 1) == 1);
*CRC = (unsigned short int)(*CRC >> 1);
if (flag)
*CRC ^= Poly;
}
return;
}