From 60516dec0dc75ef06d0d0adfa0bcf59e880d9785 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Mon, 23 Sep 2024 10:05:02 +0200 Subject: [PATCH] Improve broadcast support --- NetworkSync.cpp | 26 +++++++++++++------------- NetworkSync.h | 6 +++--- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/NetworkSync.cpp b/NetworkSync.cpp index fc3039e..c9bb0bb 100644 --- a/NetworkSync.cpp +++ b/NetworkSync.cpp @@ -20,6 +20,7 @@ NetworkSync::NetworkSync(Roboid* roboid) { this->roboid = roboid; + this->networkId = 0; } void NetworkSync::ReceiveMessage(Roboid* roboid, unsigned char bytecount) { @@ -27,7 +28,6 @@ void NetworkSync::ReceiveMessage(Roboid* roboid, unsigned char bytecount) { switch (buffer[0]) { case NetworkIdMsg: - // this->networkId = NetworkIdMsg; ReceiveNetworkId(); break; } @@ -39,7 +39,7 @@ void NetworkSync::ReceiveMessage(Roboid* roboid, unsigned char bytecount) { void NetworkSync::ReceiveNetworkId() { this->networkId = buffer[1]; #ifdef RC_DEBUG - SERIALPORT.printf("_Received network Id %d\n", this->networkId); + SERIALPORT.printf("Received network Id %d\n", this->networkId); #endif SendName(roboid); SendModel(roboid); @@ -50,6 +50,17 @@ void NetworkSync::ReceiveNetworkId() { } } +void NetworkSync::PublishDevice() { + unsigned char ix = 0; + buffer[ix++] = DeviceMsg; + buffer[ix++] = 0; // No network ID + PublishBuffer(ix); + +#ifdef RC_DEBUG + SERIALPORT.printf("Publish Device\n"); +#endif +} + void NetworkSync::PublishState(Roboid* roboid) { SendPose(roboid); PublishPerception(roboid); @@ -208,17 +219,6 @@ void NetworkSync::SendPose(Thing* thing, bool recurse) { } } -void NetworkSync::PublishClient() { - unsigned char ix = 0; - buffer[ix++] = ClientMsg; - buffer[ix++] = 0; // No network ID - SendBuffer(ix); - -#ifdef RC_DEBUG - SERIALPORT.println("Sent new Client"); -#endif -} - void NetworkSync::PublishState(Sensor* sensor) { float* value = (float*)sensor->GetValue(); if (value == nullptr) diff --git a/NetworkSync.h b/NetworkSync.h index 07ef9d2..a848c14 100644 --- a/NetworkSync.h +++ b/NetworkSync.h @@ -14,7 +14,7 @@ class NetworkSync { NetworkSync() {}; NetworkSync(Roboid* roboid); - unsigned char networkId; + unsigned char networkId = 0; /// @brief Retreive and send the roboid state /// @param roboid The roboid for which the state is updated @@ -54,7 +54,7 @@ class NetworkSync { static const unsigned char InvestigateMsg = 0x81; static const unsigned char ModelMsg = 0x90; static const unsigned char NameMsg = 0x91; - static const unsigned char ClientMsg = 0xA0; + static const unsigned char DeviceMsg = 0xA0; static const unsigned char NetworkIdMsg = 0xA1; typedef void (*Buffer)(UInt8* buffer, UInt16 bufferSize); @@ -128,7 +128,7 @@ class NetworkSync { virtual void SendBuffer(unsigned char bufferSize); virtual void PublishBuffer(unsigned char bufferSize); - void PublishClient(); + void PublishDevice(); }; } // namespace RoboidControl