From 49c19fcaf1705899bc736be87916e447a727ea55 Mon Sep 17 00:00:00 2001
From: Starbeamrainbowlabs <sbrl@starbeamrainbowlabs.com>
Date: Thu, 20 Apr 2017 19:57:26 +0100
Subject: [PATCH] [client] Start writing Message classes for client

---
 PixelHub-Client/src/Messages/ErrorMessage.cpp | 19 +++++++++++++++++++
 PixelHub-Client/src/Messages/ErrorMessage.h   | 14 ++++++++++++++
 .../Messages/HandleshakeRequestMessage.cpp    |  8 ++++++++
 .../src/Messages/HandshakeRequestMessage.h    | 12 ++++++++++++
 .../src/Messages/HandshakeResponseMessage.cpp | 16 ++++++++++++++++
 .../src/Messages/HandshakeResponseMessage.h   | 13 +++++++++++++
 PixelHub-Client/src/Messages/MoveMessage.cpp  | 17 +++++++++++++++++
 PixelHub-Client/src/Messages/MoveMessage.h    | 14 ++++++++++++++
 PixelHub-Client/src/PixelMessage.cpp          |  2 ++
 PixelHub-Client/src/PixelMessage.h            |  2 ++
 10 files changed, 117 insertions(+)
 create mode 100644 PixelHub-Client/src/Messages/ErrorMessage.cpp
 create mode 100644 PixelHub-Client/src/Messages/ErrorMessage.h
 create mode 100644 PixelHub-Client/src/Messages/HandleshakeRequestMessage.cpp
 create mode 100644 PixelHub-Client/src/Messages/HandshakeRequestMessage.h
 create mode 100644 PixelHub-Client/src/Messages/HandshakeResponseMessage.cpp
 create mode 100644 PixelHub-Client/src/Messages/HandshakeResponseMessage.h
 create mode 100644 PixelHub-Client/src/Messages/MoveMessage.cpp
 create mode 100644 PixelHub-Client/src/Messages/MoveMessage.h

diff --git a/PixelHub-Client/src/Messages/ErrorMessage.cpp b/PixelHub-Client/src/Messages/ErrorMessage.cpp
new file mode 100644
index 0000000..eef42e0
--- /dev/null
+++ b/PixelHub-Client/src/Messages/ErrorMessage.cpp
@@ -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));
+}
diff --git a/PixelHub-Client/src/Messages/ErrorMessage.h b/PixelHub-Client/src/Messages/ErrorMessage.h
new file mode 100644
index 0000000..f2ad2b0
--- /dev/null
+++ b/PixelHub-Client/src/Messages/ErrorMessage.h
@@ -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;
+};
diff --git a/PixelHub-Client/src/Messages/HandleshakeRequestMessage.cpp b/PixelHub-Client/src/Messages/HandleshakeRequestMessage.cpp
new file mode 100644
index 0000000..11c412c
--- /dev/null
+++ b/PixelHub-Client/src/Messages/HandleshakeRequestMessage.cpp
@@ -0,0 +1,8 @@
+#pragma once
+
+#include "HandshakeRequestMessage.h"
+#include "PixelMessage.h"
+
+HandshakeRequestMessage::HandshakeRequestMessage() : PixelMessage()
+{
+}
diff --git a/PixelHub-Client/src/Messages/HandshakeRequestMessage.h b/PixelHub-Client/src/Messages/HandshakeRequestMessage.h
new file mode 100644
index 0000000..c348338
--- /dev/null
+++ b/PixelHub-Client/src/Messages/HandshakeRequestMessage.h
@@ -0,0 +1,12 @@
+#pragma once
+
+#include <Arduino.h>
+#include "PixelMessage.h"
+
+struct HandshakeRequestMessage : public PixelMessage {
+public:
+	HandshakeRequestMessage();
+	~HandshakeRequestMessage();
+	
+	char* Type;
+};
diff --git a/PixelHub-Client/src/Messages/HandshakeResponseMessage.cpp b/PixelHub-Client/src/Messages/HandshakeResponseMessage.cpp
new file mode 100644
index 0000000..8e93191
--- /dev/null
+++ b/PixelHub-Client/src/Messages/HandshakeResponseMessage.cpp
@@ -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));
+}
diff --git a/PixelHub-Client/src/Messages/HandshakeResponseMessage.h b/PixelHub-Client/src/Messages/HandshakeResponseMessage.h
new file mode 100644
index 0000000..b24cd79
--- /dev/null
+++ b/PixelHub-Client/src/Messages/HandshakeResponseMessage.h
@@ -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;
+};
diff --git a/PixelHub-Client/src/Messages/MoveMessage.cpp b/PixelHub-Client/src/Messages/MoveMessage.cpp
new file mode 100644
index 0000000..05f5e3b
--- /dev/null
+++ b/PixelHub-Client/src/Messages/MoveMessage.cpp
@@ -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));
+}
diff --git a/PixelHub-Client/src/Messages/MoveMessage.h b/PixelHub-Client/src/Messages/MoveMessage.h
new file mode 100644
index 0000000..6036f25
--- /dev/null
+++ b/PixelHub-Client/src/Messages/MoveMessage.h
@@ -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;
+};
diff --git a/PixelHub-Client/src/PixelMessage.cpp b/PixelHub-Client/src/PixelMessage.cpp
index eb12978..5dbed8a 100644
--- a/PixelHub-Client/src/PixelMessage.cpp
+++ b/PixelHub-Client/src/PixelMessage.cpp
@@ -1,3 +1,5 @@
+#pragma once
+
 #include "PixelMessage.h"
 #include "PixelBot.h"
 
diff --git a/PixelHub-Client/src/PixelMessage.h b/PixelHub-Client/src/PixelMessage.h
index fdb00ef..6f646b3 100644
--- a/PixelHub-Client/src/PixelMessage.h
+++ b/PixelHub-Client/src/PixelMessage.h
@@ -1,3 +1,5 @@
+#pragma once
+
 #include <Arduino.h>
 
 
