From 1916478494d67855efb688dd54fa165588ccc1a3 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Mon, 24 Feb 2025 09:30:17 +0100 Subject: [PATCH] removed namespace Passer --- Arduino/Participant.cpp | 2 - Arduino/Participant.h | 2 - LinearAlgebra/CMakeLists.txt | 25 +++-- float16.cpp => LinearAlgebra/float16.cpp | 0 float16.h => LinearAlgebra/float16.h | 0 Messages/BinaryMsg.cpp | 19 ++-- Messages/BinaryMsg.h | 18 ++-- Messages/DestroyMsg.cpp | 2 - Messages/DestroyMsg.h | 19 ++-- Messages/InvestigateMsg.cpp | 18 ++-- Messages/InvestigateMsg.h | 6 +- Messages/LowLevelMessages.cpp | 31 +++--- Messages/LowLevelMessages.h | 24 ++--- Messages/Messages.cpp | 11 +- Messages/Messages.h | 12 +-- Messages/ModelUrlMsg.cpp | 18 ++-- Messages/ModelUrlMsg.h | 22 ++-- Messages/NameMsg.cpp | 16 ++- Messages/NameMsg.h | 6 +- Messages/NetworkIdMsg.cpp | 15 +-- Messages/NetworkIdMsg.h | 6 +- Messages/ParticipantMsg.cpp | 14 ++- Messages/ParticipantMsg.h | 4 +- Messages/PoseMsg.cpp | 19 ++-- Messages/PoseMsg.h | 6 +- Messages/TextMsg.cpp | 7 +- Messages/TextMsg.h | 6 +- Messages/ThingMsg.cpp | 14 ++- Messages/ThingMsg.h | 8 +- Participant.cpp | 4 +- Participant.h | 53 +++++----- Posix/Participant.cpp | 2 - Posix/Participant.h | 2 - README.md | 6 +- RemoteParticipant.cpp | 2 - RemoteParticipant.h | 2 - Sensors/DigitalSensor.cpp | 2 - Sensors/DigitalSensor.h | 2 - Sensors/TemperatureSensor.cpp | 15 ++- Sensors/TemperatureSensor.h | 2 - SiteServer.cpp | 2 - SiteServer.h | 24 ++--- Thing.cpp | 123 +++++++++-------------- Thing.h | 68 ++++++------- Windows/Participant.cpp | 2 - Windows/Participant.h | 2 - test/second_test.cc | 3 +- test/thing_test.cc | 4 +- 48 files changed, 276 insertions(+), 394 deletions(-) rename float16.cpp => LinearAlgebra/float16.cpp (100%) rename float16.h => LinearAlgebra/float16.h (100%) diff --git a/Arduino/Participant.cpp b/Arduino/Participant.cpp index 838aa1c..fbba67b 100644 --- a/Arduino/Participant.cpp +++ b/Arduino/Participant.cpp @@ -8,7 +8,6 @@ #endif #endif -namespace Passer { namespace RoboidControl { namespace Arduino { @@ -96,4 +95,3 @@ bool Participant::Publish(IMessage* msg) { } // namespace Arduino } // namespace RoboidControl -} // namespace Passer \ No newline at end of file diff --git a/Arduino/Participant.h b/Arduino/Participant.h index dc754c2..36a560e 100644 --- a/Arduino/Participant.h +++ b/Arduino/Participant.h @@ -2,7 +2,6 @@ #include "../Participant.h" -namespace Passer { namespace RoboidControl { namespace Arduino { @@ -19,4 +18,3 @@ class Participant : public RoboidControl::Participant { } // namespace Arduino } // namespace RoboidControl -} // namespace Passer \ No newline at end of file diff --git a/LinearAlgebra/CMakeLists.txt b/LinearAlgebra/CMakeLists.txt index 0c8f19a..ed52791 100644 --- a/LinearAlgebra/CMakeLists.txt +++ b/LinearAlgebra/CMakeLists.txt @@ -23,17 +23,20 @@ else() FetchContent_MakeAvailable(googletest) include_directories(.) - add_library(LinearAlgebra STATIC - "FloatSingle.cpp" - "Angle.cpp" - "Vector2.cpp" - "Vector3.cpp" - "Quaternion.cpp" - "Polar.cpp" - "Spherical.cpp" - "Matrix.cpp" - "SwingTwist.cpp" - "Direction.cpp" + file(GLOB srcs + *.cpp + ) + add_library(LinearAlgebra STATIC ${srcs} + # "FloatSingle.cpp" + # "Angle.cpp" + # "Vector2.cpp" + # "Vector3.cpp" + # "Quaternion.cpp" + # "Polar.cpp" + # "Spherical.cpp" + # "Matrix.cpp" + # "SwingTwist.cpp" + # "Direction.cpp" ) enable_testing() diff --git a/float16.cpp b/LinearAlgebra/float16.cpp similarity index 100% rename from float16.cpp rename to LinearAlgebra/float16.cpp diff --git a/float16.h b/LinearAlgebra/float16.h similarity index 100% rename from float16.h rename to LinearAlgebra/float16.h diff --git a/Messages/BinaryMsg.cpp b/Messages/BinaryMsg.cpp index fe8e380..81ad261 100644 --- a/Messages/BinaryMsg.cpp +++ b/Messages/BinaryMsg.cpp @@ -1,18 +1,16 @@ #include "BinaryMsg.h" -namespace Passer { namespace RoboidControl { -BinaryMsg::BinaryMsg(char *buffer) { +BinaryMsg::BinaryMsg(char* buffer) { unsigned char ix = 1; this->networkId = buffer[ix++]; this->thingId = buffer[ix++]; - this->bytes = - buffer + ix; // This is only valid because the code ensures the the msg - // lifetime is shorter than the buffer lifetime... + this->bytes = buffer + ix; // This is only valid because the code ensures the the msg + // lifetime is shorter than the buffer lifetime... } -BinaryMsg::BinaryMsg(unsigned char networkId, Thing *thing) { +BinaryMsg::BinaryMsg(unsigned char networkId, Thing* thing) { this->networkId = networkId; this->thingId = thing->id; this->thing = thing; @@ -20,10 +18,10 @@ BinaryMsg::BinaryMsg(unsigned char networkId, Thing *thing) { BinaryMsg::~BinaryMsg() {} -unsigned char BinaryMsg::Serialize(char *buffer) { +unsigned char BinaryMsg::Serialize(char* buffer) { unsigned char ix = this->length; this->thing->GenerateBinary(buffer, &ix); - if (ix <= this->length) // in this case, no data is actually sent + if (ix <= this->length) // in this case, no data is actually sent return 0; buffer[0] = this->id; @@ -32,10 +30,9 @@ unsigned char BinaryMsg::Serialize(char *buffer) { return ix; } -BinaryMsg BinaryMsg::Receive(char *buffer, unsigned char bufferSize) { +BinaryMsg BinaryMsg::Receive(char* buffer, unsigned char bufferSize) { BinaryMsg msg = BinaryMsg(buffer); return msg; } -} // namespace RoboidControl -} // namespace Passer +} // namespace RoboidControl diff --git a/Messages/BinaryMsg.h b/Messages/BinaryMsg.h index 987b8a8..986eaf0 100644 --- a/Messages/BinaryMsg.h +++ b/Messages/BinaryMsg.h @@ -2,29 +2,27 @@ #include "Messages.h" -namespace Passer { namespace RoboidControl { class BinaryMsg : public IMessage { -public: + public: static const unsigned char id = 0xB1; static const unsigned length = 3; unsigned char networkId; unsigned char thingId; - Thing *thing; + Thing* thing; unsigned char bytesSize; - char *bytes = nullptr; + char* bytes = nullptr; - BinaryMsg(char *buffer); - BinaryMsg(unsigned char networkId, Thing *thing); + BinaryMsg(char* buffer); + BinaryMsg(unsigned char networkId, Thing* thing); virtual ~BinaryMsg(); - virtual unsigned char Serialize(char *buffer) override; + virtual unsigned char Serialize(char* buffer) override; - static BinaryMsg Receive(char *buffer, unsigned char bufferSize); + static BinaryMsg Receive(char* buffer, unsigned char bufferSize); }; -} // namespace RoboidControl -} // namespace Passer +} // namespace RoboidControl diff --git a/Messages/DestroyMsg.cpp b/Messages/DestroyMsg.cpp index e2c04ad..24fbb63 100644 --- a/Messages/DestroyMsg.cpp +++ b/Messages/DestroyMsg.cpp @@ -1,6 +1,5 @@ #include "DestroyMsg.h" -namespace Passer { namespace RoboidControl { DestroyMsg::DestroyMsg(unsigned char networkId, Thing *thing) { @@ -21,4 +20,3 @@ unsigned char DestroyMsg::Serialize(char *buffer) { } } // namespace RoboidControl -} // namespace Passer diff --git a/Messages/DestroyMsg.h b/Messages/DestroyMsg.h index 66a6830..74ad2aa 100644 --- a/Messages/DestroyMsg.h +++ b/Messages/DestroyMsg.h @@ -1,10 +1,10 @@ #include "Messages.h" -namespace Passer { + namespace RoboidControl { /// @brief Message notifiying that a Thing no longer exists class DestroyMsg : public IMessage { -public: + public: /// @brief The message ID static const unsigned char id = 0x20; /// @brief The length of the message @@ -17,15 +17,14 @@ public: /// @brief Create a message for sending /// @param networkId The network ID of the thing /// @param thing The ID of the thing - DestroyMsg(unsigned char networkId, Thing *thing); - /// @copydoc Passer::RoboidControl::IMessage::IMessage(char*) - DestroyMsg(char * buffer); - /// @brief Destructor for the message + DestroyMsg(unsigned char networkId, Thing* thing); + /// @copydoc RoboidControl::IMessage::IMessage(char*) + DestroyMsg(char* buffer); + /// @brief Destructor for the message virtual ~DestroyMsg(); - /// @copydoc Passer::RoboidControl::IMessage::Serialize - virtual unsigned char Serialize(char *buffer) override; + /// @copydoc RoboidControl::IMessage::Serialize + virtual unsigned char Serialize(char* buffer) override; }; -} // namespace RoboidControl -} // namespace Passer \ No newline at end of file +} // namespace RoboidControl diff --git a/Messages/InvestigateMsg.cpp b/Messages/InvestigateMsg.cpp index da449a9..7bbde42 100644 --- a/Messages/InvestigateMsg.cpp +++ b/Messages/InvestigateMsg.cpp @@ -1,8 +1,9 @@ #include "InvestigateMsg.h" -#pragma region Investigate -InvestigateMsg::InvestigateMsg(char *buffer) { - unsigned ix = 1; // first byte is msgId +namespace RoboidControl { + +InvestigateMsg::InvestigateMsg(char* buffer) { + unsigned ix = 1; // first byte is msgId this->networkId = buffer[ix++]; this->thingId = buffer[ix++]; } @@ -12,7 +13,7 @@ InvestigateMsg::InvestigateMsg(unsigned char networkId, unsigned char thingId) { } InvestigateMsg::~InvestigateMsg() {} -unsigned char InvestigateMsg::Serialize(char *buffer) { +unsigned char InvestigateMsg::Serialize(char* buffer) { unsigned char ix = 0; buffer[ix++] = this->id; buffer[ix++] = this->networkId; @@ -20,11 +21,4 @@ unsigned char InvestigateMsg::Serialize(char *buffer) { return ix; } -// bool InvestigateMsg::Send(Participant *participant, unsigned char networkId, -// unsigned char thingId) { -// InvestigateMsg msg = InvestigateMsg(networkId, thingId); -// return msg.Send(participant); -// } - -// Investigate -#pragma endregion +} // namespace RoboidControl \ No newline at end of file diff --git a/Messages/InvestigateMsg.h b/Messages/InvestigateMsg.h index 09eb0a8..3179ec4 100644 --- a/Messages/InvestigateMsg.h +++ b/Messages/InvestigateMsg.h @@ -1,6 +1,5 @@ #include "Messages.h" -namespace Passer { namespace RoboidControl { /// @brief Message to request details for a Thing @@ -19,14 +18,13 @@ class InvestigateMsg : public IMessage { /// @param networkId The network ID for the thing /// @param thingId The ID of the thing InvestigateMsg(unsigned char networkId, unsigned char thingId); - /// @copydoc Passer::RoboidControl::IMessage::IMessage(char*) + /// @copydoc RoboidControl::IMessage::IMessage(char*) InvestigateMsg(char* buffer); /// @brief Destructor for the message virtual ~InvestigateMsg(); - /// @copydoc Passer::RoboidControl::IMessage::Serialize + /// @copydoc RoboidControl::IMessage::Serialize virtual unsigned char Serialize(char* buffer) override; }; } // namespace RoboidControl -} // namespace Passer \ No newline at end of file diff --git a/Messages/LowLevelMessages.cpp b/Messages/LowLevelMessages.cpp index ccce3b4..e951e1b 100644 --- a/Messages/LowLevelMessages.cpp +++ b/Messages/LowLevelMessages.cpp @@ -2,13 +2,13 @@ #include "float16.h" -void LowLevelMessages::SendAngle8(char *buffer, unsigned char *ix, - const float angle) { +namespace RoboidControl { + +void LowLevelMessages::SendAngle8(char* buffer, unsigned char* ix, const float angle) { Angle8 packedAngle2 = Angle8::Degrees(angle); buffer[(*ix)++] = packedAngle2.GetBinary(); } -Angle8 LowLevelMessages::ReceiveAngle8(const char *buffer, - unsigned char *startIndex) { +Angle8 LowLevelMessages::ReceiveAngle8(const char* buffer, unsigned char* startIndex) { unsigned char binary = buffer[(*startIndex)++]; Angle8 angle = Angle8::Binary(binary); @@ -16,16 +16,14 @@ Angle8 LowLevelMessages::ReceiveAngle8(const char *buffer, return angle; } -void LowLevelMessages::SendFloat16(char *buffer, unsigned char *ix, - float value) { +void LowLevelMessages::SendFloat16(char* buffer, unsigned char* ix, float value) { float16 value16 = float16(value); short binary = value16.getBinary(); buffer[(*ix)++] = (binary >> 8) & 0xFF; buffer[(*ix)++] = binary & 0xFF; } -float LowLevelMessages::ReceiveFloat16(const char *buffer, - unsigned char *startIndex) { +float LowLevelMessages::ReceiveFloat16(const char* buffer, unsigned char* startIndex) { unsigned char ix = *startIndex; unsigned char msb = buffer[ix++]; unsigned char lsb = buffer[ix++]; @@ -37,14 +35,12 @@ float LowLevelMessages::ReceiveFloat16(const char *buffer, return (float)f.toFloat(); } -void LowLevelMessages::SendSpherical16(char *buffer, unsigned char *ix, - Spherical16 s) { +void LowLevelMessages::SendSpherical16(char* buffer, unsigned char* ix, Spherical16 s) { SendFloat16(buffer, ix, s.distance); SendAngle8(buffer, ix, s.direction.horizontal.InDegrees()); SendAngle8(buffer, ix, s.direction.vertical.InDegrees()); } -Spherical16 LowLevelMessages::ReceiveSpherical16(const char *buffer, - unsigned char *startIndex) { +Spherical16 LowLevelMessages::ReceiveSpherical16(const char* buffer, unsigned char* startIndex) { float distance = ReceiveFloat16(buffer, startIndex); Angle8 horizontal8 = ReceiveAngle8(buffer, startIndex); @@ -57,9 +53,7 @@ Spherical16 LowLevelMessages::ReceiveSpherical16(const char *buffer, return s; } -void Passer::RoboidControl::LowLevelMessages::SendQuat32(char *buffer, - unsigned char *ix, - SwingTwist16 rotation) { +void LowLevelMessages::SendQuat32(char* buffer, unsigned char* ix, SwingTwist16 rotation) { Quaternion q = rotation.ToQuaternion(); unsigned char qx = (char)(q.x * 127 + 128); unsigned char qy = (char)(q.y * 127 + 128); @@ -78,8 +72,7 @@ void Passer::RoboidControl::LowLevelMessages::SendQuat32(char *buffer, buffer[(*ix)++] = qw; } -SwingTwist16 LowLevelMessages::ReceiveQuat32(const char *buffer, - unsigned char *ix) { +SwingTwist16 LowLevelMessages::ReceiveQuat32(const char* buffer, unsigned char* ix) { float qx = (buffer[(*ix)++] - 128.0F) / 127.0F; float qy = (buffer[(*ix)++] - 128.0F) / 127.0F; float qz = (buffer[(*ix)++] - 128.0F) / 127.0F; @@ -87,4 +80,6 @@ SwingTwist16 LowLevelMessages::ReceiveQuat32(const char *buffer, Quaternion q = Quaternion(qx, qy, qz, qw); SwingTwist16 s = SwingTwist16::FromQuaternion(q); return s; -} \ No newline at end of file +} + +} // namespace RoboidControl \ No newline at end of file diff --git a/Messages/LowLevelMessages.h b/Messages/LowLevelMessages.h index 0032cf4..277f1e7 100644 --- a/Messages/LowLevelMessages.h +++ b/Messages/LowLevelMessages.h @@ -1,25 +1,21 @@ #include "LinearAlgebra/Spherical.h" #include "LinearAlgebra/SwingTwist.h" -namespace Passer { 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); + 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 SendFloat16(char* buffer, unsigned char* ix, float value); + static float ReceiveFloat16(const char* buffer, unsigned char* startIndex); - static void SendSpherical16(char *buffer, unsigned char *ix, Spherical16 s); - static Spherical16 ReceiveSpherical16(const char *buffer, - unsigned char *startIndex); + static void SendSpherical16(char* buffer, unsigned char* ix, Spherical16 s); + static Spherical16 ReceiveSpherical16(const char* buffer, unsigned char* startIndex); - static void SendQuat32(char *buffer, unsigned char *ix, SwingTwist16 q); - static SwingTwist16 ReceiveQuat32(const char *buffer, unsigned char *ix); + static void SendQuat32(char* buffer, unsigned char* ix, SwingTwist16 q); + static SwingTwist16 ReceiveQuat32(const char* buffer, unsigned char* ix); }; -} // namespace RoboidControl -} // namespace Passer -using namespace Passer::RoboidControl; \ No newline at end of file +} // namespace RoboidControl diff --git a/Messages/Messages.cpp b/Messages/Messages.cpp index dfd2a4a..d4c77a2 100644 --- a/Messages/Messages.cpp +++ b/Messages/Messages.cpp @@ -4,8 +4,7 @@ #include "Participant.h" #include "string.h" -namespace Passer { - namespace RoboidControl { +namespace RoboidControl { #pragma region IMessage @@ -19,17 +18,11 @@ unsigned char IMessage::Serialize(char* buffer) { return 0; } -// void IMessage::Deserialize(unsigned char *buffer) {} - // bool IMessage::SendMsg(Participant *client, IMessage msg) { // // return SendMsg(client, client.buffer, );nameLength // return client->SendBuffer(msg.Serialize(client->buffer)); // } -// unsigned char *IMessage::ReceiveMsg(unsigned char packetSize) { -// return nullptr; -// } - // bool IMessage::Publish(Participant *participant) { // return participant->PublishBuffer(Serialize(participant->buffer)); // } @@ -40,4 +33,4 @@ unsigned char IMessage::Serialize(char* buffer) { // IMessage #pragma endregion - }} \ No newline at end of file +} // namespace RoboidControl \ No newline at end of file diff --git a/Messages/Messages.h b/Messages/Messages.h index 72263c2..1e96b1b 100644 --- a/Messages/Messages.h +++ b/Messages/Messages.h @@ -5,23 +5,19 @@ #include "Thing.h" #include "float16.h" -namespace Passer { namespace RoboidControl { class Participant; class IMessage { -public: + public: IMessage(); - virtual unsigned char Serialize(char *buffer); + virtual unsigned char Serialize(char* buffer); - static unsigned char *ReceiveMsg(unsigned char packetSize); + static unsigned char* ReceiveMsg(unsigned char packetSize); // bool Publish(Participant *participant); // bool SendTo(Participant *participant); }; -} // namespace Control -} // namespace Passer - -using namespace Passer::RoboidControl; \ No newline at end of file +} // namespace RoboidControl diff --git a/Messages/ModelUrlMsg.cpp b/Messages/ModelUrlMsg.cpp index 4d30d6a..bb7bdd0 100644 --- a/Messages/ModelUrlMsg.cpp +++ b/Messages/ModelUrlMsg.cpp @@ -2,7 +2,6 @@ #include -namespace Passer { namespace RoboidControl { // ModelUrlMsg::ModelUrlMsg(unsigned char networkId, unsigned char thingId, @@ -15,16 +14,16 @@ namespace RoboidControl { // this->scale = scale; // } -ModelUrlMsg::ModelUrlMsg(const char *buffer) { - unsigned char ix = 1; // first byte is msg id +ModelUrlMsg::ModelUrlMsg(const char* buffer) { + unsigned char ix = 1; // first byte is msg id this->networkId = buffer[ix++]; this->thingId = buffer[ix++]; this->urlLength = buffer[ix++]; - this->url = &buffer[ix]; // dangerous! name should not be used anymore after - // buffer has been re-used... + this->url = &buffer[ix]; // dangerous! name should not be used anymore after + // buffer has been re-used... } -ModelUrlMsg::ModelUrlMsg(unsigned char networkId, Thing *thing) { +ModelUrlMsg::ModelUrlMsg(unsigned char networkId, Thing* thing) { this->networkId = networkId; this->thingId = thing->id; if (thing->modelUrl == nullptr) @@ -32,12 +31,12 @@ ModelUrlMsg::ModelUrlMsg(unsigned char networkId, Thing *thing) { else this->urlLength = (unsigned char)strlen(thing->modelUrl); - this->url = thing->modelUrl; // dangerous! + this->url = thing->modelUrl; // dangerous! } ModelUrlMsg::~ModelUrlMsg() {} -unsigned char ModelUrlMsg::Serialize(char *buffer) { +unsigned char ModelUrlMsg::Serialize(char* buffer) { if (this->urlLength == 0 || this->url == nullptr) return 0; unsigned char ix = 0; @@ -51,5 +50,4 @@ unsigned char ModelUrlMsg::Serialize(char *buffer) { return ix; } -} // namespace RoboidControl -} // namespace Passer \ No newline at end of file +} // namespace RoboidControl diff --git a/Messages/ModelUrlMsg.h b/Messages/ModelUrlMsg.h index 0b3f521..27e5e25 100644 --- a/Messages/ModelUrlMsg.h +++ b/Messages/ModelUrlMsg.h @@ -1,11 +1,10 @@ #include "Messages.h" -namespace Passer { namespace RoboidControl { /// @brief Message for communicating the URL for a model of the thing class ModelUrlMsg : public IMessage { -public: + public: /// @brief The message ID static const unsigned char id = 0x90; /// @brief The length of the message without the URL string itself @@ -15,27 +14,26 @@ public: unsigned char networkId; /// @brief The ID of the thing unsigned char thingId; - + /// @brief The length of the url st5ring, excluding the null terminator unsigned char urlLength; /// @brief The url of the model, not terminated by a null character - const char *url; + const char* url; /// @brief Create a new message for sending /// @param networkId The network ID of the thing /// @param thing The thing for which to send the mode URL - ModelUrlMsg(unsigned char networkId, Thing *thing); - /// @copydoc Passer::RoboidControl::IMessage::IMessage(char*) - ModelUrlMsg(const char *buffer); + 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(); - /// @copydoc Passer::RoboidControl::IMessage::Serialize - virtual unsigned char Serialize(char *buffer) override; + /// @copydoc RoboidControl::IMessage::Serialize + virtual unsigned char Serialize(char* buffer) override; }; -} // namespace Control -} // namespace Passer \ No newline at end of file +} // namespace RoboidControl diff --git a/Messages/NameMsg.cpp b/Messages/NameMsg.cpp index d1f1992..1cd7125 100644 --- a/Messages/NameMsg.cpp +++ b/Messages/NameMsg.cpp @@ -2,26 +2,25 @@ #include -namespace Passer { namespace RoboidControl { -NameMsg::NameMsg(unsigned char networkId, Thing *thing) { +NameMsg::NameMsg(unsigned char networkId, Thing* thing) { this->networkId = networkId; this->thingId = thing->id; if (thing->name == nullptr) this->nameLength = 0; else this->nameLength = (unsigned char)strlen(thing->name); - this->name = thing->name; // dangerous! + this->name = thing->name; // dangerous! } -NameMsg::NameMsg(const char *buffer) { - unsigned char ix = 1; // first byte is msg id +NameMsg::NameMsg(const char* buffer) { + unsigned char ix = 1; // first byte is msg id this->networkId = buffer[ix++]; this->thingId = buffer[ix++]; this->nameLength = buffer[ix++]; // the name string in the buffer is not \0 terminated! - char* name = new char[this->nameLength+1]; + char* name = new char[this->nameLength + 1]; for (int i = 0; i < this->nameLength; i++) name[i] = buffer[ix++]; name[this->nameLength] = '\0'; @@ -32,7 +31,7 @@ NameMsg::~NameMsg() { delete[] this->name; } -unsigned char NameMsg::Serialize(char *buffer) { +unsigned char NameMsg::Serialize(char* buffer) { if (this->nameLength == 0 || this->name == nullptr) return 0; @@ -47,5 +46,4 @@ unsigned char NameMsg::Serialize(char *buffer) { return ix; } -} // namespace Control -} // namespace Passer \ No newline at end of file +} // namespace RoboidControl diff --git a/Messages/NameMsg.h b/Messages/NameMsg.h index 4a94237..0d1bebc 100644 --- a/Messages/NameMsg.h +++ b/Messages/NameMsg.h @@ -1,6 +1,5 @@ #include "Messages.h" -namespace Passer { namespace RoboidControl { /// @brief Message for communicating the name of a thing @@ -26,14 +25,13 @@ class NameMsg : public IMessage { // NameMsg(unsigned char networkId, unsigned char thingId, const char *name, // unsigned char nameLength); - /// @copydoc Passer::RoboidControl::IMessage::IMessage(char*) + /// @copydoc RoboidControl::IMessage::IMessage(char*) NameMsg(const char* buffer); /// @brief Destructor for the message virtual ~NameMsg(); - /// @copydoc Passer::RoboidControl::IMessage::Serialize + /// @copydoc RoboidControl::IMessage::Serialize virtual unsigned char Serialize(char* buffer) override; }; } // namespace RoboidControl -} // namespace Passer diff --git a/Messages/NetworkIdMsg.cpp b/Messages/NetworkIdMsg.cpp index b133d3c..cfa36b8 100644 --- a/Messages/NetworkIdMsg.cpp +++ b/Messages/NetworkIdMsg.cpp @@ -1,9 +1,10 @@ #include "NetworkIdMsg.h" -namespace Passer { namespace RoboidControl { -NetworkIdMsg::NetworkIdMsg(const char *buffer) { this->networkId = buffer[1]; } +NetworkIdMsg::NetworkIdMsg(const char* buffer) { + this->networkId = buffer[1]; +} NetworkIdMsg::NetworkIdMsg(unsigned char networkId) { this->networkId = networkId; @@ -11,17 +12,11 @@ NetworkIdMsg::NetworkIdMsg(unsigned char networkId) { NetworkIdMsg::~NetworkIdMsg() {} -unsigned char NetworkIdMsg::Serialize(char *buffer) { +unsigned char NetworkIdMsg::Serialize(char* buffer) { unsigned char ix = 0; buffer[ix++] = this->id; buffer[ix++] = this->networkId; return NetworkIdMsg::length; } -// NetworkIdMsg NetworkIdMsg::Receive(char *buffer, unsigned char bufferSize) { -// NetworkIdMsg msg = NetworkIdMsg(buffer); -// return msg; -// } - -} // namespace Control -} // namespace Passer \ No newline at end of file +} // namespace RoboidControl diff --git a/Messages/NetworkIdMsg.h b/Messages/NetworkIdMsg.h index afc4fb8..083439b 100644 --- a/Messages/NetworkIdMsg.h +++ b/Messages/NetworkIdMsg.h @@ -1,6 +1,5 @@ #include "Messages.h" -namespace Passer { namespace RoboidControl { /// @brief A message communicating the network ID for that participant @@ -16,14 +15,13 @@ public: /// @brief Create a new message for sending /// @param networkId The network ID for the participant NetworkIdMsg(unsigned char networkId); - /// @copydoc Passer::RoboidControl::IMessage::IMessage(char*) + /// @copydoc RoboidControl::IMessage::IMessage(char*) NetworkIdMsg(const char *buffer); /// @brief Destructor for the message virtual ~NetworkIdMsg(); - /// @copydoc Passer::RoboidControl::IMessage::Serialize + /// @copydoc RoboidControl::IMessage::Serialize virtual unsigned char Serialize(char *buffer) override; }; } // namespace Control -} // namespace Passer diff --git a/Messages/ParticipantMsg.cpp b/Messages/ParticipantMsg.cpp index e9452ea..a13fa7f 100644 --- a/Messages/ParticipantMsg.cpp +++ b/Messages/ParticipantMsg.cpp @@ -1,14 +1,18 @@ #include "ParticipantMsg.h" -namespace Passer::RoboidControl { +namespace RoboidControl { -ParticipantMsg::ParticipantMsg(char networkId) { this->networkId = networkId; } +ParticipantMsg::ParticipantMsg(char networkId) { + this->networkId = networkId; +} -ParticipantMsg::ParticipantMsg(const char *buffer) { this->networkId = buffer[1]; } +ParticipantMsg::ParticipantMsg(const char* buffer) { + this->networkId = buffer[1]; +} ParticipantMsg::~ParticipantMsg() {} -unsigned char ParticipantMsg::Serialize(char *buffer) { +unsigned char ParticipantMsg::Serialize(char* buffer) { unsigned char ix = 0; buffer[ix++] = this->id; buffer[ix++] = this->networkId; @@ -20,4 +24,4 @@ unsigned char ParticipantMsg::Serialize(char *buffer) { // } // Client Msg -} // namespace Passer::RoboidControl \ No newline at end of file +} // namespace RoboidControl \ No newline at end of file diff --git a/Messages/ParticipantMsg.h b/Messages/ParticipantMsg.h index df742e9..28f9eb5 100644 --- a/Messages/ParticipantMsg.h +++ b/Messages/ParticipantMsg.h @@ -2,7 +2,6 @@ #include "Messages.h" -namespace Passer { namespace RoboidControl { /// @brief A participant messages notifies other participants of its presence @@ -21,7 +20,7 @@ class ParticipantMsg : public IMessage { /// @param networkId The network ID known by the participant ParticipantMsg(char networkId); - /// @copydoc Passer::RoboidControl::IMessage::IMessage(char*) + /// @copydoc RoboidControl::IMessage::IMessage(char*) ParticipantMsg(const char* buffer); /// @brief Destructor for the message virtual ~ParticipantMsg(); @@ -33,4 +32,3 @@ class ParticipantMsg : public IMessage { }; } // namespace RoboidControl -} // namespace Passer \ No newline at end of file diff --git a/Messages/PoseMsg.cpp b/Messages/PoseMsg.cpp index e20c107..676e557 100644 --- a/Messages/PoseMsg.cpp +++ b/Messages/PoseMsg.cpp @@ -1,9 +1,14 @@ #include "PoseMsg.h" #include "LowLevelMessages.h" -PoseMsg::PoseMsg(unsigned char networkId, unsigned char thingId, - unsigned char poseType, Spherical16 position, - SwingTwist16 orientation, Spherical16 linearVelocity, +namespace RoboidControl { + +PoseMsg::PoseMsg(unsigned char networkId, + unsigned char thingId, + unsigned char poseType, + Spherical16 position, + SwingTwist16 orientation, + Spherical16 linearVelocity, Spherical16 angularVelocity) { this->networkId = networkId; this->thingId = thingId; @@ -14,8 +19,8 @@ PoseMsg::PoseMsg(unsigned char networkId, unsigned char thingId, this->linearVelocity = linearVelocity; this->angularVelocity = angularVelocity; } -PoseMsg::PoseMsg(const char *buffer) { - unsigned char ix = 1; // First byte is msg id +PoseMsg::PoseMsg(const char* buffer) { + unsigned char ix = 1; // First byte is msg id this->networkId = buffer[ix++]; this->thingId = buffer[ix++]; this->poseType = buffer[ix++]; @@ -25,7 +30,7 @@ PoseMsg::PoseMsg(const char *buffer) { PoseMsg::~PoseMsg() {} -unsigned char PoseMsg::Serialize(char *buffer) { +unsigned char PoseMsg::Serialize(char* buffer) { unsigned char ix = 0; buffer[ix++] = PoseMsg::id; buffer[ix++] = this->networkId; @@ -41,3 +46,5 @@ unsigned char PoseMsg::Serialize(char *buffer) { LowLevelMessages::SendSpherical16(buffer, &ix, this->angularVelocity); return ix; } + +} // namespace RoboidControl diff --git a/Messages/PoseMsg.h b/Messages/PoseMsg.h index ddb2e07..6d9151a 100644 --- a/Messages/PoseMsg.h +++ b/Messages/PoseMsg.h @@ -1,6 +1,5 @@ #include "Messages.h" -namespace Passer { namespace RoboidControl { /// @brief Message to communicate the pose of the thing @@ -53,14 +52,13 @@ class PoseMsg : public IMessage { SwingTwist16 orientation, Spherical16 linearVelocity = Spherical16(), Spherical16 angularVelocity = Spherical16()); - /// @copydoc Passer::RoboidControl::IMessage::IMessage(char*) + /// @copydoc RoboidControl::IMessage::IMessage(char*) PoseMsg(const char* buffer); /// @brief Destructor for the message virtual ~PoseMsg(); - /// @copydoc Passer::RoboidControl::IMessage::Serialize + /// @copydoc RoboidControl::IMessage::Serialize virtual unsigned char Serialize(char* buffer) override; }; } // namespace RoboidControl -} // namespace Passer \ No newline at end of file diff --git a/Messages/TextMsg.cpp b/Messages/TextMsg.cpp index 854a821..371bf92 100644 --- a/Messages/TextMsg.cpp +++ b/Messages/TextMsg.cpp @@ -1,6 +1,5 @@ #include "TextMsg.h" -namespace Passer { namespace RoboidControl { TextMsg::TextMsg(const char* text, unsigned char textLength) { @@ -22,7 +21,7 @@ TextMsg::TextMsg(char* buffer) { TextMsg::~TextMsg() {} unsigned char TextMsg::Serialize(char* buffer) { - if (this->textLength == 0 || this->text == nullptr) + if (this->textLength == 0 || this->text == nullptr) return 0; unsigned char ix = 0; @@ -31,7 +30,7 @@ unsigned char TextMsg::Serialize(char* buffer) { for (int nameIx = 0; nameIx < this->textLength; nameIx++) buffer[ix++] = this->text[nameIx]; - return ix;} + return ix; +} } // namespace RoboidControl -} // namespace Passer \ No newline at end of file diff --git a/Messages/TextMsg.h b/Messages/TextMsg.h index dcb6c85..5b25fca 100644 --- a/Messages/TextMsg.h +++ b/Messages/TextMsg.h @@ -1,6 +1,5 @@ #include "Messages.h" -namespace Passer { namespace RoboidControl { /// @brief Message for sending generic text @@ -22,14 +21,13 @@ class TextMsg : public IMessage { /// @brief Create a new message for sending /// @param text The text TextMsg(const char* text, unsigned char textLength); - /// @copydoc Passer::RoboidControl::IMessage::IMessage(char*) + /// @copydoc RoboidControl::IMessage::IMessage(char*) TextMsg(char* buffer); /// @brief Destructor for the message virtual ~TextMsg(); - /// @copydoc Passer::RoboidControl::IMessage::Serialize + /// @copydoc RoboidControl::IMessage::Serialize virtual unsigned char Serialize(char* buffer) override; }; } // namespace RoboidControl -} // namespace Passer \ No newline at end of file diff --git a/Messages/ThingMsg.cpp b/Messages/ThingMsg.cpp index 5242256..c22d58d 100644 --- a/Messages/ThingMsg.cpp +++ b/Messages/ThingMsg.cpp @@ -1,21 +1,20 @@ #include "ThingMsg.h" -namespace Passer { namespace RoboidControl { -ThingMsg::ThingMsg(const char *buffer) { - unsigned char ix = 1; // first byte is msg id +ThingMsg::ThingMsg(const char* buffer) { + unsigned char ix = 1; // first byte is msg id this->networkId = buffer[ix++]; this->thingId = buffer[ix++]; this->thingType = buffer[ix++]; this->parentId = buffer[ix++]; } -ThingMsg::ThingMsg(unsigned char networkId, Thing *thing) { +ThingMsg::ThingMsg(unsigned char networkId, Thing* thing) { this->networkId = networkId; this->thingId = thing->id; this->thingType = thing->type; - Thing *parent = thing->GetParent(); + Thing* parent = thing->GetParent(); if (parent != nullptr) this->parentId = parent->id; else @@ -32,7 +31,7 @@ ThingMsg::ThingMsg(unsigned char networkId, Thing *thing) { ThingMsg::~ThingMsg() {} -unsigned char ThingMsg::Serialize(char *buffer) { +unsigned char ThingMsg::Serialize(char* buffer) { unsigned char ix = 0; buffer[ix++] = this->id; buffer[ix++] = this->networkId; @@ -42,5 +41,4 @@ unsigned char ThingMsg::Serialize(char *buffer) { return ix; } -} // namespace Control -} // namespace Passer \ No newline at end of file +} // namespace RoboidControl diff --git a/Messages/ThingMsg.h b/Messages/ThingMsg.h index 0a6d006..c40fb97 100644 --- a/Messages/ThingMsg.h +++ b/Messages/ThingMsg.h @@ -1,6 +1,5 @@ #include "Messages.h" -namespace Passer { namespace RoboidControl { /// @brief Message providing generic information about a Thing @@ -26,14 +25,13 @@ class ThingMsg : public IMessage { // ThingMsg(unsigned char networkId, unsigned char thingId, // unsigned char thingType, unsigned char parentId); - /// @copydoc Passer::RoboidControl::IMessage::IMessage(char*) + /// @copydoc RoboidControl::IMessage::IMessage(char*) ThingMsg(const char* buffer); /// @brief Destructor for the message virtual ~ThingMsg(); - /// @copydoc Passer::RoboidControl::IMessage::Serialize + /// @copydoc RoboidControl::IMessage::Serialize virtual unsigned char Serialize(char* buffer) override; }; -} // namespace RoboidControl -} // namespace Passer \ No newline at end of file +} // namespace RoboidControl \ No newline at end of file diff --git a/Participant.cpp b/Participant.cpp index 85ba22f..bcecf6e 100644 --- a/Participant.cpp +++ b/Participant.cpp @@ -19,7 +19,6 @@ #include #endif -namespace Passer { namespace RoboidControl { Participant::Participant() {} @@ -138,7 +137,7 @@ void Participant::SendThingInfo(RemoteParticipant* remoteParticipant, Thing* thi delete modelMsg; } -void Passer::RoboidControl::Participant::PublishThingInfo(Thing* thing) { +void Participant::PublishThingInfo(Thing* thing) { // std::cout << "Publish thing info" << thing->networkId << "\n"; // Strange, when publishing, the network id is irrelevant, because it is // connected to a specific site... @@ -277,4 +276,3 @@ void Participant::Process(RemoteParticipant* sender, BinaryMsg* msg) { #pragma endregion } // namespace RoboidControl -} // namespace Passer diff --git a/Participant.h b/Participant.h index fdf53c1..9a7aea2 100644 --- a/Participant.h +++ b/Participant.h @@ -1,11 +1,11 @@ #pragma once -#include "Messages/ParticipantMsg.h" #include "Messages/BinaryMsg.h" #include "Messages/InvestigateMsg.h" #include "Messages/ModelUrlMsg.h" #include "Messages/NameMsg.h" #include "Messages/NetworkIdMsg.h" +#include "Messages/ParticipantMsg.h" #include "Messages/PoseMsg.h" #include "Messages/ThingMsg.h" #include "RemoteParticipant.h" @@ -23,26 +23,25 @@ #include #endif -namespace Passer { namespace RoboidControl { /// @brief A participant is device which can communicate with other participants class Participant : public RemoteParticipant { -public: + public: char buffer[1024]; - long publishInterval = 3000; // 3 seconds + long publishInterval = 3000; // 3 seconds // unsigned char networkId = 0; - const char *name = "Participant"; + const char* name = "Participant"; // const char *ipAddress = "0.0.0.0"; // int port = 0; int localPort = 0; #if defined(ARDUINO) - const char *remoteIpAddress = nullptr; + const char* remoteIpAddress = nullptr; unsigned short remotePort = 0; - char *broadcastIpAddress = nullptr; + char* broadcastIpAddress = nullptr; WiFiUDP udp; #else @@ -60,7 +59,7 @@ public: Participant(); Participant(int port); - Participant(const char *ipAddress, int port); + Participant(const char* ipAddress, int port); void begin(); bool connected = false; @@ -73,35 +72,33 @@ public: // void Remove(Thing *thing); // void UpdateAll(unsigned long currentTimeMs); - void SendThingInfo(RemoteParticipant* remoteParticipant, Thing *thing); - void PublishThingInfo(Thing *thing); + void SendThingInfo(RemoteParticipant* remoteParticipant, Thing* thing); + void PublishThingInfo(Thing* thing); - bool Send(RemoteParticipant* remoteParticipant, IMessage *msg); - bool Publish(IMessage *msg); + bool Send(RemoteParticipant* remoteParticipant, IMessage* msg); + bool Publish(IMessage* msg); - void ReceiveData(unsigned char bufferSize, RemoteParticipant *remoteParticipant); + void ReceiveData(unsigned char bufferSize, RemoteParticipant* remoteParticipant); -protected: - std::list senders; + protected: + std::list senders; unsigned long nextPublishMe = 0; - void SetupUDP(int localPort, const char *remoteIpAddress, int remotePort); + void SetupUDP(int localPort, const char* remoteIpAddress, int remotePort); - Participant *GetParticipant(const char *ipAddress, int port); - Participant *AddParticipant(const char *ipAddress, int port); + Participant* GetParticipant(const char* ipAddress, int port); + Participant* AddParticipant(const char* ipAddress, int port); void ReceiveUDP(); - virtual void Process(RemoteParticipant *sender, ParticipantMsg *msg); - virtual void Process(RemoteParticipant *sender, NetworkIdMsg *msg); - virtual void Process(RemoteParticipant* sender, InvestigateMsg *msg); - virtual void Process(RemoteParticipant* sender, ThingMsg *msg); - virtual void Process(RemoteParticipant* sender, NameMsg *msg); - virtual void Process(RemoteParticipant* sender, PoseMsg *msg); - virtual void Process(RemoteParticipant* sender, BinaryMsg *msg); + virtual void Process(RemoteParticipant* sender, ParticipantMsg* msg); + virtual void Process(RemoteParticipant* sender, NetworkIdMsg* msg); + virtual void Process(RemoteParticipant* sender, InvestigateMsg* msg); + virtual void Process(RemoteParticipant* sender, ThingMsg* msg); + virtual void Process(RemoteParticipant* sender, NameMsg* msg); + virtual void Process(RemoteParticipant* sender, PoseMsg* msg); + virtual void Process(RemoteParticipant* sender, BinaryMsg* msg); }; -} // namespace Control -} // namespace Passer -using namespace Passer::RoboidControl; \ No newline at end of file +} // namespace RoboidControl diff --git a/Posix/Participant.cpp b/Posix/Participant.cpp index 5205486..ff4af60 100644 --- a/Posix/Participant.cpp +++ b/Posix/Participant.cpp @@ -8,7 +8,6 @@ #include #endif -namespace Passer { namespace RoboidControl { namespace Posix { @@ -135,4 +134,3 @@ bool Participant::Publish(IMessage* msg) { } // namespace Posix } // namespace RoboidControl -} // namespace Passer \ No newline at end of file diff --git a/Posix/Participant.h b/Posix/Participant.h index 295b495..9450811 100644 --- a/Posix/Participant.h +++ b/Posix/Participant.h @@ -2,7 +2,6 @@ #include "../Participant.h" -namespace Passer { namespace RoboidControl { namespace Posix { @@ -16,4 +15,3 @@ class Participant : public RoboidControl::Participant { } // namespace Posix } // namespace RoboidControl -} // namespace Passer \ No newline at end of file diff --git a/README.md b/README.md index ac14c63..f5cabcc 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,6 @@ Supporting: # Basic components -- Passer::RoboidControl::Thing -- Passer::RoboidControl::Participant -- Passer::RoboidControl::SiteServer \ No newline at end of file +- RoboidControl::Thing +- RoboidControl::Participant +- RoboidControl::SiteServer \ No newline at end of file diff --git a/RemoteParticipant.cpp b/RemoteParticipant.cpp index 7ff7b13..2c19389 100644 --- a/RemoteParticipant.cpp +++ b/RemoteParticipant.cpp @@ -1,6 +1,5 @@ #include "RemoteParticipant.h" -namespace Passer { namespace RoboidControl { RemoteParticipant::RemoteParticipant() {} @@ -51,4 +50,3 @@ void RemoteParticipant::UpdateAll(unsigned long currentTimeMs) { } } // namespace Control -} // namespace Passer \ No newline at end of file diff --git a/RemoteParticipant.h b/RemoteParticipant.h index b3ed828..e9d76a8 100644 --- a/RemoteParticipant.h +++ b/RemoteParticipant.h @@ -1,7 +1,6 @@ #pragma once #include "Thing.h" -namespace Passer { namespace RoboidControl { class RemoteParticipant { @@ -25,4 +24,3 @@ public: }; } // namespace Control -} // namespace Passer \ No newline at end of file diff --git a/Sensors/DigitalSensor.cpp b/Sensors/DigitalSensor.cpp index de21a15..ad14f3b 100644 --- a/Sensors/DigitalSensor.cpp +++ b/Sensors/DigitalSensor.cpp @@ -1,6 +1,5 @@ #include "DigitalSensor.h" -namespace Passer { namespace RoboidControl { DigitalSensor::DigitalSensor() {} @@ -8,4 +7,3 @@ DigitalSensor::DigitalSensor() {} DigitalSensor::DigitalSensor(unsigned char networkId, unsigned char thingId) {} } // namespace RoboidControl -} // namespace Passer diff --git a/Sensors/DigitalSensor.h b/Sensors/DigitalSensor.h index 8328b33..ed0a973 100644 --- a/Sensors/DigitalSensor.h +++ b/Sensors/DigitalSensor.h @@ -2,7 +2,6 @@ #include "Thing.h" -namespace Passer { namespace RoboidControl { /// @brief A digital (on/off, 1/0, true/false) sensor @@ -20,4 +19,3 @@ class DigitalSensor : public Thing { }; } // namespace RoboidControl -} // namespace Passer \ No newline at end of file diff --git a/Sensors/TemperatureSensor.cpp b/Sensors/TemperatureSensor.cpp index ad63935..1852ef5 100644 --- a/Sensors/TemperatureSensor.cpp +++ b/Sensors/TemperatureSensor.cpp @@ -2,28 +2,27 @@ #include "Messages/LowLevelMessages.h" -namespace Passer { namespace RoboidControl { // TemperatureSensor::TemperatureSensor() : Thing(Type::TemperatureSensor) {} TemperatureSensor::TemperatureSensor() : Thing(Type::TemperatureSensor) {} -TemperatureSensor::TemperatureSensor(unsigned char networkId, - unsigned char thingId) +TemperatureSensor::TemperatureSensor(unsigned char networkId, unsigned char thingId) : Thing(nullptr, networkId, thingId, Type::TemperatureSensor) {} -void TemperatureSensor::SetTemperature(float temp) { this->temperature = temp; } +void TemperatureSensor::SetTemperature(float temp) { + this->temperature = temp; +} -void TemperatureSensor::GenerateBinary(char *buffer, unsigned char *ix) { +void TemperatureSensor::GenerateBinary(char* buffer, unsigned char* ix) { std::cout << "Send temperature: " << this->temperature << "\n"; LowLevelMessages::SendFloat16(buffer, ix, this->temperature); } -void TemperatureSensor::ProcessBinary(char *bytes) { +void TemperatureSensor::ProcessBinary(char* bytes) { unsigned char ix = 0; this->temperature = LowLevelMessages::ReceiveFloat16(bytes, &ix); } -} // namespace Control -} // namespace Passer \ No newline at end of file +} // namespace RoboidControl diff --git a/Sensors/TemperatureSensor.h b/Sensors/TemperatureSensor.h index 8ce8284..5ecec8f 100644 --- a/Sensors/TemperatureSensor.h +++ b/Sensors/TemperatureSensor.h @@ -2,7 +2,6 @@ #include "Thing.h" -namespace Passer { namespace RoboidControl { /// @brief A temperature sensor @@ -32,4 +31,3 @@ class TemperatureSensor : public Thing { }; } // namespace RoboidControl -} // namespace Passer \ No newline at end of file diff --git a/SiteServer.cpp b/SiteServer.cpp index 6510a65..c6acb88 100644 --- a/SiteServer.cpp +++ b/SiteServer.cpp @@ -5,7 +5,6 @@ #include #include -namespace Passer { namespace RoboidControl { SiteServer::SiteServer(int port) { @@ -50,4 +49,3 @@ void SiteServer::Process(RemoteParticipant *sender, ThingMsg *msg) { } } // namespace Control -} // namespace Passer diff --git a/SiteServer.h b/SiteServer.h index c9091b8..03c8223 100644 --- a/SiteServer.h +++ b/SiteServer.h @@ -6,35 +6,31 @@ #include #include -namespace Passer { namespace RoboidControl { /// @brief A participant is device which can communicate with other participants class SiteServer : public Participant { -public: + public: SiteServer(int port = 7681); // virtual void Update(unsigned long currentTimeMs = 0) override; - template void Register(unsigned char thingType) { - thingMsgProcessors[thingType] = [](unsigned char networkId, - unsigned char thingId) { + template + void Register(unsigned char thingType) { + thingMsgProcessors[thingType] = [](unsigned char networkId, unsigned char thingId) { return new ThingClass(networkId, thingId); }; }; -protected: + protected: unsigned long nextPublishMe = 0; - virtual void Process(RemoteParticipant *sender, ParticipantMsg *msg) override; - virtual void Process(RemoteParticipant *sender, NetworkIdMsg *msg) override; - virtual void Process(RemoteParticipant* sender, ThingMsg *msg) override; + virtual void Process(RemoteParticipant* sender, ParticipantMsg* msg) override; + virtual void Process(RemoteParticipant* sender, NetworkIdMsg* msg) override; + virtual void Process(RemoteParticipant* sender, ThingMsg* msg) override; - using ThingConstructor = - std::function; + using ThingConstructor = std::function; std::unordered_map thingMsgProcessors; }; -} // namespace Control -} // namespace Passer -using namespace Passer::RoboidControl; \ No newline at end of file +} // namespace RoboidControl diff --git a/Thing.cpp b/Thing.cpp index b1c2266..f1cca3e 100644 --- a/Thing.cpp +++ b/Thing.cpp @@ -1,13 +1,12 @@ #include "Thing.h" -#include "Participant.h" +#include #include #include #include -#include +#include "Participant.h" -namespace Passer { - namespace RoboidControl { +namespace RoboidControl { Thing::Thing(Type thingType) : Thing((unsigned char)thingType) {} @@ -23,8 +22,7 @@ Thing::Thing(unsigned char thingType) { this->angularVelocity = Spherical16::zero; } -Thing::Thing(RemoteParticipant *participant, unsigned char networkId, - unsigned char thingId, Type thingType) { +Thing::Thing(RemoteParticipant* participant, unsigned char networkId, unsigned char thingId, Type thingType) { // no participant reference yet.. this->participant = participant; this->networkId = networkId; @@ -41,25 +39,25 @@ void Thing::Terminate() { // Thing::Remove(this); } -Thing *Thing::FindThing(const char *name) { +Thing* Thing::FindThing(const char* name) { for (unsigned char childIx = 0; childIx < this->childCount; childIx++) { - Thing *child = this->children[childIx]; + Thing* child = this->children[childIx]; if (child == nullptr || child->name == nullptr) continue; if (strcmp(child->name, name) == 0) return child; - Thing *foundChild = child->FindThing(name); + Thing* foundChild = child->FindThing(name); if (foundChild != nullptr) return foundChild; } return nullptr; } -void Thing::SetParent(Thing *parent) { +void Thing::SetParent(Thing* parent) { if (parent == nullptr) { - Thing *parentThing = this->parent; + Thing* parentThing = this->parent; if (parentThing != nullptr) parentThing->RemoveChild(this); this->parent = nullptr; @@ -67,18 +65,19 @@ void Thing::SetParent(Thing *parent) { parent->AddChild(this); } -void Thing::SetParent(Thing *root, const char *name) { - Thing *thing = root->FindThing(name); +void Thing::SetParent(Thing* root, const char* name) { + Thing* thing = root->FindThing(name); if (thing != nullptr) this->SetParent(thing); } -Thing *Thing::GetParent() { return this->parent; } - -void Thing::AddChild(Thing *child) { +Thing* Thing::GetParent() { + return this->parent; +} +void Thing::AddChild(Thing* child) { unsigned char newChildCount = this->childCount + 1; - Thing **newChildren = new Thing *[newChildCount]; + Thing** newChildren = new Thing*[newChildCount]; for (unsigned char childIx = 0; childIx < this->childCount; childIx++) { newChildren[childIx] = this->children[childIx]; @@ -99,14 +98,14 @@ void Thing::AddChild(Thing *child) { this->childCount = newChildCount; } -Thing *Thing::RemoveChild(Thing *child) { +Thing* Thing::RemoveChild(Thing* child) { unsigned char newChildCount = this->childCount - 1; - Thing **newChildren = new Thing *[newChildCount]; + Thing** newChildren = new Thing*[newChildCount]; unsigned char newChildIx = 0; for (unsigned char childIx = 0; childIx < this->childCount; childIx++) { if (this->children[childIx] != child) { - if (newChildIx == newChildCount) { // We did not find the child + if (newChildIx == newChildCount) { // We did not find the child // stop copying and return nothing delete[] newChildren; return nullptr; @@ -124,16 +123,16 @@ Thing *Thing::RemoveChild(Thing *child) { return child; } -Thing *Thing::GetChild(unsigned char id, bool recursive) { +Thing* Thing::GetChild(unsigned char id, bool recursive) { for (unsigned char childIx = 0; childIx < this->childCount; childIx++) { - Thing *child = this->children[childIx]; + Thing* child = this->children[childIx]; if (child == nullptr) continue; if (child->id == id) return child; if (recursive) { - Thing *foundChild = child->GetChild(id, recursive); + Thing* foundChild = child->GetChild(id, recursive); if (foundChild != nullptr) return foundChild; } @@ -141,9 +140,13 @@ Thing *Thing::GetChild(unsigned char id, bool recursive) { return nullptr; } -Thing *Thing::GetChildByIndex(unsigned char ix) { return this->children[ix]; } +Thing* Thing::GetChildByIndex(unsigned char ix) { + return this->children[ix]; +} -void Thing::SetModel(const char *url) { this->modelUrl = url; } +void Thing::SetModel(const char* url) { + this->modelUrl = url; +} #if defined(ARDUINO) void Thing::Update() { @@ -151,73 +154,37 @@ void Thing::Update() { } #endif -void Thing::GenerateBinary(char *buffer, unsigned char *ix) { +void Thing::GenerateBinary(char* buffer, unsigned char* ix) { (void)buffer; (void)ix; } -void Thing::ProcessBinary(char *bytes) { (void)bytes; }; +void Thing::ProcessBinary(char* bytes) { + (void)bytes; +}; void Thing::SetPosition(Spherical16 position) { this->position = position; this->positionUpdated = true; } -Spherical16 Thing::GetPosition() { return this->position; } +Spherical16 Thing::GetPosition() { + return this->position; +} void Thing::SetOrientation(SwingTwist16 orientation) { this->orientation = orientation; this->orientationUpdated = true; } -SwingTwist16 Thing::GetOrientation() { return this->orientation; } +SwingTwist16 Thing::GetOrientation() { + return this->orientation; +} -Spherical16 Thing::GetLinearVelocity() { return this->linearVelocity; } +Spherical16 Thing::GetLinearVelocity() { + return this->linearVelocity; +} -Spherical16 Thing::GetAngularVelocity() { return this->angularVelocity; } +Spherical16 Thing::GetAngularVelocity() { + return this->angularVelocity; +} -// All things -// std::list Thing::allThings; - -// Thing *Thing::Get(unsigned char networkId, unsigned char thingId) { -// std::cout << "Get " << (int)networkId << "/" << (int)thingId << " from " -// << allThings.size() << " things\n"; -// for (auto &thing : allThings) { -// std::cout << " ? " << (int)thing->networkId << "/" << (int)thing->id -// << "\n"; -// if (thing->networkId == networkId && thing->id == thingId) { -// return thing; -// } -// } -// return nullptr; -// } - -// int Thing::Add(Thing *newThing) { -// for (Thing *thing : allThings) { -// if (thing == newThing) -// return thing->id; -// } -// std::cout << "Adding " << (int)newThing->networkId << "/" << -// (int)newThing->id -// << "\n"; -// allThings.push_back(newThing); -// return allThings.size(); -// } - -// void Thing::Remove(Thing *thing) { -// Thing::allThings.remove_if([thing](Thing *obj) { return obj == thing; }); -// std::cout << "Removing " << thing->networkId << "/" << thing->id -// << " list size = " << allThings.size() << "\n"; -// } - -// void Thing::UpdateAll(unsigned long currentTimeMs) { -// // Not very efficient, but it works for now. - -// for (Thing *thing : Thing::allThings) { -// if (thing != nullptr && -// thing->parent == nullptr) { // update all root things -// // std::cout << " update " << (int)ix << " thingid " << (int)thing->id -// // << "\n"; -// thing->Update(currentTimeMs); -// } -// } -//} - }} \ No newline at end of file +} // namespace RoboidControl \ No newline at end of file diff --git a/Thing.h b/Thing.h index 97845e4..28faea1 100644 --- a/Thing.h +++ b/Thing.h @@ -1,10 +1,9 @@ #pragma once -#include "LinearAlgebra/Spherical.h" -#include "LinearAlgebra/SwingTwist.h" #include #include +#include "LinearAlgebra/Spherical.h" +#include "LinearAlgebra/SwingTwist.h" -namespace Passer { namespace RoboidControl { class RemoteParticipant; @@ -15,8 +14,8 @@ class RemoteParticipant; /// @brief A thing is the primitive building block class Thing { -public: - RemoteParticipant *participant; + public: + RemoteParticipant* participant; unsigned char networkId = 0; /// @brief The ID of the thing unsigned char id = 0; @@ -52,31 +51,33 @@ public: /// @param networkId The network ID of the thing /// @param thingId The ID of the thing /// @param thingType The type of thing - Thing(RemoteParticipant *participant, unsigned char networkId, - unsigned char thingId, Type thingType = Type::Undetermined); + Thing(RemoteParticipant* participant, + unsigned char networkId, + unsigned char thingId, + Type thingType = Type::Undetermined); /// @brief Find a thing by name /// @param name Rhe name of the thing /// @return The found thing or nullptr when nothing is found - Thing *FindThing(const char *name); + Thing* FindThing(const char* name); /// @brief Sets the parent Thing /// @param parent The Thing which should become the parnet /// @remark This is equivalent to calling parent->AddChild(this); - virtual void SetParent(Thing *parent); - void SetParent(Thing *root, const char *name); + virtual void SetParent(Thing* parent); + void SetParent(Thing* root, const char* name); /// @brief Gets the parent Thing /// @return The parent Thing - Thing *GetParent(); + Thing* GetParent(); /// @brief Add a child Thing to this Thing /// @param child The Thing which should become a child /// @remark When the Thing is already a child, it will not be added again - virtual void AddChild(Thing *child); + virtual void AddChild(Thing* child); /// @brief Remove the given thing as a child of this thing /// @param child The child to remove /// @return The removed child or nullptr if the child could not be found - Thing *RemoveChild(Thing *child); + Thing* RemoveChild(Thing* child); /// @brief The number of children unsigned char childCount = 0; @@ -84,21 +85,21 @@ public: /// @param id The thing ID to find /// @param recursive Look recursively through all descendants /// @return The found thing of nullptr when nothing is found - Thing *GetChild(unsigned char id, bool recursive = false); + Thing* GetChild(unsigned char id, bool recursive = false); /// @brief Get a child by index /// @param ix The child index /// @return The found thing of nullptr when nothing is found - Thing *GetChildByIndex(unsigned char ix); + Thing* GetChildByIndex(unsigned char ix); -protected: - Thing *parent = nullptr; - Thing **children = nullptr; + protected: + Thing* parent = nullptr; + Thing** children = nullptr; -public: + public: /// @brief The name of the thing - const char *name = nullptr; + const char* name = nullptr; /// @brief An URL pointing to the location where a model of the thing can be found - const char *modelUrl = nullptr; + const char* modelUrl = nullptr; /// @brief The scale of the model (deprecated I think) float modelScale = 1; @@ -115,14 +116,14 @@ public: /// @return The orienation in local space SwingTwist16 GetOrientation(); /// @brief The scale of the thing (deprecated I think) - float scale = 1; // assuming uniform scale + float scale = 1; // assuming uniform scale /// @brief boolean indicating if the position was updated bool positionUpdated = false; /// @brief boolean indicating if the orientation was updated bool orientationUpdated = false; -protected: + protected: /// @brief The position in local space /// @remark When this Thing has a parent, the position is relative to the /// parent's position and orientation @@ -132,7 +133,7 @@ protected: /// parent's orientation SwingTwist16 orientation; -public: + public: Spherical16 linearVelocity; Spherical16 angularVelocity; @@ -143,7 +144,7 @@ public: /// @return The angular velocity in local space virtual Spherical16 GetAngularVelocity(); -public: + public: /// @brief Terminated things are no longer updated void Terminate(); @@ -152,12 +153,12 @@ public: /// @param url The url of the model /// @remark Although the roboid implementation is not dependent on the model, /// the only official supported model format is .obj - void SetModel(const char *url); + void SetModel(const char* url); - #if defined(ARDUINO) +#if defined(ARDUINO) void Update(); - #endif - +#endif + /// @brief Updates the state of the thing /// @param currentTimeMs The current clock time in milliseconds virtual void Update(unsigned long currentTimeMs) { (void)currentTimeMs; }; @@ -165,13 +166,10 @@ public: /// @brief Function used to generate binary data for this thing /// @param buffer The byte array for thw binary data /// @param ix The starting position for writing the binary data - virtual void GenerateBinary(char *buffer, unsigned char *ix); + virtual void GenerateBinary(char* buffer, unsigned char* ix); // /// @brief FUnction used to process binary data received for this thing /// @param bytes The binary data - virtual void ProcessBinary(char *bytes); - + virtual void ProcessBinary(char* bytes); }; -} // namespace Control -} // namespace Passer -using namespace Passer::RoboidControl; \ No newline at end of file +} // namespace RoboidControl diff --git a/Windows/Participant.cpp b/Windows/Participant.cpp index d6fa76f..431bf07 100644 --- a/Windows/Participant.cpp +++ b/Windows/Participant.cpp @@ -12,7 +12,6 @@ #include #endif -namespace Passer { namespace RoboidControl { namespace Windows { @@ -196,4 +195,3 @@ bool Participant::Publish(IMessage* msg) { } // namespace Windows } // namespace RoboidControl -} // namespace Passer \ No newline at end of file diff --git a/Windows/Participant.h b/Windows/Participant.h index a0487b4..36cd747 100644 --- a/Windows/Participant.h +++ b/Windows/Participant.h @@ -2,7 +2,6 @@ #include "../Participant.h" -namespace Passer { namespace RoboidControl { namespace Windows { @@ -16,4 +15,3 @@ class Participant : public RoboidControl::Participant { } // namespace Windows } // namespace RoboidControl -} // namespace Passer \ No newline at end of file diff --git a/test/second_test.cc b/test/second_test.cc index 6f706ad..2726b3e 100644 --- a/test/second_test.cc +++ b/test/second_test.cc @@ -4,12 +4,13 @@ // not supported using Visual Studio 2022 compiler... #include -// #include "../Thing.h" #include #include "Participant.h" #include "Thing.h" +using namespace RoboidControl; + class ControlCoreSuite2 : public ::testing::Test { protected: // SetUp and TearDown can be used to set up and clean up before/after each diff --git a/test/thing_test.cc b/test/thing_test.cc index e3d20de..98c07b4 100644 --- a/test/thing_test.cc +++ b/test/thing_test.cc @@ -12,7 +12,7 @@ #include "SiteServer.h" #include "Thing.h" -namespace Passer { +using namespace RoboidControl; // Function to get the current time in milliseconds as unsigned long unsigned long get_time_ms() { @@ -94,6 +94,4 @@ TEST_F(ControlCoreSuite, Thing) { ASSERT_EQ(1, 1); } - -} // namespace Passer #endif