Skip to content

Commit 28f53d1

Browse files
authored
refactor: change node count variables from uint8_t to uint16_t (#8478)
This is a non-breaking change that increases the internal representation of node counts from uint8_t (max 255) to uint16_t (max 65535) to support larger mesh networks, particularly on ESP32-S3 devices with PSRAM. Changes: - NodeStatus: numOnline, numTotal, lastNumTotal (uint8_t -> uint16_t) - ProtobufModule: numOnlineNodes (uint8_t -> uint16_t) - MapApplet: loop counters changed to size_t for consistency with getNumMeshNodes() - NodeStatus: Fixed log format to use %u for unsigned integers Note: Default class methods keep uint32_t for numOnlineNodes parameter to match the public API and allow flexibility, even though internal node counts use uint16_t (max 65535 nodes). This change does NOT affect protobuf definitions, maintaining wire compatibility with existing clients and devices.
1 parent f045ca2 commit 28f53d1

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

src/NodeStatus.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ class NodeStatus : public Status
1414
CallbackObserver<NodeStatus, const NodeStatus *> statusObserver =
1515
CallbackObserver<NodeStatus, const NodeStatus *>(this, &NodeStatus::updateStatus);
1616

17-
uint8_t numOnline = 0;
18-
uint8_t numTotal = 0;
17+
uint16_t numOnline = 0;
18+
uint16_t numTotal = 0;
1919

20-
uint8_t lastNumTotal = 0;
20+
uint16_t lastNumTotal = 0;
2121

2222
public:
2323
bool forceUpdate = false;
2424

2525
NodeStatus() { statusType = STATUS_TYPE_NODE; }
26-
NodeStatus(uint8_t numOnline, uint8_t numTotal, bool forceUpdate = false) : Status()
26+
NodeStatus(uint16_t numOnline, uint16_t numTotal, bool forceUpdate = false) : Status()
2727
{
2828
this->forceUpdate = forceUpdate;
2929
this->numOnline = numOnline;
@@ -34,11 +34,11 @@ class NodeStatus : public Status
3434

3535
void observe(Observable<const NodeStatus *> *source) { statusObserver.observe(source); }
3636

37-
uint8_t getNumOnline() const { return numOnline; }
37+
uint16_t getNumOnline() const { return numOnline; }
3838

39-
uint8_t getNumTotal() const { return numTotal; }
39+
uint16_t getNumTotal() const { return numTotal; }
4040

41-
uint8_t getLastNumTotal() const { return lastNumTotal; }
41+
uint16_t getLastNumTotal() const { return lastNumTotal; }
4242

4343
bool matches(const NodeStatus *newStatus) const
4444
{
@@ -56,7 +56,7 @@ class NodeStatus : public Status
5656
numTotal = newStatus->getNumTotal();
5757
}
5858
if (isDirty || newStatus->forceUpdate) {
59-
LOG_DEBUG("Node status update: %d online, %d total", numOnline, numTotal);
59+
LOG_DEBUG("Node status update: %u online, %u total", numOnline, numTotal);
6060
onNewStatus.notifyObservers(this);
6161
}
6262
return 0;

src/graphics/niche/InkHUD/Applets/Bases/Map/MapApplet.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ void InkHUD::MapApplet::getMapCenter(float *lat, float *lng)
287287
float easternmost = lngCenter;
288288
float westernmost = lngCenter;
289289

290-
for (uint8_t i = 0; i < nodeDB->getNumMeshNodes(); i++) {
290+
for (size_t i = 0; i < nodeDB->getNumMeshNodes(); i++) {
291291
meshtastic_NodeInfoLite *node = nodeDB->getMeshNodeByIndex(i);
292292

293293
// Skip if no position
@@ -474,8 +474,8 @@ void InkHUD::MapApplet::drawLabeledMarker(meshtastic_NodeInfoLite *node)
474474
// Need at least two, to draw a sensible map
475475
bool InkHUD::MapApplet::enoughMarkers()
476476
{
477-
uint8_t count = 0;
478-
for (uint8_t i = 0; i < nodeDB->getNumMeshNodes(); i++) {
477+
size_t count = 0;
478+
for (size_t i = 0; i < nodeDB->getNumMeshNodes(); i++) {
479479
meshtastic_NodeInfoLite *node = nodeDB->getMeshNodeByIndex(i);
480480

481481
// Count nodes

src/mesh/Default.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,15 @@ class Default
4646
static uint32_t getConfiguredOrDefaultMs(uint32_t configuredInterval);
4747
static uint32_t getConfiguredOrDefaultMs(uint32_t configuredInterval, uint32_t defaultInterval);
4848
static uint32_t getConfiguredOrDefault(uint32_t configured, uint32_t defaultValue);
49+
// Note: numOnlineNodes uses uint32_t to match the public API and allow flexibility,
50+
// even though internal node counts use uint16_t (max 65535 nodes)
4951
static uint32_t getConfiguredOrDefaultMsScaled(uint32_t configured, uint32_t defaultValue, uint32_t numOnlineNodes);
5052
static uint8_t getConfiguredOrDefaultHopLimit(uint8_t configured);
5153
static uint32_t getConfiguredOrMinimumValue(uint32_t configured, uint32_t minValue);
5254

5355
private:
54-
static float congestionScalingCoefficient(int numOnlineNodes)
56+
// Note: Kept as uint32_t to match the public API parameter type
57+
static float congestionScalingCoefficient(uint32_t numOnlineNodes)
5558
{
5659
// Increase frequency of broadcasts for small networks regardless of preset
5760
if (numOnlineNodes <= 10) {

src/mesh/ProtobufModule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ template <class T> class ProtobufModule : protected SinglePortModule
1313
const pb_msgdesc_t *fields;
1414

1515
public:
16-
uint8_t numOnlineNodes = 0;
16+
uint16_t numOnlineNodes = 0;
1717
/** Constructor
1818
* name is for debugging output
1919
*/

0 commit comments

Comments
 (0)