fix NO_STD issues
This commit is contained in:
parent
6265daea87
commit
40aab4dc7a
@ -1,5 +1,9 @@
|
|||||||
#include "ArduinoParticipant.h"
|
#include "ArduinoParticipant.h"
|
||||||
|
|
||||||
|
#if !defined(NO_STD)
|
||||||
|
#include <iostream>
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(ARDUINO)
|
#if defined(ARDUINO)
|
||||||
#if defined(ARDUINO_ARCH_ESP8266)
|
#if defined(ARDUINO_ARCH_ESP8266)
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
@ -29,7 +33,9 @@ void ParticipantUDP::Setup() {
|
|||||||
|
|
||||||
#if defined(UNO_R4)
|
#if defined(UNO_R4)
|
||||||
if (WiFi.status() == WL_NO_MODULE) {
|
if (WiFi.status() == WL_NO_MODULE) {
|
||||||
|
#if !defined(NO_STD)
|
||||||
std::cout << "No network available!\n";
|
std::cout << "No network available!\n";
|
||||||
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -42,11 +48,13 @@ void ParticipantUDP::Setup() {
|
|||||||
udp = new WiFiUDP();
|
udp = new WiFiUDP();
|
||||||
udp->begin(this->port);
|
udp->begin(this->port);
|
||||||
|
|
||||||
|
#if !defined(NO_STD)
|
||||||
std::cout << "Wifi sync started local " << this->port;
|
std::cout << "Wifi sync started local " << this->port;
|
||||||
if (this->remoteSite != nullptr)
|
if (this->remoteSite != nullptr)
|
||||||
std::cout << ", remote " << this->remoteSite->ipAddress << ":"
|
std::cout << ", remote " << this->remoteSite->ipAddress << ":"
|
||||||
<< this->remoteSite->port << "\n";
|
<< this->remoteSite->port << "\n";
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParticipantUDP::GetBroadcastAddress() {
|
void ParticipantUDP::GetBroadcastAddress() {
|
||||||
@ -57,8 +65,10 @@ void ParticipantUDP::GetBroadcastAddress() {
|
|||||||
this->broadcastIpAddress = new char[broadcastIpString.length() + 1];
|
this->broadcastIpAddress = new char[broadcastIpString.length() + 1];
|
||||||
broadcastIpString.toCharArray(this->broadcastIpAddress,
|
broadcastIpString.toCharArray(this->broadcastIpAddress,
|
||||||
broadcastIpString.length() + 1);
|
broadcastIpString.length() + 1);
|
||||||
|
#if !defined(NO_STD)
|
||||||
std::cout << "Broadcast address: " << broadcastIpAddress << "\n";
|
std::cout << "Broadcast address: " << broadcastIpAddress << "\n";
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void ParticipantUDP::Receive() {
|
void ParticipantUDP::Receive() {
|
||||||
@ -99,7 +109,9 @@ bool ParticipantUDP::Send(Participant* remoteParticipant, int bufferSize) {
|
|||||||
int n = 0;
|
int n = 0;
|
||||||
do {
|
do {
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
|
#if !defined(NO_STD)
|
||||||
std::cout << "Retry sending\n";
|
std::cout << "Retry sending\n";
|
||||||
|
#endif
|
||||||
delay(10);
|
delay(10);
|
||||||
}
|
}
|
||||||
n++;
|
n++;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#include "NetworkIdMsg.h"
|
#include "NetworkIdMsg.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
namespace RoboidControl {
|
namespace RoboidControl {
|
||||||
|
|
||||||
NetworkIdMsg::NetworkIdMsg(const char* buffer) {
|
NetworkIdMsg::NetworkIdMsg(const char* buffer) {
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
#include "ParticipantMsg.h"
|
#include "ParticipantMsg.h"
|
||||||
|
|
||||||
|
#if !defined(NO_STD)
|
||||||
|
#include <iostream>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace RoboidControl {
|
namespace RoboidControl {
|
||||||
|
|
||||||
ParticipantMsg::ParticipantMsg(char networkId) {
|
ParticipantMsg::ParticipantMsg(char networkId) {
|
||||||
@ -13,7 +17,7 @@ ParticipantMsg::ParticipantMsg(const char* buffer) {
|
|||||||
ParticipantMsg::~ParticipantMsg() {}
|
ParticipantMsg::~ParticipantMsg() {}
|
||||||
|
|
||||||
unsigned char ParticipantMsg::Serialize(char* buffer) {
|
unsigned char ParticipantMsg::Serialize(char* buffer) {
|
||||||
#if defined(DEBUG)
|
#if defined(DEBUG) && !defined(NO_STD)
|
||||||
std::cout << "Send ParticipantMsg [" << (int)this->networkId << "] "
|
std::cout << "Send ParticipantMsg [" << (int)this->networkId << "] "
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
#include "TextMsg.h"
|
#include "TextMsg.h"
|
||||||
|
|
||||||
|
#if !defined(NO_STD)
|
||||||
|
#include <iostream>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace RoboidControl {
|
namespace RoboidControl {
|
||||||
|
|
||||||
TextMsg::TextMsg(const char* text, unsigned char textLength) {
|
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)
|
if (this->textLength == 0 || this->text == nullptr)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
#if defined(DEBUG)
|
#if defined(DEBUG) && !defined(NO_STD)
|
||||||
std::cout << "Send TextMsg " << (int)this->textLength << " " << this->text << std::endl;
|
std::cout << "Send TextMsg " << (int)this->textLength << " " << this->text << std::endl;
|
||||||
#endif
|
#endif
|
||||||
unsigned char ix = 0;
|
unsigned char ix = 0;
|
||||||
|
@ -113,6 +113,7 @@ void Participant::Remove(Thing* thing) {
|
|||||||
|
|
||||||
Participant* ParticipantRegistry::Get(const char* ipAddress,
|
Participant* ParticipantRegistry::Get(const char* ipAddress,
|
||||||
unsigned int port) {
|
unsigned int port) {
|
||||||
|
#if !defined(NO_STD)
|
||||||
for (Participant* participant : ParticipantRegistry::participants) {
|
for (Participant* participant : ParticipantRegistry::participants) {
|
||||||
if (participant == nullptr)
|
if (participant == nullptr)
|
||||||
continue;
|
continue;
|
||||||
@ -125,10 +126,12 @@ Participant* ParticipantRegistry::Get(const char* ipAddress,
|
|||||||
}
|
}
|
||||||
std::cout << "Could not find participant " << ipAddress << ":" << (int)port
|
std::cout << "Could not find participant " << ipAddress << ":" << (int)port
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
#endif
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Participant* ParticipantRegistry::Get(unsigned char participantId) {
|
Participant* ParticipantRegistry::Get(unsigned char participantId) {
|
||||||
|
#if !defined(NO_STD)
|
||||||
for (Participant* participant : ParticipantRegistry::participants) {
|
for (Participant* participant : ParticipantRegistry::participants) {
|
||||||
if (participant == nullptr)
|
if (participant == nullptr)
|
||||||
continue;
|
continue;
|
||||||
@ -136,6 +139,7 @@ Participant* ParticipantRegistry::Get(unsigned char participantId) {
|
|||||||
return participant;
|
return participant;
|
||||||
}
|
}
|
||||||
std::cout << "Could not find participant " << (int)participantId << std::endl;
|
std::cout << "Could not find participant " << (int)participantId << std::endl;
|
||||||
|
#endif
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,19 +156,19 @@ void ParticipantRegistry::Add(Participant* participant) {
|
|||||||
|
|
||||||
if (foundParticipant == nullptr) {
|
if (foundParticipant == nullptr) {
|
||||||
#if defined(NO_STD)
|
#if defined(NO_STD)
|
||||||
this->things[this->thingCount++] = thing;
|
//this->things[this->thingCount++] = thing;
|
||||||
#else
|
#else
|
||||||
ParticipantRegistry::participants.push_back(participant);
|
ParticipantRegistry::participants.push_back(participant);
|
||||||
#endif
|
#endif
|
||||||
std::cout << "Add participant " << participant->ipAddress << ":"
|
// std::cout << "Add participant " << participant->ipAddress << ":"
|
||||||
<< participant->port << "[" << (int)participant->networkId
|
// << participant->port << "[" << (int)participant->networkId
|
||||||
<< "]\n";
|
// << "]\n";
|
||||||
std::cout << "participants " << ParticipantRegistry::participants.size()
|
// std::cout << "participants " << ParticipantRegistry::participants.size()
|
||||||
<< "\n";
|
// << "\n";
|
||||||
} else {
|
// } else {
|
||||||
std::cout << "Did not add, existing participant " << participant->ipAddress
|
// std::cout << "Did not add, existing participant " << participant->ipAddress
|
||||||
<< ":" << participant->port << "[" << (int)participant->networkId
|
// << ":" << participant->port << "[" << (int)participant->networkId
|
||||||
<< "]\n";
|
// << "]\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,9 +176,15 @@ void ParticipantRegistry::Remove(Participant* participant) {
|
|||||||
// participants.remove(participant);
|
// participants.remove(participant);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(NO_STD)
|
||||||
|
Participant** ParticipantRegistry::GetAll() const {
|
||||||
|
return ParticipantRegistry::participants;
|
||||||
|
}
|
||||||
|
#else
|
||||||
const std::list<Participant*>& ParticipantRegistry::GetAll() const {
|
const std::list<Participant*>& ParticipantRegistry::GetAll() const {
|
||||||
return ParticipantRegistry::participants;
|
return ParticipantRegistry::participants;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#pragma endregion ParticipantRegistry
|
#pragma endregion ParticipantRegistry
|
||||||
|
|
||||||
|
@ -31,13 +31,19 @@ class ParticipantRegistry {
|
|||||||
/// @param participant The participant to remove
|
/// @param participant The participant to remove
|
||||||
void Remove(Participant* participant);
|
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
|
/// @brief Get all participants
|
||||||
/// @return All participants
|
/// @return All participants
|
||||||
const std::list<Participant*>& GetAll() const;
|
const std::list<Participant*>& GetAll() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#if defined(NO_STD)
|
|
||||||
#else
|
|
||||||
/// @brief The list of known participants
|
/// @brief The list of known participants
|
||||||
std::list<Participant*> participants;
|
std::list<Participant*> participants;
|
||||||
#endif
|
#endif
|
||||||
|
@ -143,7 +143,13 @@ void ParticipantUDP::UpdateMyThings(unsigned long currentTimeMs = 0) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ParticipantUDP::UpdateOtherThings(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()) {
|
for (Participant* participant : Participant::registry.GetAll()) {
|
||||||
|
#endif
|
||||||
if (participant == nullptr || participant == this)
|
if (participant == nullptr || participant == this)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -441,7 +447,7 @@ void ParticipantUDP::Process(Participant* sender, ModelUrlMsg* msg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ParticipantUDP::Process(Participant* sender, PoseMsg* 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
|
std::cout << this->name << ": process PoseMsg [" << (int)this->networkId
|
||||||
<< "/" << (int)msg->networkId << "] " << (int)msg->poseType << "\n";
|
<< "/" << (int)msg->networkId << "] " << (int)msg->poseType << "\n";
|
||||||
#endif
|
#endif
|
||||||
|
@ -31,7 +31,13 @@ void SiteServer::UpdateMyThings(unsigned long currentTimeMs) {
|
|||||||
|
|
||||||
if (this->isIsolated == false) {
|
if (this->isIsolated == false) {
|
||||||
// Send to all other participants
|
// 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()) {
|
for (Participant* participant : Participant::registry.GetAll()) {
|
||||||
|
#endif
|
||||||
if (participant == nullptr || participant == this)
|
if (participant == nullptr || participant == this)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -71,8 +77,12 @@ void SiteServer::Process(Participant* sender, ThingMsg* msg) {
|
|||||||
if (msg->parentId != 0) {
|
if (msg->parentId != 0) {
|
||||||
thing->SetParent(Get(msg->parentId));
|
thing->SetParent(Get(msg->parentId));
|
||||||
if (thing->GetParent() != nullptr)
|
if (thing->GetParent() != nullptr)
|
||||||
|
#if defined(NO_STD)
|
||||||
|
;
|
||||||
|
#else
|
||||||
std::cout << "Could not find parent [" << (int)msg->networkId << "/"
|
std::cout << "Could not find parent [" << (int)msg->networkId << "/"
|
||||||
<< (int)msg->parentId << "]\n";
|
<< (int)msg->parentId << "]\n";
|
||||||
|
#endif
|
||||||
} else
|
} else
|
||||||
thing->SetParent(nullptr);
|
thing->SetParent(nullptr);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user