128 lines
3.6 KiB
C++
128 lines
3.6 KiB
C++
#include "Messages.h"
|
|
|
|
#include "LowLevelMessages.h"
|
|
|
|
#pragma region IMessage
|
|
|
|
unsigned char IMessage::Serialize(unsigned char *buffer) { return 0; }
|
|
|
|
bool IMessage::SendMsg(ControlClient client, IMessage msg,
|
|
unsigned char bufferSize) {
|
|
return SendMsg(client, client.buffer, msg.Serialize(client.buffer));
|
|
}
|
|
|
|
bool IMessage::SendMsg(ControlClient client, unsigned char *buffer,
|
|
unsigned char bufferSize) {
|
|
return false; // client.SendMsg(buffer, bufferSize);
|
|
}
|
|
|
|
#pragma endregion
|
|
|
|
#pragma region Investigate
|
|
|
|
InvestigateMsg::InvestigateMsg(unsigned char networkId, unsigned char thingId) {
|
|
this->networkId = networkId;
|
|
this->thingId = thingId;
|
|
}
|
|
|
|
unsigned char InvestigateMsg::Serialize(unsigned char *buffer) {
|
|
unsigned char ix = 0;
|
|
buffer[ix++] = this->id;
|
|
buffer[ix++] = this->networkId;
|
|
buffer[ix++] = this->thingId;
|
|
return ix;
|
|
}
|
|
|
|
bool InvestigateMsg::Send(ControlClient client, unsigned char networkId,
|
|
unsigned char thingId) {
|
|
InvestigateMsg msg = InvestigateMsg(networkId, thingId);
|
|
return SendMsg(client, msg, InvestigateMsg::length);
|
|
}
|
|
|
|
// Investigate
|
|
#pragma endregion
|
|
|
|
#pragma region Thing
|
|
|
|
Passer::Control::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;
|
|
}
|
|
|
|
unsigned char ThingMsg::Serialize(unsigned char *buffer) {
|
|
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;
|
|
}
|
|
|
|
bool Passer::Control::ThingMsg::Send(ControlClient client,
|
|
unsigned char networkId,
|
|
unsigned char thingId,
|
|
unsigned char thingType,
|
|
unsigned char parentId) {
|
|
ThingMsg msg = ThingMsg(networkId, thingId, thingType, parentId);
|
|
return SendMsg(client, msg, ThingMsg::length);
|
|
}
|
|
|
|
// Thing
|
|
#pragma endregion
|
|
|
|
#pragma region Name
|
|
|
|
NameMsg::NameMsg(unsigned char networkId, unsigned char thingId,
|
|
unsigned char nameLength, const char *name) {
|
|
this->networkId = networkId;
|
|
this->thingId = thingId;
|
|
this->nameLength = nameLength;
|
|
this->name = name;
|
|
}
|
|
|
|
unsigned char Passer::Control::NameMsg::Serialize(unsigned char *buffer) {
|
|
unsigned char ix = 0;
|
|
buffer[ix++] = this->id;
|
|
buffer[ix++] = this->networkId;
|
|
buffer[ix++] = this->thingId;
|
|
buffer[ix++] = this->nameLength;
|
|
for (int nameIx = 0; nameIx < this->nameLength; nameIx++)
|
|
buffer[ix++] = name[nameIx];
|
|
return ix;
|
|
}
|
|
|
|
// Name
|
|
#pragma endregion
|
|
|
|
#pragma region ModelUrl
|
|
|
|
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;
|
|
}
|
|
|
|
unsigned char ModelUrlMsg::Serialize(unsigned char *buffer) {
|
|
unsigned char ix = 0;
|
|
buffer[ix++] = this->id;
|
|
buffer[ix++] = this->networkId;
|
|
buffer[ix++] = this->thingId;
|
|
LowLevelMessages::SendFloat16(buffer, &ix, this->scale);
|
|
buffer[ix++] = this->urlLength;
|
|
for (int urlIx = 0; urlIx < this->urlLength; urlIx++)
|
|
buffer[ix++] = url[urlIx];
|
|
return ix;
|
|
}
|
|
|
|
// Model Url
|
|
#pragma endregion |