#include "message.h" #include "crc.h" enum MESSAGEERR message_validate(const union Message* message) { uint16_t length = (message->header.length_h & 0x3) * 0xFF + message->header.length_l; if(message->header.crc != crc8(message, 3)) return MESSAGEERR_HEADERCRC; struct Footer* footer = (void*)message + length - sizeof(struct Footer); if(footer->crc != crc16(message, length - sizeof(struct Footer))) return MESSAGEERR_FOOTERCRC; return MESSAGEERR_NONE; }