Browse Source

[client] Start writing Message classes for client

master
Starbeamrainbowlabs 4 years ago
parent
commit
49c19fcaf1
10 changed files with 117 additions and 0 deletions
  1. +19
    -0
      PixelHub-Client/src/Messages/ErrorMessage.cpp
  2. +14
    -0
      PixelHub-Client/src/Messages/ErrorMessage.h
  3. +8
    -0
      PixelHub-Client/src/Messages/HandleshakeRequestMessage.cpp
  4. +12
    -0
      PixelHub-Client/src/Messages/HandshakeRequestMessage.h
  5. +16
    -0
      PixelHub-Client/src/Messages/HandshakeResponseMessage.cpp
  6. +13
    -0
      PixelHub-Client/src/Messages/HandshakeResponseMessage.h
  7. +17
    -0
      PixelHub-Client/src/Messages/MoveMessage.cpp
  8. +14
    -0
      PixelHub-Client/src/Messages/MoveMessage.h
  9. +2
    -0
      PixelHub-Client/src/PixelMessage.cpp
  10. +2
    -0
      PixelHub-Client/src/PixelMessage.h

+ 19
- 0
PixelHub-Client/src/Messages/ErrorMessage.cpp 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));
}

+ 14
- 0
PixelHub-Client/src/Messages/ErrorMessage.h 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;
};

+ 8
- 0
PixelHub-Client/src/Messages/HandleshakeRequestMessage.cpp View File

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

+ 12
- 0
PixelHub-Client/src/Messages/HandshakeRequestMessage.h View File

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

+ 16
- 0
PixelHub-Client/src/Messages/HandshakeResponseMessage.cpp 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));
}

+ 13
- 0
PixelHub-Client/src/Messages/HandshakeResponseMessage.h 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;
};

+ 17
- 0
PixelHub-Client/src/Messages/MoveMessage.cpp 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));
}

+ 14
- 0
PixelHub-Client/src/Messages/MoveMessage.h 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;
};

+ 2
- 0
PixelHub-Client/src/PixelMessage.cpp View File

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


+ 2
- 0
PixelHub-Client/src/PixelMessage.h View File

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