uint16_t CRC16_CCITT(const uint8_t *buffer, uint16_t buffer_length)
{
unsigned short crc = 0x0000;
unsigned char i;
while( buffer_length-- )
{
crc ^= *buffer++ << 8;
for( i = 0; i < 8; i++ )
crc = crc & 0x8000 ? ( crc << 1 ) ^ 0x8005 : crc << 1;
}
return crc;
}