32 lines
1.2 KiB
C++
32 lines
1.2 KiB
C++
#include "PixelMessage.h"
|
|
#include "PixelBot.h"
|
|
|
|
#include <Arduino.h>
|
|
|
|
PixelMessage::PixelMessage()
|
|
{
|
|
ProtocolVersion = PixelBot::PROTOCOL_VERSION;
|
|
}
|
|
PixelMessage::PixelMessage(byte* rawMessage) : PixelMessage()
|
|
{
|
|
// Casting solution from http://stackoverflow.com/a/300837/1460422
|
|
// Basically, it casts a byte* pointer reference to the start of the bit we want to extract
|
|
// into a void* (which is just a point that points to a specific point in memory without a
|
|
// specific type associated with it), which we then cast into a pointer of the type we
|
|
// actually want. This extra step is needed to get it to cast multiple consecutive bytes
|
|
// in the raw message into the type we want.
|
|
// With the casts done, we simply dereference the pointer to shove the value into the
|
|
// instance of this class that we're building.
|
|
ProtocolVersion = *(static_cast<unsigned short*>(static_cast<void*>(rawMessage)));
|
|
MessageType = *(static_cast<unsigned short*>(static_cast<void*>(rawMessage + 2)));
|
|
MessageId = *(static_cast<unsigned int*>(static_cast<void*>(rawMessage + 4)));
|
|
MessageLength = *(static_cast<unsigned int*>(static_cast<void*>(rawMessage + 8)));
|
|
|
|
// TODO: Sort out the payload here.
|
|
}
|
|
|
|
PixelMessage::~PixelMessage()
|
|
{
|
|
|
|
}
|