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;
else
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);
SendName(thing);
SendModel(thing);
if (recurse) {
@ -122,27 +126,27 @@ void NetworkSync::PublishRelativeThing(Thing *thing, bool recurse) {
}
}
void NetworkSync::SendName(Roboid *roboid) {
if (roboid->name == nullptr)
void NetworkSync::SendName(Thing *thing) {
if (thing->name == nullptr)
return;
unsigned char len = strlen(roboid->name);
unsigned char len = strlen(thing->name);
if (len > 255)
return;
unsigned char ix = 0;
buffer[ix++] = NameMsg;
buffer[ix++] = 0x00; // objectId
buffer[ix++] = thing->id;
buffer[ix++] = len;
for (unsigned char nameIx = 0; nameIx < len; nameIx++)
buffer[ix++] = roboid->name[nameIx];
buffer[ix++] = thing->name[nameIx];
SendBuffer(ix);
#ifdef RC_DEBUG
SERIALPORT.printf("Sent Name [%d/%d] %s\n", networkId, buffer[1],
roboid->name);
thing->name);
#endif
}
@ -208,22 +212,22 @@ void NetworkSync::SendPose(Thing *thing, bool recurse) {
if (this->networkId == 0) // We're not connected to a site yet
return;
if (thing->GetLinearVelocity().distance > 0 ||
thing->GetAngularVelocity().distance > 0) {
unsigned char ix = 0;
buffer[ix++] = PoseMsg;
buffer[ix++] = thing->id;
buffer[ix++] = Pose_Position | Pose_Orientation;
SendSpherical16(buffer, &ix, thing->position);
SendQuat32(buffer, &ix, thing->orientation.ToQuaternion());
SendBuffer(ix);
// if (thing->GetLinearVelocity().distance > 0 ||
// thing->GetAngularVelocity().distance > 0) {
unsigned char ix = 0;
buffer[ix++] = PoseMsg;
buffer[ix++] = thing->id;
buffer[ix++] = Pose_Position | Pose_Orientation;
SendSpherical16(buffer, &ix, thing->position);
SendQuat32(buffer, &ix, thing->orientation.ToQuaternion());
SendBuffer(ix);
#if RC_DEBUG
if (thing->id == 0)
SERIALPORT.printf("Sent PoseMsg Thing [%d/%d] %f\n", this->networkId,
buffer[1], thing->position.distance);
// if (thing->id == 0)
SERIALPORT.printf("Sent PoseMsg Thing [%d/%d] %f\n", this->networkId,
buffer[1], thing->position.distance);
#endif
}
// }
if (recurse) {
for (unsigned char childIx = 0; childIx < thing->childCount; childIx++) {

View File

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

View File

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

View File

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

View File

@ -10,6 +10,8 @@ Thing::Thing(unsigned char id) : id(id) {
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::DistanceSensorType =
SensorType | (unsigned int)Type::DistanceSensor;

View File

@ -19,6 +19,9 @@ public:
/// @brief The type of Thing
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
// classificaton Motor, Sensor etc.
/// @brief The type of a switch sensor