diff --git a/Messages/BinaryMsg.h b/Messages/BinaryMsg.h index 10adb90..81838c0 100644 --- a/Messages/BinaryMsg.h +++ b/Messages/BinaryMsg.h @@ -1,15 +1,17 @@ #pragma once -#include "Messages.h" +#include "IMessage.h" +#include "Thing.h" namespace RoboidControl { -/// @brief Message to send thing-specific data +/// @brief A message containing binary data for custom communication class BinaryMsg : public IMessage { public: /// @brief The message ID 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; /// @brief The network ID of the thing @@ -23,7 +25,7 @@ class BinaryMsg : public IMessage { /// @brief The binary data which is communicated char* data = nullptr; - /// @brief Create a new message for sending + /// @brief Create a BinaryMsg /// @param networkId The network ID of the thing /// @param thing The thing for which binary data is sent BinaryMsg(unsigned char networkId, Thing* thing); diff --git a/Messages/DestroyMsg.cpp b/Messages/DestroyMsg.cpp index f41ba3b..948b1fe 100644 --- a/Messages/DestroyMsg.cpp +++ b/Messages/DestroyMsg.cpp @@ -15,10 +15,10 @@ DestroyMsg::DestroyMsg(char* buffer) { DestroyMsg::~DestroyMsg() {} unsigned char DestroyMsg::Serialize(char* buffer) { -//#if defined(DEBUG) +#if defined(DEBUG) std::cout << "Send DestroyMsg [" << (int)this->networkId << "/" << (int)this->thingId << "] " << std::endl; -//#endif +#endif unsigned char ix = 0; buffer[ix++] = this->id; buffer[ix++] = this->networkId; diff --git a/Messages/DestroyMsg.h b/Messages/DestroyMsg.h index 74ad2aa..dde5f81 100644 --- a/Messages/DestroyMsg.h +++ b/Messages/DestroyMsg.h @@ -1,13 +1,15 @@ -#include "Messages.h" +#pragma once + +#include "IMessage.h" 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 { public: /// @brief The message ID 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; /// @brief The network ID of the thing unsigned char networkId; diff --git a/Messages/Messages.cpp b/Messages/IMessage.cpp similarity index 73% rename from Messages/Messages.cpp rename to Messages/IMessage.cpp index d9f1a8c..86ccef7 100644 --- a/Messages/Messages.cpp +++ b/Messages/IMessage.cpp @@ -1,7 +1,4 @@ -#include "Messages.h" - -#include "LowLevelMessages.h" -#include "string.h" +#include "IMessage.h" namespace RoboidControl { diff --git a/Messages/IMessage.h b/Messages/IMessage.h new file mode 100644 index 0000000..632287e --- /dev/null +++ b/Messages/IMessage.h @@ -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 diff --git a/Messages/InvestigateMsg.cpp b/Messages/InvestigateMsg.cpp index 6420e42..7b94c8d 100644 --- a/Messages/InvestigateMsg.cpp +++ b/Messages/InvestigateMsg.cpp @@ -7,9 +7,9 @@ InvestigateMsg::InvestigateMsg(char* buffer) { this->networkId = 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->thingId = thingId; + this->thingId = thing->id; } InvestigateMsg::~InvestigateMsg() {} diff --git a/Messages/InvestigateMsg.h b/Messages/InvestigateMsg.h index 3179ec4..cff3c32 100644 --- a/Messages/InvestigateMsg.h +++ b/Messages/InvestigateMsg.h @@ -1,4 +1,7 @@ -#include "Messages.h" +#pragma once + +#include "IMessage.h" +#include "Thing.h" namespace RoboidControl { @@ -14,10 +17,10 @@ class InvestigateMsg : public IMessage { /// @brief the ID of the thing unsigned char thingId; - /// @brief Create a new message for sending + /// @brief Create an investigate message /// @param networkId The network ID for the thing - /// @param thingId The ID of the thing - InvestigateMsg(unsigned char networkId, unsigned char thingId); + /// @param thing The thing for which the details are requested + InvestigateMsg(unsigned char networkId, Thing* thing); /// @copydoc RoboidControl::IMessage::IMessage(char*) InvestigateMsg(char* buffer); /// @brief Destructor for the message diff --git a/Messages/LowLevelMessages.h b/Messages/LowLevelMessages.h index bffe010..144e50c 100644 --- a/Messages/LowLevelMessages.h +++ b/Messages/LowLevelMessages.h @@ -1,3 +1,5 @@ +#pragma once + #include "LinearAlgebra/Spherical.h" #include "LinearAlgebra/SwingTwist.h" @@ -5,18 +7,18 @@ namespace RoboidControl { class LowLevelMessages { 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 Spherical ReceiveSpherical(const char* buffer, unsigned char* startIndex); static void SendQuat32(char* buffer, unsigned char* ix, SwingTwist q); 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 diff --git a/Messages/Messages.h b/Messages/Messages.h deleted file mode 100644 index df22544..0000000 --- a/Messages/Messages.h +++ /dev/null @@ -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 diff --git a/Messages/ModelUrlMsg.h b/Messages/ModelUrlMsg.h index 7c493eb..9759aa0 100644 --- a/Messages/ModelUrlMsg.h +++ b/Messages/ModelUrlMsg.h @@ -1,4 +1,7 @@ -#include "Messages.h" +#pragma once + +#include "IMessage.h" +#include "Thing.h" namespace RoboidControl { @@ -26,8 +29,6 @@ class ModelUrlMsg : public IMessage { ModelUrlMsg(unsigned char networkId, Thing* thing); /// @copydoc RoboidControl::IMessage::IMessage(char*) 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 virtual ~ModelUrlMsg(); diff --git a/Messages/NameMsg.h b/Messages/NameMsg.h index 0d1bebc..c283a59 100644 --- a/Messages/NameMsg.h +++ b/Messages/NameMsg.h @@ -1,4 +1,7 @@ -#include "Messages.h" +#pragma once + +#include "IMessage.h" +#include "Thing.h" namespace RoboidControl { @@ -22,9 +25,6 @@ class NameMsg : public IMessage { /// @param networkId The network ID of the thing /// @param thing The ID of the 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*) NameMsg(const char* buffer); /// @brief Destructor for the message diff --git a/Messages/NetworkIdMsg.h b/Messages/NetworkIdMsg.h index 083439b..de78906 100644 --- a/Messages/NetworkIdMsg.h +++ b/Messages/NetworkIdMsg.h @@ -1,4 +1,6 @@ -#include "Messages.h" +#pragma once + +#include "IMessage.h" namespace RoboidControl { diff --git a/Messages/ParticipantMsg.h b/Messages/ParticipantMsg.h index 28f9eb5..105881d 100644 --- a/Messages/ParticipantMsg.h +++ b/Messages/ParticipantMsg.h @@ -1,6 +1,6 @@ #pragma once -#include "Messages.h" +#include "IMessage.h" namespace RoboidControl { diff --git a/Messages/PoseMsg.h b/Messages/PoseMsg.h index bc0c336..fe702da 100644 --- a/Messages/PoseMsg.h +++ b/Messages/PoseMsg.h @@ -1,4 +1,6 @@ -#include "Messages.h" +#pragma once +#include "IMessage.h" +#include "Thing.h" namespace RoboidControl { @@ -9,7 +11,7 @@ class PoseMsg : public IMessage { public: /// @brief The message ID 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; /// @brief The network ID of the thing @@ -40,7 +42,8 @@ class PoseMsg : public IMessage { /// @brief Create a new message for sending /// @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); /// @copydoc RoboidControl::IMessage::IMessage(char*) diff --git a/Messages/TextMsg.h b/Messages/TextMsg.h index 5b25fca..a5763e6 100644 --- a/Messages/TextMsg.h +++ b/Messages/TextMsg.h @@ -1,4 +1,4 @@ -#include "Messages.h" +#include "IMessage.h" namespace RoboidControl { @@ -9,10 +9,6 @@ class TextMsg : public IMessage { static const unsigned char id = 0xB0; /// @brief The length of the message without the text itself 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 const char* text; /// @brief The length of the text diff --git a/Messages/ThingMsg.h b/Messages/ThingMsg.h index c40fb97..a26b60d 100644 --- a/Messages/ThingMsg.h +++ b/Messages/ThingMsg.h @@ -1,8 +1,9 @@ -#include "Messages.h" +#include "IMessage.h" +#include "Thing.h" namespace RoboidControl { -/// @brief Message providing generic information about a Thing +/// @brief Message providing generic details about a Thing class ThingMsg : public IMessage { public: /// @brief The message ID @@ -13,17 +14,15 @@ class ThingMsg : public IMessage { unsigned char networkId; /// @brief The ID of the thing unsigned char thingId; - /// @brief The Thing.Type of the thing + /// @brief The type of thing 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; /// @brief Create a message for sending /// @param networkId The network ID of the thing /// @param thing The 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*) ThingMsg(const char* buffer);