Skip to content

Commit

Permalink
Add MaxNodes to Native config
Browse files Browse the repository at this point in the history
  • Loading branch information
jp-bennett committed Mar 16, 2024
1 parent 611f291 commit b00457d
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 2 deletions.
3 changes: 3 additions & 0 deletions bin/config-dist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 16 additions & 0 deletions src/graphics/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ namespace graphics
// #define SHOW_REDRAWS

// A text message frame + debug frame + all the node infos
#if ARCH_PORTDUINO
FrameCallback *normalFrames;
#else
static FrameCallback normalFrames[MAX_NUM_NODES + NUM_EXTRA_FRAMES];
#endif
static uint32_t targetFramerate = IDLE_FRAMERATE;
static char btPIN[16] = "888888";

Expand Down Expand Up @@ -913,6 +917,7 @@ Screen::Screen(ScanI2C::DeviceAddress address, meshtastic_Config_DisplayConfig_O
(address.port == ScanI2C::I2CPort::WIRE1) ? HW_I2C::I2C_TWO : HW_I2C::I2C_ONE);
#elif ARCH_PORTDUINO
if (settingsMap[displayPanel] != no_screen) {
graphics::normalFrames = new FrameCallback[settingsMap[maxnodes] + NUM_EXTRA_FRAMES];
LOG_DEBUG("Making TFTDisplay!\n");
dispdev = new TFTDisplay(address.address, -1, -1, geometry,
(address.port == ScanI2C::I2CPort::WIRE1) ? HW_I2C::I2C_TWO : HW_I2C::I2C_ONE);
Expand All @@ -931,6 +936,13 @@ Screen::Screen(ScanI2C::DeviceAddress address, meshtastic_Config_DisplayConfig_O
cmdQueue.setReader(this);
}

Screen::~Screen()
{
#if ARCH_PORTDUINO
delete[] graphics::normalFrames;
#endif
}

/**
* 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
Expand Down Expand Up @@ -1282,7 +1294,11 @@ void Screen::setFrames()
moduleFrames = MeshModule::GetMeshModulesWithUIFrames();
LOG_DEBUG("Showing %d module frames\n", moduleFrames.size());
#ifdef DEBUG_PORT
#if ARCH_PORTDUINO
int totalFrameCount = settingsMap[maxnodes] + NUM_EXTRA_FRAMES + moduleFrames.size();
#else
int totalFrameCount = MAX_NUM_NODES + NUM_EXTRA_FRAMES + moduleFrames.size();
#endif
LOG_DEBUG("Total frame count: %d\n", totalFrameCount);
#endif

Expand Down
2 changes: 2 additions & 0 deletions src/graphics/Screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
11 changes: 10 additions & 1 deletion src/mesh/NodeDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,11 @@ void NodeDB::installDefaultChannels()
void NodeDB::resetNodes()
{
devicestate.node_db_lite_count = 1;
#if ARCH_PORTDUINO
std::fill(&devicestate.node_db_lite[1], &devicestate.node_db_lite[settingsMap[maxnodes] - 1], meshtastic_NodeInfoLite());
#else
std::fill(&devicestate.node_db_lite[1], &devicestate.node_db_lite[MAX_NUM_NODES - 1], meshtastic_NodeInfoLite());
#endif
saveDeviceStateToDisk();
if (neighborInfoModule && moduleConfig.neighbor_info.enabled)
neighborInfoModule->resetNeighbors();
Expand Down Expand Up @@ -904,7 +908,12 @@ 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 ARCH_PORTDUINO
int maxNodes = settingsMap[maxnodes];
#else
int maxNodes = MAX_NUM_NODES;
#endif
if ((*numMeshNodes >= maxNodes) || (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");
Expand Down
14 changes: 14 additions & 0 deletions src/mesh/PacketHistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@
#include "configuration.h"
#include "mesh-pb-constants.h"

#ifdef ARCH_PORTDUINO
#include "platform/portduino/PortduinoGlue.h"
#endif

PacketHistory::PacketHistory()
{
#if ARCH_PORTDUINO
recentPackets.reserve(settingsMap[maxnodes]);
#else
recentPackets.reserve(MAX_NUM_NODES); // Prealloc the worst case # of records - to prevent heap fragmentation
// setup our periodic task
#endif
}

/**
Expand Down Expand Up @@ -48,9 +56,15 @@ bool PacketHistory::wasSeenRecently(const meshtastic_MeshPacket *p, bool withUpd

// Capacity is reerved, so only purge expired packets if recentPackets fills past 90% capacity
// Expiry is normally dealt with after having searched/found a packet (above)
#if ARCH_PORTDUINO
if (recentPackets.size() > (settingsMap[maxnodes] * 0.9)) {
clearExpiredRecentPackets();
}
#else
if (recentPackets.size() > (MAX_NUM_NODES * 0.9)) {
clearExpiredRecentPackets();
}
#endif

return seenRecently;
}
Expand Down
3 changes: 3 additions & 0 deletions src/platform/portduino/PortduinoGlue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ void portduinoSetup()
settingsMap[webserverport] = (yamlConfig["Webserver"]["Port"]).as<int>(-1);
settingsStrings[webserverrootpath] = (yamlConfig["Webserver"]["RootPath"]).as<std::string>("");
}
if (yamlConfig["General"]) {
settingsMap[maxnodes] = (yamlConfig["General"]["MaxNodes"]).as<int>(MAX_NUM_NODES);
}

} catch (YAML::Exception e) {
std::cout << "*** Exception " << e.what() << std::endl;
Expand Down
3 changes: 2 additions & 1 deletion src/platform/portduino/PortduinoGlue.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ enum configNames {
logoutputlevel,
webserver,
webserverport,
webserverrootpath
webserverrootpath,
maxnodes
};
enum { no_screen, st7789, st7735, st7735s, ili9341 };
enum { no_touchscreen, xpt2046, stmpe610 };
Expand Down
2 changes: 2 additions & 0 deletions src/shutdown.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ void powerCommandsCheck()
SPI.end();
Wire.end();
Serial1.end();
if (screen)
delete screen;
reboot();
#else
rebootAtMsec = -1;
Expand Down

0 comments on commit b00457d

Please sign in to comment.