From e83a7fe36b30eaae6c73ddf22f2eb53326a1c69e Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sat, 16 Mar 2024 16:42:15 -0500 Subject: [PATCH 01/11] Add MaxNodes to Native --- bin/config-dist.yaml | 3 +++ src/graphics/Screen.cpp | 8 +++++++- src/graphics/Screen.h | 2 ++ src/mesh/PacketHistory.cpp | 4 ++++ src/mesh/mesh-pb-constants.h | 4 ++++ src/platform/portduino/PortduinoGlue.cpp | 3 +++ src/platform/portduino/PortduinoGlue.h | 3 ++- src/shutdown.h | 2 ++ 8 files changed, 27 insertions(+), 2 deletions(-) diff --git a/bin/config-dist.yaml b/bin/config-dist.yaml index a241a929a2..22ca3e7db4 100644 --- a/bin/config-dist.yaml +++ b/bin/config-dist.yaml @@ -121,3 +121,6 @@ Logging: Webserver: # Port: 443 # Port for Webserver & Webservices # RootPath: /usr/share/doc/meshtasticd/web # Root Dir of WebServer + +General: + MaxNodes: 200 diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 7f20b56661..e6d801b195 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -71,7 +71,7 @@ namespace graphics // #define SHOW_REDRAWS // A text message frame + debug frame + all the node infos -static FrameCallback normalFrames[MAX_NUM_NODES + NUM_EXTRA_FRAMES]; +FrameCallback *normalFrames; static uint32_t targetFramerate = IDLE_FRAMERATE; static char btPIN[16] = "888888"; @@ -893,6 +893,7 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_ Screen::Screen(ScanI2C::DeviceAddress address, meshtastic_Config_DisplayConfig_OledType screenType, OLEDDISPLAY_GEOMETRY geometry) : concurrency::OSThread("Screen"), address_found(address), model(screenType), geometry(geometry), cmdQueue(32) { + graphics::normalFrames = new FrameCallback[MAX_NUM_NODES + NUM_EXTRA_FRAMES]; #if defined(USE_SH1106) || defined(USE_SH1107) || defined(USE_SH1107_128_64) dispdev = new SH1106Wire(address.address, -1, -1, geometry, (address.port == ScanI2C::I2CPort::WIRE1) ? HW_I2C::I2C_TWO : HW_I2C::I2C_ONE); @@ -931,6 +932,11 @@ Screen::Screen(ScanI2C::DeviceAddress address, meshtastic_Config_DisplayConfig_O cmdQueue.setReader(this); } +Screen::~Screen() +{ + delete[] graphics::normalFrames; +} + /** * Prepare the display for the unit going to the lowest power mode possible. Most screens will just * poweroff, but eink screens will show a "I'm sleeping" graphic, possibly with a QR code diff --git a/src/graphics/Screen.h b/src/graphics/Screen.h index 69e858dd2a..a66cc44ecc 100644 --- a/src/graphics/Screen.h +++ b/src/graphics/Screen.h @@ -125,6 +125,8 @@ class Screen : public concurrency::OSThread public: explicit Screen(ScanI2C::DeviceAddress, meshtastic_Config_DisplayConfig_OledType, OLEDDISPLAY_GEOMETRY); + ~Screen(); + Screen(const Screen &) = delete; Screen &operator=(const Screen &) = delete; diff --git a/src/mesh/PacketHistory.cpp b/src/mesh/PacketHistory.cpp index 9ecad47cd2..26a73a3fe8 100644 --- a/src/mesh/PacketHistory.cpp +++ b/src/mesh/PacketHistory.cpp @@ -2,6 +2,10 @@ #include "configuration.h" #include "mesh-pb-constants.h" +#ifdef ARCH_PORTDUINO +#include "platform/portduino/PortduinoGlue.h" +#endif + PacketHistory::PacketHistory() { recentPackets.reserve(MAX_NUM_NODES); // Prealloc the worst case # of records - to prevent heap fragmentation diff --git a/src/mesh/mesh-pb-constants.h b/src/mesh/mesh-pb-constants.h index 22a80c8e31..a044c8bd9e 100644 --- a/src/mesh/mesh-pb-constants.h +++ b/src/mesh/mesh-pb-constants.h @@ -16,7 +16,11 @@ #define MAX_RX_TOPHONE 32 /// max number of nodes allowed in the mesh +#if ARCH_PORTDUINO +#define MAX_NUM_NODES settingsMap[maxnodes] +#else #define MAX_NUM_NODES (member_size(meshtastic_DeviceState, node_db_lite) / member_size(meshtastic_DeviceState, node_db_lite[0])) +#endif /// Max number of channels allowed #define MAX_NUM_CHANNELS (member_size(meshtastic_ChannelFile, channels) / member_size(meshtastic_ChannelFile, channels[0])) diff --git a/src/platform/portduino/PortduinoGlue.cpp b/src/platform/portduino/PortduinoGlue.cpp index 997058406a..ee8bf21e99 100644 --- a/src/platform/portduino/PortduinoGlue.cpp +++ b/src/platform/portduino/PortduinoGlue.cpp @@ -199,6 +199,9 @@ void portduinoSetup() settingsMap[webserverport] = (yamlConfig["Webserver"]["Port"]).as(-1); settingsStrings[webserverrootpath] = (yamlConfig["Webserver"]["RootPath"]).as(""); } + if (yamlConfig["General"]) { + settingsMap[maxnodes] = (yamlConfig["General"]["MaxNodes"]).as(MAX_NUM_NODES); + } } catch (YAML::Exception e) { std::cout << "*** Exception " << e.what() << std::endl; diff --git a/src/platform/portduino/PortduinoGlue.h b/src/platform/portduino/PortduinoGlue.h index 3fe5f74bf0..505c436d60 100644 --- a/src/platform/portduino/PortduinoGlue.h +++ b/src/platform/portduino/PortduinoGlue.h @@ -36,7 +36,8 @@ enum configNames { logoutputlevel, webserver, webserverport, - webserverrootpath + webserverrootpath, + maxnodes }; enum { no_screen, st7789, st7735, st7735s, ili9341 }; enum { no_touchscreen, xpt2046, stmpe610 }; diff --git a/src/shutdown.h b/src/shutdown.h index 6449b129ee..21abba07ea 100644 --- a/src/shutdown.h +++ b/src/shutdown.h @@ -26,6 +26,8 @@ void powerCommandsCheck() SPI.end(); Wire.end(); Serial1.end(); + if (screen) + delete screen; reboot(); #else rebootAtMsec = -1; From 6fff34c72a753e142a6f88297200f7146d99566d Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 17 Mar 2024 17:32:43 -0500 Subject: [PATCH 02/11] It compiles... --- src/mesh/NodeDB.cpp | 58 ++++++++++++------- src/mesh/NodeDB.h | 9 +-- .../meshtastic/{admin.pb.c => admin.pb.cpp} | 0 .../{channel.pb.c => channel.pb.cpp} | 0 .../{deviceonly.pb.c => deviceonly.pb.cpp} | 2 +- src/mesh/generated/meshtastic/deviceonly.pb.h | 19 +++--- src/mesh/mesh-pb-constants.h | 3 +- 7 files changed, 57 insertions(+), 34 deletions(-) rename src/mesh/generated/meshtastic/{admin.pb.c => admin.pb.cpp} (100%) rename src/mesh/generated/meshtastic/{channel.pb.c => channel.pb.cpp} (100%) rename src/mesh/generated/meshtastic/{deviceonly.pb.c => deviceonly.pb.cpp} (90%) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 6898f77025..7894f99aca 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -17,8 +17,11 @@ #include "mesh-pb-constants.h" #include "modules/NeighborInfoModule.h" #include +#include +#include #include #include +#include #ifdef ARCH_ESP32 #include "mesh/wifi/WiFiAPClient.h" @@ -46,6 +49,16 @@ meshtastic_LocalModuleConfig moduleConfig; meshtastic_ChannelFile channelFile; meshtastic_OEMStore oemStore; +bool meshtastic_DeviceState_callback(pb_istream_t *istream, pb_ostream_t *ostream, const pb_field_iter_t *field) +{ + std::vector *vec = (std::vector *)field->pData; + + for (auto item : *vec) { + pb_encode_tag_for_field(ostream, field); + pb_encode_submessage(ostream, meshtastic_NodeInfoLite_fields, &item); + } +} + /** The current change # for radio settings. Starts at 0 on boot and any time the radio settings * might have changed is incremented. Allows others to detect they might now be on a new channel. */ @@ -68,7 +81,12 @@ uint32_t error_address = 0; static uint8_t ourMacAddr[6]; -NodeDB::NodeDB() : meshNodes(devicestate.node_db_lite), numMeshNodes(&devicestate.node_db_lite_count) {} +NodeDB::NodeDB() : meshNodes(devicestate.node_db_lite), numMeshNodes(devicestate.node_db_lite.size()) +{ + std::cout << "test" << std::endl; + std::cout << MAX_NUM_NODES << std::endl; + meshNodes.reserve(MAX_NUM_NODES); +} /** * Most (but not always) of the time we want to treat packets 'from' the local phone (where from == 0), as if they originated on @@ -359,8 +377,8 @@ void NodeDB::installDefaultChannels() void NodeDB::resetNodes() { - devicestate.node_db_lite_count = 1; - std::fill(&devicestate.node_db_lite[1], &devicestate.node_db_lite[MAX_NUM_NODES - 1], meshtastic_NodeInfoLite()); + // devicestate.node_db_lite_count = 1; + std::fill(devicestate.node_db_lite.begin(), devicestate.node_db_lite.end(), meshtastic_NodeInfoLite()); saveDeviceStateToDisk(); if (neighborInfoModule && moduleConfig.neighbor_info.enabled) neighborInfoModule->resetNeighbors(); @@ -369,13 +387,13 @@ void NodeDB::resetNodes() void NodeDB::removeNodeByNum(uint nodeNum) { int newPos = 0, removed = 0; - for (int i = 0; i < *numMeshNodes; i++) { + for (int i = 0; i < numMeshNodes; i++) { if (meshNodes[i].num != nodeNum) meshNodes[newPos++] = meshNodes[i]; else removed++; } - *numMeshNodes -= removed; + numMeshNodes -= removed; LOG_DEBUG("NodeDB::removeNodeByNum purged %d entries. Saving changes...\n", removed); saveDeviceStateToDisk(); } @@ -383,13 +401,13 @@ void NodeDB::removeNodeByNum(uint nodeNum) void NodeDB::cleanupMeshDB() { int newPos = 0, removed = 0; - for (int i = 0; i < *numMeshNodes; i++) { + for (int i = 0; i < numMeshNodes; i++) { if (meshNodes[i].has_user) meshNodes[newPos++] = meshNodes[i]; else removed++; } - *numMeshNodes -= removed; + numMeshNodes -= removed; LOG_DEBUG("cleanupMeshDB purged %d entries\n", removed); } @@ -398,12 +416,12 @@ void NodeDB::installDefaultDeviceState() LOG_INFO("Installing default DeviceState\n"); memset(&devicestate, 0, sizeof(meshtastic_DeviceState)); - *numMeshNodes = 0; + numMeshNodes = 0; // init our devicestate with valid flags so protobuf writing/reading will work devicestate.has_my_node = true; devicestate.has_owner = true; - devicestate.node_db_lite_count = 0; + // devicestate.node_db_lite_count = 0; devicestate.version = DEVICESTATE_CUR_VER; devicestate.receive_queue_count = 0; // Not yet implemented FIXME @@ -454,7 +472,7 @@ void NodeDB::init() #endif resetRadioConfig(); // If bogus settings got saved, then fix them - LOG_DEBUG("region=%d, NODENUM=0x%x, dbsize=%d\n", config.lora.region, myNodeInfo.my_node_num, *numMeshNodes); + LOG_DEBUG("region=%d, NODENUM=0x%x, dbsize=%d\n", config.lora.region, myNodeInfo.my_node_num, numMeshNodes); if (devicestateCRC != crc32Buffer(&devicestate, sizeof(devicestate))) saveWhat |= SEGMENT_DEVICESTATE; @@ -543,7 +561,7 @@ bool NodeDB::loadProto(const char *filename, size_t protoSize, size_t objSize, c void NodeDB::loadFromDisk() { // static DeviceState scratch; We no longer read into a tempbuf because this structure is 15KB of valuable RAM - if (!loadProto(prefFileName, meshtastic_DeviceState_size, sizeof(meshtastic_DeviceState), &meshtastic_DeviceState_msg, + if (!loadProto(prefFileName, sizeof(meshtastic_DeviceState), sizeof(meshtastic_DeviceState), &meshtastic_DeviceState_msg, &devicestate)) { installDefaultDeviceState(); // Our in RAM copy might now be corrupt } else { @@ -658,7 +676,7 @@ void NodeDB::saveDeviceStateToDisk() #ifdef FSCom FSCom.mkdir("/prefs"); #endif - saveProto(prefFileName, meshtastic_DeviceState_size, &meshtastic_DeviceState_msg, &devicestate); + saveProto(prefFileName, sizeof(meshtastic_DeviceState), &meshtastic_DeviceState_msg, &devicestate); } } @@ -704,7 +722,7 @@ void NodeDB::saveToDisk(int saveWhat) const meshtastic_NodeInfoLite *NodeDB::readNextMeshNode(uint32_t &readIndex) { - if (readIndex < *numMeshNodes) + if (readIndex < numMeshNodes) return &meshNodes[readIndex++]; else return NULL; @@ -740,7 +758,7 @@ size_t NodeDB::getNumOnlineMeshNodes(bool localOnly) size_t numseen = 0; // FIXME this implementation is kinda expensive - for (int i = 0; i < *numMeshNodes; i++) { + for (int i = 0; i < numMeshNodes; i++) { if (localOnly && meshNodes[i].via_mqtt) continue; if (sinceLastSeen(&meshNodes[i]) < NUM_ONLINE_SECS) @@ -891,7 +909,7 @@ uint8_t NodeDB::getMeshNodeChannel(NodeNum n) /// NOTE: This function might be called from an ISR meshtastic_NodeInfoLite *NodeDB::getMeshNode(NodeNum n) { - for (int i = 0; i < *numMeshNodes; i++) + for (int i = 0; i < numMeshNodes; i++) if (meshNodes[i].num == n) return &meshNodes[i]; @@ -904,27 +922,27 @@ meshtastic_NodeInfoLite *NodeDB::getOrCreateMeshNode(NodeNum n) meshtastic_NodeInfoLite *lite = getMeshNode(n); if (!lite) { - if ((*numMeshNodes >= MAX_NUM_NODES) || (memGet.getFreeHeap() < meshtastic_NodeInfoLite_size * 3)) { + if ((numMeshNodes >= MAX_NUM_NODES) || (memGet.getFreeHeap() < meshtastic_NodeInfoLite_size * 3)) { if (screen) screen->print("Warn: node database full!\nErasing oldest entry\n"); LOG_INFO("Warn: node database full!\nErasing oldest entry\n"); // look for oldest node and erase it uint32_t oldest = UINT32_MAX; int oldestIndex = -1; - for (int i = 1; i < *numMeshNodes; i++) { + for (int i = 1; i < numMeshNodes; i++) { if (meshNodes[i].last_heard < oldest) { oldest = meshNodes[i].last_heard; oldestIndex = i; } } // Shove the remaining nodes down the chain - for (int i = oldestIndex; i < *numMeshNodes - 1; i++) { + for (int i = oldestIndex; i < numMeshNodes - 1; i++) { meshNodes[i] = meshNodes[i + 1]; } - (*numMeshNodes)--; + (numMeshNodes)--; } // add the node at the end - lite = &meshNodes[(*numMeshNodes)++]; + lite = &meshNodes[(numMeshNodes)++]; // everything is missing except the nodenum memset(lite, 0, sizeof(*lite)); diff --git a/src/mesh/NodeDB.h b/src/mesh/NodeDB.h index b34059fb9a..4ade275f4a 100644 --- a/src/mesh/NodeDB.h +++ b/src/mesh/NodeDB.h @@ -3,6 +3,7 @@ #include "Observer.h" #include #include +#include #include "MeshTypes.h" #include "NodeStatus.h" @@ -45,8 +46,8 @@ class NodeDB // Eventually use a smarter datastructure // HashMap nodes; // Note: these two references just point into our static array we serialize to/from disk - meshtastic_NodeInfoLite *meshNodes; - pb_size_t *numMeshNodes; + std::vector meshNodes; + pb_size_t numMeshNodes; public: bool updateGUI = false; // we think the gui should definitely be redrawn, screen will clear this once handled @@ -126,12 +127,12 @@ class NodeDB meshtastic_NodeInfoLite *getMeshNodeByIndex(size_t x) { - assert(x < *numMeshNodes); + assert(x < numMeshNodes); return &meshNodes[x]; } meshtastic_NodeInfoLite *getMeshNode(NodeNum n); - size_t getNumMeshNodes() { return *numMeshNodes; } + size_t getNumMeshNodes() { return numMeshNodes; } void setLocalPosition(meshtastic_Position position, bool timeOnly = false) { diff --git a/src/mesh/generated/meshtastic/admin.pb.c b/src/mesh/generated/meshtastic/admin.pb.cpp similarity index 100% rename from src/mesh/generated/meshtastic/admin.pb.c rename to src/mesh/generated/meshtastic/admin.pb.cpp diff --git a/src/mesh/generated/meshtastic/channel.pb.c b/src/mesh/generated/meshtastic/channel.pb.cpp similarity index 100% rename from src/mesh/generated/meshtastic/channel.pb.c rename to src/mesh/generated/meshtastic/channel.pb.cpp diff --git a/src/mesh/generated/meshtastic/deviceonly.pb.c b/src/mesh/generated/meshtastic/deviceonly.pb.cpp similarity index 90% rename from src/mesh/generated/meshtastic/deviceonly.pb.c rename to src/mesh/generated/meshtastic/deviceonly.pb.cpp index 82c3fc44c5..93ab3dd981 100644 --- a/src/mesh/generated/meshtastic/deviceonly.pb.c +++ b/src/mesh/generated/meshtastic/deviceonly.pb.cpp @@ -6,7 +6,7 @@ #error Regenerate this file with the current version of nanopb generator. #endif -PB_BIND(meshtastic_DeviceState, meshtastic_DeviceState, 4) +PB_BIND(meshtastic_DeviceState, meshtastic_DeviceState, 2) PB_BIND(meshtastic_NodeInfoLite, meshtastic_NodeInfoLite, AUTO) diff --git a/src/mesh/generated/meshtastic/deviceonly.pb.h b/src/mesh/generated/meshtastic/deviceonly.pb.h index 79800d4b4b..87045c313e 100644 --- a/src/mesh/generated/meshtastic/deviceonly.pb.h +++ b/src/mesh/generated/meshtastic/deviceonly.pb.h @@ -4,6 +4,9 @@ #ifndef PB_MESHTASTIC_MESHTASTIC_DEVICEONLY_PB_H_INCLUDED #define PB_MESHTASTIC_MESHTASTIC_DEVICEONLY_PB_H_INCLUDED #include + +#include + #include "meshtastic/channel.pb.h" #include "meshtastic/localonly.pb.h" #include "meshtastic/mesh.pb.h" @@ -154,8 +157,7 @@ typedef struct _meshtastic_DeviceState { pb_size_t node_remote_hardware_pins_count; meshtastic_NodeRemoteHardwarePin node_remote_hardware_pins[12]; /* New lite version of NodeDB to decrease memory footprint */ - pb_size_t node_db_lite_count; - meshtastic_NodeInfoLite node_db_lite[100]; + std::vector node_db_lite; } meshtastic_DeviceState; @@ -178,13 +180,13 @@ extern "C" { /* Initializer values for message structs */ -#define meshtastic_DeviceState_init_default {false, meshtastic_MyNodeInfo_init_default, false, meshtastic_User_init_default, 0, {meshtastic_MeshPacket_init_default}, false, meshtastic_MeshPacket_init_default, 0, 0, 0, false, meshtastic_MeshPacket_init_default, 0, {meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default}, 0, {meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default, meshtastic_NodeInfoLite_init_default}} +#define meshtastic_DeviceState_init_default {false, meshtastic_MyNodeInfo_init_default, false, meshtastic_User_init_default, 0, {meshtastic_MeshPacket_init_default}, false, meshtastic_MeshPacket_init_default, 0, 0, 0, false, meshtastic_MeshPacket_init_default, 0, {meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default}, {{NULL}, NULL}} #define meshtastic_NodeInfoLite_init_default {0, false, meshtastic_User_init_default, false, meshtastic_PositionLite_init_default, 0, 0, false, meshtastic_DeviceMetrics_init_default, 0, 0, 0} #define meshtastic_PositionLite_init_default {0, 0, 0, 0, _meshtastic_Position_LocSource_MIN} #define meshtastic_ChannelFile_init_default {0, {meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default}, 0} #define meshtastic_OEMStore_init_default {0, 0, {0, {0}}, _meshtastic_ScreenFonts_MIN, "", {0, {0}}, false, meshtastic_LocalConfig_init_default, false, meshtastic_LocalModuleConfig_init_default} #define meshtastic_NodeRemoteHardwarePin_init_default {0, false, meshtastic_RemoteHardwarePin_init_default} -#define meshtastic_DeviceState_init_zero {false, meshtastic_MyNodeInfo_init_zero, false, meshtastic_User_init_zero, 0, {meshtastic_MeshPacket_init_zero}, false, meshtastic_MeshPacket_init_zero, 0, 0, 0, false, meshtastic_MeshPacket_init_zero, 0, {meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero}, 0, {meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero, meshtastic_NodeInfoLite_init_zero}} +#define meshtastic_DeviceState_init_zero {false, meshtastic_MyNodeInfo_init_zero, false, meshtastic_User_init_zero, 0, {meshtastic_MeshPacket_init_zero}, false, meshtastic_MeshPacket_init_zero, 0, 0, 0, false, meshtastic_MeshPacket_init_zero, 0, {meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero}, {{NULL}, NULL}} #define meshtastic_NodeInfoLite_init_zero {0, false, meshtastic_User_init_zero, false, meshtastic_PositionLite_init_zero, 0, 0, false, meshtastic_DeviceMetrics_init_zero, 0, 0, 0} #define meshtastic_PositionLite_init_zero {0, 0, 0, 0, _meshtastic_Position_LocSource_MIN} #define meshtastic_ChannelFile_init_zero {0, {meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero}, 0} @@ -240,8 +242,9 @@ X(a, STATIC, SINGULAR, BOOL, no_save, 9) \ X(a, STATIC, SINGULAR, BOOL, did_gps_reset, 11) \ X(a, STATIC, OPTIONAL, MESSAGE, rx_waypoint, 12) \ X(a, STATIC, REPEATED, MESSAGE, node_remote_hardware_pins, 13) \ -X(a, STATIC, REPEATED, MESSAGE, node_db_lite, 14) -#define meshtastic_DeviceState_CALLBACK NULL +X(a, CALLBACK, REPEATED, MESSAGE, node_db_lite, 14) +extern bool meshtastic_DeviceState_callback(pb_istream_t *istream, pb_ostream_t *ostream, const pb_field_t *field); +#define meshtastic_DeviceState_CALLBACK meshtastic_DeviceState_callback #define meshtastic_DeviceState_DEFAULT NULL #define meshtastic_DeviceState_my_node_MSGTYPE meshtastic_MyNodeInfo #define meshtastic_DeviceState_owner_MSGTYPE meshtastic_User @@ -320,8 +323,8 @@ extern const pb_msgdesc_t meshtastic_NodeRemoteHardwarePin_msg; #define meshtastic_NodeRemoteHardwarePin_fields &meshtastic_NodeRemoteHardwarePin_msg /* Maximum encoded size of messages (where known) */ +/* meshtastic_DeviceState_size depends on runtime parameters */ #define meshtastic_ChannelFile_size 702 -#define meshtastic_DeviceState_size 17571 #define meshtastic_NodeInfoLite_size 158 #define meshtastic_NodeRemoteHardwarePin_size 29 #define meshtastic_OEMStore_size 3278 @@ -331,4 +334,4 @@ extern const pb_msgdesc_t meshtastic_NodeRemoteHardwarePin_msg; } /* extern "C" */ #endif -#endif +#endif \ No newline at end of file diff --git a/src/mesh/mesh-pb-constants.h b/src/mesh/mesh-pb-constants.h index a044c8bd9e..9e747db1d6 100644 --- a/src/mesh/mesh-pb-constants.h +++ b/src/mesh/mesh-pb-constants.h @@ -1,4 +1,5 @@ #pragma once +#include #include "mesh/generated/meshtastic/admin.pb.h" #include "mesh/generated/meshtastic/deviceonly.pb.h" @@ -19,7 +20,7 @@ #if ARCH_PORTDUINO #define MAX_NUM_NODES settingsMap[maxnodes] #else -#define MAX_NUM_NODES (member_size(meshtastic_DeviceState, node_db_lite) / member_size(meshtastic_DeviceState, node_db_lite[0])) +#define MAX_NUM_NODES 100 #endif /// Max number of channels allowed From 480de1ef1cdedc90c3213cc8fe336750ddc5093d Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sun, 17 Mar 2024 22:46:02 -0500 Subject: [PATCH 03/11] Convert nodedb to use new --- src/GPSStatus.h | 23 +++++----------- src/gps/GPS.cpp | 4 +-- src/graphics/Screen.cpp | 22 +++++++-------- src/main.cpp | 8 +++--- src/mesh/MeshModule.cpp | 4 +-- src/mesh/MeshService.cpp | 24 ++++++++-------- src/mesh/NodeDB.cpp | 27 ++++++++++-------- src/mesh/NodeDB.h | 4 +-- src/mesh/PhoneAPI.cpp | 2 +- src/mesh/ProtobufModule.h | 2 +- src/mesh/RadioInterface.cpp | 4 +-- src/mesh/ReliableRouter.cpp | 2 +- src/mesh/Router.cpp | 20 +++++++------- src/mesh/SX128xInterface.cpp | 10 +++---- src/modules/AdminModule.cpp | 12 ++++---- src/modules/CannedMessageModule.cpp | 32 +++++++++++----------- src/modules/ExternalNotificationModule.cpp | 8 +++--- src/modules/NeighborInfoModule.cpp | 26 +++++++++--------- src/modules/NodeInfoModule.cpp | 6 ++-- src/modules/PositionModule.cpp | 18 ++++++------ src/modules/RangeTestModule.cpp | 8 +++--- src/modules/RoutingModule.cpp | 4 +-- src/modules/SerialModule.cpp | 12 ++++---- src/modules/Telemetry/DeviceTelemetry.cpp | 4 +-- src/modules/esp32/AudioModule.cpp | 5 ++-- src/modules/esp32/StoreForwardModule.cpp | 4 +-- src/mqtt/MQTT.cpp | 10 +++---- src/platform/portduino/PortduinoGlue.cpp | 6 ++-- src/sleep.cpp | 2 +- 29 files changed, 153 insertions(+), 160 deletions(-) diff --git a/src/GPSStatus.h b/src/GPSStatus.h index bcfb5f2eb5..14c5d0f1a6 100644 --- a/src/GPSStatus.h +++ b/src/GPSStatus.h @@ -4,7 +4,7 @@ #include "configuration.h" #include -extern NodeDB nodeDB; +// extern NodeDB *nodeDB; namespace meshtastic { @@ -55,7 +55,7 @@ class GPSStatus : public Status #ifdef GPS_EXTRAVERBOSE LOG_WARN("Using fixed latitude\n"); #endif - meshtastic_NodeInfoLite *node = nodeDB.getMeshNode(nodeDB.getNodeNum()); + meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(nodeDB->getNodeNum()); return node->position.latitude_i; } else { return p.latitude_i; @@ -68,7 +68,7 @@ class GPSStatus : public Status #ifdef GPS_EXTRAVERBOSE LOG_WARN("Using fixed longitude\n"); #endif - meshtastic_NodeInfoLite *node = nodeDB.getMeshNode(nodeDB.getNodeNum()); + meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(nodeDB->getNodeNum()); return node->position.longitude_i; } else { return p.longitude_i; @@ -81,27 +81,18 @@ class GPSStatus : public Status #ifdef GPS_EXTRAVERBOSE LOG_WARN("Using fixed altitude\n"); #endif - meshtastic_NodeInfoLite *node = nodeDB.getMeshNode(nodeDB.getNodeNum()); + meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(nodeDB->getNodeNum()); return node->position.altitude; } else { return p.altitude; } } - uint32_t getDOP() const - { - return p.PDOP; - } + uint32_t getDOP() const { return p.PDOP; } - uint32_t getHeading() const - { - return p.ground_track; - } + uint32_t getHeading() const { return p.ground_track; } - uint32_t getNumSatellites() const - { - return p.sats_in_view; - } + uint32_t getNumSatellites() const { return p.sats_in_view; } bool matches(const GPSStatus *newStatus) const { diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index 18932e066f..a09eda03d1 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -815,7 +815,7 @@ int32_t GPS::runOnce() LOG_WARN("GPS FactoryReset requested\n"); if (gps->factoryReset()) { // If we don't succeed try again next time devicestate.did_gps_reset = true; - nodeDB.saveToDisk(SEGMENT_DEVICESTATE); + nodeDB->saveToDisk(SEGMENT_DEVICESTATE); } } GPSInitFinished = true; @@ -835,7 +835,7 @@ int32_t GPS::runOnce() if (devicestate.did_gps_reset && (millis() - lastWakeStartMsec > 60000) && !hasFlow()) { LOG_DEBUG("GPS is not communicating, trying factory reset on next bootup.\n"); devicestate.did_gps_reset = false; - nodeDB.saveDeviceStateToDisk(); + nodeDB->saveDeviceStateToDisk(); return disable(); // Stop the GPS thread as it can do nothing useful until next reboot. } } diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index e6d801b195..7e36dfe4a7 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -354,7 +354,7 @@ static void drawTextMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state static char tempBuf[237]; const meshtastic_MeshPacket &mp = devicestate.rx_text_message; - meshtastic_NodeInfoLite *node = nodeDB.getMeshNode(getFrom(&mp)); + meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(getFrom(&mp)); // LOG_DEBUG("drawing text message from 0x%x: %s\n", mp.from, // mp.decoded.variant.data.decoded.bytes); @@ -392,7 +392,7 @@ static void drawWaypointFrame(OLEDDisplay *display, OLEDDisplayUiState *state, i static char tempBuf[237]; meshtastic_MeshPacket &mp = devicestate.rx_waypoint; - meshtastic_NodeInfoLite *node = nodeDB.getMeshNode(getFrom(&mp)); + meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(getFrom(&mp)); display->setTextAlignment(TEXT_ALIGN_LEFT); display->setFont(FONT_SMALL); @@ -780,16 +780,16 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_ if (state->currentFrame != prevFrame) { prevFrame = state->currentFrame; - nodeIndex = (nodeIndex + 1) % nodeDB.getNumMeshNodes(); - meshtastic_NodeInfoLite *n = nodeDB.getMeshNodeByIndex(nodeIndex); - if (n->num == nodeDB.getNodeNum()) { + nodeIndex = (nodeIndex + 1) % nodeDB->getNumMeshNodes(); + meshtastic_NodeInfoLite *n = nodeDB->getMeshNodeByIndex(nodeIndex); + if (n->num == nodeDB->getNodeNum()) { // Don't show our node, just skip to next - nodeIndex = (nodeIndex + 1) % nodeDB.getNumMeshNodes(); - n = nodeDB.getMeshNodeByIndex(nodeIndex); + nodeIndex = (nodeIndex + 1) % nodeDB->getNumMeshNodes(); + n = nodeDB->getMeshNodeByIndex(nodeIndex); } } - meshtastic_NodeInfoLite *node = nodeDB.getMeshNodeByIndex(nodeIndex); + meshtastic_NodeInfoLite *node = nodeDB->getMeshNodeByIndex(nodeIndex); display->setFont(FONT_SMALL); @@ -827,7 +827,7 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_ } else { strncpy(distStr, "? km", sizeof(distStr)); } - meshtastic_NodeInfoLite *ourNode = nodeDB.getMeshNode(nodeDB.getNodeNum()); + meshtastic_NodeInfoLite *ourNode = nodeDB->getMeshNode(nodeDB->getNodeNum()); const char *fields[] = {username, distStr, signalStr, lastStr, NULL}; int16_t compassX = 0, compassY = 0; @@ -1293,7 +1293,7 @@ void Screen::setFrames() #endif // We don't show the node info our our node (if we have it yet - we should) - size_t numMeshNodes = nodeDB.getNumMeshNodes(); + size_t numMeshNodes = nodeDB->getNumMeshNodes(); if (numMeshNodes > 0) numMeshNodes--; @@ -1799,7 +1799,7 @@ int Screen::handleStatusUpdate(const meshtastic::Status *arg) if (showingNormalScreen && nodeStatus->getLastNumTotal() != nodeStatus->getNumTotal()) { setFrames(); // Regen the list of screens } - nodeDB.updateGUI = false; + nodeDB->updateGUI = false; break; } diff --git a/src/main.cpp b/src/main.cpp index fe5d455f8a..456a98a075 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -554,7 +554,7 @@ void setup() // We do this as early as possible because this loads preferences from flash // but we need to do this after main cpu init (esp32setup), because we need the random seed set - nodeDB.init(); + nodeDB = NodeDB::init(); // If we're taking on the repeater role, use flood router and turn off 3V3_S rail because peripherals are not needed if (config.device.role == meshtastic_Config_DeviceConfig_Role_REPEATER) { @@ -648,7 +648,7 @@ void setup() } else { LOG_DEBUG("Running without GPS.\n"); } - nodeStatus->observe(&nodeDB.newStatus); + nodeStatus->observe(&nodeDB->newStatus); #ifdef HAS_I2S LOG_DEBUG("Starting audio thread\n"); @@ -842,7 +842,7 @@ void setup() if ((config.lora.region == meshtastic_Config_LoRaConfig_RegionCode_LORA_24) && (!rIf->wideLora())) { LOG_WARN("Radio chip does not support 2.4GHz LoRa. Reverting to unset.\n"); config.lora.region = meshtastic_Config_LoRaConfig_RegionCode_UNSET; - nodeDB.saveToDisk(SEGMENT_CONFIG); + nodeDB->saveToDisk(SEGMENT_CONFIG); if (!rIf->reconfigure()) { LOG_WARN("Reconfigure failed, rebooting\n"); screen->startRebootScreen(); @@ -965,4 +965,4 @@ void loop() mainDelay.delay(delayMsec); } // if (didWake) LOG_DEBUG("wake!\n"); -} +} \ No newline at end of file diff --git a/src/mesh/MeshModule.cpp b/src/mesh/MeshModule.cpp index ad0c781088..c8dd7f3d12 100644 --- a/src/mesh/MeshModule.cpp +++ b/src/mesh/MeshModule.cpp @@ -81,7 +81,7 @@ void MeshModule::callPlugins(meshtastic_MeshPacket &mp, RxSource src) bool ignoreRequest = false; // No module asked to ignore the request yet // Was this message directed to us specifically? Will be false if we are sniffing someone elses packets - auto ourNodeNum = nodeDB.getNodeNum(); + auto ourNodeNum = nodeDB->getNodeNum(); bool toUs = mp.to == NODENUM_BROADCAST || mp.to == ourNodeNum; for (auto i = modules->begin(); i != modules->end(); ++i) { @@ -279,4 +279,4 @@ AdminMessageHandleResult MeshModule::handleAdminMessageForAllPlugins(const mesht } } return handled; -} +} \ No newline at end of file diff --git a/src/mesh/MeshService.cpp b/src/mesh/MeshService.cpp index db0dd88ec1..31eb082ec4 100644 --- a/src/mesh/MeshService.cpp +++ b/src/mesh/MeshService.cpp @@ -71,7 +71,7 @@ MeshService::MeshService() void MeshService::init() { // moved much earlier in boot (called from setup()) - // nodeDB.init(); + // nodeDB->init(); if (gps) gpsObserver.observe(&gps->newStatus); @@ -81,13 +81,13 @@ int MeshService::handleFromRadio(const meshtastic_MeshPacket *mp) { powerFSM.trigger(EVENT_PACKET_FOR_PHONE); // Possibly keep the node from sleeping - nodeDB.updateFrom(*mp); // update our DB state based off sniffing every RX packet from the radio + nodeDB->updateFrom(*mp); // update our DB state based off sniffing every RX packet from the radio if (mp->which_payload_variant == meshtastic_MeshPacket_decoded_tag && mp->decoded.portnum == meshtastic_PortNum_TELEMETRY_APP && mp->decoded.request_id > 0) { LOG_DEBUG( "Received telemetry response. Skip sending our NodeInfo because this potentially a Repeater which will ignore our " "request for its NodeInfo.\n"); - } else if (mp->which_payload_variant == meshtastic_MeshPacket_decoded_tag && !nodeDB.getMeshNode(mp->from)->has_user && + } else if (mp->which_payload_variant == meshtastic_MeshPacket_decoded_tag && !nodeDB->getMeshNode(mp->from)->has_user && nodeInfoModule) { LOG_INFO("Heard a node on channel %d we don't know, sending NodeInfo and asking for a response.\n", mp->channel); nodeInfoModule->sendOurNodeInfo(mp->from, true, mp->channel); @@ -120,10 +120,10 @@ bool MeshService::reloadConfig(int saveWhat) // If we can successfully set this radio to these settings, save them to disk // This will also update the region as needed - bool didReset = nodeDB.resetRadioConfig(); // Don't let the phone send us fatally bad settings + bool didReset = nodeDB->resetRadioConfig(); // Don't let the phone send us fatally bad settings configChanged.notifyObservers(NULL); // This will cause radio hardware to change freqs etc - nodeDB.saveToDisk(saveWhat); + nodeDB->saveToDisk(saveWhat); return didReset; } @@ -133,7 +133,7 @@ void MeshService::reloadOwner(bool shouldSave) { // LOG_DEBUG("reloadOwner()\n"); // update our local data directly - nodeDB.updateUser(nodeDB.getNodeNum(), owner); + nodeDB->updateUser(nodeDB->getNodeNum(), owner); assert(nodeInfoModule); // update everyone else and save to disk if (nodeInfoModule && shouldSave) { @@ -192,7 +192,7 @@ void MeshService::handleToRadio(meshtastic_MeshPacket &p) LOG_WARN("phone tried to pick a nodenum, we don't allow that.\n"); p.from = 0; } else { - // p.from = nodeDB.getNodeNum(); + // p.from = nodeDB->getNodeNum(); } if (p.id == 0) @@ -217,7 +217,7 @@ void MeshService::handleToRadio(meshtastic_MeshPacket &p) /** Attempt to cancel a previously sent packet from this _local_ node. Returns true if a packet was found we could cancel */ bool MeshService::cancelSending(PacketId id) { - return router->cancelSending(nodeDB.getNodeNum(), id); + return router->cancelSending(nodeDB->getNodeNum(), id); } ErrorCode MeshService::sendQueueStatusToPhone(const meshtastic_QueueStatus &qs, ErrorCode res, uint32_t mesh_packet_id) @@ -245,7 +245,7 @@ ErrorCode MeshService::sendQueueStatusToPhone(const meshtastic_QueueStatus &qs, void MeshService::sendToMesh(meshtastic_MeshPacket *p, RxSource src, bool ccToPhone) { uint32_t mesh_packet_id = p->id; - nodeDB.updateFrom(*p); // update our local DB for this packet (because phone might have sent position packets etc...) + nodeDB->updateFrom(*p); // update our local DB for this packet (because phone might have sent position packets etc...) // Note: We might return !OK if our fifo was full, at that point the only option we have is to drop it ErrorCode res = router->sendLocal(p, src); @@ -265,7 +265,7 @@ void MeshService::sendToMesh(meshtastic_MeshPacket *p, RxSource src, bool ccToPh void MeshService::sendNetworkPing(NodeNum dest, bool wantReplies) { - meshtastic_NodeInfoLite *node = nodeDB.getMeshNode(nodeDB.getNodeNum()); + meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(nodeDB->getNodeNum()); assert(node); @@ -320,7 +320,7 @@ void MeshService::sendMqttMessageToClientProxy(meshtastic_MqttClientProxyMessage meshtastic_NodeInfoLite *MeshService::refreshLocalMeshNode() { - meshtastic_NodeInfoLite *node = nodeDB.getMeshNode(nodeDB.getNodeNum()); + meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(nodeDB->getNodeNum()); assert(node); // We might not have a position yet for our local node, in that case, at least try to send the time @@ -373,7 +373,7 @@ int MeshService::onGPSChanged(const meshtastic::GPSStatus *newStatus) pos.longitude_i, pos.altitude); // Update our current position in the local DB - nodeDB.updatePosition(nodeDB.getNodeNum(), pos, RX_SRC_LOCAL); + nodeDB->updatePosition(nodeDB->getNodeNum(), pos, RX_SRC_LOCAL); return 0; } diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 7894f99aca..6de2afe183 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -39,7 +39,7 @@ #include #endif -NodeDB nodeDB; +NodeDB *nodeDB = nullptr; // we have plenty of ram so statically alloc this tempbuf (for now) EXT_RAM_ATTR meshtastic_DeviceState devicestate; @@ -86,6 +86,7 @@ NodeDB::NodeDB() : meshNodes(devicestate.node_db_lite), numMeshNodes(devicestate std::cout << "test" << std::endl; std::cout << MAX_NUM_NODES << std::endl; meshNodes.reserve(MAX_NUM_NODES); + std::cout << "vector size" << meshNodes.size() << std::endl; } /** @@ -94,7 +95,7 @@ NodeDB::NodeDB() : meshNodes(devicestate.node_db_lite), numMeshNodes(devicestate */ NodeNum getFrom(const meshtastic_MeshPacket *p) { - return (p->from == 0) ? nodeDB.getNodeNum() : p->from; + return (p->from == 0) ? nodeDB->getNodeNum() : p->from; } bool NodeDB::resetRadioConfig(bool factory_reset) @@ -435,11 +436,12 @@ void NodeDB::installDefaultDeviceState() memcpy(owner.macaddr, ourMacAddr, sizeof(owner.macaddr)); } -void NodeDB::init() +NodeDB *NodeDB::init() { LOG_INFO("Initializing NodeDB\n"); - loadFromDisk(); - cleanupMeshDB(); + NodeDB *nodeDB = new NodeDB; + nodeDB->loadFromDisk(); + nodeDB->cleanupMeshDB(); uint32_t devicestateCRC = crc32Buffer(&devicestate, sizeof(devicestate)); uint32_t configCRC = crc32Buffer(&config, sizeof(config)); @@ -451,7 +453,7 @@ void NodeDB::init() myNodeInfo.min_app_version = 30200; // format is Mmmss (where M is 1+the numeric major number. i.e. 30200 means 2.2.00 // Note! We do this after loading saved settings, so that if somehow an invalid nodenum was stored in preferences we won't // keep using that nodenum forever. Crummy guess at our nodenum (but we will check against the nodedb to avoid conflicts) - pickNewNodeNum(); + nodeDB->pickNewNodeNum(); // Set our board type so we can share it with others owner.hw_model = HW_VENDOR; @@ -459,7 +461,7 @@ void NodeDB::init() owner.role = config.device.role; // Include our owner in the node db under our nodenum - meshtastic_NodeInfoLite *info = getOrCreateMeshNode(getNodeNum()); + meshtastic_NodeInfoLite *info = nodeDB->getOrCreateMeshNode(nodeDB->getNodeNum()); info->user = owner; info->has_user = true; @@ -471,8 +473,8 @@ void NodeDB::init() LOG_DEBUG("Number of Device Reboots: %d\n", myNodeInfo.reboot_count); #endif - resetRadioConfig(); // If bogus settings got saved, then fix them - LOG_DEBUG("region=%d, NODENUM=0x%x, dbsize=%d\n", config.lora.region, myNodeInfo.my_node_num, numMeshNodes); + nodeDB->resetRadioConfig(); // If bogus settings got saved, then fix them + // nodeDB->LOG_DEBUG("region=%d, NODENUM=0x%x, dbsize=%d\n", config.lora.region, myNodeInfo.my_node_num, numMeshNodes); if (devicestateCRC != crc32Buffer(&devicestate, sizeof(devicestate))) saveWhat |= SEGMENT_DEVICESTATE; @@ -491,7 +493,7 @@ void NodeDB::init() config.position.gps_enabled = 0; } - saveToDisk(saveWhat); + nodeDB->saveToDisk(saveWhat); } // We reserve a few nodenums for future use @@ -650,7 +652,7 @@ bool NodeDB::saveProto(const char *filename, size_t protoSize, const pb_msgdesc_ if (failedCounter >= 2) { FSCom.format(); // After formatting, the device needs to be restarted - nodeDB.resetRadioConfig(true); + nodeDB->resetRadioConfig(true); } #endif } @@ -676,7 +678,8 @@ void NodeDB::saveDeviceStateToDisk() #ifdef FSCom FSCom.mkdir("/prefs"); #endif - saveProto(prefFileName, sizeof(meshtastic_DeviceState), &meshtastic_DeviceState_msg, &devicestate); + saveProto(prefFileName, sizeof(meshtastic_DeviceState) + meshNodes.size() * meshtastic_NodeInfoLite_size, + &meshtastic_DeviceState_msg, &devicestate); } } diff --git a/src/mesh/NodeDB.h b/src/mesh/NodeDB.h index 4ade275f4a..362b28618b 100644 --- a/src/mesh/NodeDB.h +++ b/src/mesh/NodeDB.h @@ -59,7 +59,7 @@ class NodeDB NodeDB(); /// Called from service after app start, to do init which can only be done after OS load - void init(); + static NodeDB *init(); /// write to flash void saveToDisk(int saveWhat = SEGMENT_CONFIG | SEGMENT_MODULECONFIG | SEGMENT_DEVICESTATE | SEGMENT_CHANNELS), @@ -168,7 +168,7 @@ class NodeDB void installDefaultDeviceState(), installDefaultChannels(), installDefaultConfig(), installDefaultModuleConfig(); }; -extern NodeDB nodeDB; +extern NodeDB *nodeDB; /* If is_router is set, we use a number of different default values diff --git a/src/mesh/PhoneAPI.cpp b/src/mesh/PhoneAPI.cpp index e6b336d411..7267c768a3 100644 --- a/src/mesh/PhoneAPI.cpp +++ b/src/mesh/PhoneAPI.cpp @@ -420,7 +420,7 @@ bool PhoneAPI::available() case STATE_SEND_NODEINFO: if (nodeInfoForPhone.num == 0) { - auto nextNode = nodeDB.readNextMeshNode(readIndex); + auto nextNode = nodeDB->readNextMeshNode(readIndex); if (nextNode) { nodeInfoForPhone = TypeConversions::ConvertToNodeInfo(nextNode); } diff --git a/src/mesh/ProtobufModule.h b/src/mesh/ProtobufModule.h index d87bb47c34..1067ee01e9 100644 --- a/src/mesh/ProtobufModule.h +++ b/src/mesh/ProtobufModule.h @@ -56,7 +56,7 @@ template class ProtobufModule : protected SinglePortModule */ const char *getSenderShortName(const meshtastic_MeshPacket &mp) { - auto node = nodeDB.getMeshNode(getFrom(&mp)); + auto node = nodeDB->getMeshNode(getFrom(&mp)); const char *sender = (node) ? node->user.short_name : "???"; return sender; } diff --git a/src/mesh/RadioInterface.cpp b/src/mesh/RadioInterface.cpp index 7a27112519..859e7bea41 100644 --- a/src/mesh/RadioInterface.cpp +++ b/src/mesh/RadioInterface.cpp @@ -334,8 +334,8 @@ bool RadioInterface::init() notifyDeepSleepObserver.observe(¬ifyDeepSleep); // we now expect interfaces to operate in promiscuous mode - // radioIf.setThisAddress(nodeDB.getNodeNum()); // Note: we must do this here, because the nodenum isn't inited at constructor - // time. + // radioIf.setThisAddress(nodeDB->getNodeNum()); // Note: we must do this here, because the nodenum isn't inited at + // constructor time. applyModemConfig(); diff --git a/src/mesh/ReliableRouter.cpp b/src/mesh/ReliableRouter.cpp index 2327cbfb75..d3246b48d0 100644 --- a/src/mesh/ReliableRouter.cpp +++ b/src/mesh/ReliableRouter.cpp @@ -76,7 +76,7 @@ bool ReliableRouter::shouldFilterReceived(const meshtastic_MeshPacket *p) * Resending real ACKs is omitted, as you might receive a packet multiple times due to flooding and * flooding this ACK back to the original sender already adds redundancy. */ bool isRepeated = p->hop_start == 0 ? (p->hop_limit == HOP_RELIABLE) : (p->hop_start == p->hop_limit); - if (wasSeenRecently(p, false) && isRepeated && !MeshModule::currentReply && p->to != nodeDB.getNodeNum()) { + if (wasSeenRecently(p, false) && isRepeated && !MeshModule::currentReply && p->to != nodeDB->getNodeNum()) { LOG_DEBUG("Resending implicit ack for a repeated floodmsg\n"); meshtastic_MeshPacket *tosend = packetPool.allocCopy(*p); tosend->hop_limit--; // bump down the hop count diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index 7c739b8f28..7894b1b922 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -119,7 +119,7 @@ meshtastic_MeshPacket *Router::allocForSending() meshtastic_MeshPacket *p = packetPool.allocZeroed(); p->which_payload_variant = meshtastic_MeshPacket_decoded_tag; // Assume payload is decoded at start. - p->from = nodeDB.getNodeNum(); + p->from = nodeDB->getNodeNum(); p->to = NODENUM_BROADCAST; p->hop_limit = (config.lora.hop_limit >= HOP_MAX) ? HOP_MAX : config.lora.hop_limit; p->id = generatePacketId(); @@ -165,7 +165,7 @@ meshtastic_QueueStatus Router::getQueueStatus() ErrorCode Router::sendLocal(meshtastic_MeshPacket *p, RxSource src) { // No need to deliver externally if the destination is the local node - if (p->to == nodeDB.getNodeNum()) { + if (p->to == nodeDB->getNodeNum()) { printPacket("Enqueued local", p); enqueueReceivedMessage(p); return ERRNO_OK; @@ -182,7 +182,7 @@ ErrorCode Router::sendLocal(meshtastic_MeshPacket *p, RxSource src) } if (!p->channel) { // don't override if a channel was requested - p->channel = nodeDB.getMeshNodeChannel(p->to); + p->channel = nodeDB->getMeshNodeChannel(p->to); LOG_DEBUG("localSend to channel %d\n", p->channel); } @@ -205,7 +205,7 @@ void printBytes(const char *label, const uint8_t *p, size_t numbytes) */ ErrorCode Router::send(meshtastic_MeshPacket *p) { - if (p->to == nodeDB.getNodeNum()) { + if (p->to == nodeDB->getNodeNum()) { LOG_ERROR("BUG! send() called with packet destined for local node!\n"); packetPool.release(p); return meshtastic_Routing_Error_BAD_REQUEST; @@ -220,7 +220,7 @@ ErrorCode Router::send(meshtastic_MeshPacket *p) LOG_WARN("Duty cycle limit exceeded. Aborting send for now, you can send again in %d minutes.\n", silentMinutes); #endif meshtastic_Routing_Error err = meshtastic_Routing_Error_DUTY_CYCLE_LIMIT; - if (getFrom(p) == nodeDB.getNodeNum()) { // only send NAK to API, not to the mesh + if (getFrom(p) == nodeDB->getNodeNum()) { // only send NAK to API, not to the mesh abortSendAndNak(err, p); } else { packetPool.release(p); @@ -263,7 +263,7 @@ ErrorCode Router::send(meshtastic_MeshPacket *p) } // Only publish to MQTT if we're the original transmitter of the packet - if (moduleConfig.mqtt.enabled && p->from == nodeDB.getNodeNum() && mqtt) { + if (moduleConfig.mqtt.enabled && p->from == nodeDB->getNodeNum() && mqtt) { mqtt->onSend(*p, *p_decoded, chIndex); } packetPool.release(p_decoded); @@ -297,8 +297,8 @@ bool perhapsDecode(meshtastic_MeshPacket *p) return false; if (config.device.rebroadcast_mode == meshtastic_Config_DeviceConfig_RebroadcastMode_KNOWN_ONLY && - (nodeDB.getMeshNode(p->from) == NULL || !nodeDB.getMeshNode(p->from)->has_user)) { - LOG_DEBUG("Node 0x%x not in NodeDB. Rebroadcast mode KNOWN_ONLY will ignore packet\n", p->from); + (nodeDB->getMeshNode(p->from) == NULL || !nodeDB->getMeshNode(p->from)->has_user)) { + LOG_DEBUG("Node 0x%x not in nodeDB-> Rebroadcast mode KNOWN_ONLY will ignore packet\n", p->from); return false; } @@ -431,7 +431,7 @@ meshtastic_Routing_Error perhapsEncode(meshtastic_MeshPacket *p) NodeNum Router::getNodeNum() { - return nodeDB.getNodeNum(); + return nodeDB->getNodeNum(); } /** @@ -467,7 +467,7 @@ void Router::handleReceived(meshtastic_MeshPacket *p, RxSource src) } // Publish received message to MQTT if we're not the original transmitter of the packet - if (!skipHandle && moduleConfig.mqtt.enabled && getFrom(p) != nodeDB.getNodeNum() && mqtt) + if (!skipHandle && moduleConfig.mqtt.enabled && getFrom(p) != nodeDB->getNodeNum() && mqtt) mqtt->onSend(*p_encrypted, *p, p->channel); } else { printPacket("packet decoding failed or skipped (no PSK?)", p); diff --git a/src/mesh/SX128xInterface.cpp b/src/mesh/SX128xInterface.cpp index d0103ec291..f2220dbcf1 100644 --- a/src/mesh/SX128xInterface.cpp +++ b/src/mesh/SX128xInterface.cpp @@ -71,7 +71,7 @@ template bool SX128xInterface::init() if ((config.lora.region != meshtastic_Config_LoRaConfig_RegionCode_LORA_24) && (res == RADIOLIB_ERR_INVALID_FREQUENCY)) { LOG_WARN("Radio chip only supports 2.4GHz LoRa. Adjusting Region and rebooting.\n"); config.lora.region = meshtastic_Config_LoRaConfig_RegionCode_LORA_24; - nodeDB.saveToDisk(SEGMENT_CONFIG); + nodeDB->saveToDisk(SEGMENT_CONFIG); delay(2000); #if defined(ARCH_ESP32) ESP.restart(); @@ -251,9 +251,9 @@ template void SX128xInterface::startReceive() #endif // We use the PREAMBLE_DETECTED and HEADER_VALID IRQ flag to detect whether we are actively receiving - int err = lora.startReceive(RADIOLIB_SX128X_RX_TIMEOUT_INF, RADIOLIB_SX128X_IRQ_RX_DEFAULT | - RADIOLIB_SX128X_IRQ_PREAMBLE_DETECTED | - RADIOLIB_SX128X_IRQ_HEADER_VALID); + int err = + lora.startReceive(RADIOLIB_SX128X_RX_TIMEOUT_INF, RADIOLIB_SX128X_IRQ_RX_DEFAULT | RADIOLIB_SX128X_IRQ_PREAMBLE_DETECTED | + RADIOLIB_SX128X_IRQ_HEADER_VALID); assert(err == RADIOLIB_ERR_NONE); @@ -327,4 +327,4 @@ template bool SX128xInterface::sleep() #endif return true; -} +} \ No newline at end of file diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index 06818dc882..b363436f62 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -49,7 +49,7 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta // if handled == false, then let others look at this message also if they want bool handled = false; assert(r); - bool fromOthers = mp.from != 0 && mp.from != nodeDB.getNodeNum(); + bool fromOthers = mp.from != 0 && mp.from != nodeDB->getNodeNum(); switch (r->which_payload_variant) { @@ -149,13 +149,13 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta } case meshtastic_AdminMessage_factory_reset_tag: { LOG_INFO("Initiating factory reset\n"); - nodeDB.factoryReset(); + nodeDB->factoryReset(); reboot(DEFAULT_REBOOT_SECONDS); break; } case meshtastic_AdminMessage_nodedb_reset_tag: { LOG_INFO("Initiating node-db reset\n"); - nodeDB.resetNodes(); + nodeDB->resetNodes(); reboot(DEFAULT_REBOOT_SECONDS); break; } @@ -185,7 +185,7 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta } case meshtastic_AdminMessage_remove_by_nodenum_tag: { LOG_INFO("Client is receiving a remove_nodenum command.\n"); - nodeDB.removeNodeByNum(r->remove_by_nodenum); + nodeDB->removeNodeByNum(r->remove_by_nodenum); break; } case meshtastic_AdminMessage_enter_dfu_mode_request_tag: { @@ -301,7 +301,7 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c) config.device = c.payload_variant.device; // If we're setting router role for the first time, install its intervals if (existingRole != c.payload_variant.device.role) - nodeDB.installRoleDefaults(c.payload_variant.device.role); + nodeDB->installRoleDefaults(c.payload_variant.device.role); if (config.device.node_info_broadcast_secs < min_node_info_broadcast_secs) { LOG_DEBUG("Tried to set node_info_broadcast_secs too low, setting to %d\n", min_node_info_broadcast_secs); config.device.node_info_broadcast_secs = min_node_info_broadcast_secs; @@ -607,7 +607,7 @@ void AdminModule::handleGetNodeRemoteHardwarePins(const meshtastic_MeshPacket &r continue; } meshtastic_NodeRemoteHardwarePin nodePin = meshtastic_NodeRemoteHardwarePin_init_default; - nodePin.node_num = nodeDB.getNodeNum(); + nodePin.node_num = nodeDB->getNodeNum(); nodePin.pin = moduleConfig.remote_hardware.available_pins[i]; r.get_node_remote_hardware_pins_response.node_remote_hardware_pins[i + 12] = nodePin; } diff --git a/src/modules/CannedMessageModule.cpp b/src/modules/CannedMessageModule.cpp index b2b52d1ab3..3293e5d0d4 100644 --- a/src/modules/CannedMessageModule.cpp +++ b/src/modules/CannedMessageModule.cpp @@ -311,18 +311,18 @@ int32_t CannedMessageModule::runOnce() switch (this->payload) { case 0xb4: // left if (this->destSelect == CANNED_MESSAGE_DESTINATION_TYPE_NODE) { - size_t numMeshNodes = nodeDB.getNumMeshNodes(); + size_t numMeshNodes = nodeDB->getNumMeshNodes(); if (this->dest == NODENUM_BROADCAST) { - this->dest = nodeDB.getNodeNum(); + this->dest = nodeDB->getNodeNum(); } for (unsigned int i = 0; i < numMeshNodes; i++) { - if (nodeDB.getMeshNodeByIndex(i)->num == this->dest) { + if (nodeDB->getMeshNodeByIndex(i)->num == this->dest) { this->dest = - (i > 0) ? nodeDB.getMeshNodeByIndex(i - 1)->num : nodeDB.getMeshNodeByIndex(numMeshNodes - 1)->num; + (i > 0) ? nodeDB->getMeshNodeByIndex(i - 1)->num : nodeDB->getMeshNodeByIndex(numMeshNodes - 1)->num; break; } } - if (this->dest == nodeDB.getNodeNum()) { + if (this->dest == nodeDB->getNodeNum()) { this->dest = NODENUM_BROADCAST; } } else if (this->destSelect == CANNED_MESSAGE_DESTINATION_TYPE_CHANNEL) { @@ -346,18 +346,18 @@ int32_t CannedMessageModule::runOnce() break; case 0xb7: // right if (this->destSelect == CANNED_MESSAGE_DESTINATION_TYPE_NODE) { - size_t numMeshNodes = nodeDB.getNumMeshNodes(); + size_t numMeshNodes = nodeDB->getNumMeshNodes(); if (this->dest == NODENUM_BROADCAST) { - this->dest = nodeDB.getNodeNum(); + this->dest = nodeDB->getNodeNum(); } for (unsigned int i = 0; i < numMeshNodes; i++) { - if (nodeDB.getMeshNodeByIndex(i)->num == this->dest) { + if (nodeDB->getMeshNodeByIndex(i)->num == this->dest) { this->dest = - (i < numMeshNodes - 1) ? nodeDB.getMeshNodeByIndex(i + 1)->num : nodeDB.getMeshNodeByIndex(0)->num; + (i < numMeshNodes - 1) ? nodeDB->getMeshNodeByIndex(i + 1)->num : nodeDB->getMeshNodeByIndex(0)->num; break; } } - if (this->dest == nodeDB.getNodeNum()) { + if (this->dest == nodeDB->getNodeNum()) { this->dest = NODENUM_BROADCAST; } } else if (this->destSelect == CANNED_MESSAGE_DESTINATION_TYPE_CHANNEL) { @@ -462,7 +462,7 @@ const char *CannedMessageModule::getNodeName(NodeNum node) if (node == NODENUM_BROADCAST) { return "Broadcast"; } else { - meshtastic_NodeInfoLite *info = nodeDB.getMeshNode(node); + meshtastic_NodeInfoLite *info = nodeDB->getMeshNode(node); if (info != NULL) { return info->user.long_name; } else { @@ -618,9 +618,9 @@ ProcessMessage CannedMessageModule::handleReceived(const meshtastic_MeshPacket & void CannedMessageModule::loadProtoForModule() { - if (!nodeDB.loadProto(cannedMessagesConfigFile, meshtastic_CannedMessageModuleConfig_size, - sizeof(meshtastic_CannedMessageModuleConfig), &meshtastic_CannedMessageModuleConfig_msg, - &cannedMessageModuleConfig)) { + if (!nodeDB->loadProto(cannedMessagesConfigFile, meshtastic_CannedMessageModuleConfig_size, + sizeof(meshtastic_CannedMessageModuleConfig), &meshtastic_CannedMessageModuleConfig_msg, + &cannedMessageModuleConfig)) { installDefaultCannedMessageModuleConfig(); } } @@ -639,8 +639,8 @@ bool CannedMessageModule::saveProtoForModule() FS.mkdir("/prefs"); #endif - okay &= nodeDB.saveProto(cannedMessagesConfigFile, meshtastic_CannedMessageModuleConfig_size, - &meshtastic_CannedMessageModuleConfig_msg, &cannedMessageModuleConfig); + okay &= nodeDB->saveProto(cannedMessagesConfigFile, meshtastic_CannedMessageModuleConfig_size, + &meshtastic_CannedMessageModuleConfig_msg, &cannedMessageModuleConfig); return okay; } diff --git a/src/modules/ExternalNotificationModule.cpp b/src/modules/ExternalNotificationModule.cpp index 652965f6df..2a4fdd0aef 100644 --- a/src/modules/ExternalNotificationModule.cpp +++ b/src/modules/ExternalNotificationModule.cpp @@ -284,8 +284,8 @@ ExternalNotificationModule::ExternalNotificationModule() // moduleConfig.external_notification.alert_message_buzzer = true; if (moduleConfig.external_notification.enabled) { - if (!nodeDB.loadProto(rtttlConfigFile, meshtastic_RTTTLConfig_size, sizeof(meshtastic_RTTTLConfig), - &meshtastic_RTTTLConfig_msg, &rtttlConfig)) { + if (!nodeDB->loadProto(rtttlConfigFile, meshtastic_RTTTLConfig_size, sizeof(meshtastic_RTTTLConfig), + &meshtastic_RTTTLConfig_msg, &rtttlConfig)) { memset(rtttlConfig.ringtone, 0, sizeof(rtttlConfig.ringtone)); strncpy(rtttlConfig.ringtone, "24:d=32,o=5,b=565:f6,p,f6,4p,p,f6,p,f6,2p,p,b6,p,b6,p,b6,p,b6,p,b,p,b,p,b,p,b,p,b,p,b,p,b,p,b,1p.,2p.,p", @@ -343,7 +343,7 @@ ProcessMessage ExternalNotificationModule::handleReceived(const meshtastic_MeshP drv.setWaveform(2, 0); drv.go(); #endif - if (getFrom(&mp) != nodeDB.getNodeNum()) { + if (getFrom(&mp) != nodeDB->getNodeNum()) { // Check if the message contains a bell character. Don't do this loop for every pin, just once. auto &p = mp.decoded; bool containsBell = false; @@ -506,6 +506,6 @@ void ExternalNotificationModule::handleSetRingtone(const char *from_msg) } if (changed) { - nodeDB.saveProto(rtttlConfigFile, meshtastic_RTTTLConfig_size, &meshtastic_RTTTLConfig_msg, &rtttlConfig); + nodeDB->saveProto(rtttlConfigFile, meshtastic_RTTTLConfig_size, &meshtastic_RTTTLConfig_msg, &rtttlConfig); } } \ No newline at end of file diff --git a/src/modules/NeighborInfoModule.cpp b/src/modules/NeighborInfoModule.cpp index 2e0b04afa1..ec756b4bb7 100644 --- a/src/modules/NeighborInfoModule.cpp +++ b/src/modules/NeighborInfoModule.cpp @@ -16,7 +16,7 @@ NOTE: For debugging only void NeighborInfoModule::printNeighborInfo(const char *header, const meshtastic_NeighborInfo *np) { LOG_DEBUG("%s NEIGHBORINFO PACKET from Node 0x%x to Node 0x%x (last sent by 0x%x)\n", header, np->node_id, - nodeDB.getNodeNum(), np->last_sent_by_id); + nodeDB->getNodeNum(), np->last_sent_by_id); LOG_DEBUG("----------------\n"); LOG_DEBUG("Packet contains %d neighbors\n", np->neighbors_count); for (int i = 0; i < np->neighbors_count; i++) { @@ -30,12 +30,12 @@ NOTE: for debugging only */ void NeighborInfoModule::printNodeDBNodes(const char *header) { - int num_nodes = nodeDB.getNumMeshNodes(); - LOG_DEBUG("%s NODEDB SELECTION from Node 0x%x:\n", header, nodeDB.getNodeNum()); + int num_nodes = nodeDB->getNumMeshNodes(); + LOG_DEBUG("%s NODEDB SELECTION from Node 0x%x:\n", header, nodeDB->getNodeNum()); LOG_DEBUG("----------------\n"); LOG_DEBUG("DB contains %d nodes\n", num_nodes); for (int i = 0; i < num_nodes; i++) { - const meshtastic_NodeInfoLite *dbEntry = nodeDB.getMeshNodeByIndex(i); + const meshtastic_NodeInfoLite *dbEntry = nodeDB->getMeshNodeByIndex(i); LOG_DEBUG(" Node %d: node_id=0x%x, snr=%.2f\n", i, dbEntry->num, dbEntry->snr); } LOG_DEBUG("----------------\n"); @@ -48,7 +48,7 @@ NOTE: for debugging only void NeighborInfoModule::printNodeDBNeighbors(const char *header) { int num_neighbors = getNumNeighbors(); - LOG_DEBUG("%s NODEDB SELECTION from Node 0x%x:\n", header, nodeDB.getNodeNum()); + LOG_DEBUG("%s NODEDB SELECTION from Node 0x%x:\n", header, nodeDB->getNodeNum()); LOG_DEBUG("----------------\n"); LOG_DEBUG("DB contains %d neighbors\n", num_neighbors); for (int i = 0; i < num_neighbors; i++) { @@ -66,7 +66,7 @@ NOTE: For debugging only void NeighborInfoModule::printNodeDBSelection(const char *header, const meshtastic_NeighborInfo *np) { int num_neighbors = getNumNeighbors(); - LOG_DEBUG("%s NODEDB SELECTION from Node 0x%x:\n", header, nodeDB.getNodeNum()); + LOG_DEBUG("%s NODEDB SELECTION from Node 0x%x:\n", header, nodeDB->getNodeNum()); LOG_DEBUG("----------------\n"); LOG_DEBUG("Selected %d neighbors of %d DB neighbors\n", np->neighbors_count, num_neighbors); for (int i = 0; i < num_neighbors; i++) { @@ -111,7 +111,7 @@ Assumes that the neighborInfo packet has been allocated */ uint32_t NeighborInfoModule::collectNeighborInfo(meshtastic_NeighborInfo *neighborInfo) { - uint my_node_id = nodeDB.getNodeNum(); + uint my_node_id = nodeDB->getNodeNum(); neighborInfo->node_id = my_node_id; neighborInfo->last_sent_by_id = my_node_id; neighborInfo->node_broadcast_interval_secs = moduleConfig.neighbor_info.update_interval; @@ -142,7 +142,7 @@ size_t NeighborInfoModule::cleanUpNeighbors() { uint32_t now = getTime(); int num_neighbors = getNumNeighbors(); - NodeNum my_node_id = nodeDB.getNodeNum(); + NodeNum my_node_id = nodeDB->getNodeNum(); // Find neighbors to remove std::vector indices_to_remove; @@ -226,7 +226,7 @@ void NeighborInfoModule::updateLastSentById(meshtastic_MeshPacket *p) pb_decode_from_bytes(incoming.payload.bytes, incoming.payload.size, &meshtastic_NeighborInfo_msg, &scratch); updated = &scratch; - updated->last_sent_by_id = nodeDB.getNodeNum(); + updated->last_sent_by_id = nodeDB->getNodeNum(); // Set updated last_sent_by_id to the payload of the to be flooded packet p->decoded.payload.size = @@ -255,7 +255,7 @@ meshtastic_Neighbor *NeighborInfoModule::getOrCreateNeighbor(NodeNum originalSen { // our node and the phone are the same node (not neighbors) if (n == 0) { - n = nodeDB.getNodeNum(); + n = nodeDB->getNodeNum(); } // look for one in the existing list for (int i = 0; i < (*numNeighbors); i++) { @@ -291,8 +291,8 @@ meshtastic_Neighbor *NeighborInfoModule::getOrCreateNeighbor(NodeNum originalSen void NeighborInfoModule::loadProtoForModule() { - if (!nodeDB.loadProto(neighborInfoConfigFile, meshtastic_NeighborInfo_size, sizeof(meshtastic_NeighborInfo), - &meshtastic_NeighborInfo_msg, &neighborState)) { + if (!nodeDB->loadProto(neighborInfoConfigFile, meshtastic_NeighborInfo_size, sizeof(meshtastic_NeighborInfo), + &meshtastic_NeighborInfo_msg, &neighborState)) { neighborState = meshtastic_NeighborInfo_init_zero; } } @@ -311,7 +311,7 @@ bool NeighborInfoModule::saveProtoForModule() FS.mkdir("/prefs"); #endif - okay &= nodeDB.saveProto(neighborInfoConfigFile, meshtastic_NeighborInfo_size, &meshtastic_NeighborInfo_msg, &neighborState); + okay &= nodeDB->saveProto(neighborInfoConfigFile, meshtastic_NeighborInfo_size, &meshtastic_NeighborInfo_msg, &neighborState); return okay; } \ No newline at end of file diff --git a/src/modules/NodeInfoModule.cpp b/src/modules/NodeInfoModule.cpp index 5177af33a8..6aa28d5791 100644 --- a/src/modules/NodeInfoModule.cpp +++ b/src/modules/NodeInfoModule.cpp @@ -12,7 +12,7 @@ bool NodeInfoModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, mes { auto p = *pptr; - bool hasChanged = nodeDB.updateUser(getFrom(&mp), p, mp.channel); + bool hasChanged = nodeDB->updateUser(getFrom(&mp), p, mp.channel); bool wasBroadcast = mp.to == NODENUM_BROADCAST; @@ -24,7 +24,7 @@ bool NodeInfoModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, mes } // if user has changed while packet was not for us, inform phone - if (hasChanged && !wasBroadcast && mp.to != nodeDB.getNodeNum()) + if (hasChanged && !wasBroadcast && mp.to != nodeDB->getNodeNum()) service.sendToPhone(packetPool.allocCopy(mp)); // LOG_DEBUG("did handleReceived\n"); @@ -92,4 +92,4 @@ int32_t NodeInfoModule::runOnce() sendOurNodeInfo(NODENUM_BROADCAST, requestReplies); // Send our info (don't request replies) } return getConfiguredOrDefaultMs(config.device.node_info_broadcast_secs, default_node_info_broadcast_secs); -} +} \ No newline at end of file diff --git a/src/modules/PositionModule.cpp b/src/modules/PositionModule.cpp index 59f62bd5c3..8f677315d9 100644 --- a/src/modules/PositionModule.cpp +++ b/src/modules/PositionModule.cpp @@ -40,12 +40,12 @@ PositionModule::PositionModule() void PositionModule::clearPosition() { LOG_DEBUG("Clearing position on startup for sleepy tracker (ー。ー) zzz\n"); - meshtastic_NodeInfoLite *node = nodeDB.getMeshNode(nodeDB.getNodeNum()); + 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); + nodeDB->setLocalPosition(meshtastic_Position_init_default); } bool PositionModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Position *pptr) @@ -58,15 +58,15 @@ bool PositionModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, mes // FIXME this can in fact happen with packets sent from EUD (src=RX_SRC_USER) // to set fixed location, EUD-GPS location or just the time (see also issue #900) bool isLocal = false; - if (nodeDB.getNodeNum() == getFrom(&mp)) { + if (nodeDB->getNodeNum() == getFrom(&mp)) { isLocal = true; if (config.position.fixed_position) { LOG_DEBUG("Ignore incoming position update from myself except for time, because position.fixed_position is true\n"); - nodeDB.setLocalPosition(p, true); + nodeDB->setLocalPosition(p, true); return false; } else { LOG_DEBUG("Incoming update from MYSELF\n"); - nodeDB.setLocalPosition(p); + nodeDB->setLocalPosition(p); } } @@ -88,7 +88,7 @@ bool PositionModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, mes perhapsSetRTC(isLocal ? RTCQualityNTP : RTCQualityFromNet, &tv); } - nodeDB.updatePosition(getFrom(&mp), p); + nodeDB->updatePosition(getFrom(&mp), p); if (channels.getByIndex(mp.channel).settings.has_module_settings) { precision = channels.getByIndex(mp.channel).settings.module_settings.position_precision; } else if (channels.getByIndex(mp.channel).role == meshtastic_Channel_Role_PRIMARY) { @@ -118,7 +118,7 @@ meshtastic_MeshPacket *PositionModule::allocReply() meshtastic_Position p = meshtastic_Position_init_default; // Start with an empty structure // if localPosition is totally empty, put our last saved position (lite) in there if (localPosition.latitude_i == 0 && localPosition.longitude_i == 0) { - nodeDB.setLocalPosition(TypeConversions::ConvertToPosition(node->position)); + nodeDB->setLocalPosition(TypeConversions::ConvertToPosition(node->position)); } localPosition.seq_number++; @@ -285,7 +285,7 @@ int32_t PositionModule::runOnce() doDeepSleep(nightyNightMs, false); } - meshtastic_NodeInfoLite *node = nodeDB.getMeshNode(nodeDB.getNodeNum()); + meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(nodeDB->getNodeNum()); if (node == nullptr) return RUNONCE_INTERVAL; @@ -399,7 +399,7 @@ struct SmartPosition PositionModule::getDistanceTraveledSinceLastSend(meshtastic void PositionModule::handleNewPosition() { - meshtastic_NodeInfoLite *node = nodeDB.getMeshNode(nodeDB.getNodeNum()); + meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(nodeDB->getNodeNum()); const meshtastic_NodeInfoLite *node2 = service.refreshLocalMeshNode(); // should guarantee there is now a position // We limit our GPS broadcasts to a max rate uint32_t now = millis(); diff --git a/src/modules/RangeTestModule.cpp b/src/modules/RangeTestModule.cpp index 904fb25db3..a66a0513ea 100644 --- a/src/modules/RangeTestModule.cpp +++ b/src/modules/RangeTestModule.cpp @@ -142,14 +142,14 @@ ProcessMessage RangeTestModuleRadio::handleReceived(const meshtastic_MeshPacket LOG_INFO.getNodeNum(), mp.from, mp.to, mp.id, p.payload.size, p.payload.bytes); */ - if (getFrom(&mp) != nodeDB.getNodeNum()) { + if (getFrom(&mp) != nodeDB->getNodeNum()) { if (moduleConfig.range_test.save) { appendFile(mp); } /* - NodeInfoLite *n = nodeDB.getMeshNode(getFrom(&mp)); + NodeInfoLite *n = nodeDB->getMeshNode(getFrom(&mp)); LOG_DEBUG("-----------------------------------------\n"); LOG_DEBUG("p.payload.bytes \"%s\"\n", p.payload.bytes); @@ -188,7 +188,7 @@ bool RangeTestModuleRadio::appendFile(const meshtastic_MeshPacket &mp) #ifdef ARCH_ESP32 auto &p = mp.decoded; - meshtastic_NodeInfoLite *n = nodeDB.getMeshNode(getFrom(&mp)); + meshtastic_NodeInfoLite *n = nodeDB->getMeshNode(getFrom(&mp)); /* LOG_DEBUG("-----------------------------------------\n"); LOG_DEBUG("p.payload.bytes \"%s\"\n", p.payload.bytes); @@ -295,4 +295,4 @@ bool RangeTestModuleRadio::appendFile(const meshtastic_MeshPacket &mp) #endif return 1; -} +} \ No newline at end of file diff --git a/src/modules/RoutingModule.cpp b/src/modules/RoutingModule.cpp index 37a7c37551..a52328ca49 100644 --- a/src/modules/RoutingModule.cpp +++ b/src/modules/RoutingModule.cpp @@ -14,7 +14,7 @@ bool RoutingModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, mesh // FIXME - move this to a non promsicious PhoneAPI module? // Note: we are careful not to send back packets that started with the phone back to the phone - if ((mp.to == NODENUM_BROADCAST || mp.to == nodeDB.getNodeNum()) && (mp.from != 0)) { + if ((mp.to == NODENUM_BROADCAST || mp.to == nodeDB->getNodeNum()) && (mp.from != 0)) { printPacket("Delivering rx packet", &mp); service.handleFromRadio(&mp); } @@ -63,4 +63,4 @@ RoutingModule::RoutingModule() : ProtobufModule("routing", meshtastic_PortNum_RO isPromiscuous = true; encryptedOk = config.device.rebroadcast_mode != meshtastic_Config_DeviceConfig_RebroadcastMode_LOCAL_ONLY && config.device.rebroadcast_mode != meshtastic_Config_DeviceConfig_RebroadcastMode_KNOWN_ONLY; -} +} \ No newline at end of file diff --git a/src/modules/SerialModule.cpp b/src/modules/SerialModule.cpp index 1dee42a8d2..663bc1d86c 100644 --- a/src/modules/SerialModule.cpp +++ b/src/modules/SerialModule.cpp @@ -190,11 +190,11 @@ int32_t SerialModule::runOnce() if (millis() - lastNmeaTime > 10000) { lastNmeaTime = millis(); uint32_t readIndex = 0; - const meshtastic_NodeInfoLite *tempNodeInfo = nodeDB.readNextMeshNode(readIndex); + const meshtastic_NodeInfoLite *tempNodeInfo = nodeDB->readNextMeshNode(readIndex); while (tempNodeInfo != NULL && tempNodeInfo->has_user && hasValidPosition(tempNodeInfo)) { printWPL(outbuf, sizeof(outbuf), tempNodeInfo->position, tempNodeInfo->user.long_name, true); serialPrint->printf("%s", outbuf); - tempNodeInfo = nodeDB.readNextMeshNode(readIndex); + tempNodeInfo = nodeDB->readNextMeshNode(readIndex); } } } @@ -265,9 +265,9 @@ ProcessMessage SerialModuleRadio::handleReceived(const meshtastic_MeshPacket &mp auto &p = mp.decoded; // LOG_DEBUG("Received text msg self=0x%0x, from=0x%0x, to=0x%0x, id=%d, msg=%.*s\n", - // nodeDB.getNodeNum(), mp.from, mp.to, mp.id, p.payload.size, p.payload.bytes); + // nodeDB->getNodeNum(), mp.from, mp.to, mp.id, p.payload.size, p.payload.bytes); - if (getFrom(&mp) == nodeDB.getNodeNum()) { + if (getFrom(&mp) == nodeDB->getNodeNum()) { /* * If moduleConfig.serial.echo is true, then echo the packets that are sent out @@ -290,7 +290,7 @@ ProcessMessage SerialModuleRadio::handleReceived(const meshtastic_MeshPacket &mp moduleConfig.serial.mode == meshtastic_ModuleConfig_SerialConfig_Serial_Mode_SIMPLE) { serialPrint->write(p.payload.bytes, p.payload.size); } else if (moduleConfig.serial.mode == meshtastic_ModuleConfig_SerialConfig_Serial_Mode_TEXTMSG) { - meshtastic_NodeInfoLite *node = nodeDB.getMeshNode(getFrom(&mp)); + meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(getFrom(&mp)); String sender = (node && node->has_user) ? node->user.short_name : "???"; serialPrint->println(); serialPrint->printf("%s: %s", sender, p.payload.bytes); @@ -306,7 +306,7 @@ ProcessMessage SerialModuleRadio::handleReceived(const meshtastic_MeshPacket &mp decoded = &scratch; } // send position packet as WPL to the serial port - printWPL(outbuf, sizeof(outbuf), *decoded, nodeDB.getMeshNode(getFrom(&mp))->user.long_name, + printWPL(outbuf, sizeof(outbuf), *decoded, nodeDB->getMeshNode(getFrom(&mp))->user.long_name, moduleConfig.serial.mode == meshtastic_ModuleConfig_SerialConfig_Serial_Mode_CALTOPO); serialPrint->printf("%s", outbuf); } diff --git a/src/modules/Telemetry/DeviceTelemetry.cpp b/src/modules/Telemetry/DeviceTelemetry.cpp index 55000e4c6c..7b1f69cacd 100644 --- a/src/modules/Telemetry/DeviceTelemetry.cpp +++ b/src/modules/Telemetry/DeviceTelemetry.cpp @@ -44,7 +44,7 @@ bool DeviceTelemetryModule::handleReceivedProtobuf(const meshtastic_MeshPacket & t->variant.device_metrics.air_util_tx, t->variant.device_metrics.channel_utilization, t->variant.device_metrics.battery_level, t->variant.device_metrics.voltage); #endif - nodeDB.updateTelemetry(getFrom(&mp), *t, RX_SRC_RADIO); + nodeDB->updateTelemetry(getFrom(&mp), *t, RX_SRC_RADIO); } return false; // Let others look at this message also if they want } @@ -93,7 +93,7 @@ bool DeviceTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly) p->decoded.want_response = false; p->priority = meshtastic_MeshPacket_Priority_BACKGROUND; - nodeDB.updateTelemetry(nodeDB.getNodeNum(), telemetry, RX_SRC_LOCAL); + nodeDB->updateTelemetry(nodeDB->getNodeNum(), telemetry, RX_SRC_LOCAL); if (phoneOnly) { LOG_INFO("Sending packet to phone\n"); service.sendToPhone(p); diff --git a/src/modules/esp32/AudioModule.cpp b/src/modules/esp32/AudioModule.cpp index a10cae9541..130654fa9f 100644 --- a/src/modules/esp32/AudioModule.cpp +++ b/src/modules/esp32/AudioModule.cpp @@ -1,12 +1,11 @@ - #include "configuration.h" #if defined(ARCH_ESP32) && defined(USE_SX1280) #include "AudioModule.h" #include "FSCommon.h" #include "MeshService.h" -#include "NodeDB.h" #include "RTC.h" #include "Router.h" +#include "nodeDB->h" /* AudioModule @@ -274,7 +273,7 @@ ProcessMessage AudioModule::handleReceived(const meshtastic_MeshPacket &mp) { if ((moduleConfig.audio.codec2_enabled) && (myRegion->audioPermitted)) { auto &p = mp.decoded; - if (getFrom(&mp) != nodeDB.getNodeNum()) { + if (getFrom(&mp) != nodeDB->getNodeNum()) { memcpy(rx_encode_frame, p.payload.bytes, p.payload.size); radio_state = RadioState::rx; rx_encode_frame_index = p.payload.size; diff --git a/src/modules/esp32/StoreForwardModule.cpp b/src/modules/esp32/StoreForwardModule.cpp index 71d75750a5..a60065e569 100644 --- a/src/modules/esp32/StoreForwardModule.cpp +++ b/src/modules/esp32/StoreForwardModule.cpp @@ -320,11 +320,11 @@ ProcessMessage StoreForwardModule::handleReceived(const meshtastic_MeshPacket &m if (moduleConfig.store_forward.enabled) { // The router node should not be sending messages as a client. Unless he is a ROUTER_CLIENT - if ((getFrom(&mp) != nodeDB.getNodeNum()) || (config.device.role == meshtastic_Config_DeviceConfig_Role_ROUTER_CLIENT)) { + if ((getFrom(&mp) != nodeDB->getNodeNum()) || (config.device.role == meshtastic_Config_DeviceConfig_Role_ROUTER_CLIENT)) { if ((mp.decoded.portnum == meshtastic_PortNum_TEXT_MESSAGE_APP) && is_server) { auto &p = mp.decoded; - if (mp.to == nodeDB.getNodeNum() && (p.payload.bytes[0] == 'S') && (p.payload.bytes[1] == 'F') && + if (mp.to == nodeDB->getNodeNum() && (p.payload.bytes[0] == 'S') && (p.payload.bytes[1] == 'F') && (p.payload.bytes[2] == 0x00)) { LOG_DEBUG("*** Legacy Request to send\n"); diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index 0d99a3cfdc..2243aaf8a5 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -134,7 +134,7 @@ void MQTT::onReceive(char *topic, byte *payload, size_t length) // Generate an implicit ACK towards ourselves (handled and processed only locally!) for this message. // We do this because packets are not rebroadcasted back into MQTT anymore and we assume that at least one node // receives it when we get our own packet back. Then we'll stop our retransmissions. - if (e.packet && getFrom(e.packet) == nodeDB.getNodeNum()) + if (e.packet && getFrom(e.packet) == nodeDB->getNodeNum()) routingModule->sendAckNak(meshtastic_Routing_Error_NONE, getFrom(e.packet), e.packet->id, ch.index); else LOG_INFO("Ignoring downlink message we originally sent.\n"); @@ -555,7 +555,7 @@ void MQTT::perhapsReportToMap() // Allocate MeshPacket and fill it meshtastic_MeshPacket *mp = packetPool.allocZeroed(); mp->which_payload_variant = meshtastic_MeshPacket_decoded_tag; - mp->from = nodeDB.getNodeNum(); + mp->from = nodeDB->getNodeNum(); mp->to = NODENUM_BROADCAST; mp->decoded.portnum = meshtastic_PortNum_MAP_REPORT_APP; @@ -583,7 +583,7 @@ void MQTT::perhapsReportToMap() mapReport.altitude = localPosition.altitude; mapReport.position_precision = map_position_precision; - mapReport.num_online_local_nodes = nodeDB.getNumOnlineMeshNodes(true); + mapReport.num_online_local_nodes = nodeDB->getNumOnlineMeshNodes(true); // Encode MapReport message and set it to MeshPacket in ServiceEnvelope mp->decoded.payload.size = pb_encode_to_bytes(mp->decoded.payload.bytes, sizeof(mp->decoded.payload.bytes), @@ -793,7 +793,7 @@ std::string MQTT::meshPacketToJson(meshtastic_MeshPacket *mp) // Lambda function for adding a long name to the route auto addToRoute = [](JSONArray *route, NodeNum num) { char long_name[40] = "Unknown"; - meshtastic_NodeInfoLite *node = nodeDB.getMeshNode(num); + meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(num); bool name_known = node ? node->has_user : false; if (name_known) memcpy(long_name, node->user.long_name, sizeof(long_name)); @@ -899,7 +899,7 @@ bool MQTT::isValidJsonEnvelope(JSONObject &json) // if "sender" is provided, avoid processing packets we uplinked return (json.find("sender") != json.end() ? (json["sender"]->AsString().compare(owner.id) != 0) : true) && (json.find("from") != json.end()) && json["from"]->IsNumber() && - (json["from"]->AsNumber() == nodeDB.getNodeNum()) && // only accept message if the "from" is us + (json["from"]->AsNumber() == nodeDB->getNodeNum()) && // only accept message if the "from" is us (json.find("type") != json.end()) && json["type"]->IsString() && // should specify a type (json.find("payload") != json.end()); // should have a payload } \ No newline at end of file diff --git a/src/platform/portduino/PortduinoGlue.cpp b/src/platform/portduino/PortduinoGlue.cpp index ee8bf21e99..7f299ce38a 100644 --- a/src/platform/portduino/PortduinoGlue.cpp +++ b/src/platform/portduino/PortduinoGlue.cpp @@ -199,9 +199,9 @@ void portduinoSetup() settingsMap[webserverport] = (yamlConfig["Webserver"]["Port"]).as(-1); settingsStrings[webserverrootpath] = (yamlConfig["Webserver"]["RootPath"]).as(""); } - if (yamlConfig["General"]) { - settingsMap[maxnodes] = (yamlConfig["General"]["MaxNodes"]).as(MAX_NUM_NODES); - } + // if (yamlConfig["General"]) { + settingsMap[maxnodes] = (yamlConfig["General"]["MaxNodes"]).as(150); + //} } catch (YAML::Exception e) { std::cout << "*** Exception " << e.what() << std::endl; diff --git a/src/sleep.cpp b/src/sleep.cpp index 6d8e4f3cc3..f170e2ab7c 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -198,7 +198,7 @@ void doDeepSleep(uint32_t msecToWake, bool skipPreflight = false) screen->doDeepSleep(); // datasheet says this will draw only 10ua - nodeDB.saveToDisk(); + nodeDB->saveToDisk(); #ifdef TTGO_T_ECHO #ifdef PIN_POWER_EN From 308f03b2702e1dc311fbdf7ba58a98398ec1eca4 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Mon, 18 Mar 2024 19:32:44 -0500 Subject: [PATCH 04/11] Closer but still broken. --- src/mesh/NodeDB.cpp | 30 ++++++++++--------- .../{apponly.pb.c => apponly.pb.cpp} | 0 .../meshtastic/{atak.pb.c => atak.pb.cpp} | 0 ...nedmessages.pb.c => cannedmessages.pb.cpp} | 0 .../{clientonly.pb.c => clientonly.pb.cpp} | 0 .../meshtastic/{config.pb.c => config.pb.cpp} | 0 ...n_status.pb.c => connection_status.pb.cpp} | 0 src/mesh/generated/meshtastic/deviceonly.pb.h | 13 ++++---- .../{localonly.pb.c => localonly.pb.cpp} | 0 .../meshtastic/{mesh.pb.c => mesh.pb.cpp} | 0 ...odule_config.pb.c => module_config.pb.cpp} | 0 .../meshtastic/{mqtt.pb.c => mqtt.pb.cpp} | 0 .../{paxcount.pb.c => paxcount.pb.cpp} | 0 .../{portnums.pb.c => portnums.pb.cpp} | 0 ...e_hardware.pb.c => remote_hardware.pb.cpp} | 0 .../meshtastic/{rtttl.pb.c => rtttl.pb.cpp} | 0 ...{storeforward.pb.c => storeforward.pb.cpp} | 0 .../{telemetry.pb.c => telemetry.pb.cpp} | 0 .../meshtastic/{xmodem.pb.c => xmodem.pb.cpp} | 0 19 files changed, 23 insertions(+), 20 deletions(-) rename src/mesh/generated/meshtastic/{apponly.pb.c => apponly.pb.cpp} (100%) rename src/mesh/generated/meshtastic/{atak.pb.c => atak.pb.cpp} (100%) rename src/mesh/generated/meshtastic/{cannedmessages.pb.c => cannedmessages.pb.cpp} (100%) rename src/mesh/generated/meshtastic/{clientonly.pb.c => clientonly.pb.cpp} (100%) rename src/mesh/generated/meshtastic/{config.pb.c => config.pb.cpp} (100%) rename src/mesh/generated/meshtastic/{connection_status.pb.c => connection_status.pb.cpp} (100%) rename src/mesh/generated/meshtastic/{localonly.pb.c => localonly.pb.cpp} (100%) rename src/mesh/generated/meshtastic/{mesh.pb.c => mesh.pb.cpp} (100%) rename src/mesh/generated/meshtastic/{module_config.pb.c => module_config.pb.cpp} (100%) rename src/mesh/generated/meshtastic/{mqtt.pb.c => mqtt.pb.cpp} (100%) rename src/mesh/generated/meshtastic/{paxcount.pb.c => paxcount.pb.cpp} (100%) rename src/mesh/generated/meshtastic/{portnums.pb.c => portnums.pb.cpp} (100%) rename src/mesh/generated/meshtastic/{remote_hardware.pb.c => remote_hardware.pb.cpp} (100%) rename src/mesh/generated/meshtastic/{rtttl.pb.c => rtttl.pb.cpp} (100%) rename src/mesh/generated/meshtastic/{storeforward.pb.c => storeforward.pb.cpp} (100%) rename src/mesh/generated/meshtastic/{telemetry.pb.c => telemetry.pb.cpp} (100%) rename src/mesh/generated/meshtastic/{xmodem.pb.c => xmodem.pb.cpp} (100%) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 6de2afe183..8fb03055ce 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -81,12 +81,13 @@ uint32_t error_address = 0; static uint8_t ourMacAddr[6]; -NodeDB::NodeDB() : meshNodes(devicestate.node_db_lite), numMeshNodes(devicestate.node_db_lite.size()) +NodeDB::NodeDB() : meshNodes(devicestate.node_db_lite) { - std::cout << "test" << std::endl; + std::cout << "test " << numMeshNodes << std::endl; std::cout << MAX_NUM_NODES << std::endl; meshNodes.reserve(MAX_NUM_NODES); - std::cout << "vector size" << meshNodes.size() << std::endl; + std::cout << "vector size " << meshNodes.size() << std::endl; + numMeshNodes = devicestate.node_db_lite_count; } /** @@ -378,8 +379,8 @@ void NodeDB::installDefaultChannels() void NodeDB::resetNodes() { - // devicestate.node_db_lite_count = 1; - std::fill(devicestate.node_db_lite.begin(), devicestate.node_db_lite.end(), meshtastic_NodeInfoLite()); + numMeshNodes = 1; + std::fill(devicestate.node_db_lite.begin() + 1, devicestate.node_db_lite.end(), meshtastic_NodeInfoLite()); saveDeviceStateToDisk(); if (neighborInfoModule && moduleConfig.neighbor_info.enabled) neighborInfoModule->resetNeighbors(); @@ -415,7 +416,7 @@ void NodeDB::cleanupMeshDB() void NodeDB::installDefaultDeviceState() { LOG_INFO("Installing default DeviceState\n"); - memset(&devicestate, 0, sizeof(meshtastic_DeviceState)); + // memset(&devicestate, 0, sizeof(meshtastic_DeviceState)); numMeshNodes = 0; @@ -439,9 +440,9 @@ void NodeDB::installDefaultDeviceState() NodeDB *NodeDB::init() { LOG_INFO("Initializing NodeDB\n"); - NodeDB *nodeDB = new NodeDB; - nodeDB->loadFromDisk(); - nodeDB->cleanupMeshDB(); + NodeDB *newnodeDB = new NodeDB; + newnodeDB->loadFromDisk(); + newnodeDB->cleanupMeshDB(); uint32_t devicestateCRC = crc32Buffer(&devicestate, sizeof(devicestate)); uint32_t configCRC = crc32Buffer(&config, sizeof(config)); @@ -453,7 +454,7 @@ NodeDB *NodeDB::init() myNodeInfo.min_app_version = 30200; // format is Mmmss (where M is 1+the numeric major number. i.e. 30200 means 2.2.00 // Note! We do this after loading saved settings, so that if somehow an invalid nodenum was stored in preferences we won't // keep using that nodenum forever. Crummy guess at our nodenum (but we will check against the nodedb to avoid conflicts) - nodeDB->pickNewNodeNum(); + newnodeDB->pickNewNodeNum(); // Set our board type so we can share it with others owner.hw_model = HW_VENDOR; @@ -461,7 +462,7 @@ NodeDB *NodeDB::init() owner.role = config.device.role; // Include our owner in the node db under our nodenum - meshtastic_NodeInfoLite *info = nodeDB->getOrCreateMeshNode(nodeDB->getNodeNum()); + meshtastic_NodeInfoLite *info = newnodeDB->getOrCreateMeshNode(newnodeDB->getNodeNum()); info->user = owner; info->has_user = true; @@ -473,7 +474,7 @@ NodeDB *NodeDB::init() LOG_DEBUG("Number of Device Reboots: %d\n", myNodeInfo.reboot_count); #endif - nodeDB->resetRadioConfig(); // If bogus settings got saved, then fix them + newnodeDB->resetRadioConfig(); // If bogus settings got saved, then fix them // nodeDB->LOG_DEBUG("region=%d, NODENUM=0x%x, dbsize=%d\n", config.lora.region, myNodeInfo.my_node_num, numMeshNodes); if (devicestateCRC != crc32Buffer(&devicestate, sizeof(devicestate))) @@ -492,6 +493,7 @@ NodeDB *NodeDB::init() config.position.gps_mode = meshtastic_Config_PositionConfig_GpsMode_ENABLED; config.position.gps_enabled = 0; } + return newnodeDB; nodeDB->saveToDisk(saveWhat); } @@ -678,8 +680,8 @@ void NodeDB::saveDeviceStateToDisk() #ifdef FSCom FSCom.mkdir("/prefs"); #endif - saveProto(prefFileName, sizeof(meshtastic_DeviceState) + meshNodes.size() * meshtastic_NodeInfoLite_size, - &meshtastic_DeviceState_msg, &devicestate); + saveProto(prefFileName, sizeof(devicestate) + numMeshNodes * meshtastic_NodeInfoLite_size, &meshtastic_DeviceState_msg, + &devicestate); } } diff --git a/src/mesh/generated/meshtastic/apponly.pb.c b/src/mesh/generated/meshtastic/apponly.pb.cpp similarity index 100% rename from src/mesh/generated/meshtastic/apponly.pb.c rename to src/mesh/generated/meshtastic/apponly.pb.cpp diff --git a/src/mesh/generated/meshtastic/atak.pb.c b/src/mesh/generated/meshtastic/atak.pb.cpp similarity index 100% rename from src/mesh/generated/meshtastic/atak.pb.c rename to src/mesh/generated/meshtastic/atak.pb.cpp diff --git a/src/mesh/generated/meshtastic/cannedmessages.pb.c b/src/mesh/generated/meshtastic/cannedmessages.pb.cpp similarity index 100% rename from src/mesh/generated/meshtastic/cannedmessages.pb.c rename to src/mesh/generated/meshtastic/cannedmessages.pb.cpp diff --git a/src/mesh/generated/meshtastic/clientonly.pb.c b/src/mesh/generated/meshtastic/clientonly.pb.cpp similarity index 100% rename from src/mesh/generated/meshtastic/clientonly.pb.c rename to src/mesh/generated/meshtastic/clientonly.pb.cpp diff --git a/src/mesh/generated/meshtastic/config.pb.c b/src/mesh/generated/meshtastic/config.pb.cpp similarity index 100% rename from src/mesh/generated/meshtastic/config.pb.c rename to src/mesh/generated/meshtastic/config.pb.cpp diff --git a/src/mesh/generated/meshtastic/connection_status.pb.c b/src/mesh/generated/meshtastic/connection_status.pb.cpp similarity index 100% rename from src/mesh/generated/meshtastic/connection_status.pb.c rename to src/mesh/generated/meshtastic/connection_status.pb.cpp diff --git a/src/mesh/generated/meshtastic/deviceonly.pb.h b/src/mesh/generated/meshtastic/deviceonly.pb.h index 87045c313e..27acbea67a 100644 --- a/src/mesh/generated/meshtastic/deviceonly.pb.h +++ b/src/mesh/generated/meshtastic/deviceonly.pb.h @@ -4,9 +4,7 @@ #ifndef PB_MESHTASTIC_MESHTASTIC_DEVICEONLY_PB_H_INCLUDED #define PB_MESHTASTIC_MESHTASTIC_DEVICEONLY_PB_H_INCLUDED #include - #include - #include "meshtastic/channel.pb.h" #include "meshtastic/localonly.pb.h" #include "meshtastic/mesh.pb.h" @@ -158,6 +156,7 @@ typedef struct _meshtastic_DeviceState { meshtastic_NodeRemoteHardwarePin node_remote_hardware_pins[12]; /* New lite version of NodeDB to decrease memory footprint */ std::vector node_db_lite; + uint32_t node_db_lite_count; } meshtastic_DeviceState; @@ -180,13 +179,13 @@ extern "C" { /* Initializer values for message structs */ -#define meshtastic_DeviceState_init_default {false, meshtastic_MyNodeInfo_init_default, false, meshtastic_User_init_default, 0, {meshtastic_MeshPacket_init_default}, false, meshtastic_MeshPacket_init_default, 0, 0, 0, false, meshtastic_MeshPacket_init_default, 0, {meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default}, {{NULL}, NULL}} +#define meshtastic_DeviceState_init_default {false, meshtastic_MyNodeInfo_init_default, false, meshtastic_User_init_default, 0, {meshtastic_MeshPacket_init_default}, false, meshtastic_MeshPacket_init_default, 0, 0, 0, false, meshtastic_MeshPacket_init_default, 0, {meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default}, {{NULL}, NULL}, 0} #define meshtastic_NodeInfoLite_init_default {0, false, meshtastic_User_init_default, false, meshtastic_PositionLite_init_default, 0, 0, false, meshtastic_DeviceMetrics_init_default, 0, 0, 0} #define meshtastic_PositionLite_init_default {0, 0, 0, 0, _meshtastic_Position_LocSource_MIN} #define meshtastic_ChannelFile_init_default {0, {meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default}, 0} #define meshtastic_OEMStore_init_default {0, 0, {0, {0}}, _meshtastic_ScreenFonts_MIN, "", {0, {0}}, false, meshtastic_LocalConfig_init_default, false, meshtastic_LocalModuleConfig_init_default} #define meshtastic_NodeRemoteHardwarePin_init_default {0, false, meshtastic_RemoteHardwarePin_init_default} -#define meshtastic_DeviceState_init_zero {false, meshtastic_MyNodeInfo_init_zero, false, meshtastic_User_init_zero, 0, {meshtastic_MeshPacket_init_zero}, false, meshtastic_MeshPacket_init_zero, 0, 0, 0, false, meshtastic_MeshPacket_init_zero, 0, {meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero}, {{NULL}, NULL}} +#define meshtastic_DeviceState_init_zero {false, meshtastic_MyNodeInfo_init_zero, false, meshtastic_User_init_zero, 0, {meshtastic_MeshPacket_init_zero}, false, meshtastic_MeshPacket_init_zero, 0, 0, 0, false, meshtastic_MeshPacket_init_zero, 0, {meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero}, {{NULL}, NULL}, 0} #define meshtastic_NodeInfoLite_init_zero {0, false, meshtastic_User_init_zero, false, meshtastic_PositionLite_init_zero, 0, 0, false, meshtastic_DeviceMetrics_init_zero, 0, 0, 0} #define meshtastic_PositionLite_init_zero {0, 0, 0, 0, _meshtastic_Position_LocSource_MIN} #define meshtastic_ChannelFile_init_zero {0, {meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero}, 0} @@ -230,6 +229,7 @@ extern "C" { #define meshtastic_DeviceState_rx_waypoint_tag 12 #define meshtastic_DeviceState_node_remote_hardware_pins_tag 13 #define meshtastic_DeviceState_node_db_lite_tag 14 +#define meshtastic_DeviceState_node_db_lite_count_tag 15 /* Struct field encoding specification for nanopb */ #define meshtastic_DeviceState_FIELDLIST(X, a) \ @@ -242,7 +242,8 @@ X(a, STATIC, SINGULAR, BOOL, no_save, 9) \ X(a, STATIC, SINGULAR, BOOL, did_gps_reset, 11) \ X(a, STATIC, OPTIONAL, MESSAGE, rx_waypoint, 12) \ X(a, STATIC, REPEATED, MESSAGE, node_remote_hardware_pins, 13) \ -X(a, CALLBACK, REPEATED, MESSAGE, node_db_lite, 14) +X(a, CALLBACK, REPEATED, MESSAGE, node_db_lite, 14) \ +X(a, STATIC, SINGULAR, UINT32, node_db_lite_count, 15) extern bool meshtastic_DeviceState_callback(pb_istream_t *istream, pb_ostream_t *ostream, const pb_field_t *field); #define meshtastic_DeviceState_CALLBACK meshtastic_DeviceState_callback #define meshtastic_DeviceState_DEFAULT NULL @@ -334,4 +335,4 @@ extern const pb_msgdesc_t meshtastic_NodeRemoteHardwarePin_msg; } /* extern "C" */ #endif -#endif \ No newline at end of file +#endif diff --git a/src/mesh/generated/meshtastic/localonly.pb.c b/src/mesh/generated/meshtastic/localonly.pb.cpp similarity index 100% rename from src/mesh/generated/meshtastic/localonly.pb.c rename to src/mesh/generated/meshtastic/localonly.pb.cpp diff --git a/src/mesh/generated/meshtastic/mesh.pb.c b/src/mesh/generated/meshtastic/mesh.pb.cpp similarity index 100% rename from src/mesh/generated/meshtastic/mesh.pb.c rename to src/mesh/generated/meshtastic/mesh.pb.cpp diff --git a/src/mesh/generated/meshtastic/module_config.pb.c b/src/mesh/generated/meshtastic/module_config.pb.cpp similarity index 100% rename from src/mesh/generated/meshtastic/module_config.pb.c rename to src/mesh/generated/meshtastic/module_config.pb.cpp diff --git a/src/mesh/generated/meshtastic/mqtt.pb.c b/src/mesh/generated/meshtastic/mqtt.pb.cpp similarity index 100% rename from src/mesh/generated/meshtastic/mqtt.pb.c rename to src/mesh/generated/meshtastic/mqtt.pb.cpp diff --git a/src/mesh/generated/meshtastic/paxcount.pb.c b/src/mesh/generated/meshtastic/paxcount.pb.cpp similarity index 100% rename from src/mesh/generated/meshtastic/paxcount.pb.c rename to src/mesh/generated/meshtastic/paxcount.pb.cpp diff --git a/src/mesh/generated/meshtastic/portnums.pb.c b/src/mesh/generated/meshtastic/portnums.pb.cpp similarity index 100% rename from src/mesh/generated/meshtastic/portnums.pb.c rename to src/mesh/generated/meshtastic/portnums.pb.cpp diff --git a/src/mesh/generated/meshtastic/remote_hardware.pb.c b/src/mesh/generated/meshtastic/remote_hardware.pb.cpp similarity index 100% rename from src/mesh/generated/meshtastic/remote_hardware.pb.c rename to src/mesh/generated/meshtastic/remote_hardware.pb.cpp diff --git a/src/mesh/generated/meshtastic/rtttl.pb.c b/src/mesh/generated/meshtastic/rtttl.pb.cpp similarity index 100% rename from src/mesh/generated/meshtastic/rtttl.pb.c rename to src/mesh/generated/meshtastic/rtttl.pb.cpp diff --git a/src/mesh/generated/meshtastic/storeforward.pb.c b/src/mesh/generated/meshtastic/storeforward.pb.cpp similarity index 100% rename from src/mesh/generated/meshtastic/storeforward.pb.c rename to src/mesh/generated/meshtastic/storeforward.pb.cpp diff --git a/src/mesh/generated/meshtastic/telemetry.pb.c b/src/mesh/generated/meshtastic/telemetry.pb.cpp similarity index 100% rename from src/mesh/generated/meshtastic/telemetry.pb.c rename to src/mesh/generated/meshtastic/telemetry.pb.cpp diff --git a/src/mesh/generated/meshtastic/xmodem.pb.c b/src/mesh/generated/meshtastic/xmodem.pb.cpp similarity index 100% rename from src/mesh/generated/meshtastic/xmodem.pb.c rename to src/mesh/generated/meshtastic/xmodem.pb.cpp From 53cdae098b39c6922c1ba0256f0450e5e93e5beb Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Tue, 19 Mar 2024 22:21:32 -0500 Subject: [PATCH 05/11] Finally working --- bin/regen-protos.sh | 4 +- src/mesh/NodeDB.cpp | 68 +++++++++++-------- src/mesh/NodeDB.h | 6 +- src/mesh/generated/meshtastic/deviceonly.pb.h | 9 +-- src/platform/portduino/PortduinoGlue.cpp | 5 +- 5 files changed, 51 insertions(+), 41 deletions(-) diff --git a/bin/regen-protos.sh b/bin/regen-protos.sh index ad771ab452..b3395de30c 100755 --- a/bin/regen-protos.sh +++ b/bin/regen-protos.sh @@ -10,7 +10,9 @@ echo "prebuilt binaries for your computer into nanopb-0.4.7" cd protobufs ../nanopb-0.4.7/generator-bin/protoc --nanopb_out=-v:../src/mesh/generated/ -I=../protobufs meshtastic/*.proto --experimental_allow_proto3_optional -# cd ../src/mesh/generated/meshtastic +cd ../src/mesh/generated/meshtastic +rename .c .cpp *.c +cd ../../../.. # sed -i 's/#include "meshtastic/#include "./g' -- * # sed -i 's/meshtastic_//g' -- * diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 8fb03055ce..47a46476fc 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -51,12 +51,22 @@ meshtastic_OEMStore oemStore; bool meshtastic_DeviceState_callback(pb_istream_t *istream, pb_ostream_t *ostream, const pb_field_iter_t *field) { - std::vector *vec = (std::vector *)field->pData; + if (ostream) { + std::vector *vec = (std::vector *)field->pData; + for (auto item : *vec) { + if (!pb_encode_tag_for_field(ostream, field)) + return false; + pb_encode_submessage(ostream, meshtastic_NodeInfoLite_fields, &item); + } + } + if (istream) { + meshtastic_NodeInfoLite node; // this gets good data + std::vector *vec = (std::vector *)field->pData; - for (auto item : *vec) { - pb_encode_tag_for_field(ostream, field); - pb_encode_submessage(ostream, meshtastic_NodeInfoLite_fields, &item); + if (istream->bytes_left && pb_decode(istream, meshtastic_NodeInfoLite_fields, &node)) + vec->push_back(node); } + return true; } /** The current change # for radio settings. Starts at 0 on boot and any time the radio settings @@ -81,14 +91,7 @@ uint32_t error_address = 0; static uint8_t ourMacAddr[6]; -NodeDB::NodeDB() : meshNodes(devicestate.node_db_lite) -{ - std::cout << "test " << numMeshNodes << std::endl; - std::cout << MAX_NUM_NODES << std::endl; - meshNodes.reserve(MAX_NUM_NODES); - std::cout << "vector size " << meshNodes.size() << std::endl; - numMeshNodes = devicestate.node_db_lite_count; -} +NodeDB::NodeDB() {} /** * Most (but not always) of the time we want to treat packets 'from' the local phone (where from == 0), as if they originated on @@ -390,12 +393,14 @@ void NodeDB::removeNodeByNum(uint nodeNum) { int newPos = 0, removed = 0; for (int i = 0; i < numMeshNodes; i++) { - if (meshNodes[i].num != nodeNum) - meshNodes[newPos++] = meshNodes[i]; + if (meshNodes->at(i).num != nodeNum) + meshNodes->at(newPos++) = meshNodes->at(i); else removed++; } numMeshNodes -= removed; + std::fill(devicestate.node_db_lite.begin() + numMeshNodes, devicestate.node_db_lite.begin() + numMeshNodes + 1, + meshtastic_NodeInfoLite()); LOG_DEBUG("NodeDB::removeNodeByNum purged %d entries. Saving changes...\n", removed); saveDeviceStateToDisk(); } @@ -404,12 +409,14 @@ void NodeDB::cleanupMeshDB() { int newPos = 0, removed = 0; for (int i = 0; i < numMeshNodes; i++) { - if (meshNodes[i].has_user) - meshNodes[newPos++] = meshNodes[i]; + if (meshNodes->at(i).has_user) + meshNodes->at(newPos++) = meshNodes->at(i); else removed++; } numMeshNodes -= removed; + std::fill(devicestate.node_db_lite.begin() + numMeshNodes, devicestate.node_db_lite.begin() + numMeshNodes + removed, + meshtastic_NodeInfoLite()); LOG_DEBUG("cleanupMeshDB purged %d entries\n", removed); } @@ -419,6 +426,7 @@ void NodeDB::installDefaultDeviceState() // memset(&devicestate, 0, sizeof(meshtastic_DeviceState)); numMeshNodes = 0; + meshNodes = &devicestate.node_db_lite; // init our devicestate with valid flags so protobuf writing/reading will work devicestate.has_my_node = true; @@ -565,17 +573,21 @@ bool NodeDB::loadProto(const char *filename, size_t protoSize, size_t objSize, c void NodeDB::loadFromDisk() { // static DeviceState scratch; We no longer read into a tempbuf because this structure is 15KB of valuable RAM - if (!loadProto(prefFileName, sizeof(meshtastic_DeviceState), sizeof(meshtastic_DeviceState), &meshtastic_DeviceState_msg, - &devicestate)) { + if (!loadProto(prefFileName, sizeof(meshtastic_DeviceState) + MAX_NUM_NODES * sizeof(meshtastic_NodeInfo), + sizeof(meshtastic_DeviceState), &meshtastic_DeviceState_msg, &devicestate)) { installDefaultDeviceState(); // Our in RAM copy might now be corrupt } else { if (devicestate.version < DEVICESTATE_MIN_VER) { LOG_WARN("Devicestate %d is old, discarding\n", devicestate.version); factoryReset(); } else { - LOG_INFO("Loaded saved devicestate version %d\n", devicestate.version); + LOG_INFO("Loaded saved devicestate version %d, with nodecount: %d\n", devicestate.version, + devicestate.node_db_lite.size()); + meshNodes = &devicestate.node_db_lite; + numMeshNodes = devicestate.node_db_lite.size(); } } + meshNodes->resize(MAX_NUM_NODES); if (!loadProto(configFileName, meshtastic_LocalConfig_size, sizeof(meshtastic_LocalConfig), &meshtastic_LocalConfig_msg, &config)) { @@ -728,7 +740,7 @@ void NodeDB::saveToDisk(int saveWhat) const meshtastic_NodeInfoLite *NodeDB::readNextMeshNode(uint32_t &readIndex) { if (readIndex < numMeshNodes) - return &meshNodes[readIndex++]; + return &meshNodes->at(readIndex++); else return NULL; } @@ -764,9 +776,9 @@ size_t NodeDB::getNumOnlineMeshNodes(bool localOnly) // FIXME this implementation is kinda expensive for (int i = 0; i < numMeshNodes; i++) { - if (localOnly && meshNodes[i].via_mqtt) + if (localOnly && meshNodes->at(i).via_mqtt) continue; - if (sinceLastSeen(&meshNodes[i]) < NUM_ONLINE_SECS) + if (sinceLastSeen(&meshNodes->at(i)) < NUM_ONLINE_SECS) numseen++; } @@ -915,8 +927,8 @@ uint8_t NodeDB::getMeshNodeChannel(NodeNum n) meshtastic_NodeInfoLite *NodeDB::getMeshNode(NodeNum n) { for (int i = 0; i < numMeshNodes; i++) - if (meshNodes[i].num == n) - return &meshNodes[i]; + if (meshNodes->at(i).num == n) + return &meshNodes->at(i); return NULL; } @@ -935,19 +947,19 @@ meshtastic_NodeInfoLite *NodeDB::getOrCreateMeshNode(NodeNum n) uint32_t oldest = UINT32_MAX; int oldestIndex = -1; for (int i = 1; i < numMeshNodes; i++) { - if (meshNodes[i].last_heard < oldest) { - oldest = meshNodes[i].last_heard; + if (meshNodes->at(i).last_heard < oldest) { + oldest = meshNodes->at(i).last_heard; oldestIndex = i; } } // Shove the remaining nodes down the chain for (int i = oldestIndex; i < numMeshNodes - 1; i++) { - meshNodes[i] = meshNodes[i + 1]; + meshNodes->at(i) = meshNodes->at(i + 1); } (numMeshNodes)--; } // add the node at the end - lite = &meshNodes[(numMeshNodes)++]; + lite = &meshNodes->at((numMeshNodes)++); // everything is missing except the nodenum memset(lite, 0, sizeof(*lite)); diff --git a/src/mesh/NodeDB.h b/src/mesh/NodeDB.h index 362b28618b..a2e83fb5cf 100644 --- a/src/mesh/NodeDB.h +++ b/src/mesh/NodeDB.h @@ -46,13 +46,13 @@ class NodeDB // Eventually use a smarter datastructure // HashMap nodes; // Note: these two references just point into our static array we serialize to/from disk - std::vector meshNodes; - pb_size_t numMeshNodes; public: + std::vector *meshNodes; bool updateGUI = false; // we think the gui should definitely be redrawn, screen will clear this once handled meshtastic_NodeInfoLite *updateGUIforNode = NULL; // if currently showing this node, we think you should update the GUI Observable newStatus; + pb_size_t numMeshNodes; /// don't do mesh based algorithm for node id assignment (initially) /// instead just store in flash - possibly even in the initial alpha release do this hack @@ -128,7 +128,7 @@ class NodeDB meshtastic_NodeInfoLite *getMeshNodeByIndex(size_t x) { assert(x < numMeshNodes); - return &meshNodes[x]; + return &meshNodes->at(x); } meshtastic_NodeInfoLite *getMeshNode(NodeNum n); diff --git a/src/mesh/generated/meshtastic/deviceonly.pb.h b/src/mesh/generated/meshtastic/deviceonly.pb.h index 27acbea67a..9ba9edac37 100644 --- a/src/mesh/generated/meshtastic/deviceonly.pb.h +++ b/src/mesh/generated/meshtastic/deviceonly.pb.h @@ -156,7 +156,6 @@ typedef struct _meshtastic_DeviceState { meshtastic_NodeRemoteHardwarePin node_remote_hardware_pins[12]; /* New lite version of NodeDB to decrease memory footprint */ std::vector node_db_lite; - uint32_t node_db_lite_count; } meshtastic_DeviceState; @@ -179,13 +178,13 @@ extern "C" { /* Initializer values for message structs */ -#define meshtastic_DeviceState_init_default {false, meshtastic_MyNodeInfo_init_default, false, meshtastic_User_init_default, 0, {meshtastic_MeshPacket_init_default}, false, meshtastic_MeshPacket_init_default, 0, 0, 0, false, meshtastic_MeshPacket_init_default, 0, {meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default}, {{NULL}, NULL}, 0} +#define meshtastic_DeviceState_init_default {false, meshtastic_MyNodeInfo_init_default, false, meshtastic_User_init_default, 0, {meshtastic_MeshPacket_init_default}, false, meshtastic_MeshPacket_init_default, 0, 0, 0, false, meshtastic_MeshPacket_init_default, 0, {meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default, meshtastic_NodeRemoteHardwarePin_init_default}, {{NULL}, NULL}} #define meshtastic_NodeInfoLite_init_default {0, false, meshtastic_User_init_default, false, meshtastic_PositionLite_init_default, 0, 0, false, meshtastic_DeviceMetrics_init_default, 0, 0, 0} #define meshtastic_PositionLite_init_default {0, 0, 0, 0, _meshtastic_Position_LocSource_MIN} #define meshtastic_ChannelFile_init_default {0, {meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default, meshtastic_Channel_init_default}, 0} #define meshtastic_OEMStore_init_default {0, 0, {0, {0}}, _meshtastic_ScreenFonts_MIN, "", {0, {0}}, false, meshtastic_LocalConfig_init_default, false, meshtastic_LocalModuleConfig_init_default} #define meshtastic_NodeRemoteHardwarePin_init_default {0, false, meshtastic_RemoteHardwarePin_init_default} -#define meshtastic_DeviceState_init_zero {false, meshtastic_MyNodeInfo_init_zero, false, meshtastic_User_init_zero, 0, {meshtastic_MeshPacket_init_zero}, false, meshtastic_MeshPacket_init_zero, 0, 0, 0, false, meshtastic_MeshPacket_init_zero, 0, {meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero}, {{NULL}, NULL}, 0} +#define meshtastic_DeviceState_init_zero {false, meshtastic_MyNodeInfo_init_zero, false, meshtastic_User_init_zero, 0, {meshtastic_MeshPacket_init_zero}, false, meshtastic_MeshPacket_init_zero, 0, 0, 0, false, meshtastic_MeshPacket_init_zero, 0, {meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero, meshtastic_NodeRemoteHardwarePin_init_zero}, {{NULL}, NULL}} #define meshtastic_NodeInfoLite_init_zero {0, false, meshtastic_User_init_zero, false, meshtastic_PositionLite_init_zero, 0, 0, false, meshtastic_DeviceMetrics_init_zero, 0, 0, 0} #define meshtastic_PositionLite_init_zero {0, 0, 0, 0, _meshtastic_Position_LocSource_MIN} #define meshtastic_ChannelFile_init_zero {0, {meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero, meshtastic_Channel_init_zero}, 0} @@ -229,7 +228,6 @@ extern "C" { #define meshtastic_DeviceState_rx_waypoint_tag 12 #define meshtastic_DeviceState_node_remote_hardware_pins_tag 13 #define meshtastic_DeviceState_node_db_lite_tag 14 -#define meshtastic_DeviceState_node_db_lite_count_tag 15 /* Struct field encoding specification for nanopb */ #define meshtastic_DeviceState_FIELDLIST(X, a) \ @@ -242,8 +240,7 @@ X(a, STATIC, SINGULAR, BOOL, no_save, 9) \ X(a, STATIC, SINGULAR, BOOL, did_gps_reset, 11) \ X(a, STATIC, OPTIONAL, MESSAGE, rx_waypoint, 12) \ X(a, STATIC, REPEATED, MESSAGE, node_remote_hardware_pins, 13) \ -X(a, CALLBACK, REPEATED, MESSAGE, node_db_lite, 14) \ -X(a, STATIC, SINGULAR, UINT32, node_db_lite_count, 15) +X(a, CALLBACK, REPEATED, MESSAGE, node_db_lite, 14) extern bool meshtastic_DeviceState_callback(pb_istream_t *istream, pb_ostream_t *ostream, const pb_field_t *field); #define meshtastic_DeviceState_CALLBACK meshtastic_DeviceState_callback #define meshtastic_DeviceState_DEFAULT NULL diff --git a/src/platform/portduino/PortduinoGlue.cpp b/src/platform/portduino/PortduinoGlue.cpp index 7f299ce38a..b255c0ce1a 100644 --- a/src/platform/portduino/PortduinoGlue.cpp +++ b/src/platform/portduino/PortduinoGlue.cpp @@ -199,9 +199,8 @@ void portduinoSetup() settingsMap[webserverport] = (yamlConfig["Webserver"]["Port"]).as(-1); settingsStrings[webserverrootpath] = (yamlConfig["Webserver"]["RootPath"]).as(""); } - // if (yamlConfig["General"]) { - settingsMap[maxnodes] = (yamlConfig["General"]["MaxNodes"]).as(150); - //} + + settingsMap[maxnodes] = (yamlConfig["General"]["MaxNodes"]).as(200); } catch (YAML::Exception e) { std::cout << "*** Exception " << e.what() << std::endl; From 788f39d9524d9c7abcce80259abb3d48b2683e62 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Tue, 19 Mar 2024 22:36:14 -0500 Subject: [PATCH 06/11] Remove unintended lines --- src/GPSStatus.h | 4 +--- src/mesh/NodeDB.cpp | 5 ++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/GPSStatus.h b/src/GPSStatus.h index 14c5d0f1a6..1245d5e5dc 100644 --- a/src/GPSStatus.h +++ b/src/GPSStatus.h @@ -4,8 +4,6 @@ #include "configuration.h" #include -// extern NodeDB *nodeDB; - namespace meshtastic { @@ -140,4 +138,4 @@ class GPSStatus : public Status } // namespace meshtastic -extern meshtastic::GPSStatus *gpsStatus; \ No newline at end of file +extern meshtastic::GPSStatus *gpsStatus; diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 4a4aebf7b9..37232e6edf 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -683,9 +683,8 @@ void NodeDB::saveDeviceStateToDisk() #ifdef FSCom FSCom.mkdir("/prefs"); #endif - saveProto(prefFileName, sizeof(devicestate) + numMeshNodes * meshtastic_NodeInfoLite_size, &meshtastic_DeviceState_msg, - &devicestate); - } + saveProto(prefFileName, sizeof(devicestate) + numMeshNodes * meshtastic_NodeInfoLite_size, &meshtastic_DeviceState_msg, + &devicestate); } void NodeDB::saveToDisk(int saveWhat) From 251bca5b0c43bedb122fa7d929166639bc1c8194 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Tue, 19 Mar 2024 23:16:47 -0500 Subject: [PATCH 07/11] Don't include a pointer --- src/modules/esp32/AudioModule.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/esp32/AudioModule.cpp b/src/modules/esp32/AudioModule.cpp index 130654fa9f..bafbe3b344 100644 --- a/src/modules/esp32/AudioModule.cpp +++ b/src/modules/esp32/AudioModule.cpp @@ -5,7 +5,7 @@ #include "MeshService.h" #include "RTC.h" #include "Router.h" -#include "nodeDB->h" +#include "nodeDB.h" /* AudioModule From b7f52facef7a6945d647985eea9c0f84220572fa Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Wed, 20 Mar 2024 13:38:11 -0500 Subject: [PATCH 08/11] Capitalization matters. --- src/modules/esp32/AudioModule.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/esp32/AudioModule.cpp b/src/modules/esp32/AudioModule.cpp index bafbe3b344..4a7b1c2c60 100644 --- a/src/modules/esp32/AudioModule.cpp +++ b/src/modules/esp32/AudioModule.cpp @@ -3,9 +3,9 @@ #include "AudioModule.h" #include "FSCommon.h" #include "MeshService.h" +#include "NodeDB.h" #include "RTC.h" #include "Router.h" -#include "nodeDB.h" /* AudioModule From 3e69d63adb481ab16ee8e9e80a3b31132996567a Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Wed, 20 Mar 2024 14:40:21 -0500 Subject: [PATCH 09/11] avoid rename in protocol regen --- bin/regen-protos.bat | 2 +- bin/regen-protos.sh | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/bin/regen-protos.bat b/bin/regen-protos.bat index 1422f79145..1d55c25064 100644 --- a/bin/regen-protos.bat +++ b/bin/regen-protos.bat @@ -1 +1 @@ -cd protobufs && ..\nanopb-0.4.7\generator-bin\protoc.exe --experimental_allow_proto3_optional --nanopb_out=-v:..\src\mesh\generated -I=..\protobufs ..\protobufs\meshtastic\*.proto +cd protobufs && ..\nanopb-0.4.7\generator-bin\protoc.exe --experimental_allow_proto3_optional "--nanopb_out=-S.cpp -v:..\src\mesh\generated\" -I=..\protobufs ..\protobufs\meshtastic\*.proto diff --git a/bin/regen-protos.sh b/bin/regen-protos.sh index b3395de30c..7c751208ae 100755 --- a/bin/regen-protos.sh +++ b/bin/regen-protos.sh @@ -8,11 +8,8 @@ echo "prebuilt binaries for your computer into nanopb-0.4.7" # the nanopb tool seems to require that the .options file be in the current directory! cd protobufs -../nanopb-0.4.7/generator-bin/protoc --nanopb_out=-v:../src/mesh/generated/ -I=../protobufs meshtastic/*.proto --experimental_allow_proto3_optional +../nanopb-0.4.7/generator-bin/protoc "--nanopb_out=-S.cpp -v:../src/mesh/generated/" -I=../protobufs meshtastic/*.proto --experimental_allow_proto3_optional -cd ../src/mesh/generated/meshtastic -rename .c .cpp *.c -cd ../../../.. # sed -i 's/#include "meshtastic/#include "./g' -- * # sed -i 's/meshtastic_//g' -- * From 63c86d6b480228dc2ce376d177a88db71de4d2aa Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Wed, 20 Mar 2024 15:43:55 -0500 Subject: [PATCH 10/11] When trimming the nodeDB, start with a cleanup --- src/mesh/NodeDB.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 37232e6edf..1e92ac72c4 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -925,6 +925,8 @@ meshtastic_NodeInfoLite *NodeDB::getOrCreateMeshNode(NodeNum n) meshtastic_NodeInfoLite *lite = getMeshNode(n); if (!lite) { + if ((numMeshNodes >= MAX_NUM_NODES) || (memGet.getFreeHeap() < meshtastic_NodeInfoLite_size * 3)) + cleanupMeshDB(); if ((numMeshNodes >= MAX_NUM_NODES) || (memGet.getFreeHeap() < meshtastic_NodeInfoLite_size * 3)) { if (screen) screen->print("Warn: node database full!\nErasing oldest entry\n"); From 8316221ebb29ab0a771f1f4b39490080017e56c7 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Thu, 21 Mar 2024 08:36:17 -0500 Subject: [PATCH 11/11] Remove extra cleanupMeshDB() call for now --- src/mesh/NodeDB.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 1e92ac72c4..37232e6edf 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -925,8 +925,6 @@ meshtastic_NodeInfoLite *NodeDB::getOrCreateMeshNode(NodeNum n) meshtastic_NodeInfoLite *lite = getMeshNode(n); if (!lite) { - if ((numMeshNodes >= MAX_NUM_NODES) || (memGet.getFreeHeap() < meshtastic_NodeInfoLite_size * 3)) - cleanupMeshDB(); if ((numMeshNodes >= MAX_NUM_NODES) || (memGet.getFreeHeap() < meshtastic_NodeInfoLite_size * 3)) { if (screen) screen->print("Warn: node database full!\nErasing oldest entry\n");