Skip to content

Commit bbf050b

Browse files
committed
Optimize Flash: wrap debug output with SILENT, remove CLI aliases, add region commands
- Wrap Serial.printf in mesh/ headers (Identity.h, Advert.h, Contacts.h) with #ifndef SILENT - Compress help text from 7 lines to 3 - Remove duplicate CLI aliases: passwd, erase, stats-radio, stats-packets, set/get repeat, set/get advert.interval, get radio, set/get tx, txpower auto, set name - Change password syntax: password admin/guest <pw> (serial) - Add region CLI commands: region, region put/remove/allowf/denyf (MeshCore 1.10.0+) - Net effect: ~1,088 bytes freed, region CLI fits in Flash (99.3%, 928 bytes free)
1 parent de157ee commit bbf050b

4 files changed

Lines changed: 53 additions & 48 deletions

File tree

src/main.cpp

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -233,24 +233,24 @@ static bool dispatchSharedCommand(const char* cmd, CmdCtx& ctx, bool isAdmin) {
233233
CP("%ld.%06ld,%ld.%06ld\n", lat/1000000, abs(lat%1000000), lon/1000000, abs(lon%1000000));
234234
} else CP("No loc\n");
235235
}
236-
else if (strcmp(cmd, "repeat") == 0 || strcmp(cmd, "set repeat") == 0 || strcmp(cmd, "get repeat") == 0) {
236+
else if (strcmp(cmd, "repeat") == 0) {
237237
CP("Rpt:%s hops:%d\n", repeaterHelper.isRepeatEnabled() ? "on" : "off", repeaterHelper.getMaxFloodHops());
238238
}
239-
else if (strcmp(cmd, "advert interval") == 0 || strcmp(cmd, "set advert.interval") == 0 || strcmp(cmd, "get advert.interval") == 0) {
239+
else if (strcmp(cmd, "advert interval") == 0) {
240240
CP("Int:%lum next:%lus\n", advertGen.getInterval() / 60000, advertGen.getTimeUntilNext());
241241
}
242-
else if (strcmp(cmd, "radiostats") == 0 || strcmp(cmd, "stats-radio") == 0) {
242+
else if (strcmp(cmd, "radiostats") == 0) {
243243
const RadioStats& rs = repeaterHelper.getRadioStats();
244244
CP("Noise:%ddBm RSSI:%d SNR:%d.%ddB\n", rs.noiseFloor, rs.lastRssi, rs.lastSnr/4, abs(rs.lastSnr%4)*25);
245245
CP("Airtime TX:%lus RX:%lus\n", rs.txAirTimeSec, rs.rxAirTimeSec);
246246
}
247-
else if (strcmp(cmd, "packetstats") == 0 || strcmp(cmd, "stats-packets") == 0) {
247+
else if (strcmp(cmd, "packetstats") == 0) {
248248
const PacketStats& ps = repeaterHelper.getPacketStats();
249249
CP("RX:%lu TX:%lu FL:%lu/%lu DR:%lu/%lu\n",
250250
ps.numRecvPackets, ps.numSentPackets,
251251
ps.numRecvFlood, ps.numSentFlood, ps.numRecvDirect, ps.numSentDirect);
252252
}
253-
else if (strcmp(cmd, "radio") == 0 || strcmp(cmd, "get radio") == 0) {
253+
else if (strcmp(cmd, "radio") == 0) {
254254
{ uint32_t fM = (uint32_t)(MC_FREQUENCY * 1000); uint32_t bT = (uint32_t)(MC_BANDWIDTH * 10);
255255
CP("%lu.%03lu BW%lu.%lu SF%d CR%d %ddBm\n", fM/1000, fM%1000, bT/10, bT%10, MC_SPREADING, MC_CODING_RATE, MC_TX_POWER); }
256256
if (tempRadioActive) {
@@ -354,7 +354,7 @@ static bool dispatchSharedCommand(const char* cmd, CmdCtx& ctx, bool isAdmin) {
354354
else if (strcmp(cmd, "cb") == 0) {
355355
CP("CB:%d\n", repeaterHelper.getNeighbours().getCircuitBreakerCount());
356356
}
357-
else if (strcmp(cmd, "txpower") == 0 || strcmp(cmd, "set tx") == 0 || strcmp(cmd, "get tx") == 0) {
357+
else if (strcmp(cmd, "txpower") == 0) {
358358
CP("TxP:%ddBm max:%d auto:%s\n", repeaterHelper.getCurrentTxPower(),
359359
MC_TX_POWER, repeaterHelper.isAdaptiveTxEnabled() ? "on" : "off");
360360
}
@@ -501,7 +501,7 @@ static bool dispatchSharedCommand(const char* cmd, CmdCtx& ctx, bool isAdmin) {
501501
CP("name=%s\n", n);
502502
} else CP("E:1-15\n");
503503
}
504-
else if (strcmp(cmd, "set name") == 0 || strcmp(cmd, "name") == 0) {
504+
else if (strcmp(cmd, "name") == 0) {
505505
CP("Name:%s\n", nodeIdentity.getNodeName());
506506
}
507507
else if (strncmp(cmd, "set lat ", 8) == 0) {
@@ -644,10 +644,10 @@ static bool dispatchSharedCommand(const char* cmd, CmdCtx& ctx, bool isAdmin) {
644644
} else CP("E:quiet <start> <end>\n");
645645
}
646646
}
647-
else if (strcmp(cmd, "set tx auto on") == 0 || strcmp(cmd, "txpower auto on") == 0) {
647+
else if (strcmp(cmd, "set tx auto on") == 0) {
648648
repeaterHelper.setAdaptiveTxEnabled(true); CP("TxP auto:on\n");
649649
}
650-
else if (strcmp(cmd, "set tx auto off") == 0 || strcmp(cmd, "txpower auto off") == 0) {
650+
else if (strcmp(cmd, "set tx auto off") == 0) {
651651
repeaterHelper.setAdaptiveTxEnabled(false);
652652
repeaterHelper.setTxPower(MC_TX_POWER);
653653
radio.setOutputPower(MC_TX_POWER);
@@ -780,7 +780,7 @@ static bool dispatchSharedCommand(const char* cmd, CmdCtx& ctx, bool isAdmin) {
780780
else if (strcmp(cmd, "save") == 0) {
781781
saveConfig(); CP("saved\n");
782782
}
783-
else if (strcmp(cmd, "reset") == 0 || strcmp(cmd, "erase") == 0) {
783+
else if (strcmp(cmd, "reset") == 0) {
784784
resetConfig(); applyPowerSettings(); CP("reset\n");
785785
}
786786
else if (strcmp(cmd, "reboot") == 0) {
@@ -790,6 +790,26 @@ static bool dispatchSharedCommand(const char* cmd, CmdCtx& ctx, bool isAdmin) {
790790
timeSync = TimeSync();
791791
CP("clkreboot\n");
792792
}
793+
// Region commands (MeshCore 1.10.0+)
794+
else if (strcmp(cmd, "region") == 0) {
795+
CP("*:%c\n", (regionMap.getWildcard().flags & REGION_DENY_FLOOD) ? 'D' : 'A');
796+
for (uint8_t i = 0; i < regionMap.getCount(); i++) {
797+
const RegionEntry* e = regionMap.getEntry(i);
798+
CP("%s:%c\n", e->name, (e->flags & REGION_DENY_FLOOD) ? 'D' : 'A');
799+
}
800+
}
801+
else if (isAdmin && strncmp(cmd, "region put ", 11) == 0) {
802+
CP(regionMap.put(cmd + 11) ? "OK\n" : "ERR\n");
803+
}
804+
else if (isAdmin && strncmp(cmd, "region remove ", 14) == 0) {
805+
CP(regionMap.remove(cmd + 14) ? "OK\n" : "ERR\n");
806+
}
807+
else if (isAdmin && strncmp(cmd, "region allowf ", 14) == 0) {
808+
CP(regionMap.allowFlood(cmd + 14) ? "OK\n" : "ERR\n");
809+
}
810+
else if (isAdmin && strncmp(cmd, "region denyf ", 13) == 0) {
811+
CP(regionMap.denyFlood(cmd + 13) ? "OK\n" : "ERR\n");
812+
}
793813
else {
794814
return false; // command not handled
795815
}
@@ -820,13 +840,9 @@ void processCommand(char* cmd) {
820840

821841
// Serial-only commands
822842
if (strcmp(cmd, "?") == 0 || strcmp(cmd, "help") == 0) {
823-
LOG_RAW("status stats lifetime radiostats packetstats advert nodes contacts\n\r"
824-
"neighbours telemetry identity location time ver clock nodetype\n\r"
825-
"password set guest.password set name set lat set lon set tx\n\r"
826-
"set advert.interval set radio set repeat set flood.max\n\r"
827-
"powersaving mode sleep rxboost radio tempradio ratelimit\n\r"
828-
"savestats alert newid power acl ping trace rssi report health\n\r"
829-
"clear stats neighbor.remove mailbox erase reset save reboot\n\r");
843+
LOG_RAW("status stats nodes neighbours ver time advert radio\n\r"
844+
"set name|lat|lon|tx|repeat|flood.max|radio\n\r"
845+
"password region acl save reset reboot\n\r");
830846
}
831847
else if (strcmp(cmd, "newid") == 0) {
832848
LOG_RAW("Gen new ID...\n\r");
@@ -910,25 +926,17 @@ void processCommand(char* cmd) {
910926
nodeIdentity.setFlags(flags); nodeIdentity.save();
911927
LOG_RAW("Type: RPT 0x%02X\n\r", flags);
912928
}
913-
else if (strcmp(cmd, "password") == 0 || strcmp(cmd, "passwd") == 0) {
914-
LOG_RAW("Admin: %s Guest: %s\n\r",
929+
else if (strcmp(cmd, "password") == 0) {
930+
LOG_RAW("A:%s G:%s\n\r",
915931
sessionManager.getAdminPassword(), sessionManager.getGuestPassword());
916932
}
917-
else if (strncmp(cmd, "password ", 9) == 0) {
918-
sessionManager.setAdminPassword(cmd + 9); saveConfig();
919-
LOG_RAW("Admin pwd: %s\n\r", cmd + 9);
920-
}
921-
else if (strncmp(cmd, "passwd admin ", 13) == 0) {
922-
sessionManager.setAdminPassword(cmd + 13); saveConfig();
923-
LOG_RAW("Admin pwd: %s\n\r", cmd + 13);
924-
}
925-
else if (strncmp(cmd, "set guest.password ", 19) == 0) {
926-
sessionManager.setGuestPassword(cmd + 19); saveConfig();
927-
LOG_RAW("Guest pwd: %s\n\r", cmd + 19);
933+
else if (strncmp(cmd, "password admin ", 15) == 0) {
934+
sessionManager.setAdminPassword(cmd + 15); saveConfig();
935+
LOG_RAW("A:%s\n\r", cmd + 15);
928936
}
929-
else if (strncmp(cmd, "passwd guest ", 13) == 0) {
930-
sessionManager.setGuestPassword(cmd + 13); saveConfig();
931-
LOG_RAW("Guest pwd: %s\n\r", cmd + 13);
937+
else if (strncmp(cmd, "password guest ", 15) == 0) {
938+
sessionManager.setGuestPassword(cmd + 15); saveConfig();
939+
LOG_RAW("G:%s\n\r", cmd + 15);
932940
}
933941
else if (strcmp(cmd, "savestats") == 0) {
934942
savePersistentStats(); LOG_RAW("Stats saved\n\r");

src/mesh/Advert.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,10 @@ class AdvertGenerator {
421421
appdata[pos++] = (lon >> 16) & 0xFF;
422422
appdata[pos++] = (lon >> 24) & 0xFF;
423423

424-
Serial.printf("[DEBUG] ADVERT location: %ld.%06ld, %ld.%06ld\n\r",
424+
#ifndef SILENT
425+
Serial.printf("[ADV] loc:%ld.%06ld,%ld.%06ld\n\r",
425426
lat/1000000, abs(lat%1000000), lon/1000000, abs(lon%1000000));
427+
#endif
426428
}
427429

428430
// Name

src/mesh/Contacts.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,6 @@ class ContactManager {
150150
contacts[slot].name[MC_CONTACT_NAME_MAX - 1] = '\0';
151151
}
152152

153-
Serial.printf("[CONTACT] Added: %s (hash=%02X)\n\r",
154-
contacts[slot].name[0] ? contacts[slot].name : "Unknown",
155-
hash);
156-
157153
return &contacts[slot];
158154
}
159155

@@ -370,7 +366,6 @@ class MessageCrypto {
370366

371367
// Verify ciphertext is block-aligned
372368
if (ciphertextLen % MC_AES_BLOCK_SIZE != 0) {
373-
Serial.printf("[CRYPTO] Error: ciphertext not block-aligned\n\r");
374369
return 0;
375370
}
376371

@@ -382,7 +377,6 @@ class MessageCrypto {
382377

383378
// Verify MAC (first 2 bytes)
384379
if (input[0] != mac[0] || input[1] != mac[1]) {
385-
Serial.printf("[CRYPTO] MAC verification failed\n\r");
386380
return 0;
387381
}
388382

src/mesh/Identity.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,23 @@ class IdentityManager {
9898

9999
// Try to load existing identity
100100
if (load()) {
101-
Serial.printf("[ID] Loaded identity from EEPROM\n\r");
101+
#ifndef SILENT
102+
Serial.printf("[ID] Loaded\n\r");
103+
#endif
102104
initialized = true;
103105
return true;
104106
}
105107

106-
Serial.printf("[ID] No valid identity in EEPROM, generating new...\n\r");
108+
#ifndef SILENT
109+
Serial.printf("[ID] New key\n\r");
110+
#endif
107111

108112
// Generate new identity
109113
if (generate()) {
110114
if (save()) {
111-
Serial.printf("[ID] New identity saved to EEPROM\n\r");
112-
} else {
113-
Serial.printf("[ID] WARNING: Failed to save identity!\n\r");
115+
#ifndef SILENT
116+
Serial.printf("[ID] Saved\n\r");
117+
#endif
114118
}
115119
initialized = true;
116120
return true;
@@ -126,9 +130,6 @@ class IdentityManager {
126130
bool load() {
127131
EEPROM.get(IDENTITY_EEPROM_OFFSET, identity);
128132

129-
Serial.printf("[ID] EEPROM magic=%04X (expected %04X) version=%d (expected %d)\n\r",
130-
identity.magic, IDENTITY_MAGIC, identity.version, IDENTITY_VERSION);
131-
132133
if (identity.magic == IDENTITY_MAGIC &&
133134
identity.version == IDENTITY_VERSION) {
134135
return true;

0 commit comments

Comments
 (0)