touch sensor is receiving
This commit is contained in:
parent
25a0d5e9a4
commit
417005b489
@ -54,11 +54,11 @@ void Participant::Receive() {
|
|||||||
RemoteParticipant* remoteParticipant = this->GetParticipant(sender_ipAddress, sender_port);
|
RemoteParticipant* remoteParticipant = this->GetParticipant(sender_ipAddress, sender_port);
|
||||||
if (remoteParticipant == nullptr) {
|
if (remoteParticipant == nullptr) {
|
||||||
remoteParticipant = this->AddParticipant(sender_ipAddress, sender_port);
|
remoteParticipant = this->AddParticipant(sender_ipAddress, sender_port);
|
||||||
std::cout << "New sender " << sender_ipAddress << ":" << sender_port
|
// std::cout << "New sender " << sender_ipAddress << ":" << sender_port
|
||||||
<< "\n";
|
// << "\n";
|
||||||
std::cout << "New remote participant " << remoteParticipant->ipAddress
|
// std::cout << "New remote participant " << remoteParticipant->ipAddress
|
||||||
<< ":" << remoteParticipant->port << " "
|
// << ":" << remoteParticipant->port << " "
|
||||||
<< (int)remoteParticipant->networkId << "\n";
|
// << (int)remoteParticipant->networkId << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
ReceiveData(packetSize, remoteParticipant);
|
ReceiveData(packetSize, remoteParticipant);
|
||||||
|
@ -118,7 +118,7 @@ void Participant::ReceiveUDP() {
|
|||||||
|
|
||||||
RemoteParticipant* Participant::GetParticipant(const char* ipAddress, int port) {
|
RemoteParticipant* Participant::GetParticipant(const char* ipAddress, int port) {
|
||||||
for (RemoteParticipant* sender : this->senders) {
|
for (RemoteParticipant* sender : this->senders) {
|
||||||
if (sender->ipAddress == ipAddress && sender->port == port)
|
if (strcmp(sender->ipAddress, ipAddress) == 0 && sender->port == port)
|
||||||
return sender;
|
return sender;
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -135,7 +135,7 @@ RemoteParticipant* Participant::AddParticipant(const char* ipAddress, int port)
|
|||||||
#pragma region Send
|
#pragma region Send
|
||||||
|
|
||||||
void Participant::SendThingInfo(RemoteParticipant* remoteParticipant, Thing* thing) {
|
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);
|
ThingMsg* thingMsg = new ThingMsg(this->networkId, thing);
|
||||||
this->Send(remoteParticipant, thingMsg);
|
this->Send(remoteParticipant, thingMsg);
|
||||||
delete thingMsg;
|
delete thingMsg;
|
||||||
@ -280,11 +280,11 @@ void Participant::Process(RemoteParticipant* sender, PoseMsg* msg) {}
|
|||||||
void Participant::Process(RemoteParticipant* sender, BinaryMsg* msg) {
|
void Participant::Process(RemoteParticipant* sender, BinaryMsg* msg) {
|
||||||
// std::cout << this->name << ": process Binary [" << (int)this->networkId << "/"
|
// std::cout << this->name << ": process Binary [" << (int)this->networkId << "/"
|
||||||
// << (int)msg->networkId << "]\n";
|
// << (int)msg->networkId << "]\n";
|
||||||
Thing* thing = sender->Get(msg->networkId, msg->thingId);
|
Thing* thing = this->Get(msg->networkId, msg->thingId);
|
||||||
if (thing != nullptr)
|
if (thing != nullptr)
|
||||||
thing->ProcessBinary(msg->bytes);
|
thing->ProcessBinary(msg->bytes);
|
||||||
else
|
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
|
// Receive
|
||||||
|
@ -24,7 +24,8 @@ RemoteParticipant::~RemoteParticipant() {
|
|||||||
|
|
||||||
Thing* RemoteParticipant::Get(unsigned char networkId, unsigned char thingId) {
|
Thing* RemoteParticipant::Get(unsigned char networkId, unsigned char thingId) {
|
||||||
for (Thing* thing : this->things) {
|
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;
|
return thing;
|
||||||
}
|
}
|
||||||
// std::cout << "Could not find thing " << this->ipAddress << ":" << this->port
|
// std::cout << "Could not find thing " << this->ipAddress << ":" << this->port
|
||||||
|
@ -3,14 +3,20 @@
|
|||||||
namespace RoboidControl {
|
namespace RoboidControl {
|
||||||
|
|
||||||
TouchSensor::TouchSensor(RemoteParticipant* participant) : Thing(participant) {
|
TouchSensor::TouchSensor(RemoteParticipant* participant) : Thing(participant) {
|
||||||
this->touchedSomething = false;
|
this->touchedSomething = false;
|
||||||
this->type = (unsigned char) Thing::Type::TouchSensor;
|
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;
|
// this->touchedSomething = false;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
void TouchSensor::GenerateBinary(char* bytes, unsigned char* ix) {}
|
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
|
} // namespace RoboidControl
|
Loading…
x
Reference in New Issue
Block a user