diff --git a/Arduino/Participant.cpp b/Arduino/Participant.cpp index 180a468..550e2d3 100644 --- a/Arduino/Participant.cpp +++ b/Arduino/Participant.cpp @@ -49,19 +49,20 @@ void Participant::Receive() { String senderAddress = udp.remoteIP().toString(); char sender_ipAddress[16]; senderAddress.toCharArray(sender_ipAddress, 16); - int sender_port = udp.remotePort(); + unsigned int sender_port = udp.remotePort(); - 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"; - } + // 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"; + // } - ReceiveData(packetSize, remoteParticipant); + // ReceiveData(packetSize, remoteParticipant); + ReceiveData(packetSize, sender_ipAddress, sender_port); packetSize = udp.parsePacket(); } #endif diff --git a/Participant.cpp b/Participant.cpp index 0bece41..0323fd0 100644 --- a/Participant.cpp +++ b/Participant.cpp @@ -134,19 +134,19 @@ RemoteParticipant* Participant::AddParticipant(const char* ipAddress, int port) #pragma region Send -void Participant::SendThingInfo(RemoteParticipant* remoteParticipant, Thing* thing) { +void Participant::SendThingInfo(RemoteParticipant* owner, Thing* thing) { std::cout << "Send thing info " << thing->id << " \n"; ThingMsg* thingMsg = new ThingMsg(this->networkId, thing); - this->Send(remoteParticipant, thingMsg); + this->Send(owner, thingMsg); delete thingMsg; NameMsg* nameMsg = new NameMsg(this->networkId, thing); - this->Send(remoteParticipant, nameMsg); + this->Send(owner, nameMsg); delete nameMsg; ModelUrlMsg* modelMsg = new ModelUrlMsg(this->networkId, thing); - this->Send(remoteParticipant, modelMsg); + this->Send(owner, modelMsg); delete modelMsg; PoseMsg* poseMsg = new PoseMsg(this->networkId, thing); - this->Send(remoteParticipant, poseMsg); + this->Send(owner, poseMsg); delete poseMsg; } @@ -203,6 +203,20 @@ bool Participant::Publish(IMessage* msg) { #pragma region Receive +void Participant::ReceiveData(unsigned char packetSize, char* senderIpAddress, unsigned int senderPort) { + RemoteParticipant* remoteParticipant = this->GetParticipant(senderIpAddress, senderPort); + if (remoteParticipant == nullptr) { + remoteParticipant = this->AddParticipant(senderIpAddress, senderPort); + // 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); +} + void Participant::ReceiveData(unsigned char bufferSize, RemoteParticipant* remoteParticipant) { unsigned char msgId = this->buffer[0]; // std::cout << "receive msg " << (int)msgId << "\n"; diff --git a/Participant.h b/Participant.h index 83c36e2..c863576 100644 --- a/Participant.h +++ b/Participant.h @@ -68,6 +68,7 @@ class Participant : public RemoteParticipant { bool Send(RemoteParticipant* remoteParticipant, IMessage* msg); bool Publish(IMessage* msg); + void ReceiveData(unsigned char bufferSize, char* senderIpAddress, unsigned int senderPort); void ReceiveData(unsigned char bufferSize, RemoteParticipant* remoteParticipant); protected: diff --git a/Posix/Participant.cpp b/Posix/Participant.cpp index 78a82d2..8d034cb 100644 --- a/Posix/Participant.cpp +++ b/Posix/Participant.cpp @@ -71,19 +71,20 @@ void Participant::Receive() { if (packetSize > 0) { char sender_ipAddress[INET_ADDRSTRLEN]; inet_ntop(AF_INET, &(client_addr.sin_addr), sender_ipAddress, INET_ADDRSTRLEN); - int sender_port = ntohs(client_addr.sin_port); + unsigned int sender_port = ntohs(client_addr.sin_port); - RoboidControl::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"; - } + ReceiveData(packetSize, sender_ipAddress, sender_port); + // RoboidControl::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"; + // } - ReceiveData(packetSize, remoteParticipant); + // ReceiveData(packetSize, remoteParticipant); // std::cout << "Received data\n"; } #endif @@ -94,8 +95,8 @@ bool Participant::Send(RemoteParticipant* remoteParticipant, int bufferSize) { // Set up the destination address // char ip_str[INET_ADDRSTRLEN]; // inet_ntop(AF_INET, &(remote_addr.sin_addr), ip_str, INET_ADDRSTRLEN); - // std::cout << "Send to " << ip_str << ":" << ntohs(remote_addr.sin_port) - // << "\n"; + std::cout << "Send to " << ip_str << ":" << ntohs(remote_addr.sin_port) + << "\n"; struct sockaddr_in dest_addr; memset(&dest_addr, 0, sizeof(dest_addr)); dest_addr.sin_family = AF_INET; diff --git a/Sensors/TouchSensor.cpp b/Sensors/TouchSensor.cpp index 3e007d4..aca6123 100644 --- a/Sensors/TouchSensor.cpp +++ b/Sensors/TouchSensor.cpp @@ -15,8 +15,8 @@ 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) - std::cout << "Touching something!\n"; + // if (this->touchedSomething) + // std::cout << "Touching something!\n"; } } // namespace RoboidControl \ No newline at end of file diff --git a/SiteServer.cpp b/SiteServer.cpp index 6aa4d17..72ffc7f 100644 --- a/SiteServer.cpp +++ b/SiteServer.cpp @@ -24,9 +24,8 @@ SiteServer::SiteServer(int port) { void SiteServer::Process(RemoteParticipant *sender, ParticipantMsg *msg) { if (msg->networkId == 0) { std::cout << this->name << " received New Client -> " << sender->ipAddress - << " " << (int)sender->networkId << "\n"; + << ":" << (int)sender->port << "\n"; SiteMsg *msg = new SiteMsg(sender->networkId); - //sender->Send(msg); this->Send(sender, msg); delete msg; } diff --git a/Windows/Participant.cpp b/Windows/Participant.cpp index 431bf07..c3e3ee8 100644 --- a/Windows/Participant.cpp +++ b/Windows/Participant.cpp @@ -120,21 +120,22 @@ void Participant::Receive() { } else if (packetSize > 0) { char sender_ipAddress[INET_ADDRSTRLEN]; inet_ntop(AF_INET, &(client_addr.sin_addr), sender_ipAddress, INET_ADDRSTRLEN); - int sender_port = ntohs(client_addr.sin_port); + unsigned int sender_port = ntohs(client_addr.sin_port); - RoboidControl::Participant* 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"; - } + ReceiveData(packetSize, sender_ipAddress, sender_port); + // RoboidControl::Participant* 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"; + // } - ReceiveData(packetSize, remoteParticipant); + // ReceiveData(packetSize, remoteParticipant); } #endif }