#include #include #include #include #include "livoxProto1Protocol.h" namespace livoxProto1 { namespace comms { // Header methods void Header::swapToHostEndianness() { if (endian::isLittleEndian()) { return; } length = __builtin_bswap16(length); seq_num = __builtin_bswap16(seq_num); crc_16 = __builtin_bswap16(crc_16); } bool Header::sanityCheck() const { return (sof == 0xAA) && (version == 1); } // Footer methods void Footer::swapToHostEndianness() { if (endian::isLittleEndian()) { return; } crc_32 = __builtin_bswap32(crc_32); } bool Footer::sanityCheck() const { /** FIXME: * Add CRC validation here. */ return true; } // BroadcastMessage methods void BroadcastMessage::swapToHostEndianness() { if (endian::isLittleEndian()) { return; } header.swapToHostEndianness(); reserved = __builtin_bswap16(reserved); footer.swapToHostEndianness(); } bool BroadcastMessage::sanityCheck() const { return header.sanityCheck() && (cmd_set == 0x00) && (cmd_id == 0x00) && (header.cmd_type == 0x02) && footer.sanityCheck(); } } // namespace comms } // namespace livoxProto1