From c7650f1be1d698c7ae87b2dd9535f73af7ee7bae Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Thu, 27 Feb 2025 11:20:13 +0100 Subject: [PATCH] ESP32 ant following trail --- Participant.cpp | 16 +++++++++++----- Participant.h | 6 +++--- Sensors/TouchSensor.cpp | 1 + 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Participant.cpp b/Participant.cpp index c764bd2..f25e40e 100644 --- a/Participant.cpp +++ b/Participant.cpp @@ -120,20 +120,23 @@ RemoteParticipant* Participant::AddParticipant(const char* ipAddress, int port) #pragma region Send -void Participant::SendThingInfo(RemoteParticipant* owner, Thing* thing) { +void Participant::SendThingInfo(RemoteParticipant* remoteParticipant, Thing* thing) { std::cout << "Send thing info " << (int)thing->id << " \n"; ThingMsg* thingMsg = new ThingMsg(this->networkId, thing); - this->Send(owner, thingMsg); + this->Send(remoteParticipant, thingMsg); delete thingMsg; NameMsg* nameMsg = new NameMsg(this->networkId, thing); - this->Send(owner, nameMsg); + this->Send(remoteParticipant, nameMsg); delete nameMsg; ModelUrlMsg* modelMsg = new ModelUrlMsg(this->networkId, thing); - this->Send(owner, modelMsg); + this->Send(remoteParticipant, modelMsg); delete modelMsg; PoseMsg* poseMsg = new PoseMsg(this->networkId, thing, true); - this->Send(owner, poseMsg); + this->Send(remoteParticipant, poseMsg); delete poseMsg; + BinaryMsg* customMsg = new BinaryMsg(this->networkId, thing); + this->Send(remoteParticipant, customMsg); + delete customMsg; } bool Participant::Send(RemoteParticipant* remoteParticipant, IMessage* msg) { @@ -166,6 +169,9 @@ void Participant::PublishThingInfo(Thing* thing) { ModelUrlMsg* modelMsg = new ModelUrlMsg(this->networkId, thing); this->Publish(modelMsg); delete modelMsg; + PoseMsg* poseMsg = new PoseMsg(this->networkId, thing, true); + this->Publish(poseMsg); + delete poseMsg; BinaryMsg* customMsg = new BinaryMsg(this->networkId, thing); this->Publish(customMsg); delete customMsg; diff --git a/Participant.h b/Participant.h index 31685fd..e467e6e 100644 --- a/Participant.h +++ b/Participant.h @@ -4,9 +4,9 @@ #include "Messages/InvestigateMsg.h" #include "Messages/ModelUrlMsg.h" #include "Messages/NameMsg.h" -#include "Messages/SiteMsg.h" #include "Messages/ParticipantMsg.h" #include "Messages/PoseMsg.h" +#include "Messages/SiteMsg.h" #include "Messages/ThingMsg.h" #include "RemoteParticipant.h" @@ -33,7 +33,7 @@ class Participant : public RemoteParticipant { const char* name = "Participant"; - //int localPort = 0; + // int localPort = 0; RemoteParticipant* site = nullptr; #if defined(ARDUINO) @@ -72,9 +72,9 @@ class Participant : public RemoteParticipant { void ReceiveData(unsigned char bufferSize, char* senderIpAddress, unsigned int senderPort); void ReceiveData(unsigned char bufferSize, RemoteParticipant* remoteParticipant); - protected: std::list senders; + protected: unsigned long nextPublishMe = 0; void SetupUDP(int localPort, const char* remoteIpAddress, int remotePort); diff --git a/Sensors/TouchSensor.cpp b/Sensors/TouchSensor.cpp index aca6123..f4e9976 100644 --- a/Sensors/TouchSensor.cpp +++ b/Sensors/TouchSensor.cpp @@ -13,6 +13,7 @@ TouchSensor::TouchSensor(RemoteParticipant* participant) : Thing(participant) { // } void TouchSensor::GenerateBinary(char* bytes, unsigned char* ix) {} + void TouchSensor::ProcessBinary(char* bytes) { this->touchedSomething = (bytes[0] == 1); // if (this->touchedSomething)