[client] Create PixelMessage class with initial constructor.
This commit is contained in:
parent
078d9eb75a
commit
e16ff31b92
4 changed files with 53 additions and 6 deletions
|
@ -38,6 +38,12 @@ public:
|
||||||
PixelBot();
|
PixelBot();
|
||||||
~PixelBot();
|
~PixelBot();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The current protocol version that this this PixelBot implementation understands.
|
||||||
|
/// Very important to avoid strange behavious when a PixelBot hasn't has it's code updated.
|
||||||
|
/// </summary>
|
||||||
|
static const unsigned short PROTOCOL_VERSION = 1;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Listens for beacon pings that reveal the location of the PixelHub server.
|
/// Listens for beacon pings that reveal the location of the PixelHub server.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
|
|
29
PixelHub-Client/PixelMessage.cpp
Normal file
29
PixelHub-Client/PixelMessage.cpp
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#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)));
|
||||||
|
}
|
||||||
|
|
||||||
|
PixelMessage::~PixelMessage()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -1,17 +1,30 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
|
||||||
struct PixelMessage
|
struct PixelMessage
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PixelMessage();
|
PixelMessage();
|
||||||
|
PixelMessage(byte* rawMessage);
|
||||||
~PixelMessage();
|
~PixelMessage();
|
||||||
|
|
||||||
const ushort ProtocolVersion;
|
/// <summary>
|
||||||
const ushort MessageType;
|
/// The length of the message header, in bytes.
|
||||||
const uint MessageId;
|
/// The message header contains things like the protocol version, the payload length, and the message type.
|
||||||
const uint MessageLength;
|
/// </summary>
|
||||||
|
static const unsigned int MESSAGE_HEADER_LENGTH = 12;
|
||||||
|
|
||||||
|
// The protocol version associated with this message.
|
||||||
|
unsigned short ProtocolVersion = 1;
|
||||||
|
unsigned short MessageType = 1;
|
||||||
|
unsigned int MessageId = 0;
|
||||||
|
unsigned int MessageLength = 0;
|
||||||
|
|
||||||
|
//const byte* Payload;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
Reference in a new issue