diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e989fe..9b5e493 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,7 +28,7 @@ else() LinearAlgebra ) file(GLOB srcs - *.cpp + *.cpp Sensors/*.cpp Messages/*.cpp Arduino/*.cpp diff --git a/Messages/CustomMsg.cpp b/Messages/BinaryMsg.cpp similarity index 70% rename from Messages/CustomMsg.cpp rename to Messages/BinaryMsg.cpp index 6dd3fc0..fe8e380 100644 --- a/Messages/CustomMsg.cpp +++ b/Messages/BinaryMsg.cpp @@ -1,9 +1,9 @@ -#include "CustomMsg.h" +#include "BinaryMsg.h" namespace Passer { namespace RoboidControl { -CustomMsg::CustomMsg(char *buffer) { +BinaryMsg::BinaryMsg(char *buffer) { unsigned char ix = 1; this->networkId = buffer[ix++]; this->thingId = buffer[ix++]; @@ -12,15 +12,15 @@ CustomMsg::CustomMsg(char *buffer) { // lifetime is shorter than the buffer lifetime... } -CustomMsg::CustomMsg(unsigned char networkId, Thing *thing) { +BinaryMsg::BinaryMsg(unsigned char networkId, Thing *thing) { this->networkId = networkId; this->thingId = thing->id; this->thing = thing; } -CustomMsg::~CustomMsg() {} +BinaryMsg::~BinaryMsg() {} -unsigned char CustomMsg::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 @@ -32,8 +32,8 @@ unsigned char CustomMsg::Serialize(char *buffer) { return ix; } -CustomMsg CustomMsg::Receive(char *buffer, unsigned char bufferSize) { - CustomMsg msg = CustomMsg(buffer); +BinaryMsg BinaryMsg::Receive(char *buffer, unsigned char bufferSize) { + BinaryMsg msg = BinaryMsg(buffer); return msg; } diff --git a/Messages/CustomMsg.h b/Messages/BinaryMsg.h similarity index 66% rename from Messages/CustomMsg.h rename to Messages/BinaryMsg.h index acdbbc6..987b8a8 100644 --- a/Messages/CustomMsg.h +++ b/Messages/BinaryMsg.h @@ -5,7 +5,7 @@ namespace Passer { namespace RoboidControl { -class CustomMsg : public IMessage { +class BinaryMsg : public IMessage { public: static const unsigned char id = 0xB1; static const unsigned length = 3; @@ -17,13 +17,13 @@ public: unsigned char bytesSize; char *bytes = nullptr; - CustomMsg(char *buffer); - CustomMsg(unsigned char networkId, Thing *thing); - virtual ~CustomMsg(); + BinaryMsg(char *buffer); + BinaryMsg(unsigned char networkId, Thing *thing); + virtual ~BinaryMsg(); virtual unsigned char Serialize(char *buffer) override; - static CustomMsg Receive(char *buffer, unsigned char bufferSize); + static BinaryMsg Receive(char *buffer, unsigned char bufferSize); }; } // namespace RoboidControl diff --git a/Messages/ClientMsg.cpp b/Messages/ClientMsg.cpp deleted file mode 100644 index 0959a37..0000000 --- a/Messages/ClientMsg.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "ClientMsg.h" - -namespace Passer::RoboidControl { - -ClientMsg::ClientMsg(char networkId) { this->networkId = networkId; } - -ClientMsg::ClientMsg(const char *buffer) { this->networkId = buffer[1]; } - -ClientMsg::~ClientMsg() {} - -unsigned char ClientMsg::Serialize(char *buffer) { - unsigned char ix = 0; - buffer[ix++] = this->id; - buffer[ix++] = this->networkId; - return ClientMsg::length; -} - -// bool ClientMsg::Send(Participant *participant, unsigned char networkId) { -// ClientMsg msg = ClientMsg() -// } -// Client Msg - -} // namespace Passer::RoboidControl \ No newline at end of file diff --git a/Messages/ClientMsg.h b/Messages/ClientMsg.h deleted file mode 100644 index f512c90..0000000 --- a/Messages/ClientMsg.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include "Messages.h" - -namespace Passer { -namespace RoboidControl { - -/// @brief A client message announces the presence of a participant -/// When received by another participant, it can be followed by a NetworkIdMsg -/// to announce that participant to this client such that it can join privately -class ClientMsg : public IMessage { -public: - static const unsigned char id = 0xA0; - static const unsigned char length = 2; - unsigned char networkId; - - ClientMsg(char networkId); - ClientMsg(const char *buffer); - virtual ~ClientMsg(); - - virtual unsigned char Serialize(char *buffer) override; -}; - -} // namespace RoboidControl -} // namespace Passer \ No newline at end of file diff --git a/Messages/DestroyMsg.cpp b/Messages/DestroyMsg.cpp index 9ad67e5..e2c04ad 100644 --- a/Messages/DestroyMsg.cpp +++ b/Messages/DestroyMsg.cpp @@ -8,6 +8,8 @@ DestroyMsg::DestroyMsg(unsigned char networkId, Thing *thing) { this->thingId = thing->id; } +DestroyMsg::DestroyMsg(char* buffer) {} + DestroyMsg::~DestroyMsg() {} unsigned char DestroyMsg::Serialize(char *buffer) { diff --git a/Messages/DestroyMsg.h b/Messages/DestroyMsg.h index 4d30a08..66a6830 100644 --- a/Messages/DestroyMsg.h +++ b/Messages/DestroyMsg.h @@ -2,16 +2,28 @@ namespace Passer { namespace RoboidControl { +/// @brief 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 static const unsigned length = 3; + /// @brief The network ID of the thing unsigned char networkId; + /// @brief The ID of the thing unsigned char thingId; + /// @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 virtual ~DestroyMsg(); + /// @copydoc Passer::RoboidControl::IMessage::Serialize virtual unsigned char Serialize(char *buffer) override; }; diff --git a/Messages/InvestigateMsg.h b/Messages/InvestigateMsg.h index 21cf98d..09eb0a8 100644 --- a/Messages/InvestigateMsg.h +++ b/Messages/InvestigateMsg.h @@ -1,15 +1,32 @@ #include "Messages.h" +namespace Passer { +namespace RoboidControl { + +/// @brief Message to request details for a Thing class InvestigateMsg : public IMessage { -public: + public: + /// @brief The message ID static const unsigned char id = 0x81; + /// @brief The length of the message static const unsigned char length = 3; + /// @brief The network ID of the thing unsigned char networkId; + /// @brief the ID of the thing unsigned char thingId; - InvestigateMsg(char *buffer); + /// @brief Create a new message for sending + /// @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*) + InvestigateMsg(char* buffer); + /// @brief Destructor for the message virtual ~InvestigateMsg(); - virtual unsigned char Serialize(char *buffer) override; + /// @copydoc Passer::RoboidControl::IMessage::Serialize + virtual unsigned char Serialize(char* buffer) override; }; + +} // namespace RoboidControl +} // namespace Passer \ No newline at end of file diff --git a/Messages/Messages.cpp b/Messages/Messages.cpp index dab6b01..147e764 100644 --- a/Messages/Messages.cpp +++ b/Messages/Messages.cpp @@ -1,7 +1,7 @@ #include "Messages.h" #include "LowLevelMessages.h" -// #include "Messages/CustomMsg.h" +// #include "Messages/BinaryMsg.h" #include "Participant.h" #include "string.h" @@ -11,7 +11,11 @@ IMessage::IMessage() {} // IMessage::IMessage(unsigned char *buffer) { Deserialize(buffer); } -unsigned char IMessage::Serialize(char *buffer) { return 0; } +IMessage::IMessage(char* buffer) {} + +unsigned char IMessage::Serialize(char* buffer) { + return 0; +} // void IMessage::Deserialize(unsigned char *buffer) {} @@ -20,9 +24,9 @@ unsigned char IMessage::Serialize(char *buffer) { return 0; } // return client->SendBuffer(msg.Serialize(client->buffer)); // } -unsigned char *IMessage::ReceiveMsg(unsigned char packetSize) { - return nullptr; -} +// unsigned char *IMessage::ReceiveMsg(unsigned char packetSize) { +// return nullptr; +// } // bool IMessage::Publish(Participant *participant) { // return participant->PublishBuffer(Serialize(participant->buffer)); diff --git a/Messages/Messages.h b/Messages/Messages.h index 1091f8e..90399dd 100644 --- a/Messages/Messages.h +++ b/Messages/Messages.h @@ -8,17 +8,20 @@ namespace Passer { namespace RoboidControl { -class Participant; - +/// @brief Root structure for all communcation messages class IMessage { public: + /// @brief Default constructor for a message IMessage(); + /// @brief Create a message for receiving + /// @param buffer The byte array to parse + IMessage(char* buffer); + + /// @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); - static unsigned char *ReceiveMsg(unsigned char packetSize); - - // bool Publish(Participant *participant); - // bool SendTo(Participant *participant); }; } // namespace RoboidControl diff --git a/Messages/ModelUrlMsg.h b/Messages/ModelUrlMsg.h index 145e8ed..0b3f521 100644 --- a/Messages/ModelUrlMsg.h +++ b/Messages/ModelUrlMsg.h @@ -3,23 +3,37 @@ namespace Passer { namespace RoboidControl { +/// @brief Message for communicating the URL for a model of the thing class ModelUrlMsg : public IMessage { public: + /// @brief The message ID static const unsigned char id = 0x90; + /// @brief The length of the message without the URL string itself + static const unsigned char length = 3; + /// @brief The network ID of the thing unsigned char networkId; + /// @brief The ID of the thing unsigned char thingId; - - float scale; + + /// @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; - ModelUrlMsg(const char *buffer); + /// @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, 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; }; diff --git a/Messages/NameMsg.cpp b/Messages/NameMsg.cpp index e37e2e8..9f926ce 100644 --- a/Messages/NameMsg.cpp +++ b/Messages/NameMsg.cpp @@ -5,6 +5,16 @@ namespace Passer { namespace RoboidControl { +NameMsg::NameMsg(unsigned char networkId, Thing *thing) { + this->networkId = networkId; + this->thingId = thing->id; + if (thing->name == nullptr) + this->nameLength = 0; + else + this->nameLength = strlen(thing->name); + this->name = thing->name; // dangerous! +} + NameMsg::NameMsg(const char *buffer) { unsigned char ix = 1; // first byte is msg id this->networkId = buffer[ix++]; @@ -18,16 +28,6 @@ NameMsg::NameMsg(const char *buffer) { this->name = name; } -NameMsg::NameMsg(unsigned char networkId, Thing *thing) { - this->networkId = networkId; - this->thingId = thing->id; - if (thing->name == nullptr) - this->nameLength = 0; - else - this->nameLength = strlen(thing->name); - this->name = thing->name; // dangerous! -} - NameMsg::~NameMsg() { delete[] this->name; } diff --git a/Messages/NameMsg.h b/Messages/NameMsg.h index 0afc8a4..4a94237 100644 --- a/Messages/NameMsg.h +++ b/Messages/NameMsg.h @@ -3,23 +3,37 @@ namespace Passer { namespace RoboidControl { +/// @brief Message for communicating the name of a thing class NameMsg : public IMessage { -public: + public: + /// @brief The message ID static const unsigned char id = 0x91; + /// @brief The length of the message static const unsigned char length = 4; + /// @brief The network ID of the thing unsigned char networkId; + /// @brief The ID of the thing unsigned char thingId; + /// @brief The length of the name, excluding the null terminator unsigned char nameLength; - const char *name; + /// @brief The name of the thing, not terminated with a null character + const char* name; - NameMsg(const char *buffer); - NameMsg(unsigned char networkId, Thing *thing); + /// @brief Create a new message for sending + /// @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 Passer::RoboidControl::IMessage::IMessage(char*) + NameMsg(const char* buffer); + /// @brief Destructor for the message virtual ~NameMsg(); - virtual unsigned char Serialize(char *buffer) override; + /// @copydoc Passer::RoboidControl::IMessage::Serialize + virtual unsigned char Serialize(char* buffer) override; }; -} // namespace Control -} // namespace Passer +} // namespace RoboidControl +} // namespace Passer diff --git a/Messages/NetworkIdMsg.h b/Messages/NetworkIdMsg.h index 353bd38..afc4fb8 100644 --- a/Messages/NetworkIdMsg.h +++ b/Messages/NetworkIdMsg.h @@ -3,18 +3,26 @@ namespace Passer { namespace RoboidControl { +/// @brief A message communicating the network ID for that participant class NetworkIdMsg : public IMessage { public: + /// @brief The message ID static const unsigned char id = 0xA1; + /// @brief The length of the message static const unsigned char length = 2; + /// @brief The network ID for the participant unsigned char networkId; - NetworkIdMsg(const char *buffer); + /// @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*) + NetworkIdMsg(const char *buffer); + /// @brief Destructor for the message virtual ~NetworkIdMsg(); + /// @copydoc Passer::RoboidControl::IMessage::Serialize virtual unsigned char Serialize(char *buffer) override; - // static NetworkIdMsg Receive(char *buffer, unsigned char bufferSize); }; } // namespace Control diff --git a/Messages/ParticipantMsg.cpp b/Messages/ParticipantMsg.cpp new file mode 100644 index 0000000..e9452ea --- /dev/null +++ b/Messages/ParticipantMsg.cpp @@ -0,0 +1,23 @@ +#include "ParticipantMsg.h" + +namespace Passer::RoboidControl { + +ParticipantMsg::ParticipantMsg(char networkId) { this->networkId = networkId; } + +ParticipantMsg::ParticipantMsg(const char *buffer) { this->networkId = buffer[1]; } + +ParticipantMsg::~ParticipantMsg() {} + +unsigned char ParticipantMsg::Serialize(char *buffer) { + unsigned char ix = 0; + buffer[ix++] = this->id; + buffer[ix++] = this->networkId; + return ParticipantMsg::length; +} + +// bool ParticipantMsg::Send(Participant *participant, unsigned char networkId) { +// ParticipantMsg msg = ParticipantMsg() +// } +// Client Msg + +} // namespace Passer::RoboidControl \ No newline at end of file diff --git a/Messages/ParticipantMsg.h b/Messages/ParticipantMsg.h new file mode 100644 index 0000000..df742e9 --- /dev/null +++ b/Messages/ParticipantMsg.h @@ -0,0 +1,36 @@ +#pragma once + +#include "Messages.h" + +namespace Passer { +namespace RoboidControl { + +/// @brief A participant messages notifies other participants of its presence +/// When received by another participant, it can be followed by a NetworkIdMsg +/// to announce that participant to this client such that it can join privately +class ParticipantMsg : public IMessage { + public: + /// @brief The message ID + static const unsigned char id = 0xA0; + /// @brief The length of the message + static const unsigned char length = 2; + /// @brief The network ID known by the participant + unsigned char networkId; + + /// @brief Create a new message for sending + /// @param networkId The network ID known by the participant + ParticipantMsg(char networkId); + + /// @copydoc Passer::RoboidControl::IMessage::IMessage(char*) + ParticipantMsg(const char* buffer); + /// @brief Destructor for the message + virtual ~ParticipantMsg(); + + /// @brief Serialize the message into a byte array + /// @param buffer The buffer to serialize into + /// @return The length of the message in the buffer + virtual unsigned char Serialize(char* buffer) override; +}; + +} // namespace RoboidControl +} // namespace Passer \ No newline at end of file diff --git a/Messages/PoseMsg.h b/Messages/PoseMsg.h index a5facd9..ddb2e07 100644 --- a/Messages/PoseMsg.h +++ b/Messages/PoseMsg.h @@ -1,30 +1,66 @@ #include "Messages.h" +namespace Passer { +namespace RoboidControl { + +/// @brief Message to communicate the pose of the thing +/// The pose is in local space relative to the parent. If there is not parent (the thing is a root thing), the pose will +/// be in world space. class PoseMsg : public IMessage { -public: + public: + /// @brief The message ID static const unsigned char id = 0x10; + /// @brief The length of the message unsigned char length = 4 + 4 + 4; + /// @brief The network ID of the thing unsigned char networkId; + /// @brief The ID of the thing unsigned char thingId; + /// @brief Bit pattern stating which pose components are available unsigned char poseType; + /// @brief Bit pattern for a pose with position static const unsigned char Pose_Position = 0x01; + /// @brief Bit pattern for a pose with orientation static const unsigned char Pose_Orientation = 0x02; - static const unsigned char Pose_LinearVelocity = 0x04; // For future use - static const unsigned char Pose_AngularVelocity = 0x08; // For future use + /// @brief Bit pattern for a pose with linear velocity + static const unsigned char Pose_LinearVelocity = 0x04; + /// @brief Bit pattern for a pose with angular velocity + static const unsigned char Pose_AngularVelocity = 0x08; + /// @brief The position of the thing in local space in meters Spherical16 position; + /// @brief The orientation of the thing in local space SwingTwist16 orientation; + /// @brief The linear velocity of the thing in local space in meters per second Spherical16 linearVelocity; + /// @brief The angular velocity of the thing in local space Spherical16 angularVelocity; - PoseMsg(unsigned char networkId, unsigned char thingId, - unsigned char poseType, Spherical16 position, - SwingTwist16 orientation, Spherical16 linearVelocity = Spherical16(), + /// @brief Create a new message for sending + /// @param networkId The network ID of the thing + /// @param thingId The ID of the thing + /// @param poseType Bit pattern stating which pose components are available + /// @param position The position of the thing in local space in meters + /// @param orientation The orientation of the thing in local space + /// @param linearVelocity The linear velocity of the thing in local space in meters per second + /// @param angularVelocity The angular velocity of the thing in local space + PoseMsg(unsigned char networkId, + unsigned char thingId, + unsigned char poseType, + Spherical16 position, + SwingTwist16 orientation, + Spherical16 linearVelocity = Spherical16(), Spherical16 angularVelocity = Spherical16()); - PoseMsg(const char *buffer); + /// @copydoc Passer::RoboidControl::IMessage::IMessage(char*) + PoseMsg(const char* buffer); + /// @brief Destructor for the message virtual ~PoseMsg(); - virtual unsigned char Serialize(char *buffer) override; + /// @copydoc Passer::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 new file mode 100644 index 0000000..854a821 --- /dev/null +++ b/Messages/TextMsg.cpp @@ -0,0 +1,37 @@ +#include "TextMsg.h" + +namespace Passer { +namespace RoboidControl { + +TextMsg::TextMsg(const char* text, unsigned char textLength) { + this->text = text; + this->textLength = textLength; +} + +TextMsg::TextMsg(char* buffer) { + unsigned char ix = 1; // first byte is msg id + + this->textLength = buffer[ix++]; + char* text = new char[this->textLength + 1]; + for (int i = 0; i < this->textLength; i++) + text[i] = buffer[ix++]; + text[this->textLength] = '\0'; + this->text = text; +} + +TextMsg::~TextMsg() {} + +unsigned char TextMsg::Serialize(char* buffer) { + if (this->textLength == 0 || this->text == nullptr) + return 0; + + unsigned char ix = 0; + buffer[ix++] = this->id; + buffer[ix++] = this->textLength; + for (int nameIx = 0; nameIx < this->textLength; nameIx++) + buffer[ix++] = this->text[nameIx]; + + return ix;} + +} // namespace RoboidControl +} // namespace Passer \ No newline at end of file diff --git a/Messages/TextMsg.h b/Messages/TextMsg.h new file mode 100644 index 0000000..dcb6c85 --- /dev/null +++ b/Messages/TextMsg.h @@ -0,0 +1,35 @@ +#include "Messages.h" + +namespace Passer { +namespace RoboidControl { + +/// @brief Message for sending generic text +class TextMsg : public IMessage { + public: + /// @brief The message ID + 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 + unsigned char textLength; + + /// @brief Create a new message for sending + /// @param text The text + TextMsg(const char* text, unsigned char textLength); + /// @copydoc Passer::RoboidControl::IMessage::IMessage(char*) + TextMsg(char* buffer); + /// @brief Destructor for the message + virtual ~TextMsg(); + + /// @copydoc Passer::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.h b/Messages/ThingMsg.h index bfdd8fa..0a6d006 100644 --- a/Messages/ThingMsg.h +++ b/Messages/ThingMsg.h @@ -3,23 +3,37 @@ namespace Passer { namespace RoboidControl { +/// @brief Message providing generic information about a Thing class ThingMsg : public IMessage { -public: + public: + /// @brief The message ID static const unsigned char id = 0x80; + /// @brief The length of the message static const unsigned char length = 5; + /// @brief The network ID of the thing unsigned char networkId; + /// @brief The ID of the thing unsigned char thingId; + /// @brief The Thing.Type of the thing unsigned char thingType; + /// @brief The parent of the thing in the hierarachy. This is null for root Things unsigned char parentId; - ThingMsg(const char *buffer); - ThingMsg(unsigned char networkId, Thing *thing); + /// @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 Passer::RoboidControl::IMessage::IMessage(char*) + ThingMsg(const char* buffer); + /// @brief Destructor for the message virtual ~ThingMsg(); - virtual unsigned char Serialize(char *buffer) override; + /// @copydoc Passer::RoboidControl::IMessage::Serialize + virtual unsigned char Serialize(char* buffer) override; }; -} // namespace Control -} // namespace Passer \ No newline at end of file +} // namespace RoboidControl +} // namespace Passer \ No newline at end of file diff --git a/Participant.cpp b/Participant.cpp index 6d97749..a0e18dc 100644 --- a/Participant.cpp +++ b/Participant.cpp @@ -79,10 +79,10 @@ void Participant::Update(unsigned long currentTimeMs) { begin(); if (this->publishInterval > 0 && currentTimeMs > this->nextPublishMe) { - ClientMsg* msg = new ClientMsg(this->networkId); + ParticipantMsg* msg = new ParticipantMsg(this->networkId); this->Publish(msg); delete msg; - std::cout << this->name << " published ClientMsg\n"; + std::cout << this->name << " published ParticipantMsg\n"; this->nextPublishMe = currentTimeMs + this->publishInterval; } this->ReceiveUDP(); @@ -150,7 +150,7 @@ void Passer::RoboidControl::Participant::PublishThingInfo(Thing* thing) { ModelUrlMsg* modelMsg = new ModelUrlMsg(this->networkId, thing); this->Publish(modelMsg); delete modelMsg; - CustomMsg* customMsg = new CustomMsg(this->networkId, thing); + BinaryMsg* customMsg = new BinaryMsg(this->networkId, thing); this->Publish(customMsg); delete customMsg; } @@ -194,8 +194,8 @@ void Participant::ReceiveData(unsigned char bufferSize, RemoteParticipant* remot unsigned char msgId = this->buffer[0]; // std::cout << "receive msg " << (int)msgId << "\n"; switch (msgId) { - case ClientMsg::id: { - ClientMsg* msg = new ClientMsg(this->buffer); + case ParticipantMsg::id: { + ParticipantMsg* msg = new ParticipantMsg(this->buffer); Process(remoteParticipant, msg); delete msg; } break; @@ -224,15 +224,15 @@ void Participant::ReceiveData(unsigned char bufferSize, RemoteParticipant* remot Process(remoteParticipant, msg); delete msg; } break; - case CustomMsg::id: { - CustomMsg* msg = new CustomMsg(this->buffer); + case BinaryMsg::id: { + BinaryMsg* msg = new BinaryMsg(this->buffer); Process(remoteParticipant, msg); delete msg; } break; }; } -void Participant::Process(RemoteParticipant* sender, ClientMsg* msg) {} +void Participant::Process(RemoteParticipant* sender, ParticipantMsg* msg) {} void Participant::Process(RemoteParticipant* sender, NetworkIdMsg* msg) { std::cout << this->name << ": process NetworkId [" << (int)this->networkId << "/" << (int)msg->networkId << "]\n"; @@ -261,7 +261,7 @@ void Participant::Process(RemoteParticipant* sender, NameMsg* msg) { void Participant::Process(RemoteParticipant* sender, PoseMsg* msg) {} -void Participant::Process(RemoteParticipant* sender, CustomMsg* msg) { +void Participant::Process(RemoteParticipant* sender, BinaryMsg* msg) { // std::cout << this->name << ": process Binary [" << (int)this->networkId << "/" // << (int)msg->networkId << "]\n"; Thing* thing = sender->Get(msg->networkId, msg->thingId); diff --git a/Participant.h b/Participant.h index e5a951c..da5b169 100644 --- a/Participant.h +++ b/Participant.h @@ -1,8 +1,8 @@ #pragma once //#include "Messages/" -#include "Messages/ClientMsg.h" -#include "Messages/CustomMsg.h" +#include "Messages/ParticipantMsg.h" +#include "Messages/BinaryMsg.h" #include "Messages/InvestigateMsg.h" #include "Messages/ModelUrlMsg.h" #include "Messages/NameMsg.h" @@ -94,13 +94,13 @@ protected: void ReceiveUDP(); - virtual void Process(RemoteParticipant *sender, ClientMsg *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, CustomMsg *msg); + virtual void Process(RemoteParticipant* sender, BinaryMsg *msg); }; } // namespace Control diff --git a/Sensors/TemperatureSensor.cpp b/Sensors/TemperatureSensor.cpp index fca16cb..ad63935 100644 --- a/Sensors/TemperatureSensor.cpp +++ b/Sensors/TemperatureSensor.cpp @@ -13,16 +13,16 @@ TemperatureSensor::TemperatureSensor(unsigned char networkId, unsigned char thingId) : Thing(nullptr, networkId, thingId, Type::TemperatureSensor) {} -void TemperatureSensor::SetTemperature(float temp) { this->temp = temp; } +void TemperatureSensor::SetTemperature(float temp) { this->temperature = temp; } void TemperatureSensor::GenerateBinary(char *buffer, unsigned char *ix) { - std::cout << "Send temperature: " << this->temp << "\n"; - LowLevelMessages::SendFloat16(buffer, ix, this->temp); + std::cout << "Send temperature: " << this->temperature << "\n"; + LowLevelMessages::SendFloat16(buffer, ix, this->temperature); } void TemperatureSensor::ProcessBinary(char *bytes) { unsigned char ix = 0; - this->temp = LowLevelMessages::ReceiveFloat16(bytes, &ix); + this->temperature = LowLevelMessages::ReceiveFloat16(bytes, &ix); } } // namespace Control diff --git a/Sensors/TemperatureSensor.h b/Sensors/TemperatureSensor.h index 7eb3a94..8ce8284 100644 --- a/Sensors/TemperatureSensor.h +++ b/Sensors/TemperatureSensor.h @@ -5,19 +5,31 @@ namespace Passer { namespace RoboidControl { +/// @brief A temperature sensor class TemperatureSensor : public Thing { -public: + public: + /// @brief The measured temperature + float temperature = 0; + + /// @brief The default constructor TemperatureSensor(); + /// @brief Create a temperature sensor with the given ID + /// @param networkId The network ID of the sensor + /// @param thingId The ID of the thing TemperatureSensor(unsigned char networkId, unsigned char thingId); - virtual void SetTemperature(float temp); + /// @brief Manually override the measured temperature + /// @param temperature The new temperature + virtual void SetTemperature(float temperature); - void GenerateBinary(char *buffer, unsigned char *ix) override; - virtual void ProcessBinary(char *bytes) override; - -protected: - float temp = 0; + /// @brief Function to create a binary message with the temperature + /// @param buffer The byte array for thw binary data + /// @param ix The starting position for writing the binary data + void GenerateBinary(char* bytes, unsigned char* ix) override; + /// @brief Function to extract the temperature received in the binary message + /// @param bytes The binary data + virtual void ProcessBinary(char* bytes) override; }; -} // namespace Control -} // namespace Passer \ No newline at end of file +} // namespace RoboidControl +} // namespace Passer \ No newline at end of file diff --git a/SiteServer.cpp b/SiteServer.cpp index bb5a213..6510a65 100644 --- a/SiteServer.cpp +++ b/SiteServer.cpp @@ -22,7 +22,7 @@ SiteServer::SiteServer(int port) { Register((unsigned char)Thing::Type::TemperatureSensor); } -void SiteServer::Process(RemoteParticipant *sender, ClientMsg *msg) { +void SiteServer::Process(RemoteParticipant *sender, ParticipantMsg *msg) { if (msg->networkId == 0) { std::cout << this->name << " received New Client -> " << sender->ipAddress << " " << (int)sender->networkId << "\n"; diff --git a/SiteServer.h b/SiteServer.h index c657ca6..c9091b8 100644 --- a/SiteServer.h +++ b/SiteServer.h @@ -26,7 +26,7 @@ public: protected: unsigned long nextPublishMe = 0; - virtual void Process(RemoteParticipant *sender, ClientMsg *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;