Improve debug logging
This commit is contained in:
parent
304856ea0a
commit
32ca8f5f71
@ -132,8 +132,8 @@ void ParticipantUDP::Receive() {
|
||||
|
||||
bool ParticipantUDP::Send(Participant* remoteParticipant, int bufferSize) {
|
||||
#if defined(IDF_VER)
|
||||
std::cout << "Sending to " << remoteParticipant->ipAddress << ":"
|
||||
<< remoteParticipant->port << "\n";
|
||||
// std::cout << "Sending to " << remoteParticipant->ipAddress << ":"
|
||||
// << remoteParticipant->port << "\n";
|
||||
|
||||
int err = sendto(this->sockfd, buffer, bufferSize, 0,
|
||||
(struct sockaddr*)&dest_addr, sizeof(dest_addr));
|
||||
|
@ -4,16 +4,6 @@
|
||||
|
||||
namespace RoboidControl {
|
||||
|
||||
// ModelUrlMsg::ModelUrlMsg(unsigned char networkId, unsigned char thingId,
|
||||
// unsigned char urlLength, const char *url,
|
||||
// float scale) {
|
||||
// this->networkId = networkId;
|
||||
// this->thingId = thingId;
|
||||
// this->urlLength = urlLength;
|
||||
// this->url = url;
|
||||
// this->scale = scale;
|
||||
// }
|
||||
|
||||
ModelUrlMsg::ModelUrlMsg(unsigned char networkId, Thing* thing) {
|
||||
this->networkId = networkId;
|
||||
this->thingId = thing->id;
|
||||
@ -22,8 +12,6 @@ ModelUrlMsg::ModelUrlMsg(unsigned char networkId, Thing* thing) {
|
||||
else
|
||||
this->urlLength = (unsigned char)strlen(thing->modelUrl);
|
||||
|
||||
// this->url = thing->modelUrl; // dangerous!
|
||||
|
||||
// the url string in the buffer is not \0 terminated!
|
||||
char* url = new char[this->urlLength + 1];
|
||||
for (int i = 0; i < this->urlLength; i++)
|
||||
|
@ -15,7 +15,7 @@ class ModelUrlMsg : public IMessage {
|
||||
/// @brief The ID of the thing
|
||||
unsigned char thingId;
|
||||
|
||||
/// @brief The length of the url st5ring, excluding the null terminator
|
||||
/// @brief The length of the url string, excluding the null terminator
|
||||
unsigned char urlLength;
|
||||
/// @brief The url of the model, not terminated by a null character
|
||||
const char* url;
|
||||
|
@ -39,8 +39,8 @@ Thing* Participant::Get(unsigned char thingId) {
|
||||
if (thing->id == thingId)
|
||||
return thing;
|
||||
}
|
||||
std::cout << "Could not find thing " << this->ipAddress << ":" << this->port
|
||||
<< "[" << (int)thingId << "]\n";
|
||||
// std::cout << "Could not find thing " << this->ipAddress << ":" << this->port
|
||||
// << "[" << (int)thingId << "]\n";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -88,7 +88,6 @@ void ParticipantUDP::Update(unsigned long currentTimeMs) {
|
||||
|
||||
if (this->publishInterval > 0 && currentTimeMs > this->nextPublishMe) {
|
||||
ParticipantMsg* msg = new ParticipantMsg(this->networkId);
|
||||
std::cout << "Send Participant\n";
|
||||
if (this->remoteSite == nullptr)
|
||||
this->Publish(msg);
|
||||
else
|
||||
@ -160,7 +159,7 @@ Participant* ParticipantUDP::AddParticipant(const char* ipAddress, int port) {
|
||||
|
||||
void ParticipantUDP::SendThingInfo(Participant* remoteParticipant,
|
||||
Thing* thing) {
|
||||
std::cout << "Send thing info [" << (int)thing->id << "] \n";
|
||||
// std::cout << "Send thing info [" << (int)thing->id << "] \n";
|
||||
ThingMsg* thingMsg = new ThingMsg(this->networkId, thing);
|
||||
this->Send(remoteParticipant, thingMsg);
|
||||
delete thingMsg;
|
||||
@ -253,12 +252,11 @@ bool ParticipantUDP::Publish(IMessage* msg) {
|
||||
void ParticipantUDP::ReceiveData(unsigned char packetSize,
|
||||
char* senderIpAddress,
|
||||
unsigned int senderPort) {
|
||||
Participant* sender =
|
||||
this->GetParticipant(senderIpAddress, senderPort);
|
||||
Participant* sender = this->GetParticipant(senderIpAddress, senderPort);
|
||||
if (sender == nullptr) {
|
||||
sender = this->AddParticipant(senderIpAddress, senderPort);
|
||||
std::cout << "New remote participant " << sender->ipAddress
|
||||
<< ":" << sender->port << std::endl;
|
||||
std::cout << "New remote participant " << sender->ipAddress << ":"
|
||||
<< sender->port << std::endl;
|
||||
}
|
||||
|
||||
ReceiveData(packetSize, sender);
|
||||
@ -267,7 +265,7 @@ void ParticipantUDP::ReceiveData(unsigned char packetSize,
|
||||
void ParticipantUDP::ReceiveData(unsigned char bufferSize,
|
||||
Participant* sender) {
|
||||
unsigned char msgId = this->buffer[0];
|
||||
std::cout << "receive msg " << (int)msgId << "\n";
|
||||
// std::cout << "receive msg " << (int)msgId << "\n";
|
||||
// std::cout << " buffer size = " <<(int) bufferSize << "\n";
|
||||
switch (msgId) {
|
||||
case ParticipantMsg::id: {
|
||||
@ -325,13 +323,18 @@ void ParticipantUDP::ReceiveData(unsigned char bufferSize,
|
||||
}
|
||||
|
||||
void ParticipantUDP::Process(Participant* sender, ParticipantMsg* msg) {
|
||||
std::cout << this->name << ": Process Participant " << (int)msg->networkId
|
||||
#if defined(DEBUG)
|
||||
std::cout << this->name << ": Process ParticipantMsg " << (int)msg->networkId
|
||||
<< "\n";
|
||||
#endif
|
||||
}
|
||||
|
||||
void ParticipantUDP::Process(Participant* sender, SiteMsg* msg) {
|
||||
std::cout << this->name << ": process Site Id " << (int)this->networkId
|
||||
<< "->" << (int)msg->networkId << "\n";
|
||||
#if defined(DEBUG)
|
||||
std::cout << this->name << ": process SiteMsg " << (int)this->networkId
|
||||
<< " -> " << (int)msg->networkId << "\n";
|
||||
#endif
|
||||
|
||||
if (this->networkId != msg->networkId) {
|
||||
this->networkId = msg->networkId;
|
||||
// std::cout << this->things.size() << " things\n";
|
||||
@ -340,16 +343,25 @@ void ParticipantUDP::Process(Participant* sender, SiteMsg* msg) {
|
||||
}
|
||||
}
|
||||
|
||||
void ParticipantUDP::Process(Participant* sender, InvestigateMsg* msg) {}
|
||||
void ParticipantUDP::Process(Participant* sender, InvestigateMsg* msg) {
|
||||
#if defined(DEBUG)
|
||||
std::cout << this->name << ": Process InvestigateMsg [" << (int)msg->networkId
|
||||
<< "/" << (int)msg->thingId << "]\n";
|
||||
#endif
|
||||
}
|
||||
|
||||
void ParticipantUDP::Process(Participant* sender, ThingMsg* msg) {
|
||||
std::cout << this->name << ": process Thing [" << (int)msg->networkId << "/"
|
||||
<< (int)msg->thingId << "]\n";
|
||||
#if defined(DEBUG)
|
||||
std::cout << this->name << ": process ThingMsg [" << (int)msg->networkId
|
||||
<< "/" << (int)msg->thingId << "] " << (int)msg->thingType << " " << (int)msg->parentId << "\n";
|
||||
#endif
|
||||
}
|
||||
|
||||
void ParticipantUDP::Process(Participant* sender, NameMsg* msg) {
|
||||
std::cout << this->name << ": process Name [" << (int)msg->networkId << "/"
|
||||
#if defined(DEBUG)
|
||||
std::cout << this->name << ": process NameMsg [" << (int)msg->networkId << "/"
|
||||
<< (int)msg->thingId << "] ";
|
||||
#endif
|
||||
|
||||
Thing* thing = sender->Get(msg->thingId);
|
||||
if (thing != nullptr) {
|
||||
@ -374,18 +386,25 @@ void ParticipantUDP::Process(Participant* sender, NameMsg* msg) {
|
||||
}
|
||||
|
||||
void ParticipantUDP::Process(Participant* sender, ModelUrlMsg* msg) {
|
||||
std::cout << this->name << ": process model url [" << (int)msg->networkId
|
||||
#if defined(DEBUG)
|
||||
std::cout << this->name << ": process ModelUrlMsg [" << (int)msg->networkId
|
||||
<< "/" << (int)msg->thingId << "]\n";
|
||||
#endif
|
||||
}
|
||||
|
||||
void ParticipantUDP::Process(Participant* sender, PoseMsg* msg) {
|
||||
std::cout << this->name << ": process Pose [" << (int)this->networkId << "/"
|
||||
<< (int)msg->networkId << "]\n";
|
||||
#if defined(DEBUG)
|
||||
std::cout << this->name << ": process PoseMsg [" << (int)this->networkId
|
||||
<< "/" << (int)msg->networkId << "]\n";
|
||||
#endif
|
||||
}
|
||||
|
||||
void ParticipantUDP::Process(Participant* sender, BinaryMsg* msg) {
|
||||
std::cout << this->name << ": process Binary [" << (int)msg->networkId << "/"
|
||||
<< (int)msg->thingId << "] ";
|
||||
#if defined(DEBUG)
|
||||
std::cout << this->name << ": process BinaryMsg [" << (int)msg->networkId
|
||||
<< "/" << (int)msg->thingId << "] ";
|
||||
#endif
|
||||
|
||||
Thing* thing = sender->Get(msg->thingId);
|
||||
if (thing != nullptr)
|
||||
thing->ProcessBinary(msg->data);
|
||||
|
Loading…
x
Reference in New Issue
Block a user