Improve broadcast support

This commit is contained in:
Pascal Serrarens 2024-09-23 10:05:02 +02:00
parent 9de2fa6492
commit 60516dec0d
2 changed files with 16 additions and 16 deletions

View File

@ -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)

View File

@ -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