fix #622 - we might not have a local position yet early in the boot

1.2-legacy
Kevin Hester 2021-01-03 20:11:26 +08:00
rodzic 01848a9e5d
commit 34faea6100
1 zmienionych plików z 8 dodań i 2 usunięć

Wyświetl plik

@ -31,10 +31,16 @@ MeshPacket *PositionPlugin::allocReply()
{ {
NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum()); NodeInfo *node = nodeDB.getNode(nodeDB.getNodeNum());
assert(node); assert(node);
assert(node->has_position);
// We might not have a position yet for our local node, in that case, at least try to send the time
if(!node->has_position) {
memset(&node->position, 0, sizeof(node->position));
node->has_position = true;
}
Position &position = node->position;
// Update our local node info with our position (even if we don't decide to update anyone else) // Update our local node info with our position (even if we don't decide to update anyone else)
auto position = node->position;
position.time = getValidTime(RTCQualityGPS); // This nodedb timestamp might be stale, so update it if our clock is valid. position.time = getValidTime(RTCQualityGPS); // This nodedb timestamp might be stale, so update it if our clock is valid.
return allocDataProtobuf(position); return allocDataProtobuf(position);