Thing Name support

This commit is contained in:
Pascal Serrarens 2024-11-14 11:29:08 +01:00
parent 610121f944
commit 51e605ca6d
6 changed files with 30 additions and 26 deletions

View File

@ -108,9 +108,13 @@ void NetworkSync::PublishRelativeThing(Thing *thing, bool recurse) {
buffer[ix++] = parentThing->id; buffer[ix++] = parentThing->id;
else else
buffer[ix++] = 0x00; buffer[ix++] = 0x00;
SendSpherical16(buffer, &ix, thing->position); SendSpherical16(
buffer, &ix,
thing->position); // Do we need this if we already send a pose?
SendBuffer(ix); SendBuffer(ix);
SendName(thing);
SendModel(thing); SendModel(thing);
if (recurse) { if (recurse) {
@ -122,27 +126,27 @@ void NetworkSync::PublishRelativeThing(Thing *thing, bool recurse) {
} }
} }
void NetworkSync::SendName(Roboid *roboid) { void NetworkSync::SendName(Thing *thing) {
if (roboid->name == nullptr) if (thing->name == nullptr)
return; return;
unsigned char len = strlen(roboid->name); unsigned char len = strlen(thing->name);
if (len > 255) if (len > 255)
return; return;
unsigned char ix = 0; unsigned char ix = 0;
buffer[ix++] = NameMsg; buffer[ix++] = NameMsg;
buffer[ix++] = 0x00; // objectId buffer[ix++] = thing->id;
buffer[ix++] = len; buffer[ix++] = len;
for (unsigned char nameIx = 0; nameIx < len; nameIx++) for (unsigned char nameIx = 0; nameIx < len; nameIx++)
buffer[ix++] = roboid->name[nameIx]; buffer[ix++] = thing->name[nameIx];
SendBuffer(ix); SendBuffer(ix);
#ifdef RC_DEBUG #ifdef RC_DEBUG
SERIALPORT.printf("Sent Name [%d/%d] %s\n", networkId, buffer[1], SERIALPORT.printf("Sent Name [%d/%d] %s\n", networkId, buffer[1],
roboid->name); thing->name);
#endif #endif
} }
@ -208,8 +212,8 @@ void NetworkSync::SendPose(Thing *thing, bool recurse) {
if (this->networkId == 0) // We're not connected to a site yet if (this->networkId == 0) // We're not connected to a site yet
return; return;
if (thing->GetLinearVelocity().distance > 0 || // if (thing->GetLinearVelocity().distance > 0 ||
thing->GetAngularVelocity().distance > 0) { // thing->GetAngularVelocity().distance > 0) {
unsigned char ix = 0; unsigned char ix = 0;
buffer[ix++] = PoseMsg; buffer[ix++] = PoseMsg;
buffer[ix++] = thing->id; buffer[ix++] = thing->id;
@ -219,11 +223,11 @@ void NetworkSync::SendPose(Thing *thing, bool recurse) {
SendBuffer(ix); SendBuffer(ix);
#if RC_DEBUG #if RC_DEBUG
if (thing->id == 0) // if (thing->id == 0)
SERIALPORT.printf("Sent PoseMsg Thing [%d/%d] %f\n", this->networkId, SERIALPORT.printf("Sent PoseMsg Thing [%d/%d] %f\n", this->networkId,
buffer[1], thing->position.distance); buffer[1], thing->position.distance);
#endif #endif
} // }
if (recurse) { if (recurse) {
for (unsigned char childIx = 0; childIx < thing->childCount; childIx++) { for (unsigned char childIx = 0; childIx < thing->childCount; childIx++) {

View File

@ -24,7 +24,7 @@ public:
virtual void SendDestroyThing(InterestingThing *obj); virtual void SendDestroyThing(InterestingThing *obj);
virtual void NewObject(InterestingThing *obj); virtual void NewObject(InterestingThing *obj);
void SendThing(Thing *thing); void SendThing(Thing *thing);
void SendName(Roboid *roboid); void SendName(Thing *roboid);
virtual void SendModel(Roboid *obj); virtual void SendModel(Roboid *obj);
void SendModel(Thing *thing); void SendModel(Thing *thing);

View File

@ -30,8 +30,6 @@ Roboid::Roboid(Propulsion *propulsion) : Roboid() {
propulsion->roboid = this; propulsion->roboid = this;
} }
void Roboid::SetName(const char *name) { this->name = name; }
void Roboid::Update(unsigned long currentTimeMs) { void Roboid::Update(unsigned long currentTimeMs) {
if (perception != nullptr) if (perception != nullptr)
perception->Update(currentTimeMs); perception->Update(currentTimeMs);

View File

@ -20,9 +20,6 @@ public:
/// @param propulsion The Propulsion implementation to use for this Roboid /// @param propulsion The Propulsion implementation to use for this Roboid
Roboid(Propulsion *propulsion); Roboid(Propulsion *propulsion);
const char *name = nullptr;
void SetName(const char *name);
/// @brief Update the state of the Roboid /// @brief Update the state of the Roboid
/// @param currentTimeMs The time in milliseconds when calling this /// @param currentTimeMs The time in milliseconds when calling this
/// function /// function

View File

@ -10,6 +10,8 @@ Thing::Thing(unsigned char id) : id(id) {
this->children = nullptr; this->children = nullptr;
} }
void Thing::SetName(const char *name) { this->name = name; }
const unsigned int Thing::SwitchType = SensorType | (unsigned int)Type::Switch; const unsigned int Thing::SwitchType = SensorType | (unsigned int)Type::Switch;
const unsigned int Thing::DistanceSensorType = const unsigned int Thing::DistanceSensorType =
SensorType | (unsigned int)Type::DistanceSensor; SensorType | (unsigned int)Type::DistanceSensor;

View File

@ -19,6 +19,9 @@ public:
/// @brief The type of Thing /// @brief The type of Thing
unsigned int type; unsigned int type;
const char *name = nullptr;
void SetName(const char *name);
// I hate this, better is to have an additional field stating the thing // I hate this, better is to have an additional field stating the thing
// classificaton Motor, Sensor etc. // classificaton Motor, Sensor etc.
/// @brief The type of a switch sensor /// @brief The type of a switch sensor