touch sensor is receiving

This commit is contained in:
Pascal Serrarens 2025-02-25 17:42:27 +01:00
parent 25a0d5e9a4
commit 417005b489
4 changed files with 21 additions and 14 deletions

View File

@ -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);

View File

@ -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

View File

@ -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

View File

@ -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