fix NO_STD issues

This commit is contained in:
Pascal Serrarens 2025-05-13 09:38:30 +02:00
parent 6265daea87
commit 40aab4dc7a
8 changed files with 73 additions and 19 deletions

View File

@ -1,5 +1,9 @@
#include "ArduinoParticipant.h"
#if !defined(NO_STD)
#include <iostream>
#endif
#if defined(ARDUINO)
#if defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266WiFi.h>
@ -29,7 +33,9 @@ void ParticipantUDP::Setup() {
#if defined(UNO_R4)
if (WiFi.status() == WL_NO_MODULE) {
#if !defined(NO_STD)
std::cout << "No network available!\n";
#endif
return;
}
#else
@ -42,11 +48,13 @@ void ParticipantUDP::Setup() {
udp = new WiFiUDP();
udp->begin(this->port);
#if !defined(NO_STD)
std::cout << "Wifi sync started local " << this->port;
if (this->remoteSite != nullptr)
std::cout << ", remote " << this->remoteSite->ipAddress << ":"
<< this->remoteSite->port << "\n";
#endif
#endif
}
void ParticipantUDP::GetBroadcastAddress() {
@ -57,8 +65,10 @@ void ParticipantUDP::GetBroadcastAddress() {
this->broadcastIpAddress = new char[broadcastIpString.length() + 1];
broadcastIpString.toCharArray(this->broadcastIpAddress,
broadcastIpString.length() + 1);
#if !defined(NO_STD)
std::cout << "Broadcast address: " << broadcastIpAddress << "\n";
#endif
#endif
}
void ParticipantUDP::Receive() {
@ -99,7 +109,9 @@ bool ParticipantUDP::Send(Participant* remoteParticipant, int bufferSize) {
int n = 0;
do {
if (n > 0) {
#if !defined(NO_STD)
std::cout << "Retry sending\n";
#endif
delay(10);
}
n++;

View File

@ -1,5 +1,7 @@
#include "NetworkIdMsg.h"
#include <iostream>
namespace RoboidControl {
NetworkIdMsg::NetworkIdMsg(const char* buffer) {

View File

@ -1,5 +1,9 @@
#include "ParticipantMsg.h"
#if !defined(NO_STD)
#include <iostream>
#endif
namespace RoboidControl {
ParticipantMsg::ParticipantMsg(char networkId) {
@ -13,7 +17,7 @@ ParticipantMsg::ParticipantMsg(const char* buffer) {
ParticipantMsg::~ParticipantMsg() {}
unsigned char ParticipantMsg::Serialize(char* buffer) {
#if defined(DEBUG)
#if defined(DEBUG) && !defined(NO_STD)
std::cout << "Send ParticipantMsg [" << (int)this->networkId << "] "
<< std::endl;
#endif

View File

@ -1,5 +1,9 @@
#include "TextMsg.h"
#if !defined(NO_STD)
#include <iostream>
#endif
namespace RoboidControl {
TextMsg::TextMsg(const char* text, unsigned char textLength) {
@ -24,7 +28,7 @@ unsigned char TextMsg::Serialize(char* buffer) {
if (this->textLength == 0 || this->text == nullptr)
return 0;
#if defined(DEBUG)
#if defined(DEBUG) && !defined(NO_STD)
std::cout << "Send TextMsg " << (int)this->textLength << " " << this->text << std::endl;
#endif
unsigned char ix = 0;

View File

@ -112,7 +112,8 @@ void Participant::Remove(Thing* thing) {
#pragma region ParticipantRegistry
Participant* ParticipantRegistry::Get(const char* ipAddress,
unsigned int port) {
unsigned int port) {
#if !defined(NO_STD)
for (Participant* participant : ParticipantRegistry::participants) {
if (participant == nullptr)
continue;
@ -125,10 +126,12 @@ Participant* ParticipantRegistry::Get(const char* ipAddress,
}
std::cout << "Could not find participant " << ipAddress << ":" << (int)port
<< std::endl;
#endif
return nullptr;
}
Participant* ParticipantRegistry::Get(unsigned char participantId) {
#if !defined(NO_STD)
for (Participant* participant : ParticipantRegistry::participants) {
if (participant == nullptr)
continue;
@ -136,11 +139,12 @@ Participant* ParticipantRegistry::Get(unsigned char participantId) {
return participant;
}
std::cout << "Could not find participant " << (int)participantId << std::endl;
#endif
return nullptr;
}
Participant* ParticipantRegistry::Add(const char* ipAddress,
unsigned int port) {
unsigned int port) {
Participant* participant = new Participant(ipAddress, port);
Add(participant);
return participant;
@ -152,19 +156,19 @@ void ParticipantRegistry::Add(Participant* participant) {
if (foundParticipant == nullptr) {
#if defined(NO_STD)
this->things[this->thingCount++] = thing;
//this->things[this->thingCount++] = thing;
#else
ParticipantRegistry::participants.push_back(participant);
#endif
std::cout << "Add participant " << participant->ipAddress << ":"
<< participant->port << "[" << (int)participant->networkId
<< "]\n";
std::cout << "participants " << ParticipantRegistry::participants.size()
<< "\n";
} else {
std::cout << "Did not add, existing participant " << participant->ipAddress
<< ":" << participant->port << "[" << (int)participant->networkId
<< "]\n";
// std::cout << "Add participant " << participant->ipAddress << ":"
// << participant->port << "[" << (int)participant->networkId
// << "]\n";
// std::cout << "participants " << ParticipantRegistry::participants.size()
// << "\n";
// } else {
// std::cout << "Did not add, existing participant " << participant->ipAddress
// << ":" << participant->port << "[" << (int)participant->networkId
// << "]\n";
}
}
@ -172,9 +176,15 @@ void ParticipantRegistry::Remove(Participant* participant) {
// participants.remove(participant);
}
#if defined(NO_STD)
Participant** ParticipantRegistry::GetAll() const {
return ParticipantRegistry::participants;
}
#else
const std::list<Participant*>& ParticipantRegistry::GetAll() const {
return ParticipantRegistry::participants;
}
#endif
#pragma endregion ParticipantRegistry

View File

@ -31,13 +31,19 @@ class ParticipantRegistry {
/// @param participant The participant to remove
void Remove(Participant* participant);
private:
#if defined(NO_STD)
public:
Participant** GetAll() const;
int count = 0;
private:
Participant** participants;
#else
public:
/// @brief Get all participants
/// @return All participants
const std::list<Participant*>& GetAll() const;
private:
#if defined(NO_STD)
#else
private:
/// @brief The list of known participants
std::list<Participant*> participants;
#endif

View File

@ -143,7 +143,13 @@ void ParticipantUDP::UpdateMyThings(unsigned long currentTimeMs = 0) {
}
void ParticipantUDP::UpdateOtherThings(unsigned long currentTimeMs = 0) {
#if defined(NO_STD)
Participant** participants = Participant::registry.GetAll();
for (int ix = 0; ix < Participant::registry.count; ix++) {
Participant* participant = participants[ix];
#else
for (Participant* participant : Participant::registry.GetAll()) {
#endif
if (participant == nullptr || participant == this)
continue;
@ -441,7 +447,7 @@ void ParticipantUDP::Process(Participant* sender, ModelUrlMsg* msg) {
}
void ParticipantUDP::Process(Participant* sender, PoseMsg* msg) {
#if !defined(DEBUG)
#if !defined(DEBUG) && !defined(NO_STD)
std::cout << this->name << ": process PoseMsg [" << (int)this->networkId
<< "/" << (int)msg->networkId << "] " << (int)msg->poseType << "\n";
#endif

View File

@ -31,7 +31,13 @@ void SiteServer::UpdateMyThings(unsigned long currentTimeMs) {
if (this->isIsolated == false) {
// Send to all other participants
#if defined(NO_STD)
Participant** participants = Participant::registry.GetAll();
for (int ix = 0; ix < Participant::registry.count; ix++) {
Participant* participant = participants[ix];
#else
for (Participant* participant : Participant::registry.GetAll()) {
#endif
if (participant == nullptr || participant == this)
continue;
@ -71,8 +77,12 @@ void SiteServer::Process(Participant* sender, ThingMsg* msg) {
if (msg->parentId != 0) {
thing->SetParent(Get(msg->parentId));
if (thing->GetParent() != nullptr)
#if defined(NO_STD)
;
#else
std::cout << "Could not find parent [" << (int)msg->networkId << "/"
<< (int)msg->parentId << "]\n";
#endif
} else
thing->SetParent(nullptr);
}