diff --git a/ModelUrlMsg.cpp b/ModelUrlMsg.cpp index 5aa233c..67add43 100644 --- a/ModelUrlMsg.cpp +++ b/ModelUrlMsg.cpp @@ -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; diff --git a/NameMsg.cpp b/NameMsg.cpp index 6f06dc7..20de696 100644 --- a/NameMsg.cpp +++ b/NameMsg.cpp @@ -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; diff --git a/Thing.cpp b/Thing.cpp index 7c0ea52..4cc43a9 100644 --- a/Thing.cpp +++ b/Thing.cpp @@ -6,12 +6,14 @@ #include #include -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); diff --git a/Thing.h b/Thing.h index 61d7fa7..bdb4b92 100644 --- a/Thing.h +++ b/Thing.h @@ -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 allThings;