removed namespace Passer

This commit is contained in:
Pascal Serrarens 2025-02-24 09:30:17 +01:00
parent 4342e3bbd0
commit 1916478494
48 changed files with 276 additions and 394 deletions

View File

@ -8,7 +8,6 @@
#endif #endif
#endif #endif
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
namespace Arduino { namespace Arduino {
@ -96,4 +95,3 @@ bool Participant::Publish(IMessage* msg) {
} // namespace Arduino } // namespace Arduino
} // namespace RoboidControl } // namespace RoboidControl
} // namespace Passer

View File

@ -2,7 +2,6 @@
#include "../Participant.h" #include "../Participant.h"
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
namespace Arduino { namespace Arduino {
@ -19,4 +18,3 @@ class Participant : public RoboidControl::Participant {
} // namespace Arduino } // namespace Arduino
} // namespace RoboidControl } // namespace RoboidControl
} // namespace Passer

View File

@ -23,17 +23,20 @@ else()
FetchContent_MakeAvailable(googletest) FetchContent_MakeAvailable(googletest)
include_directories(.) include_directories(.)
add_library(LinearAlgebra STATIC file(GLOB srcs
"FloatSingle.cpp" *.cpp
"Angle.cpp" )
"Vector2.cpp" add_library(LinearAlgebra STATIC ${srcs}
"Vector3.cpp" # "FloatSingle.cpp"
"Quaternion.cpp" # "Angle.cpp"
"Polar.cpp" # "Vector2.cpp"
"Spherical.cpp" # "Vector3.cpp"
"Matrix.cpp" # "Quaternion.cpp"
"SwingTwist.cpp" # "Polar.cpp"
"Direction.cpp" # "Spherical.cpp"
# "Matrix.cpp"
# "SwingTwist.cpp"
# "Direction.cpp"
) )
enable_testing() enable_testing()

View File

@ -1,14 +1,12 @@
#include "BinaryMsg.h" #include "BinaryMsg.h"
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
BinaryMsg::BinaryMsg(char* buffer) { BinaryMsg::BinaryMsg(char* buffer) {
unsigned char ix = 1; unsigned char ix = 1;
this->networkId = buffer[ix++]; this->networkId = buffer[ix++];
this->thingId = buffer[ix++]; this->thingId = buffer[ix++];
this->bytes = this->bytes = buffer + ix; // This is only valid because the code ensures the the msg
buffer + ix; // This is only valid because the code ensures the the msg
// lifetime is shorter than the buffer lifetime... // lifetime is shorter than the buffer lifetime...
} }
@ -38,4 +36,3 @@ BinaryMsg BinaryMsg::Receive(char *buffer, unsigned char bufferSize) {
} }
} // namespace RoboidControl } // namespace RoboidControl
} // namespace Passer

View File

@ -2,7 +2,6 @@
#include "Messages.h" #include "Messages.h"
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
class BinaryMsg : public IMessage { class BinaryMsg : public IMessage {
@ -27,4 +26,3 @@ public:
}; };
} // namespace RoboidControl } // namespace RoboidControl
} // namespace Passer

View File

@ -1,6 +1,5 @@
#include "DestroyMsg.h" #include "DestroyMsg.h"
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
DestroyMsg::DestroyMsg(unsigned char networkId, Thing *thing) { DestroyMsg::DestroyMsg(unsigned char networkId, Thing *thing) {
@ -21,4 +20,3 @@ unsigned char DestroyMsg::Serialize(char *buffer) {
} }
} // namespace RoboidControl } // namespace RoboidControl
} // namespace Passer

View File

@ -1,5 +1,5 @@
#include "Messages.h" #include "Messages.h"
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
/// @brief Message notifiying that a Thing no longer exists /// @brief Message notifiying that a Thing no longer exists
@ -18,14 +18,13 @@ public:
/// @param networkId The network ID of the thing /// @param networkId The network ID of the thing
/// @param thing The ID of the thing /// @param thing The ID of the thing
DestroyMsg(unsigned char networkId, Thing* thing); DestroyMsg(unsigned char networkId, Thing* thing);
/// @copydoc Passer::RoboidControl::IMessage::IMessage(char*) /// @copydoc RoboidControl::IMessage::IMessage(char*)
DestroyMsg(char* buffer); DestroyMsg(char* buffer);
/// @brief Destructor for the message /// @brief Destructor for the message
virtual ~DestroyMsg(); virtual ~DestroyMsg();
/// @copydoc Passer::RoboidControl::IMessage::Serialize /// @copydoc RoboidControl::IMessage::Serialize
virtual unsigned char Serialize(char* buffer) override; virtual unsigned char Serialize(char* buffer) override;
}; };
} // namespace RoboidControl } // namespace RoboidControl
} // namespace Passer

View File

@ -1,5 +1,6 @@
#include "InvestigateMsg.h" #include "InvestigateMsg.h"
#pragma region Investigate
namespace RoboidControl {
InvestigateMsg::InvestigateMsg(char* buffer) { InvestigateMsg::InvestigateMsg(char* buffer) {
unsigned ix = 1; // first byte is msgId unsigned ix = 1; // first byte is msgId
@ -20,11 +21,4 @@ unsigned char InvestigateMsg::Serialize(char *buffer) {
return ix; return ix;
} }
// bool InvestigateMsg::Send(Participant *participant, unsigned char networkId, } // namespace RoboidControl
// unsigned char thingId) {
// InvestigateMsg msg = InvestigateMsg(networkId, thingId);
// return msg.Send(participant);
// }
// Investigate
#pragma endregion

View File

@ -1,6 +1,5 @@
#include "Messages.h" #include "Messages.h"
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
/// @brief Message to request details for a Thing /// @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 networkId The network ID for the thing
/// @param thingId The ID of the thing /// @param thingId The ID of the thing
InvestigateMsg(unsigned char networkId, unsigned char thingId); InvestigateMsg(unsigned char networkId, unsigned char thingId);
/// @copydoc Passer::RoboidControl::IMessage::IMessage(char*) /// @copydoc RoboidControl::IMessage::IMessage(char*)
InvestigateMsg(char* buffer); InvestigateMsg(char* buffer);
/// @brief Destructor for the message /// @brief Destructor for the message
virtual ~InvestigateMsg(); virtual ~InvestigateMsg();
/// @copydoc Passer::RoboidControl::IMessage::Serialize /// @copydoc RoboidControl::IMessage::Serialize
virtual unsigned char Serialize(char* buffer) override; virtual unsigned char Serialize(char* buffer) override;
}; };
} // namespace RoboidControl } // namespace RoboidControl
} // namespace Passer

View File

@ -2,13 +2,13 @@
#include "float16.h" #include "float16.h"
void LowLevelMessages::SendAngle8(char *buffer, unsigned char *ix, namespace RoboidControl {
const float angle) {
void LowLevelMessages::SendAngle8(char* buffer, unsigned char* ix, const float angle) {
Angle8 packedAngle2 = Angle8::Degrees(angle); Angle8 packedAngle2 = Angle8::Degrees(angle);
buffer[(*ix)++] = packedAngle2.GetBinary(); buffer[(*ix)++] = packedAngle2.GetBinary();
} }
Angle8 LowLevelMessages::ReceiveAngle8(const char *buffer, Angle8 LowLevelMessages::ReceiveAngle8(const char* buffer, unsigned char* startIndex) {
unsigned char *startIndex) {
unsigned char binary = buffer[(*startIndex)++]; unsigned char binary = buffer[(*startIndex)++];
Angle8 angle = Angle8::Binary(binary); Angle8 angle = Angle8::Binary(binary);
@ -16,16 +16,14 @@ Angle8 LowLevelMessages::ReceiveAngle8(const char *buffer,
return angle; return angle;
} }
void LowLevelMessages::SendFloat16(char *buffer, unsigned char *ix, void LowLevelMessages::SendFloat16(char* buffer, unsigned char* ix, float value) {
float value) {
float16 value16 = float16(value); float16 value16 = float16(value);
short binary = value16.getBinary(); short binary = value16.getBinary();
buffer[(*ix)++] = (binary >> 8) & 0xFF; buffer[(*ix)++] = (binary >> 8) & 0xFF;
buffer[(*ix)++] = binary & 0xFF; buffer[(*ix)++] = binary & 0xFF;
} }
float LowLevelMessages::ReceiveFloat16(const char *buffer, float LowLevelMessages::ReceiveFloat16(const char* buffer, unsigned char* startIndex) {
unsigned char *startIndex) {
unsigned char ix = *startIndex; unsigned char ix = *startIndex;
unsigned char msb = buffer[ix++]; unsigned char msb = buffer[ix++];
unsigned char lsb = buffer[ix++]; unsigned char lsb = buffer[ix++];
@ -37,14 +35,12 @@ float LowLevelMessages::ReceiveFloat16(const char *buffer,
return (float)f.toFloat(); return (float)f.toFloat();
} }
void LowLevelMessages::SendSpherical16(char *buffer, unsigned char *ix, void LowLevelMessages::SendSpherical16(char* buffer, unsigned char* ix, Spherical16 s) {
Spherical16 s) {
SendFloat16(buffer, ix, s.distance); SendFloat16(buffer, ix, s.distance);
SendAngle8(buffer, ix, s.direction.horizontal.InDegrees()); SendAngle8(buffer, ix, s.direction.horizontal.InDegrees());
SendAngle8(buffer, ix, s.direction.vertical.InDegrees()); SendAngle8(buffer, ix, s.direction.vertical.InDegrees());
} }
Spherical16 LowLevelMessages::ReceiveSpherical16(const char *buffer, Spherical16 LowLevelMessages::ReceiveSpherical16(const char* buffer, unsigned char* startIndex) {
unsigned char *startIndex) {
float distance = ReceiveFloat16(buffer, startIndex); float distance = ReceiveFloat16(buffer, startIndex);
Angle8 horizontal8 = ReceiveAngle8(buffer, startIndex); Angle8 horizontal8 = ReceiveAngle8(buffer, startIndex);
@ -57,9 +53,7 @@ Spherical16 LowLevelMessages::ReceiveSpherical16(const char *buffer,
return s; return s;
} }
void Passer::RoboidControl::LowLevelMessages::SendQuat32(char *buffer, void LowLevelMessages::SendQuat32(char* buffer, unsigned char* ix, SwingTwist16 rotation) {
unsigned char *ix,
SwingTwist16 rotation) {
Quaternion q = rotation.ToQuaternion(); Quaternion q = rotation.ToQuaternion();
unsigned char qx = (char)(q.x * 127 + 128); unsigned char qx = (char)(q.x * 127 + 128);
unsigned char qy = (char)(q.y * 127 + 128); unsigned char qy = (char)(q.y * 127 + 128);
@ -78,8 +72,7 @@ void Passer::RoboidControl::LowLevelMessages::SendQuat32(char *buffer,
buffer[(*ix)++] = qw; buffer[(*ix)++] = qw;
} }
SwingTwist16 LowLevelMessages::ReceiveQuat32(const char *buffer, SwingTwist16 LowLevelMessages::ReceiveQuat32(const char* buffer, unsigned char* ix) {
unsigned char *ix) {
float qx = (buffer[(*ix)++] - 128.0F) / 127.0F; float qx = (buffer[(*ix)++] - 128.0F) / 127.0F;
float qy = (buffer[(*ix)++] - 128.0F) / 127.0F; float qy = (buffer[(*ix)++] - 128.0F) / 127.0F;
float qz = (buffer[(*ix)++] - 128.0F) / 127.0F; float qz = (buffer[(*ix)++] - 128.0F) / 127.0F;
@ -88,3 +81,5 @@ SwingTwist16 LowLevelMessages::ReceiveQuat32(const char *buffer,
SwingTwist16 s = SwingTwist16::FromQuaternion(q); SwingTwist16 s = SwingTwist16::FromQuaternion(q);
return s; return s;
} }
} // namespace RoboidControl

View File

@ -1,7 +1,6 @@
#include "LinearAlgebra/Spherical.h" #include "LinearAlgebra/Spherical.h"
#include "LinearAlgebra/SwingTwist.h" #include "LinearAlgebra/SwingTwist.h"
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
class LowLevelMessages { class LowLevelMessages {
@ -13,13 +12,10 @@ public:
static float ReceiveFloat16(const char* buffer, unsigned char* startIndex); static float ReceiveFloat16(const char* buffer, unsigned char* startIndex);
static void SendSpherical16(char* buffer, unsigned char* ix, Spherical16 s); static void SendSpherical16(char* buffer, unsigned char* ix, Spherical16 s);
static Spherical16 ReceiveSpherical16(const char *buffer, static Spherical16 ReceiveSpherical16(const char* buffer, unsigned char* startIndex);
unsigned char *startIndex);
static void SendQuat32(char* buffer, unsigned char* ix, SwingTwist16 q); static void SendQuat32(char* buffer, unsigned char* ix, SwingTwist16 q);
static SwingTwist16 ReceiveQuat32(const char* buffer, unsigned char* ix); static SwingTwist16 ReceiveQuat32(const char* buffer, unsigned char* ix);
}; };
} // namespace RoboidControl } // namespace RoboidControl
} // namespace Passer
using namespace Passer::RoboidControl;

View File

@ -4,7 +4,6 @@
#include "Participant.h" #include "Participant.h"
#include "string.h" #include "string.h"
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
#pragma region IMessage #pragma region IMessage
@ -19,17 +18,11 @@ unsigned char IMessage::Serialize(char* buffer) {
return 0; return 0;
} }
// void IMessage::Deserialize(unsigned char *buffer) {}
// bool IMessage::SendMsg(Participant *client, IMessage msg) { // bool IMessage::SendMsg(Participant *client, IMessage msg) {
// // return SendMsg(client, client.buffer, );nameLength // // return SendMsg(client, client.buffer, );nameLength
// return client->SendBuffer(msg.Serialize(client->buffer)); // return client->SendBuffer(msg.Serialize(client->buffer));
// } // }
// unsigned char *IMessage::ReceiveMsg(unsigned char packetSize) {
// return nullptr;
// }
// bool IMessage::Publish(Participant *participant) { // bool IMessage::Publish(Participant *participant) {
// return participant->PublishBuffer(Serialize(participant->buffer)); // return participant->PublishBuffer(Serialize(participant->buffer));
// } // }
@ -40,4 +33,4 @@ unsigned char IMessage::Serialize(char* buffer) {
// IMessage // IMessage
#pragma endregion #pragma endregion
}} } // namespace RoboidControl

View File

@ -5,7 +5,6 @@
#include "Thing.h" #include "Thing.h"
#include "float16.h" #include "float16.h"
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
class Participant; class Participant;
@ -21,7 +20,4 @@ public:
// bool SendTo(Participant *participant); // bool SendTo(Participant *participant);
}; };
} // namespace Control } // namespace RoboidControl
} // namespace Passer
using namespace Passer::RoboidControl;

View File

@ -2,7 +2,6 @@
#include <string.h> #include <string.h>
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
// ModelUrlMsg::ModelUrlMsg(unsigned char networkId, unsigned char thingId, // ModelUrlMsg::ModelUrlMsg(unsigned char networkId, unsigned char thingId,
@ -52,4 +51,3 @@ unsigned char ModelUrlMsg::Serialize(char *buffer) {
} }
} // namespace RoboidControl } // namespace RoboidControl
} // namespace Passer

View File

@ -1,6 +1,5 @@
#include "Messages.h" #include "Messages.h"
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
/// @brief Message for communicating the URL for a model of the thing /// @brief Message for communicating the URL for a model of the thing
@ -25,7 +24,7 @@ public:
/// @param networkId The network ID of the thing /// @param networkId The network ID of the thing
/// @param thing The thing for which to send the mode URL /// @param thing The thing for which to send the mode URL
ModelUrlMsg(unsigned char networkId, Thing* thing); ModelUrlMsg(unsigned char networkId, Thing* thing);
/// @copydoc Passer::RoboidControl::IMessage::IMessage(char*) /// @copydoc RoboidControl::IMessage::IMessage(char*)
ModelUrlMsg(const char* buffer); ModelUrlMsg(const char* buffer);
// ModelUrlMsg(unsigned char networkId, unsigned char thingId, // ModelUrlMsg(unsigned char networkId, unsigned char thingId,
// unsigned char urlLegth, const char *url, float scale = 1); // unsigned char urlLegth, const char *url, float scale = 1);
@ -33,9 +32,8 @@ public:
/// @brief Destructor for the message /// @brief Destructor for the message
virtual ~ModelUrlMsg(); virtual ~ModelUrlMsg();
/// @copydoc Passer::RoboidControl::IMessage::Serialize /// @copydoc RoboidControl::IMessage::Serialize
virtual unsigned char Serialize(char* buffer) override; virtual unsigned char Serialize(char* buffer) override;
}; };
} // namespace Control } // namespace RoboidControl
} // namespace Passer

View File

@ -2,7 +2,6 @@
#include <string.h> #include <string.h>
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
NameMsg::NameMsg(unsigned char networkId, Thing* thing) { NameMsg::NameMsg(unsigned char networkId, Thing* thing) {
@ -47,5 +46,4 @@ unsigned char NameMsg::Serialize(char *buffer) {
return ix; return ix;
} }
} // namespace Control } // namespace RoboidControl
} // namespace Passer

View File

@ -1,6 +1,5 @@
#include "Messages.h" #include "Messages.h"
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
/// @brief Message for communicating the name of a thing /// @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, // NameMsg(unsigned char networkId, unsigned char thingId, const char *name,
// unsigned char nameLength); // unsigned char nameLength);
/// @copydoc Passer::RoboidControl::IMessage::IMessage(char*) /// @copydoc RoboidControl::IMessage::IMessage(char*)
NameMsg(const char* buffer); NameMsg(const char* buffer);
/// @brief Destructor for the message /// @brief Destructor for the message
virtual ~NameMsg(); virtual ~NameMsg();
/// @copydoc Passer::RoboidControl::IMessage::Serialize /// @copydoc RoboidControl::IMessage::Serialize
virtual unsigned char Serialize(char* buffer) override; virtual unsigned char Serialize(char* buffer) override;
}; };
} // namespace RoboidControl } // namespace RoboidControl
} // namespace Passer

View File

@ -1,9 +1,10 @@
#include "NetworkIdMsg.h" #include "NetworkIdMsg.h"
namespace Passer {
namespace RoboidControl { 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) { NetworkIdMsg::NetworkIdMsg(unsigned char networkId) {
this->networkId = networkId; this->networkId = networkId;
@ -18,10 +19,4 @@ unsigned char NetworkIdMsg::Serialize(char *buffer) {
return NetworkIdMsg::length; return NetworkIdMsg::length;
} }
// NetworkIdMsg NetworkIdMsg::Receive(char *buffer, unsigned char bufferSize) { } // namespace RoboidControl
// NetworkIdMsg msg = NetworkIdMsg(buffer);
// return msg;
// }
} // namespace Control
} // namespace Passer

View File

@ -1,6 +1,5 @@
#include "Messages.h" #include "Messages.h"
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
/// @brief A message communicating the network ID for that participant /// @brief A message communicating the network ID for that participant
@ -16,14 +15,13 @@ public:
/// @brief Create a new message for sending /// @brief Create a new message for sending
/// @param networkId The network ID for the participant /// @param networkId The network ID for the participant
NetworkIdMsg(unsigned char networkId); NetworkIdMsg(unsigned char networkId);
/// @copydoc Passer::RoboidControl::IMessage::IMessage(char*) /// @copydoc RoboidControl::IMessage::IMessage(char*)
NetworkIdMsg(const char *buffer); NetworkIdMsg(const char *buffer);
/// @brief Destructor for the message /// @brief Destructor for the message
virtual ~NetworkIdMsg(); virtual ~NetworkIdMsg();
/// @copydoc Passer::RoboidControl::IMessage::Serialize /// @copydoc RoboidControl::IMessage::Serialize
virtual unsigned char Serialize(char *buffer) override; virtual unsigned char Serialize(char *buffer) override;
}; };
} // namespace Control } // namespace Control
} // namespace Passer

View File

@ -1,10 +1,14 @@
#include "ParticipantMsg.h" #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() {} ParticipantMsg::~ParticipantMsg() {}
@ -20,4 +24,4 @@ unsigned char ParticipantMsg::Serialize(char *buffer) {
// } // }
// Client Msg // Client Msg
} // namespace Passer::RoboidControl } // namespace RoboidControl

View File

@ -2,7 +2,6 @@
#include "Messages.h" #include "Messages.h"
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
/// @brief A participant messages notifies other participants of its presence /// @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 /// @param networkId The network ID known by the participant
ParticipantMsg(char networkId); ParticipantMsg(char networkId);
/// @copydoc Passer::RoboidControl::IMessage::IMessage(char*) /// @copydoc RoboidControl::IMessage::IMessage(char*)
ParticipantMsg(const char* buffer); ParticipantMsg(const char* buffer);
/// @brief Destructor for the message /// @brief Destructor for the message
virtual ~ParticipantMsg(); virtual ~ParticipantMsg();
@ -33,4 +32,3 @@ class ParticipantMsg : public IMessage {
}; };
} // namespace RoboidControl } // namespace RoboidControl
} // namespace Passer

View File

@ -1,9 +1,14 @@
#include "PoseMsg.h" #include "PoseMsg.h"
#include "LowLevelMessages.h" #include "LowLevelMessages.h"
PoseMsg::PoseMsg(unsigned char networkId, unsigned char thingId, namespace RoboidControl {
unsigned char poseType, Spherical16 position,
SwingTwist16 orientation, Spherical16 linearVelocity, PoseMsg::PoseMsg(unsigned char networkId,
unsigned char thingId,
unsigned char poseType,
Spherical16 position,
SwingTwist16 orientation,
Spherical16 linearVelocity,
Spherical16 angularVelocity) { Spherical16 angularVelocity) {
this->networkId = networkId; this->networkId = networkId;
this->thingId = thingId; this->thingId = thingId;
@ -41,3 +46,5 @@ unsigned char PoseMsg::Serialize(char *buffer) {
LowLevelMessages::SendSpherical16(buffer, &ix, this->angularVelocity); LowLevelMessages::SendSpherical16(buffer, &ix, this->angularVelocity);
return ix; return ix;
} }
} // namespace RoboidControl

View File

@ -1,6 +1,5 @@
#include "Messages.h" #include "Messages.h"
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
/// @brief Message to communicate the pose of the thing /// @brief Message to communicate the pose of the thing
@ -53,14 +52,13 @@ class PoseMsg : public IMessage {
SwingTwist16 orientation, SwingTwist16 orientation,
Spherical16 linearVelocity = Spherical16(), Spherical16 linearVelocity = Spherical16(),
Spherical16 angularVelocity = Spherical16()); Spherical16 angularVelocity = Spherical16());
/// @copydoc Passer::RoboidControl::IMessage::IMessage(char*) /// @copydoc RoboidControl::IMessage::IMessage(char*)
PoseMsg(const char* buffer); PoseMsg(const char* buffer);
/// @brief Destructor for the message /// @brief Destructor for the message
virtual ~PoseMsg(); virtual ~PoseMsg();
/// @copydoc Passer::RoboidControl::IMessage::Serialize /// @copydoc RoboidControl::IMessage::Serialize
virtual unsigned char Serialize(char* buffer) override; virtual unsigned char Serialize(char* buffer) override;
}; };
} // namespace RoboidControl } // namespace RoboidControl
} // namespace Passer

View File

@ -1,6 +1,5 @@
#include "TextMsg.h" #include "TextMsg.h"
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
TextMsg::TextMsg(const char* text, unsigned char textLength) { TextMsg::TextMsg(const char* text, unsigned char textLength) {
@ -31,7 +30,7 @@ unsigned char TextMsg::Serialize(char* buffer) {
for (int nameIx = 0; nameIx < this->textLength; nameIx++) for (int nameIx = 0; nameIx < this->textLength; nameIx++)
buffer[ix++] = this->text[nameIx]; buffer[ix++] = this->text[nameIx];
return ix;} return ix;
}
} // namespace RoboidControl } // namespace RoboidControl
} // namespace Passer

View File

@ -1,6 +1,5 @@
#include "Messages.h" #include "Messages.h"
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
/// @brief Message for sending generic text /// @brief Message for sending generic text
@ -22,14 +21,13 @@ class TextMsg : public IMessage {
/// @brief Create a new message for sending /// @brief Create a new message for sending
/// @param text The text /// @param text The text
TextMsg(const char* text, unsigned char textLength); TextMsg(const char* text, unsigned char textLength);
/// @copydoc Passer::RoboidControl::IMessage::IMessage(char*) /// @copydoc RoboidControl::IMessage::IMessage(char*)
TextMsg(char* buffer); TextMsg(char* buffer);
/// @brief Destructor for the message /// @brief Destructor for the message
virtual ~TextMsg(); virtual ~TextMsg();
/// @copydoc Passer::RoboidControl::IMessage::Serialize /// @copydoc RoboidControl::IMessage::Serialize
virtual unsigned char Serialize(char* buffer) override; virtual unsigned char Serialize(char* buffer) override;
}; };
} // namespace RoboidControl } // namespace RoboidControl
} // namespace Passer

View File

@ -1,6 +1,5 @@
#include "ThingMsg.h" #include "ThingMsg.h"
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
ThingMsg::ThingMsg(const char* buffer) { ThingMsg::ThingMsg(const char* buffer) {
@ -42,5 +41,4 @@ unsigned char ThingMsg::Serialize(char *buffer) {
return ix; return ix;
} }
} // namespace Control } // namespace RoboidControl
} // namespace Passer

View File

@ -1,6 +1,5 @@
#include "Messages.h" #include "Messages.h"
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
/// @brief Message providing generic information about a Thing /// @brief Message providing generic information about a Thing
@ -26,14 +25,13 @@ class ThingMsg : public IMessage {
// ThingMsg(unsigned char networkId, unsigned char thingId, // ThingMsg(unsigned char networkId, unsigned char thingId,
// unsigned char thingType, unsigned char parentId); // unsigned char thingType, unsigned char parentId);
/// @copydoc Passer::RoboidControl::IMessage::IMessage(char*) /// @copydoc RoboidControl::IMessage::IMessage(char*)
ThingMsg(const char* buffer); ThingMsg(const char* buffer);
/// @brief Destructor for the message /// @brief Destructor for the message
virtual ~ThingMsg(); virtual ~ThingMsg();
/// @copydoc Passer::RoboidControl::IMessage::Serialize /// @copydoc RoboidControl::IMessage::Serialize
virtual unsigned char Serialize(char* buffer) override; virtual unsigned char Serialize(char* buffer) override;
}; };
} // namespace RoboidControl } // namespace RoboidControl
} // namespace Passer

View File

@ -19,7 +19,6 @@
#include <chrono> #include <chrono>
#endif #endif
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
Participant::Participant() {} Participant::Participant() {}
@ -138,7 +137,7 @@ void Participant::SendThingInfo(RemoteParticipant* remoteParticipant, Thing* thi
delete modelMsg; delete modelMsg;
} }
void Passer::RoboidControl::Participant::PublishThingInfo(Thing* thing) { void Participant::PublishThingInfo(Thing* thing) {
// std::cout << "Publish thing info" << thing->networkId << "\n"; // std::cout << "Publish thing info" << thing->networkId << "\n";
// Strange, when publishing, the network id is irrelevant, because it is // Strange, when publishing, the network id is irrelevant, because it is
// connected to a specific site... // connected to a specific site...
@ -277,4 +276,3 @@ void Participant::Process(RemoteParticipant* sender, BinaryMsg* msg) {
#pragma endregion #pragma endregion
} // namespace RoboidControl } // namespace RoboidControl
} // namespace Passer

View File

@ -1,11 +1,11 @@
#pragma once #pragma once
#include "Messages/ParticipantMsg.h"
#include "Messages/BinaryMsg.h" #include "Messages/BinaryMsg.h"
#include "Messages/InvestigateMsg.h" #include "Messages/InvestigateMsg.h"
#include "Messages/ModelUrlMsg.h" #include "Messages/ModelUrlMsg.h"
#include "Messages/NameMsg.h" #include "Messages/NameMsg.h"
#include "Messages/NetworkIdMsg.h" #include "Messages/NetworkIdMsg.h"
#include "Messages/ParticipantMsg.h"
#include "Messages/PoseMsg.h" #include "Messages/PoseMsg.h"
#include "Messages/ThingMsg.h" #include "Messages/ThingMsg.h"
#include "RemoteParticipant.h" #include "RemoteParticipant.h"
@ -23,7 +23,6 @@
#include <WiFiUdp.h> #include <WiFiUdp.h>
#endif #endif
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
/// @brief A participant is device which can communicate with other participants /// @brief A participant is device which can communicate with other participants
@ -102,6 +101,4 @@ protected:
virtual void Process(RemoteParticipant* sender, BinaryMsg* msg); virtual void Process(RemoteParticipant* sender, BinaryMsg* msg);
}; };
} // namespace Control } // namespace RoboidControl
} // namespace Passer
using namespace Passer::RoboidControl;

View File

@ -8,7 +8,6 @@
#include <unistd.h> #include <unistd.h>
#endif #endif
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
namespace Posix { namespace Posix {
@ -135,4 +134,3 @@ bool Participant::Publish(IMessage* msg) {
} // namespace Posix } // namespace Posix
} // namespace RoboidControl } // namespace RoboidControl
} // namespace Passer

View File

@ -2,7 +2,6 @@
#include "../Participant.h" #include "../Participant.h"
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
namespace Posix { namespace Posix {
@ -16,4 +15,3 @@ class Participant : public RoboidControl::Participant {
} // namespace Posix } // namespace Posix
} // namespace RoboidControl } // namespace RoboidControl
} // namespace Passer

View File

@ -9,6 +9,6 @@ Supporting:
# Basic components # Basic components
- Passer::RoboidControl::Thing - RoboidControl::Thing
- Passer::RoboidControl::Participant - RoboidControl::Participant
- Passer::RoboidControl::SiteServer - RoboidControl::SiteServer

View File

@ -1,6 +1,5 @@
#include "RemoteParticipant.h" #include "RemoteParticipant.h"
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
RemoteParticipant::RemoteParticipant() {} RemoteParticipant::RemoteParticipant() {}
@ -51,4 +50,3 @@ void RemoteParticipant::UpdateAll(unsigned long currentTimeMs) {
} }
} // namespace Control } // namespace Control
} // namespace Passer

View File

@ -1,7 +1,6 @@
#pragma once #pragma once
#include "Thing.h" #include "Thing.h"
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
class RemoteParticipant { class RemoteParticipant {
@ -25,4 +24,3 @@ public:
}; };
} // namespace Control } // namespace Control
} // namespace Passer

View File

@ -1,6 +1,5 @@
#include "DigitalSensor.h" #include "DigitalSensor.h"
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
DigitalSensor::DigitalSensor() {} DigitalSensor::DigitalSensor() {}
@ -8,4 +7,3 @@ DigitalSensor::DigitalSensor() {}
DigitalSensor::DigitalSensor(unsigned char networkId, unsigned char thingId) {} DigitalSensor::DigitalSensor(unsigned char networkId, unsigned char thingId) {}
} // namespace RoboidControl } // namespace RoboidControl
} // namespace Passer

View File

@ -2,7 +2,6 @@
#include "Thing.h" #include "Thing.h"
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
/// @brief A digital (on/off, 1/0, true/false) sensor /// @brief A digital (on/off, 1/0, true/false) sensor
@ -20,4 +19,3 @@ class DigitalSensor : public Thing {
}; };
} // namespace RoboidControl } // namespace RoboidControl
} // namespace Passer

View File

@ -2,18 +2,18 @@
#include "Messages/LowLevelMessages.h" #include "Messages/LowLevelMessages.h"
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
// TemperatureSensor::TemperatureSensor() : Thing(Type::TemperatureSensor) {} // TemperatureSensor::TemperatureSensor() : Thing(Type::TemperatureSensor) {}
TemperatureSensor::TemperatureSensor() : Thing(Type::TemperatureSensor) {} TemperatureSensor::TemperatureSensor() : Thing(Type::TemperatureSensor) {}
TemperatureSensor::TemperatureSensor(unsigned char networkId, TemperatureSensor::TemperatureSensor(unsigned char networkId, unsigned char thingId)
unsigned char thingId)
: Thing(nullptr, networkId, thingId, Type::TemperatureSensor) {} : 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"; std::cout << "Send temperature: " << this->temperature << "\n";
@ -25,5 +25,4 @@ void TemperatureSensor::ProcessBinary(char *bytes) {
this->temperature = LowLevelMessages::ReceiveFloat16(bytes, &ix); this->temperature = LowLevelMessages::ReceiveFloat16(bytes, &ix);
} }
} // namespace Control } // namespace RoboidControl
} // namespace Passer

View File

@ -2,7 +2,6 @@
#include "Thing.h" #include "Thing.h"
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
/// @brief A temperature sensor /// @brief A temperature sensor
@ -32,4 +31,3 @@ class TemperatureSensor : public Thing {
}; };
} // namespace RoboidControl } // namespace RoboidControl
} // namespace Passer

View File

@ -5,7 +5,6 @@
#include <functional> #include <functional>
#include <memory> #include <memory>
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
SiteServer::SiteServer(int port) { SiteServer::SiteServer(int port) {
@ -50,4 +49,3 @@ void SiteServer::Process(RemoteParticipant *sender, ThingMsg *msg) {
} }
} // namespace Control } // namespace Control
} // namespace Passer

View File

@ -6,7 +6,6 @@
#include <memory> #include <memory>
#include <unordered_map> #include <unordered_map>
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
/// @brief A participant is device which can communicate with other participants /// @brief A participant is device which can communicate with other participants
@ -16,9 +15,9 @@ public:
// virtual void Update(unsigned long currentTimeMs = 0) override; // virtual void Update(unsigned long currentTimeMs = 0) override;
template <typename ThingClass> void Register(unsigned char thingType) { template <typename ThingClass>
thingMsgProcessors[thingType] = [](unsigned char networkId, void Register(unsigned char thingType) {
unsigned char thingId) { thingMsgProcessors[thingType] = [](unsigned char networkId, unsigned char thingId) {
return new ThingClass(networkId, thingId); return new ThingClass(networkId, thingId);
}; };
}; };
@ -30,11 +29,8 @@ protected:
virtual void Process(RemoteParticipant* sender, NetworkIdMsg* msg) override; virtual void Process(RemoteParticipant* sender, NetworkIdMsg* msg) override;
virtual void Process(RemoteParticipant* sender, ThingMsg* msg) override; virtual void Process(RemoteParticipant* sender, ThingMsg* msg) override;
using ThingConstructor = using ThingConstructor = std::function<Thing*(unsigned char networkId, unsigned char thingId)>;
std::function<Thing *(unsigned char networkId, unsigned char thingId)>;
std::unordered_map<unsigned char, ThingConstructor> thingMsgProcessors; std::unordered_map<unsigned char, ThingConstructor> thingMsgProcessors;
}; };
} // namespace Control } // namespace RoboidControl
} // namespace Passer
using namespace Passer::RoboidControl;

View File

@ -1,12 +1,11 @@
#include "Thing.h" #include "Thing.h"
#include "Participant.h" #include <string.h>
#include <algorithm> #include <algorithm>
#include <iostream> #include <iostream>
#include <list> #include <list>
#include <string.h> #include "Participant.h"
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
Thing::Thing(Type thingType) : Thing((unsigned char)thingType) {} Thing::Thing(Type thingType) : Thing((unsigned char)thingType) {}
@ -23,8 +22,7 @@ Thing::Thing(unsigned char thingType) {
this->angularVelocity = Spherical16::zero; this->angularVelocity = Spherical16::zero;
} }
Thing::Thing(RemoteParticipant *participant, unsigned char networkId, Thing::Thing(RemoteParticipant* participant, unsigned char networkId, unsigned char thingId, Type thingType) {
unsigned char thingId, Type thingType) {
// no participant reference yet.. // no participant reference yet..
this->participant = participant; this->participant = participant;
this->networkId = networkId; this->networkId = networkId;
@ -73,10 +71,11 @@ void Thing::SetParent(Thing *root, const char *name) {
this->SetParent(thing); this->SetParent(thing);
} }
Thing *Thing::GetParent() { return this->parent; } Thing* Thing::GetParent() {
return this->parent;
}
void Thing::AddChild(Thing* child) { void Thing::AddChild(Thing* child) {
unsigned char newChildCount = this->childCount + 1; unsigned char newChildCount = this->childCount + 1;
Thing** newChildren = new Thing*[newChildCount]; Thing** newChildren = new Thing*[newChildCount];
@ -141,9 +140,13 @@ Thing *Thing::GetChild(unsigned char id, bool recursive) {
return nullptr; 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) #if defined(ARDUINO)
void Thing::Update() { void Thing::Update() {
@ -155,69 +158,33 @@ void Thing::GenerateBinary(char *buffer, unsigned char *ix) {
(void)buffer; (void)buffer;
(void)ix; (void)ix;
} }
void Thing::ProcessBinary(char *bytes) { (void)bytes; }; void Thing::ProcessBinary(char* bytes) {
(void)bytes;
};
void Thing::SetPosition(Spherical16 position) { void Thing::SetPosition(Spherical16 position) {
this->position = position; this->position = position;
this->positionUpdated = true; this->positionUpdated = true;
} }
Spherical16 Thing::GetPosition() { return this->position; } Spherical16 Thing::GetPosition() {
return this->position;
}
void Thing::SetOrientation(SwingTwist16 orientation) { void Thing::SetOrientation(SwingTwist16 orientation) {
this->orientation = orientation; this->orientation = orientation;
this->orientationUpdated = true; 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 } // namespace RoboidControl
// std::list<Thing *> 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);
// }
// }
//}
}}

16
Thing.h
View File

@ -1,10 +1,9 @@
#pragma once #pragma once
#include "LinearAlgebra/Spherical.h"
#include "LinearAlgebra/SwingTwist.h"
#include <iostream> #include <iostream>
#include <list> #include <list>
#include "LinearAlgebra/Spherical.h"
#include "LinearAlgebra/SwingTwist.h"
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
class RemoteParticipant; class RemoteParticipant;
@ -52,8 +51,10 @@ public:
/// @param networkId The network ID of the thing /// @param networkId The network ID of the thing
/// @param thingId The ID of the thing /// @param thingId The ID of the thing
/// @param thingType The type of thing /// @param thingType The type of thing
Thing(RemoteParticipant *participant, unsigned char networkId, Thing(RemoteParticipant* participant,
unsigned char thingId, Type thingType = Type::Undetermined); unsigned char networkId,
unsigned char thingId,
Type thingType = Type::Undetermined);
/// @brief Find a thing by name /// @brief Find a thing by name
/// @param name Rhe name of the thing /// @param name Rhe name of the thing
@ -169,9 +170,6 @@ public:
// /// @brief FUnction used to process binary data received for this thing // /// @brief FUnction used to process binary data received for this thing
/// @param bytes The binary data /// @param bytes The binary data
virtual void ProcessBinary(char* bytes); virtual void ProcessBinary(char* bytes);
}; };
} // namespace Control } // namespace RoboidControl
} // namespace Passer
using namespace Passer::RoboidControl;

View File

@ -12,7 +12,6 @@
#include <unistd.h> #include <unistd.h>
#endif #endif
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
namespace Windows { namespace Windows {
@ -196,4 +195,3 @@ bool Participant::Publish(IMessage* msg) {
} // namespace Windows } // namespace Windows
} // namespace RoboidControl } // namespace RoboidControl
} // namespace Passer

View File

@ -2,7 +2,6 @@
#include "../Participant.h" #include "../Participant.h"
namespace Passer {
namespace RoboidControl { namespace RoboidControl {
namespace Windows { namespace Windows {
@ -16,4 +15,3 @@ class Participant : public RoboidControl::Participant {
} // namespace Windows } // namespace Windows
} // namespace RoboidControl } // namespace RoboidControl
} // namespace Passer

View File

@ -4,12 +4,13 @@
// not supported using Visual Studio 2022 compiler... // not supported using Visual Studio 2022 compiler...
#include <gtest/gtest.h> #include <gtest/gtest.h>
// #include "../Thing.h"
#include <chrono> #include <chrono>
#include "Participant.h" #include "Participant.h"
#include "Thing.h" #include "Thing.h"
using namespace RoboidControl;
class ControlCoreSuite2 : public ::testing::Test { class ControlCoreSuite2 : public ::testing::Test {
protected: protected:
// SetUp and TearDown can be used to set up and clean up before/after each // SetUp and TearDown can be used to set up and clean up before/after each

View File

@ -12,7 +12,7 @@
#include "SiteServer.h" #include "SiteServer.h"
#include "Thing.h" #include "Thing.h"
namespace Passer { using namespace RoboidControl;
// Function to get the current time in milliseconds as unsigned long // Function to get the current time in milliseconds as unsigned long
unsigned long get_time_ms() { unsigned long get_time_ms() {
@ -94,6 +94,4 @@ TEST_F(ControlCoreSuite, Thing) {
ASSERT_EQ(1, 1); ASSERT_EQ(1, 1);
} }
} // namespace Passer
#endif #endif