From 417005b489f9274c5a4acc7f339c7ca90c00d10b Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Tue, 25 Feb 2025 17:42:27 +0100 Subject: [PATCH] touch sensor is receiving --- Arduino/Participant.cpp | 10 +++++----- Participant.cpp | 8 ++++---- RemoteParticipant.cpp | 3 ++- Sensors/TouchSensor.cpp | 14 ++++++++++---- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/Arduino/Participant.cpp b/Arduino/Participant.cpp index bb9142f..180a468 100644 --- a/Arduino/Participant.cpp +++ b/Arduino/Participant.cpp @@ -54,11 +54,11 @@ void Participant::Receive() { RemoteParticipant* remoteParticipant = this->GetParticipant(sender_ipAddress, sender_port); if (remoteParticipant == nullptr) { remoteParticipant = this->AddParticipant(sender_ipAddress, sender_port); - std::cout << "New sender " << sender_ipAddress << ":" << sender_port - << "\n"; - std::cout << "New remote participant " << remoteParticipant->ipAddress - << ":" << remoteParticipant->port << " " - << (int)remoteParticipant->networkId << "\n"; + // std::cout << "New sender " << sender_ipAddress << ":" << sender_port + // << "\n"; + // std::cout << "New remote participant " << remoteParticipant->ipAddress + // << ":" << remoteParticipant->port << " " + // << (int)remoteParticipant->networkId << "\n"; } ReceiveData(packetSize, remoteParticipant); diff --git a/Participant.cpp b/Participant.cpp index 974d4fc..0bece41 100644 --- a/Participant.cpp +++ b/Participant.cpp @@ -118,7 +118,7 @@ void Participant::ReceiveUDP() { RemoteParticipant* Participant::GetParticipant(const char* ipAddress, int port) { for (RemoteParticipant* sender : this->senders) { - if (sender->ipAddress == ipAddress && sender->port == port) + if (strcmp(sender->ipAddress, ipAddress) == 0 && sender->port == port) return sender; } return nullptr; @@ -135,7 +135,7 @@ RemoteParticipant* Participant::AddParticipant(const char* ipAddress, int port) #pragma region Send void Participant::SendThingInfo(RemoteParticipant* remoteParticipant, Thing* thing) { - std::cout << "Send thing info\n"; + std::cout << "Send thing info " << thing->id << " \n"; ThingMsg* thingMsg = new ThingMsg(this->networkId, thing); this->Send(remoteParticipant, thingMsg); delete thingMsg; @@ -280,11 +280,11 @@ void Participant::Process(RemoteParticipant* sender, PoseMsg* msg) {} void Participant::Process(RemoteParticipant* sender, BinaryMsg* msg) { // std::cout << this->name << ": process Binary [" << (int)this->networkId << "/" // << (int)msg->networkId << "]\n"; - Thing* thing = sender->Get(msg->networkId, msg->thingId); + Thing* thing = this->Get(msg->networkId, msg->thingId); if (thing != nullptr) thing->ProcessBinary(msg->bytes); else - std::cout << "custom msg for unknown thing " << (int)msg->networkId << ":" << (int)msg->thingId << "\n"; + std::cout << "custom msg for unknown thing [" << (int)msg->networkId << "/" << (int)msg->thingId << "]\n"; } // Receive diff --git a/RemoteParticipant.cpp b/RemoteParticipant.cpp index 52efd53..ee24bae 100644 --- a/RemoteParticipant.cpp +++ b/RemoteParticipant.cpp @@ -24,7 +24,8 @@ RemoteParticipant::~RemoteParticipant() { Thing* RemoteParticipant::Get(unsigned char networkId, unsigned char thingId) { for (Thing* thing : this->things) { - if (thing->networkId == networkId && thing->id == thingId) + //if (thing->networkId == networkId && thing->id == thingId) + if (thing->id == thingId) return thing; } // std::cout << "Could not find thing " << this->ipAddress << ":" << this->port diff --git a/Sensors/TouchSensor.cpp b/Sensors/TouchSensor.cpp index 508aa8c..3e007d4 100644 --- a/Sensors/TouchSensor.cpp +++ b/Sensors/TouchSensor.cpp @@ -3,14 +3,20 @@ namespace RoboidControl { TouchSensor::TouchSensor(RemoteParticipant* participant) : Thing(participant) { - this->touchedSomething = false; - this->type = (unsigned char) Thing::Type::TouchSensor; + this->touchedSomething = false; + this->type = (unsigned char)Thing::Type::TouchSensor; } -// TouchSensor::TouchSensor(RemoteParticipant* participant, unsigned char networkId, unsigned char thingId) : Thing(participant, networkId, thingId) { +// TouchSensor::TouchSensor(RemoteParticipant* participant, unsigned char networkId, unsigned char thingId) : +// Thing(participant, networkId, thingId) { // this->touchedSomething = false; // } void TouchSensor::GenerateBinary(char* bytes, unsigned char* ix) {} -void TouchSensor::ProcessBinary(char* bytes) {} +void TouchSensor::ProcessBinary(char* bytes) { + this->touchedSomething = (bytes[0] == 1); + if (this->touchedSomething) + std::cout << "Touching something!\n"; +} + } // namespace RoboidControl \ No newline at end of file