This repository has been archived on 2019-06-21. You can view files and clone it, but cannot push or open issues or pull requests.
PixelHub/PixelHub-Client/src/PixelMessage.cpp

31 lines
1.1 KiB
C++

#include "PixelMessage.h"
#include <Arduino.h>
PixelMessage::PixelMessage()
{
}
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()
{
}