Added initial ControlCore code

This commit is contained in:
Pascal Serrarens 2024-12-10 16:56:32 +01:00
parent f05ab5c742
commit 14e3499742
2 changed files with 67 additions and 0 deletions

39
ControlCore/Messages.cpp Normal file
View File

@ -0,0 +1,39 @@
#include "Messages.h"
#pragma region IMessage
unsigned char *IMessage::Serialize() { return nullptr; }
bool IMessage::SendMsg(IMessage msg, unsigned char bufferSize) {
return SendMsg(msg.Serialize(), bufferSize);
}
bool IMessage::SendMsg(unsigned char *buffer, unsigned char bufferSize) {
// SendBuffer(buffer, bufferSize);
return false;
}
#pragma endregion
#pragma region Investigate
InvestigateMsg::InvestigateMsg(unsigned char thingId) {
this->networkId = 0;
this->thingId = thingId;
}
unsigned char *InvestigateMsg::Serialize() {
unsigned char *buffer = IMessage::buffer;
buffer[0] = InvestigateMsg::id;
buffer[1] = this->networkId;
buffer[2] = this->thingId;
return buffer;
}
bool InvestigateMsg::Send(unsigned char thingId) {
InvestigateMsg msg = InvestigateMsg(thingId);
return SendMsg(msg, InvestigateMsg::length);
}
// Investiaget
#pragma endregion

28
ControlCore/Messages.h Normal file
View File

@ -0,0 +1,28 @@
namespace Passer::Control {
class IMessage {
public:
static unsigned char buffer[256];
virtual unsigned char *Serialize();
static bool SendMsg(IMessage msg, unsigned char bufferSize);
static bool SendMsg(unsigned char *buffer, unsigned char bufferSize);
};
class InvestigateMsg : public IMessage {
public:
static const unsigned char id = 0x81;
static const unsigned char length = 3;
unsigned char networkId;
unsigned char thingId;
InvestigateMsg(unsigned char thingId);
virtual unsigned char *Serialize() override;
static bool Send(unsigned char thingId);
};
} // namespace Passer::Control
using namespace Passer::Control;