[client] Start writing Message classes for client

This commit is contained in:
Starbeamrainbowlabs 2017-04-20 19:57:26 +01:00
parent 516c10ee5b
commit 49c19fcaf1
10 changed files with 117 additions and 0 deletions

View file

@ -0,0 +1,19 @@
#pragma once
#include "ErrorMessage.h"
#include "PixelMessage.h"
ErrorMessage::ErrorMessage() : PixelMessage()
{
}
ErrorMessage::ErrorMessage(byte* rawMessage) : PixelMessage(rawMessage)
{
// The position of the start of the message body
void* messageBodyStart = static_cast<void*>(rawMessage + PixelMessage::MESSAGE_HEADER_LENGTH);
ErrorCode = *(static_cast<unsigned int*>(messageBodyStart));
// NOTE: This might cause issues. This constructor probably won't be used
// anyway though
*Message = *(static_cast<char*>(messageBodyStart + 4));
}

View file

@ -0,0 +1,14 @@
#pragma once
#include <Arduino.h>
#include <PixelMessage.h>
struct ErrorMessage : public PixelMessage {
public:
ErrorMessage();
ErrorMessage(byte* rawMessage);
~ErrorMessage();
unsigned int ErrorCode;
char* Message;
};

View file

@ -0,0 +1,8 @@
#pragma once
#include "HandshakeRequestMessage.h"
#include "PixelMessage.h"
HandshakeRequestMessage::HandshakeRequestMessage() : PixelMessage()
{
}

View file

@ -0,0 +1,12 @@
#pragma once
#include <Arduino.h>
#include "PixelMessage.h"
struct HandshakeRequestMessage : public PixelMessage {
public:
HandshakeRequestMessage();
~HandshakeRequestMessage();
char* Type;
};

View file

@ -0,0 +1,16 @@
#pragma once
#include "HandshakeResponseMessage.h"
#include "PixelMessage.h"
HandshakeResponseMessage::HandshakeResponseMessage() : PixelMessage()
{
}
HandshakeResponseMessage::HandshakeResponseMessage(byte* rawMessage) : PixelMessage(rawMessage)
{
// The position of the start of the message body
void* messageBodyStart = static_cast<void*>(rawMessage + PixelMessage::MESSAGE_HEADER_LENGTH);
Id = *(static_cast<unsigned int*>(messageBodyStart));
}

View file

@ -0,0 +1,13 @@
#pragma once
#include <Arduino.h>
#include "PixelMessage.h"
struct HandshakeResponseMessage : public PixelMessage {
public:
HandshakeResponseMessage();
HandshakeResponseMessage(byte* rawMessage);
~HandshakeResponseMessage();
unsigned int Id;
};

View file

@ -0,0 +1,17 @@
#pragma once
#include "MoveMessage.h"
#include "PixelMessage.h"
MoveMessage::MoveMessage() : PixelMessage()
{
}
MoveMessage::MoveMessage(byte* rawMessage) : PixelMessage(rawMessage)
{
// The position of the start of the message body
void* messageBodyStart = static_cast<void*>(rawMessage + PixelMessage::MESSAGE_HEADER_LENGTH);
byte MovementType = *(static_cast<byte*>(messageBodyStart));
unsigned short TickCount = *(static_cast<unsigned short*>(messageBodyStart + 1));
}

View file

@ -0,0 +1,14 @@
#pragma once
#include <Arduino.h>
#include "PixelMessage.h"
struct MoveMessage : public PixelMessage {
public:
MoveMessage();
MoveMessage(byte* rawMessage);
~MoveMessage();
byte MovementType;
unsigned short TickCount;
};

View file

@ -1,3 +1,5 @@
#pragma once
#include "PixelMessage.h" #include "PixelMessage.h"
#include "PixelBot.h" #include "PixelBot.h"

View file

@ -1,3 +1,5 @@
#pragma once
#include <Arduino.h> #include <Arduino.h>