Add i2c_message_t and use it all across the codebase. This will allow handling variable-length I2C messages and validation with minimal effort. The test LED and brightness PWM update features got temporarily broken and will fix them soon.
This commit is contained in:
@@ -36,21 +36,20 @@ void crc16_finalize(crc16_data_t *crc16Config, uint16_t *hash)
|
||||
|
||||
crc16_data_t crc16data;
|
||||
|
||||
void CRC16_AppendToMessage(uint8_t *message, uint32_t lengthInBytes)
|
||||
void CRC16_UpdateMessageChecksum(i2c_message_t *message)
|
||||
{
|
||||
uint16_t hash;
|
||||
crc16_init(&crc16data);
|
||||
crc16_update(&crc16data, message, lengthInBytes);
|
||||
crc16_update(&crc16data, message->data, message->length);
|
||||
crc16_finalize(&crc16data, &hash);
|
||||
message[lengthInBytes] = hash & 0xff;
|
||||
message[lengthInBytes+1] = hash >> 8;
|
||||
message->crc = hash;
|
||||
}
|
||||
|
||||
bool CRC16_IsMessageValid(uint8_t *message, uint32_t lengthInBytes)
|
||||
bool CRC16_IsMessageValid(i2c_message_t *message)
|
||||
{
|
||||
uint16_t hash;
|
||||
crc16_init(&crc16data);
|
||||
crc16_update(&crc16data, message, lengthInBytes);
|
||||
crc16_update(&crc16data, message->data, message->length);
|
||||
crc16_finalize(&crc16data, &hash);
|
||||
return (message[lengthInBytes] == (hash & 0xff)) && (message[lengthInBytes+1] == (hash >> 8));
|
||||
return message->crc == hash;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user