Aligned Messages

This commit is contained in:
Pascal Serrarens 2025-05-01 11:01:51 +02:00
parent db1265a135
commit 8d778ab41e
16 changed files with 71 additions and 70 deletions

View File

@ -1,15 +1,17 @@
#pragma once #pragma once
#include "Messages.h" #include "IMessage.h"
#include "Thing.h"
namespace RoboidControl { namespace RoboidControl {
/// @brief Message to send thing-specific data /// @brief A message containing binary data for custom communication
class BinaryMsg : public IMessage { class BinaryMsg : public IMessage {
public: public:
/// @brief The message ID /// @brief The message ID
static const unsigned char id = 0xB1; static const unsigned char id = 0xB1;
/// @brief The length of the message without the binary data itslef /// @brief The length of the message in bytes, excluding the binary data
/// For the total size of the message this.bytes.Length should be added to this value.
static const unsigned length = 4; static const unsigned length = 4;
/// @brief The network ID of the thing /// @brief The network ID of the thing
@ -23,7 +25,7 @@ class BinaryMsg : public IMessage {
/// @brief The binary data which is communicated /// @brief The binary data which is communicated
char* data = nullptr; char* data = nullptr;
/// @brief Create a new message for sending /// @brief Create a BinaryMsg
/// @param networkId The network ID of the thing /// @param networkId The network ID of the thing
/// @param thing The thing for which binary data is sent /// @param thing The thing for which binary data is sent
BinaryMsg(unsigned char networkId, Thing* thing); BinaryMsg(unsigned char networkId, Thing* thing);

View File

@ -15,10 +15,10 @@ DestroyMsg::DestroyMsg(char* buffer) {
DestroyMsg::~DestroyMsg() {} DestroyMsg::~DestroyMsg() {}
unsigned char DestroyMsg::Serialize(char* buffer) { unsigned char DestroyMsg::Serialize(char* buffer) {
//#if defined(DEBUG) #if defined(DEBUG)
std::cout << "Send DestroyMsg [" << (int)this->networkId << "/" std::cout << "Send DestroyMsg [" << (int)this->networkId << "/"
<< (int)this->thingId << "] " << std::endl; << (int)this->thingId << "] " << std::endl;
//#endif #endif
unsigned char ix = 0; unsigned char ix = 0;
buffer[ix++] = this->id; buffer[ix++] = this->id;
buffer[ix++] = this->networkId; buffer[ix++] = this->networkId;

View File

@ -1,13 +1,15 @@
#include "Messages.h" #pragma once
#include "IMessage.h"
namespace RoboidControl { namespace RoboidControl {
/// @brief Message notifiying that a Thing no longer exists /// @brief A Message notifiying that a Thing no longer exists
class DestroyMsg : public IMessage { class DestroyMsg : public IMessage {
public: public:
/// @brief The message ID /// @brief The message ID
static const unsigned char id = 0x20; static const unsigned char id = 0x20;
/// @brief The length of the message /// @brief The length of the message in bytes
static const unsigned length = 3; static const unsigned length = 3;
/// @brief The network ID of the thing /// @brief The network ID of the thing
unsigned char networkId; unsigned char networkId;

View File

@ -1,7 +1,4 @@
#include "Messages.h" #include "IMessage.h"
#include "LowLevelMessages.h"
#include "string.h"
namespace RoboidControl { namespace RoboidControl {

16
Messages/IMessage.h Normal file
View File

@ -0,0 +1,16 @@
#pragma once
namespace RoboidControl {
/// @brief Root structure for all communcation messages
class IMessage {
public:
IMessage();
/// @brief Serialize the message into a byte array for sending
/// @param buffer The buffer to serilize into
/// @return The length of the message in the buffer
virtual unsigned char Serialize(char* buffer);
};
} // namespace RoboidControl

View File

@ -7,9 +7,9 @@ InvestigateMsg::InvestigateMsg(char* buffer) {
this->networkId = buffer[ix++]; this->networkId = buffer[ix++];
this->thingId = buffer[ix++]; this->thingId = buffer[ix++];
} }
InvestigateMsg::InvestigateMsg(unsigned char networkId, unsigned char thingId) { InvestigateMsg::InvestigateMsg(unsigned char networkId, Thing* thing) {
this->networkId = networkId; this->networkId = networkId;
this->thingId = thingId; this->thingId = thing->id;
} }
InvestigateMsg::~InvestigateMsg() {} InvestigateMsg::~InvestigateMsg() {}

View File

@ -1,4 +1,7 @@
#include "Messages.h" #pragma once
#include "IMessage.h"
#include "Thing.h"
namespace RoboidControl { namespace RoboidControl {
@ -14,10 +17,10 @@ class InvestigateMsg : public IMessage {
/// @brief the ID of the thing /// @brief the ID of the thing
unsigned char thingId; unsigned char thingId;
/// @brief Create a new message for sending /// @brief Create an investigate message
/// @param networkId The network ID for the thing /// @param networkId The network ID for the thing
/// @param thingId The ID of the thing /// @param thing The thing for which the details are requested
InvestigateMsg(unsigned char networkId, unsigned char thingId); InvestigateMsg(unsigned char networkId, Thing* thing);
/// @copydoc RoboidControl::IMessage::IMessage(char*) /// @copydoc RoboidControl::IMessage::IMessage(char*)
InvestigateMsg(char* buffer); InvestigateMsg(char* buffer);
/// @brief Destructor for the message /// @brief Destructor for the message

View File

@ -1,3 +1,5 @@
#pragma once
#include "LinearAlgebra/Spherical.h" #include "LinearAlgebra/Spherical.h"
#include "LinearAlgebra/SwingTwist.h" #include "LinearAlgebra/SwingTwist.h"
@ -5,18 +7,18 @@ namespace RoboidControl {
class LowLevelMessages { class LowLevelMessages {
public: public:
static void SendAngle8(char* buffer, unsigned char* ix, const float angle);
static Angle8 ReceiveAngle8(const char* buffer, unsigned char* startIndex);
static void SendFloat16(char* buffer, unsigned char* ix, float value);
static float ReceiveFloat16(const char* buffer, unsigned char* startIndex);
static void SendSpherical(char* buffer, unsigned char* ix, Spherical s); static void SendSpherical(char* buffer, unsigned char* ix, Spherical s);
static Spherical ReceiveSpherical(const char* buffer, static Spherical ReceiveSpherical(const char* buffer,
unsigned char* startIndex); unsigned char* startIndex);
static void SendQuat32(char* buffer, unsigned char* ix, SwingTwist q); static void SendQuat32(char* buffer, unsigned char* ix, SwingTwist q);
static SwingTwist ReceiveQuat32(const char* buffer, unsigned char* ix); static SwingTwist ReceiveQuat32(const char* buffer, unsigned char* ix);
static void SendAngle8(char* buffer, unsigned char* ix, const float angle);
static Angle8 ReceiveAngle8(const char* buffer, unsigned char* startIndex);
static void SendFloat16(char* buffer, unsigned char* ix, float value);
static float ReceiveFloat16(const char* buffer, unsigned char* startIndex);
}; };
} // namespace RoboidControl } // namespace RoboidControl

View File

@ -1,22 +0,0 @@
#pragma once
#include "LinearAlgebra/Spherical.h"
#include "LinearAlgebra/SwingTwist.h"
#include "Thing.h"
namespace RoboidControl {
class ParticipantUDP;
class IMessage {
public:
IMessage();
virtual unsigned char Serialize(char* buffer);
static unsigned char* ReceiveMsg(unsigned char packetSize);
// bool Publish(ParticipantUDP *participant);
// bool SendTo(ParticipantUDP *participant);
};
} // namespace RoboidControl

View File

@ -1,4 +1,7 @@
#include "Messages.h" #pragma once
#include "IMessage.h"
#include "Thing.h"
namespace RoboidControl { namespace RoboidControl {
@ -26,8 +29,6 @@ class ModelUrlMsg : public IMessage {
ModelUrlMsg(unsigned char networkId, Thing* thing); ModelUrlMsg(unsigned char networkId, Thing* thing);
/// @copydoc RoboidControl::IMessage::IMessage(char*) /// @copydoc RoboidControl::IMessage::IMessage(char*)
ModelUrlMsg(const char* buffer); ModelUrlMsg(const char* buffer);
// ModelUrlMsg(unsigned char networkId, unsigned char thingId,
// unsigned char urlLegth, const char *url, float scale = 1);
/// @brief Destructor for the message /// @brief Destructor for the message
virtual ~ModelUrlMsg(); virtual ~ModelUrlMsg();

View File

@ -1,4 +1,7 @@
#include "Messages.h" #pragma once
#include "IMessage.h"
#include "Thing.h"
namespace RoboidControl { namespace RoboidControl {
@ -22,9 +25,6 @@ class NameMsg : public IMessage {
/// @param networkId The network ID of the thing /// @param networkId The network ID of the thing
/// @param thing The ID of the thing /// @param thing The ID of the thing
NameMsg(unsigned char networkId, Thing* thing); NameMsg(unsigned char networkId, Thing* thing);
// NameMsg(unsigned char networkId, unsigned char thingId, const char *name,
// unsigned char nameLength);
/// @copydoc RoboidControl::IMessage::IMessage(char*) /// @copydoc RoboidControl::IMessage::IMessage(char*)
NameMsg(const char* buffer); NameMsg(const char* buffer);
/// @brief Destructor for the message /// @brief Destructor for the message

View File

@ -1,4 +1,6 @@
#include "Messages.h" #pragma once
#include "IMessage.h"
namespace RoboidControl { namespace RoboidControl {

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "Messages.h" #include "IMessage.h"
namespace RoboidControl { namespace RoboidControl {

View File

@ -1,4 +1,6 @@
#include "Messages.h" #pragma once
#include "IMessage.h"
#include "Thing.h"
namespace RoboidControl { namespace RoboidControl {
@ -9,7 +11,7 @@ class PoseMsg : public IMessage {
public: public:
/// @brief The message ID /// @brief The message ID
static const unsigned char id = 0x10; static const unsigned char id = 0x10;
/// @brief The length of the message /// @brief The length of the message in bytes
unsigned char length = 4 + 4 + 4; unsigned char length = 4 + 4 + 4;
/// @brief The network ID of the thing /// @brief The network ID of the thing
@ -40,7 +42,8 @@ class PoseMsg : public IMessage {
/// @brief Create a new message for sending /// @brief Create a new message for sending
/// @param networkId he network ID of the thing /// @param networkId he network ID of the thing
/// @param thing The thing for which the pose shouldbe sent /// @param thing The thing for which the pose should be sent
/// @param force If true, position and orientation are always included, even when they are not updated
PoseMsg(unsigned char networkId, Thing* thing, bool force = false); PoseMsg(unsigned char networkId, Thing* thing, bool force = false);
/// @copydoc RoboidControl::IMessage::IMessage(char*) /// @copydoc RoboidControl::IMessage::IMessage(char*)

View File

@ -1,4 +1,4 @@
#include "Messages.h" #include "IMessage.h"
namespace RoboidControl { namespace RoboidControl {
@ -9,10 +9,6 @@ class TextMsg : public IMessage {
static const unsigned char id = 0xB0; static const unsigned char id = 0xB0;
/// @brief The length of the message without the text itself /// @brief The length of the message without the text itself
static const unsigned char length = 2; static const unsigned char length = 2;
/// @brief The network ID of the thing
unsigned char networkId;
/// @brief the ID of the thing
unsigned char thingId;
/// @brief The text without the null terminator /// @brief The text without the null terminator
const char* text; const char* text;
/// @brief The length of the text /// @brief The length of the text

View File

@ -1,8 +1,9 @@
#include "Messages.h" #include "IMessage.h"
#include "Thing.h"
namespace RoboidControl { namespace RoboidControl {
/// @brief Message providing generic information about a Thing /// @brief Message providing generic details about a Thing
class ThingMsg : public IMessage { class ThingMsg : public IMessage {
public: public:
/// @brief The message ID /// @brief The message ID
@ -13,17 +14,15 @@ class ThingMsg : public IMessage {
unsigned char networkId; unsigned char networkId;
/// @brief The ID of the thing /// @brief The ID of the thing
unsigned char thingId; unsigned char thingId;
/// @brief The Thing.Type of the thing /// @brief The type of thing
unsigned char thingType; unsigned char thingType;
/// @brief The parent of the thing in the hierarachy. This is null for root Things /// @brief The ID of the parent thing in the hierarchy. This is zero for root things
unsigned char parentId; unsigned char parentId;
/// @brief Create a message for sending /// @brief Create a message for sending
/// @param networkId The network ID of the thing</param> /// @param networkId The network ID of the thing</param>
/// @param thing The thing /// @param thing The thing
ThingMsg(unsigned char networkId, Thing* thing); ThingMsg(unsigned char networkId, Thing* thing);
// ThingMsg(unsigned char networkId, unsigned char thingId,
// unsigned char thingType, unsigned char parentId);
/// @copydoc RoboidControl::IMessage::IMessage(char*) /// @copydoc RoboidControl::IMessage::IMessage(char*)
ThingMsg(const char* buffer); ThingMsg(const char* buffer);