Send only when connected
This commit is contained in:
parent
b2adaac890
commit
25cb1e1822
@ -131,6 +131,9 @@ void NetworkPerception::ReceiveSphere(unsigned char* data, Roboid* roboid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void NetworkPerception::ReceivePoseMsg(unsigned char* data, Roboid* roboid) {
|
void NetworkPerception::ReceivePoseMsg(unsigned char* data, Roboid* roboid) {
|
||||||
|
if (roboid->networkSync->networkId == 0) // We're not connected to a site yet
|
||||||
|
return;
|
||||||
|
|
||||||
unsigned char networkId = data[1];
|
unsigned char networkId = data[1];
|
||||||
unsigned char objectId = data[2];
|
unsigned char objectId = data[2];
|
||||||
unsigned char poseType = data[3];
|
unsigned char poseType = data[3];
|
||||||
@ -138,15 +141,15 @@ void NetworkPerception::ReceivePoseMsg(unsigned char* data, Roboid* roboid) {
|
|||||||
if (networkId == roboid->networkSync->networkId)
|
if (networkId == roboid->networkSync->networkId)
|
||||||
networkId = 0x00;
|
networkId = 0x00;
|
||||||
|
|
||||||
#if RC_DEBUG
|
|
||||||
printf("Received PoseMsg [%d/%d]\n", networkId, objectId);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (objectId == 0x80)
|
if (objectId == 0x80)
|
||||||
return ReceivePlane(data, roboid);
|
return ReceivePlane(data, roboid);
|
||||||
else if (objectId == 0x81)
|
else if (objectId == 0x81)
|
||||||
return ReceiveSphere(data, roboid);
|
return ReceiveSphere(data, roboid);
|
||||||
|
|
||||||
|
#if RC_DEBUG
|
||||||
|
// printf("Received PoseMsg [%d/%d]\n", networkId, objectId);
|
||||||
|
#endif
|
||||||
|
|
||||||
Quaternion roboidOrientation = roboid->GetOrientation();
|
Quaternion roboidOrientation = roboid->GetOrientation();
|
||||||
Spherical16 position = Spherical16::zero;
|
Spherical16 position = Spherical16::zero;
|
||||||
Quaternion orientation = Quaternion::identity;
|
Quaternion orientation = Quaternion::identity;
|
||||||
@ -184,7 +187,7 @@ void NetworkPerception::ReceivePoseMsg(unsigned char* data, Roboid* roboid) {
|
|||||||
this, position, orientation, 0x81, 0x81, networkId);
|
this, position, orientation, 0x81, 0x81, networkId);
|
||||||
if (thing->networkId != 0x00 && thing->type == 0xFF) {
|
if (thing->networkId != 0x00 && thing->type == 0xFF) {
|
||||||
// Unknown thing
|
// Unknown thing
|
||||||
roboid->networkSync->SendInvestigateThing(thing);
|
roboid->networkSync->SendInvestigate(thing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,8 @@ void NetworkSync::NewObject(InterestingThing* thing) {
|
|||||||
printf("Sent CreateMsg [%d/%d] %d\n", networkId, buffer[1], buffer[2]);
|
printf("Sent CreateMsg [%d/%d] %d\n", networkId, buffer[1], buffer[2]);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// PublishTrackedObject(roboid, obj);
|
thing->updated = true;
|
||||||
|
PublishTrackedObject(roboid, thing);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkSync::PublishRelativeThing(Thing* thing, bool recurse) {
|
void NetworkSync::PublishRelativeThing(Thing* thing, bool recurse) {
|
||||||
@ -128,18 +129,24 @@ void NetworkSync::PublishModel(Thing* thing) {
|
|||||||
SendBuffer(ix);
|
SendBuffer(ix);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkSync::DestroyObject(InterestingThing* thing) {
|
void NetworkSync::SendDestroyThing(InterestingThing* thing) {
|
||||||
|
if (networkId == 0) // We're not connected to a site yet
|
||||||
|
return;
|
||||||
|
|
||||||
unsigned char ix = 0;
|
unsigned char ix = 0;
|
||||||
buffer[ix++] = DestroyMsg;
|
buffer[ix++] = DestroyMsg;
|
||||||
buffer[ix++] = thing->id;
|
buffer[ix++] = thing->id;
|
||||||
SendBuffer(ix);
|
SendBuffer(ix);
|
||||||
|
|
||||||
#if RC_DEBUG
|
#if RC_DEBUG
|
||||||
printf("Sent DestroyMsg %d %d\n", buffer[1], buffer[2]);
|
printf("Sent DestroyMsg [%d/%d]\n", thing->networkId, thing->id);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkSync::SendPose(Roboid* roboid, bool recurse) {
|
void NetworkSync::SendPose(Roboid* roboid, bool recurse) {
|
||||||
|
if (networkId == 0) // We're not connected to a site yet
|
||||||
|
return;
|
||||||
|
|
||||||
unsigned char ix = 0;
|
unsigned char ix = 0;
|
||||||
buffer[ix++] = PoseMsg;
|
buffer[ix++] = PoseMsg;
|
||||||
buffer[ix++] = 0x00;
|
buffer[ix++] = 0x00;
|
||||||
@ -149,7 +156,7 @@ void NetworkSync::SendPose(Roboid* roboid, bool recurse) {
|
|||||||
SendBuffer(ix);
|
SendBuffer(ix);
|
||||||
|
|
||||||
#if RC_DEBUG
|
#if RC_DEBUG
|
||||||
printf("Sent PoseMsg [%d/%d]\n", networkId, buffer[1]);
|
// printf("Sent PoseMsg [%d/%d]\n", networkId, buffer[1]);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (recurse) {
|
if (recurse) {
|
||||||
@ -196,6 +203,9 @@ void NetworkSync::PublishClient() {
|
|||||||
|
|
||||||
void NetworkSync::PublishTrackedObjects(Roboid* roboid,
|
void NetworkSync::PublishTrackedObjects(Roboid* roboid,
|
||||||
InterestingThing** objects) {
|
InterestingThing** objects) {
|
||||||
|
if (networkId == 0) // We're not connected to a site yet
|
||||||
|
return;
|
||||||
|
|
||||||
int n = 0;
|
int n = 0;
|
||||||
for (unsigned char objIx = 0; objIx < Perception::maxObjectCount; objIx++) {
|
for (unsigned char objIx = 0; objIx < Perception::maxObjectCount; objIx++) {
|
||||||
InterestingThing* obj = objects[objIx];
|
InterestingThing* obj = objects[objIx];
|
||||||
@ -288,25 +298,26 @@ void NetworkSync::SendPoseMsg(Buffer sendBuffer, Roboid* roboid) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkSync::SendDestroyObject(Buffer sendBuffer, InterestingThing* obj) {
|
// void NetworkSync::SendDestroyThing(Buffer sendBuffer, InterestingThing*
|
||||||
#ifdef RC_DEBUG
|
// thing) {
|
||||||
Serial.print("Send Destroy ");
|
// unsigned char ix = 0;
|
||||||
Serial.println((int)obj->id);
|
// buffer[ix++] = DestroyMsg;
|
||||||
#else
|
// buffer[ix++] = thing->id;
|
||||||
unsigned char buffer[2] = {DestroyMsg, (unsigned char)obj->id};
|
// SendBuffer(ix);
|
||||||
sendBuffer(buffer, 2);
|
// #ifdef RC_DEBUG
|
||||||
#endif
|
// printf("Sent DestroyThing [%d/%d]", thing->networkId, thing->id);
|
||||||
}
|
// #endif
|
||||||
|
// }
|
||||||
|
|
||||||
void NetworkSync::SendInvestigateThing(InterestingThing* thing) {
|
void NetworkSync::SendInvestigate(InterestingThing* thing) {
|
||||||
#ifdef RC_DEBUG
|
|
||||||
printf("Investigate [%d/%d]\n", thing->networkId, thing->id);
|
|
||||||
#endif
|
|
||||||
unsigned char ix = 0;
|
unsigned char ix = 0;
|
||||||
buffer[ix++] = InvestigateMsg;
|
buffer[ix++] = InvestigateMsg;
|
||||||
buffer[ix++] = thing->networkId;
|
buffer[ix++] = thing->networkId;
|
||||||
buffer[ix++] = thing->id;
|
buffer[ix++] = thing->id;
|
||||||
SendBuffer(ix);
|
SendBuffer(ix);
|
||||||
|
#ifdef RC_DEBUG
|
||||||
|
printf("Sent Investigate [%d/%d]\n", thing->networkId, thing->id);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkSync::SendText(const char* s) {
|
void NetworkSync::SendText(const char* s) {
|
||||||
|
@ -20,7 +20,7 @@ class NetworkSync {
|
|||||||
virtual void NetworkUpdate(Roboid* roboid) = 0;
|
virtual void NetworkUpdate(Roboid* roboid) = 0;
|
||||||
/// @brief Inform that the given object is no longer being tracked
|
/// @brief Inform that the given object is no longer being tracked
|
||||||
/// @param obj
|
/// @param obj
|
||||||
virtual void DestroyObject(InterestingThing* obj);
|
virtual void SendDestroyThing(InterestingThing* obj);
|
||||||
virtual void NewObject(InterestingThing* obj);
|
virtual void NewObject(InterestingThing* obj);
|
||||||
virtual void PublishModel(Roboid* obj);
|
virtual void PublishModel(Roboid* obj);
|
||||||
void PublishModel(Thing* thing);
|
void PublishModel(Thing* thing);
|
||||||
@ -58,11 +58,11 @@ class NetworkSync {
|
|||||||
|
|
||||||
void ReceiveNetworkId();
|
void ReceiveNetworkId();
|
||||||
|
|
||||||
void SendInvestigateThing(InterestingThing* thing);
|
void SendInvestigate(InterestingThing* thing);
|
||||||
|
|
||||||
void SendPoseMsg(Buffer sendBuffer, Roboid* roboid);
|
void SendPoseMsg(Buffer sendBuffer, Roboid* roboid);
|
||||||
void SendDestroyObject(Buffer sendBuffer, InterestingThing* obj);
|
// void SendDestroyThing(Buffer sendBuffer, InterestingThing* obj);
|
||||||
void PublishNewObject();
|
// void PublishNewObject();
|
||||||
void PublishRelativeThing(Thing* thing, bool recurse = false);
|
void PublishRelativeThing(Thing* thing, bool recurse = false);
|
||||||
|
|
||||||
void PublishTrackedObjects(Roboid* roboid, InterestingThing** objects);
|
void PublishTrackedObjects(Roboid* roboid, InterestingThing** objects);
|
||||||
|
@ -510,7 +510,7 @@ void Perception::Update(unsigned long currentTimeMs) {
|
|||||||
if (thing->DegradeConfidence(deltaTime) == false) {
|
if (thing->DegradeConfidence(deltaTime) == false) {
|
||||||
// delete obj
|
// delete obj
|
||||||
if (roboid != nullptr && roboid->networkSync != nullptr) {
|
if (roboid != nullptr && roboid->networkSync != nullptr) {
|
||||||
roboid->networkSync->DestroyObject(thing);
|
roboid->networkSync->SendDestroyThing(thing);
|
||||||
}
|
}
|
||||||
this->trackedObjects[objIx] = nullptr;
|
this->trackedObjects[objIx] = nullptr;
|
||||||
delete thing;
|
delete thing;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user