Thing name processing fix

This commit is contained in:
Pascal Serrarens 2025-02-02 14:38:12 +01:00
parent 8d85881047
commit c19508179d

View File

@ -256,10 +256,13 @@ void Participant::Process(ThingMsg *msg) {}
void Participant::Process(NameMsg *msg) { void Participant::Process(NameMsg *msg) {
Thing *thing = this->Get(msg->networkId, msg->thingId); Thing *thing = this->Get(msg->networkId, msg->thingId);
if (thing != nullptr) { if (thing != nullptr) {
char *thingName = new char[strlen(msg->name)]; int nameLength = msg->nameLength;
char *thingName = new char[nameLength + 1];
strcpy(thingName, msg->name); strcpy(thingName, msg->name);
thingName[nameLength] = '\0';
thing->name = thingName; thing->name = thingName;
std::cout << "thing name = " << thing->name << "\n"; std::cout << "thing name = " << thing->name << " length = " << nameLength
<< "\n";
} }
} }
@ -272,7 +275,7 @@ void Participant::Process(CustomMsg *msg) {
else else
std::cout << "custom msg for unknown thing " << (int)msg->networkId << ":" std::cout << "custom msg for unknown thing " << (int)msg->networkId << ":"
<< (int)msg->thingId << "\n"; << (int)msg->thingId << "\n";
std::cout << "Processed custom msg\n"; // std::cout << "Processed custom msg\n";
} }
// Receive // Receive
@ -281,8 +284,8 @@ void Participant::Process(CustomMsg *msg) {
#pragma region Things #pragma region Things
Thing *Participant::Get(unsigned char networkId, unsigned char thingId) { Thing *Participant::Get(unsigned char networkId, unsigned char thingId) {
std::cout << "Get " << (int)networkId << "/" << (int)thingId << " from " // std::cout << "Get " << (int)networkId << "/" << (int)thingId << " from "
<< this->things.size() << " things\n"; // << this->things.size() << " things\n";
for (auto &thing : this->things) { for (auto &thing : this->things) {
// std::cout << " ? " << (int)thing->networkId << "/" << (int)thing->id // std::cout << " ? " << (int)thing->networkId << "/" << (int)thing->id
// << "\n"; // << "\n";