Files
salmanoff/commonLibs/livoxProto1/livoxProto1Protocol.cpp
T
hayodea 3e9eecc279 livoxProto1: Keep protocol headers pure;
Split the BroadcastListener, DiscoveredDevice and other concerns
out of the protocol header and implementation files.
2025-09-06 22:46:03 -04:00

59 lines
1.1 KiB
C++

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#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