LivoxProto1: Add en/disablePcloudDataReq()
Untested, but this should enable us to enable and disable data from the device.
This commit is contained in:
@@ -708,5 +708,98 @@ bool DisconnectMessage::validateCrc32() const
|
||||
return isValid;
|
||||
}
|
||||
|
||||
// StartStopSamplingMessage methods
|
||||
StartStopSamplingMessage::StartStopSamplingMessage()
|
||||
{
|
||||
// Initialize header
|
||||
header.sof = 0xAA;
|
||||
header.version = 1;
|
||||
header.length = sizeof(StartStopSamplingMessage) - sizeof(Header) - sizeof(Footer);
|
||||
header.cmd_type = 0x02; // MSG type
|
||||
header.seq_num = 0; // Will be set by caller if needed
|
||||
header.crc_16 = 0; // Will be calculated
|
||||
|
||||
// Initialize command
|
||||
command.cmd_set = 0x00; // General command set
|
||||
command.cmd_id = 0x04; // Sampling command ID
|
||||
|
||||
// Initialize data - enable flag will be set manually by caller
|
||||
enable = 0x00; // Default to stop, caller will override
|
||||
|
||||
// Initialize footer
|
||||
footer.crc_32 = 0; // Will be calculated
|
||||
}
|
||||
|
||||
uint32_t StartStopSamplingMessage::calculateCrc32() const
|
||||
{
|
||||
// Calculate CRC32 for the entire message excluding the footer CRC32 field
|
||||
const uint8_t* messageData = reinterpret_cast<const uint8_t*>(this);
|
||||
size_t messageSize = sizeof(StartStopSamplingMessage) - sizeof(footer.crc_32);
|
||||
|
||||
return comms::calculateCrc32(messageData, messageSize);
|
||||
}
|
||||
|
||||
void StartStopSamplingMessage::swapContentsToProtocolEndianness()
|
||||
{
|
||||
header.swapToProtocolEndianness();
|
||||
command.swapToProtocolEndianness();
|
||||
footer.swapToProtocolEndianness();
|
||||
}
|
||||
|
||||
|
||||
bool StartStopSamplingMessage::sanityCheck() const
|
||||
{
|
||||
return header.sanityCheck() && command.sanityCheck() && footer.sanityCheck();
|
||||
}
|
||||
|
||||
bool StartStopSamplingMessage::validateCrc32() const
|
||||
{
|
||||
uint32_t calculatedCrc = calculateCrc32();
|
||||
bool isValid = (calculatedCrc == footer.crc_32);
|
||||
|
||||
// Debug output only if validation fails
|
||||
if (!isValid)
|
||||
{
|
||||
std::cout << "StartStopSamplingMessage CRC32 Debug: calculated=0x"
|
||||
<< std::hex << calculatedCrc
|
||||
<< ", received=0x" << footer.crc_32 << std::dec << std::endl;
|
||||
}
|
||||
|
||||
return isValid;
|
||||
}
|
||||
|
||||
// SamplingResponse methods
|
||||
void SamplingResponse::swapContentsToHostEndianness()
|
||||
{
|
||||
header.swapToHostEndianness();
|
||||
command.swapToHostEndianness();
|
||||
footer.swapToHostEndianness();
|
||||
}
|
||||
|
||||
bool SamplingResponse::sanityCheck() const
|
||||
{
|
||||
return header.sanityCheck() && command.sanityCheck() && footer.sanityCheck();
|
||||
}
|
||||
|
||||
bool SamplingResponse::validateCrc32() const
|
||||
{
|
||||
// Calculate CRC32 for the entire message excluding the footer CRC32 field
|
||||
const uint8_t* messageData = reinterpret_cast<const uint8_t*>(this);
|
||||
size_t messageSize = sizeof(SamplingResponse) - sizeof(footer.crc_32);
|
||||
|
||||
uint32_t calculatedCrc = comms::calculateCrc32(messageData, messageSize);
|
||||
bool isValid = (calculatedCrc == footer.crc_32);
|
||||
|
||||
// Debug output only if validation fails
|
||||
if (!isValid)
|
||||
{
|
||||
std::cout << "SamplingResponse CRC32 Debug: calculated=0x"
|
||||
<< std::hex << calculatedCrc
|
||||
<< ", received=0x" << footer.crc_32 << std::dec << std::endl;
|
||||
}
|
||||
|
||||
return isValid;
|
||||
}
|
||||
|
||||
} // namespace comms
|
||||
} // namespace livoxProto1
|
||||
|
||||
Reference in New Issue
Block a user