Proof-of-concept works

This commit is contained in:
Pascal Serrarens 2025-01-08 14:57:16 +01:00
parent 8338e2f5cd
commit 1d89b5401d
4 changed files with 36 additions and 28 deletions

View File

@ -36,6 +36,8 @@ ModelUrlMsg::ModelUrlMsg(unsigned char networkId, Thing *thing) {
}
unsigned char ModelUrlMsg::Serialize(char *buffer) {
if (this->urlLength == 0 || this->url == nullptr)
return 0;
unsigned char ix = 0;
buffer[ix++] = this->id;
buffer[ix++] = this->networkId;

View File

@ -33,6 +33,9 @@ NameMsg::NameMsg(unsigned char networkId, Thing *thing) {
// }
unsigned char NameMsg::Serialize(char *buffer) {
if (this->nameLength == 0 || this->name == nullptr)
return 0;
unsigned char ix = 0;
buffer[ix++] = this->id;
buffer[ix++] = this->networkId;

View File

@ -6,12 +6,14 @@
#include <list>
#include <string.h>
Thing::Thing(unsigned char networkId, unsigned char thingType) {
Thing::Thing(Type thingType) : Thing((unsigned char)thingType) {}
Thing::Thing(unsigned char thingType) {
// this->position = Spherical16::zero;
// this->orientation = SwingTwist16::identity;
this->type = thingType;
this->networkId = networkId;
this->networkId = 0;
this->Init();
int thingId = Thing::Add(this);

53
Thing.h
View File

@ -19,6 +19,27 @@ public:
/// @char The id of the thing
unsigned char id = 0;
/// @brief Basic Thing types
enum class Type {
Undetermined,
// Sensor,
Switch,
DistanceSensor,
DirectionalSensor,
TemperatureSensor,
// Motor,
ControlledMotor,
UncontrolledMotor,
Servo,
// Other
Roboid,
Humanoid,
ExternalSensor,
};
Thing(Type thingType = Type::Undetermined);
Thing(unsigned char thingType);
Thing *FindThing(const char *name);
// Thing *FindChild(unsigned char id);
@ -53,24 +74,6 @@ public:
float modelScale = 1;
// protected Sensor sensor;
/// @brief Basic Thing types
enum class Type {
Undetermined,
// Sensor,
Switch,
DistanceSensor,
DirectionalSensor,
TemperatureSensor,
// Motor,
ControlledMotor,
UncontrolledMotor,
Servo,
// Other
Roboid,
Humanoid,
ExternalSensor,
};
void SetPosition(Spherical16 position);
Spherical16 GetPosition();
void SetOrientation(SwingTwist16 orientation);
@ -97,8 +100,6 @@ public:
virtual Spherical16 GetAngularVelocity();
public:
Thing(unsigned char networkId = 0,
unsigned char thingType = (unsigned char)Type::Undetermined);
/// @brief Terminated thins are no longer updated
void Terminate();
@ -111,13 +112,13 @@ public:
/// @brief Updates the state of the thing
/// @param currentTimeMs The current clock time in milliseconds
virtual void Update(unsigned long currentTimeMs) { currentTimeMs; };
virtual void Update(unsigned long currentTimeMs) { (void)currentTimeMs; };
virtual void SendBytes(char *buffer, unsigned char *ix) {
buffer;
ix;
(void)buffer;
(void)ix;
};
virtual void ProcessBytes(char *bytes) { bytes; };
virtual void ProcessBytes(char *bytes) { (void)bytes; };
protected:
virtual void Init();
@ -130,8 +131,8 @@ public:
static void Remove(Thing *thing);
static void UpdateAll(unsigned long currentTimeMs);
//private:
// static Thing *allThings[];
// private:
// static Thing *allThings[];
};
static std::list<Thing *> allThings;