mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-22 10:42:49 +00:00
For our first position send on boot, validate that we have received a fresh position (#9023)
This commit is contained in:
@@ -276,6 +276,10 @@ bool MeshService::trySendPosition(NodeNum dest, bool wantReplies)
|
|||||||
if (nodeDB->hasValidPosition(node)) {
|
if (nodeDB->hasValidPosition(node)) {
|
||||||
#if HAS_GPS && !MESHTASTIC_EXCLUDE_GPS
|
#if HAS_GPS && !MESHTASTIC_EXCLUDE_GPS
|
||||||
if (positionModule) {
|
if (positionModule) {
|
||||||
|
if (!config.position.fixed_position && !nodeDB->hasLocalPositionSinceBoot()) {
|
||||||
|
LOG_DEBUG("Skip position ping; no fresh position since boot");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
LOG_INFO("Send position ping to 0x%x, wantReplies=%d, channel=%d", dest, wantReplies, node->channel);
|
LOG_INFO("Send position ping to 0x%x, wantReplies=%d, channel=%d", dest, wantReplies, node->channel);
|
||||||
positionModule->sendOurPosition(dest, wantReplies, node->channel);
|
positionModule->sendOurPosition(dest, wantReplies, node->channel);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -1043,6 +1043,7 @@ void NodeDB::clearLocalPosition()
|
|||||||
node->position.altitude = 0;
|
node->position.altitude = 0;
|
||||||
node->position.time = 0;
|
node->position.time = 0;
|
||||||
setLocalPosition(meshtastic_Position_init_default);
|
setLocalPosition(meshtastic_Position_init_default);
|
||||||
|
localPositionUpdatedSinceBoot = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeDB::cleanupMeshDB()
|
void NodeDB::cleanupMeshDB()
|
||||||
|
|||||||
@@ -279,9 +279,13 @@ class NodeDB
|
|||||||
LOG_DEBUG("Set local position: lat=%i lon=%i time=%u timestamp=%u", position.latitude_i, position.longitude_i,
|
LOG_DEBUG("Set local position: lat=%i lon=%i time=%u timestamp=%u", position.latitude_i, position.longitude_i,
|
||||||
position.time, position.timestamp);
|
position.time, position.timestamp);
|
||||||
localPosition = position;
|
localPosition = position;
|
||||||
|
if (position.latitude_i != 0 || position.longitude_i != 0) {
|
||||||
|
localPositionUpdatedSinceBoot = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasValidPosition(const meshtastic_NodeInfoLite *n);
|
bool hasValidPosition(const meshtastic_NodeInfoLite *n);
|
||||||
|
bool hasLocalPositionSinceBoot() const { return localPositionUpdatedSinceBoot; }
|
||||||
|
|
||||||
#if !defined(MESHTASTIC_EXCLUDE_PKI)
|
#if !defined(MESHTASTIC_EXCLUDE_PKI)
|
||||||
bool checkLowEntropyPublicKey(const meshtastic_Config_SecurityConfig_public_key_t &keyToTest);
|
bool checkLowEntropyPublicKey(const meshtastic_Config_SecurityConfig_public_key_t &keyToTest);
|
||||||
@@ -301,6 +305,7 @@ class NodeDB
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool duplicateWarned = false;
|
bool duplicateWarned = false;
|
||||||
|
bool localPositionUpdatedSinceBoot = false;
|
||||||
uint32_t lastNodeDbSave = 0; // when we last saved our db to flash
|
uint32_t lastNodeDbSave = 0; // when we last saved our db to flash
|
||||||
uint32_t lastBackupAttempt = 0; // when we last tried a backup automatically or manually
|
uint32_t lastBackupAttempt = 0; // when we last tried a backup automatically or manually
|
||||||
uint32_t lastSort = 0; // When last sorted the nodeDB
|
uint32_t lastSort = 0; // When last sorted the nodeDB
|
||||||
|
|||||||
@@ -349,6 +349,11 @@ void PositionModule::sendOurPosition()
|
|||||||
|
|
||||||
void PositionModule::sendOurPosition(NodeNum dest, bool wantReplies, uint8_t channel)
|
void PositionModule::sendOurPosition(NodeNum dest, bool wantReplies, uint8_t channel)
|
||||||
{
|
{
|
||||||
|
if (!config.position.fixed_position && !nodeDB->hasLocalPositionSinceBoot()) {
|
||||||
|
LOG_DEBUG("Skip position send; no fresh position since boot");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// cancel any not yet sent (now stale) position packets
|
// cancel any not yet sent (now stale) position packets
|
||||||
if (prevPacketId) // if we wrap around to zero, we'll simply fail to cancel in that rare case (no big deal)
|
if (prevPacketId) // if we wrap around to zero, we'll simply fail to cancel in that rare case (no big deal)
|
||||||
service->cancelSending(prevPacketId);
|
service->cancelSending(prevPacketId);
|
||||||
@@ -420,8 +425,12 @@ int32_t PositionModule::runOnce()
|
|||||||
return RUNONCE_INTERVAL;
|
return RUNONCE_INTERVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool waitingForFreshPosition = (lastGpsSend == 0) && !config.position.fixed_position && !nodeDB->hasLocalPositionSinceBoot();
|
||||||
|
|
||||||
if (lastGpsSend == 0 || msSinceLastSend >= intervalMs) {
|
if (lastGpsSend == 0 || msSinceLastSend >= intervalMs) {
|
||||||
if (nodeDB->hasValidPosition(node)) {
|
if (waitingForFreshPosition) {
|
||||||
|
LOG_DEBUG("Skip initial position send; no fresh position since boot");
|
||||||
|
} else if (nodeDB->hasValidPosition(node)) {
|
||||||
lastGpsSend = now;
|
lastGpsSend = now;
|
||||||
|
|
||||||
lastGpsLatitude = node->position.latitude_i;
|
lastGpsLatitude = node->position.latitude_i;
|
||||||
|
|||||||
Reference in New Issue
Block a user