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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user