#include "ThingMsg.h" namespace RoboidControl { ThingMsg::ThingMsg(const char* buffer) { unsigned char ix = 1; // first byte is msg id this->networkId = buffer[ix++]; this->thingId = buffer[ix++]; this->thingType = buffer[ix++]; this->parentId = buffer[ix++]; } ThingMsg::ThingMsg(unsigned char networkId, Thing* thing) { this->networkId = networkId; this->thingId = thing->id; this->thingType = thing->type; Thing* parent = thing->GetParent(); if (parent != nullptr) this->parentId = parent->id; else this->parentId = 0; } // ThingMsg::ThingMsg(unsigned char networkId, unsigned char thingId, // unsigned char thingType, unsigned char parentId) { // this->networkId = networkId; // this->thingId = thingId; // this->thingType = thingType; // this->parentId = parentId; // } ThingMsg::~ThingMsg() {} unsigned char ThingMsg::Serialize(char* buffer) { #if defined(DEBUG) std::cout << "Send ThingMsg [" << (int)this->networkId << "/" << (int)this->thingId << "] " << (int)this->thingType << " " << (int)this->parentId << std::endl; #endif unsigned char ix = 0; buffer[ix++] = this->id; buffer[ix++] = this->networkId; buffer[ix++] = this->thingId; buffer[ix++] = this->thingType; buffer[ix++] = this->parentId; return ix; } } // namespace RoboidControl