From 7344fa676b8b19bc8c6274c24a40a3e8f162bdb5 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Mon, 24 Feb 2025 09:45:26 +0100 Subject: [PATCH] Fix namespace issues --- Arduino/Participant.cpp | 14 ++++++++------ Messages/LowLevelMessages.cpp | 2 +- Messages/Messages.h | 1 - Participant.cpp | 3 ++- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Arduino/Participant.cpp b/Arduino/Participant.cpp index fbba67b..30f22f6 100644 --- a/Arduino/Participant.cpp +++ b/Arduino/Participant.cpp @@ -3,8 +3,10 @@ #if defined(ARDUINO) #if defined(ARDUINO_ARCH_ESP8266) #include + #elif defined(ESP32) #include + #endif #endif @@ -12,7 +14,7 @@ namespace RoboidControl { namespace Arduino { void Participant::Setup(int localPort, const char* remoteIpAddress, int remotePort) { -#if ARDUINO +#if defined(ARDUINO) this->remoteIpAddress = remoteIpAddress; this->remotePort = remotePort; GetBroadcastAddress(); @@ -28,7 +30,7 @@ void Participant::Setup(int localPort, const char* remoteIpAddress, int remotePo } void Participant::GetBroadcastAddress() { -#if ARDUINO +#if defined(ARDUINO) IPAddress broadcastAddress = WiFi.localIP(); broadcastAddress[3] = 255; String broadcastIpString = broadcastAddress.toString(); @@ -39,7 +41,7 @@ void Participant::GetBroadcastAddress() { } void Participant::Receive() { -#if ARDUINO +#if defined(ARDUINO) int packetSize = udp.parsePacket(); while (packetSize > 0) { udp.read(buffer, packetSize); @@ -66,9 +68,9 @@ void Participant::Receive() { } bool Participant::Send(RemoteParticipant* remoteParticipant, int bufferSize) { -#if ARDUINO +#if defined(ARDUINO) udp.beginPacket(remoteParticipant->ipAddress, remoteParticipant->port); - udp.write(buffer, bufferSize); + udp.write((unsigned char*)buffer, bufferSize); udp.endPacket(); // std::cout << "Sent to " << this->remoteIpAddress << ":" @@ -84,7 +86,7 @@ bool Participant::Publish(IMessage* msg) { return true; udp.beginPacket(this->broadcastIpAddress, this->remotePort); - udp.write(buffer, bufferSize); + udp.write((unsigned char*)buffer, bufferSize); udp.endPacket(); // std::cout << "Publish to " << this->broadcastIpAddress << ":" diff --git a/Messages/LowLevelMessages.cpp b/Messages/LowLevelMessages.cpp index e951e1b..3f2d9d8 100644 --- a/Messages/LowLevelMessages.cpp +++ b/Messages/LowLevelMessages.cpp @@ -1,6 +1,6 @@ #include "LowLevelMessages.h" -#include "float16.h" +#include "LinearAlgebra/float16.h" namespace RoboidControl { diff --git a/Messages/Messages.h b/Messages/Messages.h index 1e96b1b..3624c5d 100644 --- a/Messages/Messages.h +++ b/Messages/Messages.h @@ -3,7 +3,6 @@ #include "LinearAlgebra/Spherical.h" #include "LinearAlgebra/SwingTwist.h" #include "Thing.h" -#include "float16.h" namespace RoboidControl { diff --git a/Participant.cpp b/Participant.cpp index bcecf6e..014e3e3 100644 --- a/Participant.cpp +++ b/Participant.cpp @@ -253,7 +253,8 @@ void Participant::Process(RemoteParticipant* sender, NameMsg* msg) { int nameLength = msg->nameLength; int stringLen = nameLength + 1; char* thingName = new char[stringLen]; - strcpy_s(thingName, stringLen, msg->name); + // Use strncpy with bounds checking for other platforms (Arduino, POSIX, ESP-IDF) + strncpy(thingName, msg->name, stringLen - 1); // Leave space for null terminator thingName[nameLength] = '\0'; thing->name = thingName; std::cout << "thing name = " << thing->name << " length = " << nameLength << "\n";