LivoxProto1: Add UdpCommandDemuxer.

We haven't genericized it with an unordered_map or integrated it
into device.cpp's async methods yet.
This commit is contained in:
2025-10-22 06:17:42 -04:00
parent 66a9db13c3
commit 10afec2532
7 changed files with 391 additions and 1 deletions
+50
View File
@@ -1743,4 +1743,54 @@ void Device::cleanupPcloudDataSocket()
pcloudDataActive.store(false);
}
void Device::handleUdpDgram(const uint8_t *data, ssize_t bytesReceived,
const struct sockaddr_in &senderAddr)
{
(void)senderAddr;
// Check minimum size for any valid protocol message
if (bytesReceived < static_cast<ssize_t>(
sizeof(comms::Header) + sizeof(comms::Command)))
{
// Too small for header + command
return;
}
// Extract command set and command ID from the first two bytes after the header
uint8_t cmd_set = data[sizeof(comms::Header)];
uint8_t cmd_id = data[sizeof(comms::Header) + 1];
// Route based on command type
if (cmd_set == 0x00 && cmd_id == 0x01)
{
// Handshake ACK - check if we have enough data for HandshakeResponse
if (bytesReceived >= static_cast<ssize_t>(
sizeof(comms::HandshakeResponse)))
{
std::cout << __func__ << ": Received handshake ACK from "
<< discoveredDevice.deviceIdentifier << std::endl;
}
}
else if (cmd_set == 0x00 && cmd_id == 0x03)
{
// Heartbeat ACK - check if we have enough data for HeartbeatMessage
if (bytesReceived >= static_cast<ssize_t>(
sizeof(comms::HeartbeatMessage)))
{
// Empty intentionally.
}
}
else if (cmd_set == 0x00 && cmd_id == 0x04)
{
// Sampling response - check if we have enough data for SamplingResponse
if (bytesReceived >= static_cast<ssize_t>(
sizeof(comms::SamplingResponse)))
{
std::cout << __func__ << ": Received sampling response from "
<< discoveredDevice.deviceIdentifier << std::endl;
}
}
// Unknown command types are silently ignored
}
} // namespace livoxProto1