43 lines
1.1 KiB
C++
43 lines
1.1 KiB
C++
#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;
|
|
if (thing->IsRoot())
|
|
this->parentId = 0;
|
|
else {
|
|
Thing* parent = thing->GetParent();
|
|
this->parentId = parent->id;
|
|
}
|
|
}
|
|
|
|
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
|