[client] Start writing Message classes for client
This commit is contained in:
parent
516c10ee5b
commit
49c19fcaf1
10 changed files with 117 additions and 0 deletions
19
PixelHub-Client/src/Messages/ErrorMessage.cpp
Normal file
19
PixelHub-Client/src/Messages/ErrorMessage.cpp
Normal 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));
|
||||||
|
}
|
14
PixelHub-Client/src/Messages/ErrorMessage.h
Normal file
14
PixelHub-Client/src/Messages/ErrorMessage.h
Normal 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;
|
||||||
|
};
|
|
@ -0,0 +1,8 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "HandshakeRequestMessage.h"
|
||||||
|
#include "PixelMessage.h"
|
||||||
|
|
||||||
|
HandshakeRequestMessage::HandshakeRequestMessage() : PixelMessage()
|
||||||
|
{
|
||||||
|
}
|
12
PixelHub-Client/src/Messages/HandshakeRequestMessage.h
Normal file
12
PixelHub-Client/src/Messages/HandshakeRequestMessage.h
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "PixelMessage.h"
|
||||||
|
|
||||||
|
struct HandshakeRequestMessage : public PixelMessage {
|
||||||
|
public:
|
||||||
|
HandshakeRequestMessage();
|
||||||
|
~HandshakeRequestMessage();
|
||||||
|
|
||||||
|
char* Type;
|
||||||
|
};
|
16
PixelHub-Client/src/Messages/HandshakeResponseMessage.cpp
Normal file
16
PixelHub-Client/src/Messages/HandshakeResponseMessage.cpp
Normal 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));
|
||||||
|
}
|
13
PixelHub-Client/src/Messages/HandshakeResponseMessage.h
Normal file
13
PixelHub-Client/src/Messages/HandshakeResponseMessage.h
Normal 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;
|
||||||
|
};
|
17
PixelHub-Client/src/Messages/MoveMessage.cpp
Normal file
17
PixelHub-Client/src/Messages/MoveMessage.cpp
Normal 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));
|
||||||
|
}
|
14
PixelHub-Client/src/Messages/MoveMessage.h
Normal file
14
PixelHub-Client/src/Messages/MoveMessage.h
Normal 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;
|
||||||
|
};
|
|
@ -1,3 +1,5 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
#include "PixelMessage.h"
|
#include "PixelMessage.h"
|
||||||
#include "PixelBot.h"
|
#include "PixelBot.h"
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in a new issue