Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear local position on nodedb-reset #3451

Merged
merged 5 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/mesh/NodeDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ void NodeDB::resetNodes()
{
numMeshNodes = 1;
std::fill(devicestate.node_db_lite.begin() + 1, devicestate.node_db_lite.end(), meshtastic_NodeInfoLite());
clearLocalPosition();
saveDeviceStateToDisk();
if (neighborInfoModule && moduleConfig.neighbor_info.enabled)
neighborInfoModule->resetNeighbors();
Expand All @@ -399,6 +400,16 @@ void NodeDB::removeNodeByNum(uint nodeNum)
saveDeviceStateToDisk();
}

void NodeDB::clearLocalPosition()
{
meshtastic_NodeInfoLite *node = getMeshNode(nodeDB.getNodeNum());
node->position.latitude_i = 0;
node->position.longitude_i = 0;
node->position.altitude = 0;
node->position.time = 0;
setLocalPosition(meshtastic_Position_init_default);
}

void NodeDB::cleanupMeshDB()
{
int newPos = 0, removed = 0;
Expand Down
2 changes: 2 additions & 0 deletions src/mesh/NodeDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ class NodeDB
meshtastic_NodeInfoLite *getMeshNode(NodeNum n);
size_t getNumMeshNodes() { return numMeshNodes; }

void clearLocalPosition();

void setLocalPosition(meshtastic_Position position, bool timeOnly = false)
{
if (timeOnly) {
Expand Down
14 changes: 2 additions & 12 deletions src/modules/PositionModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,11 @@ PositionModule::PositionModule()
if ((config.device.role == meshtastic_Config_DeviceConfig_Role_TRACKER ||
config.device.role == meshtastic_Config_DeviceConfig_Role_TAK_TRACKER) &&
config.power.is_power_saving) {
clearPosition();
LOG_DEBUG("Clearing position on startup for sleepy tracker (ー。ー) zzz\n");
nodeDB.clearLocalPosition();
}
}

void PositionModule::clearPosition()
{
LOG_DEBUG("Clearing position on startup for sleepy tracker (ー。ー) zzz\n");
meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(nodeDB->getNodeNum());
node->position.latitude_i = 0;
node->position.longitude_i = 0;
node->position.altitude = 0;
node->position.time = 0;
nodeDB->setLocalPosition(meshtastic_Position_init_default);
}

bool PositionModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Position *pptr)
{
auto p = *pptr;
Expand Down
3 changes: 0 additions & 3 deletions src/modules/PositionModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ class PositionModule : public ProtobufModule<meshtastic_Position>, private concu
struct SmartPosition getDistanceTraveledSinceLastSend(meshtastic_PositionLite currentPosition);
meshtastic_MeshPacket *allocAtakPli();
uint32_t precision;

/** Only used in power saving trackers for now */
void clearPosition();
void sendLostAndFoundText();
};

Expand Down
Loading