Skip to content

Commit

Permalink
Save Neighbors to flash
Browse files Browse the repository at this point in the history
  • Loading branch information
GUVWAF committed Aug 2, 2023
1 parent f1bcc30 commit e05c8e6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/mesh/NodeDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ bool NodeDB::factoryReset()
installDefaultChannels();
// third, write everything to disk
saveToDisk();
// write NeighbourInfo
neighborInfoModule->saveProtoForModule();
#ifdef ARCH_ESP32
// This will erase what's in NVS including ssl keys, persistent variables and ble pairing
nvs_flash_erase();
Expand Down Expand Up @@ -290,7 +288,8 @@ void NodeDB::resetNodes()
devicestate.node_db_lite_count = 0;
memset(devicestate.node_db_lite, 0, sizeof(devicestate.node_db_lite));
saveDeviceStateToDisk();
neighborInfoModule->resetNeighbors();
if (neighborInfoModule && moduleConfig.neighbor_info.enabled)
neighborInfoModule->resetNeighbors();
}

void NodeDB::installDefaultDeviceState()
Expand Down Expand Up @@ -841,4 +840,4 @@ void recordCriticalError(meshtastic_CriticalErrorCode code, uint32_t address, co
LOG_ERROR("A critical failure occurred, portduino is exiting...");
exit(2);
#endif
}
}
10 changes: 9 additions & 1 deletion src/modules/NeighborInfoModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ size_t NeighborInfoModule::cleanUpNeighbors()
(*numNeighbors)--;
}

// Save the neighbor list if we removed any neighbors
if (indices_to_remove.size() > 0) {
saveProtoForModule();
}

return *numNeighbors;
}

Expand Down Expand Up @@ -207,7 +212,7 @@ Pass it to an upper client; do not persist this data on the mesh
*/
bool NeighborInfoModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_NeighborInfo *np)
{
printNeighborInfo("RECIEVED", np);
printNeighborInfo("RECEIVED", np);
updateNeighbors(mp, np);
// Allow others to handle this packet
return false;
Expand All @@ -234,6 +239,7 @@ void NeighborInfoModule::updateLastSentById(meshtastic_MeshPacket *p)

void NeighborInfoModule::resetNeighbors()
{
*numNeighbors = 0;
neighborState.neighbors_count = 0;
memset(neighborState.neighbors, 0, sizeof(neighborState.neighbors));
saveProtoForModule();
Expand Down Expand Up @@ -265,6 +271,7 @@ meshtastic_Neighbor *NeighborInfoModule::getOrCreateNeighbor(NodeNum originalSen
// Only if this is the original sender, the broadcast interval corresponds to it
if (originalSender == n)
nbr->node_broadcast_interval_secs = node_broadcast_interval_secs;
saveProtoForModule(); // Save the updated neighbor
return nbr;
}
}
Expand All @@ -280,6 +287,7 @@ meshtastic_Neighbor *NeighborInfoModule::getOrCreateNeighbor(NodeNum originalSen
// Only if this is the original sender, the broadcast interval corresponds to it
if (originalSender == n)
new_nbr->node_broadcast_interval_secs = node_broadcast_interval_secs;
saveProtoForModule(); // Save the new neighbor
return new_nbr;
}

Expand Down

0 comments on commit e05c8e6

Please sign in to comment.