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
namespace Passer {
namespace RoboidControl {
namespace Arduino {
@ -96,4 +95,3 @@ bool Participant::Publish(IMessage* msg) {
} // namespace Arduino
} // namespace RoboidControl
} // namespace Passer

View File

@ -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

View File

@ -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()

View File

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

View File

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

View File

@ -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

View File

@ -1,5 +1,5 @@
#include "Messages.h"
namespace Passer {
namespace RoboidControl {
/// @brief Message notifiying that a Thing no longer exists
@ -18,14 +18,13 @@ public:
/// @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*)
/// @copydoc RoboidControl::IMessage::IMessage(char*)
DestroyMsg(char* buffer);
/// @brief Destructor for the message
virtual ~DestroyMsg();
/// @copydoc Passer::RoboidControl::IMessage::Serialize
/// @copydoc RoboidControl::IMessage::Serialize
virtual unsigned char Serialize(char* buffer) override;
};
} // namespace RoboidControl
} // namespace Passer

View File

@ -1,5 +1,6 @@
#include "InvestigateMsg.h"
#pragma region Investigate
namespace RoboidControl {
InvestigateMsg::InvestigateMsg(char* buffer) {
unsigned ix = 1; // first byte is msgId
@ -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

View File

@ -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

View File

@ -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;
@ -88,3 +81,5 @@ SwingTwist16 LowLevelMessages::ReceiveQuat32(const char *buffer,
SwingTwist16 s = SwingTwist16::FromQuaternion(q);
return s;
}
} // namespace RoboidControl

View File

@ -1,7 +1,6 @@
#include "LinearAlgebra/Spherical.h"
#include "LinearAlgebra/SwingTwist.h"
namespace Passer {
namespace RoboidControl {
class LowLevelMessages {
@ -13,13 +12,10 @@ public:
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 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);
};
} // namespace RoboidControl
} // namespace Passer
using namespace Passer::RoboidControl;

View File

@ -4,7 +4,6 @@
#include "Participant.h"
#include "string.h"
namespace Passer {
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
}}
} // namespace RoboidControl

View File

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

View File

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

View File

@ -1,6 +1,5 @@
#include "Messages.h"
namespace Passer {
namespace RoboidControl {
/// @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 thing The thing for which to send the mode URL
ModelUrlMsg(unsigned char networkId, Thing* thing);
/// @copydoc Passer::RoboidControl::IMessage::IMessage(char*)
/// @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);
@ -33,9 +32,8 @@ public:
/// @brief Destructor for the message
virtual ~ModelUrlMsg();
/// @copydoc Passer::RoboidControl::IMessage::Serialize
/// @copydoc RoboidControl::IMessage::Serialize
virtual unsigned char Serialize(char* buffer) override;
};
} // namespace Control
} // namespace Passer
} // namespace RoboidControl

View File

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

View File

@ -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

View File

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

View File

@ -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

View File

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

View File

@ -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

View File

@ -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;
@ -41,3 +46,5 @@ unsigned char PoseMsg::Serialize(char *buffer) {
LowLevelMessages::SendSpherical16(buffer, &ix, this->angularVelocity);
return ix;
}
} // namespace RoboidControl

View File

@ -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

View File

@ -1,6 +1,5 @@
#include "TextMsg.h"
namespace Passer {
namespace RoboidControl {
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++)
buffer[ix++] = this->text[nameIx];
return ix;}
return ix;
}
} // namespace RoboidControl
} // namespace Passer

View File

@ -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

View File

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

View File

@ -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

View File

@ -19,7 +19,6 @@
#include <chrono>
#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

View File

@ -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,7 +23,6 @@
#include <WiFiUdp.h>
#endif
namespace Passer {
namespace RoboidControl {
/// @brief A participant is device which can communicate with other participants
@ -102,6 +101,4 @@ protected:
virtual void Process(RemoteParticipant* sender, BinaryMsg* msg);
};
} // namespace Control
} // namespace Passer
using namespace Passer::RoboidControl;
} // namespace RoboidControl

View File

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

View File

@ -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

View File

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

View File

@ -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

View File

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

View File

@ -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

View File

@ -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

View File

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

View File

@ -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

View File

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

View File

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

View File

@ -1,12 +1,11 @@
#include "Thing.h"
#include "Participant.h"
#include <string.h>
#include <algorithm>
#include <iostream>
#include <list>
#include <string.h>
#include "Participant.h"
namespace Passer {
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;
@ -73,10 +71,11 @@ void Thing::SetParent(Thing *root, const char *name) {
this->SetParent(thing);
}
Thing *Thing::GetParent() { return this->parent; }
Thing* Thing::GetParent() {
return this->parent;
}
void Thing::AddChild(Thing* child) {
unsigned char newChildCount = this->childCount + 1;
Thing** newChildren = new Thing*[newChildCount];
@ -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() {
@ -155,69 +158,33 @@ 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 *> 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);
// }
// }
//}
}}
} // namespace RoboidControl

16
Thing.h
View File

@ -1,10 +1,9 @@
#pragma once
#include "LinearAlgebra/Spherical.h"
#include "LinearAlgebra/SwingTwist.h"
#include <iostream>
#include <list>
#include "LinearAlgebra/Spherical.h"
#include "LinearAlgebra/SwingTwist.h"
namespace Passer {
namespace RoboidControl {
class RemoteParticipant;
@ -52,8 +51,10 @@ 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
@ -169,9 +170,6 @@ public:
// /// @brief FUnction used to process binary data received for this thing
/// @param bytes The binary data
virtual void ProcessBinary(char* bytes);
};
} // namespace Control
} // namespace Passer
using namespace Passer::RoboidControl;
} // namespace RoboidControl

View File

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

View File

@ -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

View File

@ -4,12 +4,13 @@
// not supported using Visual Studio 2022 compiler...
#include <gtest/gtest.h>
// #include "../Thing.h"
#include <chrono>
#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

View File

@ -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