feat(repeater/analyzer): big console pages + physics-sized tables (rxlog 512, heard 128)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0ddda8cb6c
commit
4d9648ba90
4 files changed
+37
-20
No files matched your search
@@ -182,10 +182,10 @@ void MyMesh::putHeardNode(const mesh::Identity& id, uint32_t advert_timestamp, u
|
|||||||
// <pkthash> = join key: group `rxlog` records by it to get EVERY path this
|
// <pkthash> = join key: group `rxlog` records by it to get EVERY path this
|
||||||
// node's advert arrived by (multi-path). <path> is a single representative
|
// node's advert arrived by (multi-path). <path> is a single representative
|
||||||
// (direct/0-hop preferred). Trailer line: E,<next_offset>,<total>
|
// (direct/0-hop preferred). Trailer line: E,<next_offset>,<total>
|
||||||
void MyMesh::formatNodesReply(char* reply, uint16_t offset) {
|
void MyMesh::formatNodesReply(char* reply, int max_len, uint16_t offset) {
|
||||||
char* dp = reply;
|
char* dp = reply;
|
||||||
int total = 0;
|
int total = 0;
|
||||||
HeardNode* sorted[MAX_HEARD_NODES];
|
static HeardNode* sorted[MAX_HEARD_NODES]; // BSS, ne stack (128 ptrů; volá se jen z loop tasku)
|
||||||
for (int i = 0; i < MAX_HEARD_NODES; i++) {
|
for (int i = 0; i < MAX_HEARD_NODES; i++) {
|
||||||
if (heard_nodes[i].heard_timestamp > 0) sorted[total++] = &heard_nodes[i];
|
if (heard_nodes[i].heard_timestamp > 0) sorted[total++] = &heard_nodes[i];
|
||||||
}
|
}
|
||||||
@@ -207,7 +207,7 @@ void MyMesh::formatNodesReply(char* reply, uint16_t offset) {
|
|||||||
(int)n->snr, (int)n->rssi, (unsigned long)(now - n->heard_timestamp),
|
(int)n->snr, (int)n->rssi, (unsigned long)(now - n->heard_timestamp),
|
||||||
(unsigned long)n->pkt_hash, pathhex, n->name);
|
(unsigned long)n->pkt_hash, pathhex, n->name);
|
||||||
int ll = strlen(line);
|
int ll = strlen(line);
|
||||||
if (i > offset && (dp - reply) + ll + 24 > 150) break; // room for trailer; always emit >=1
|
if (i > offset && (dp - reply) + ll + 24 > max_len) break; // room for trailer; always emit >=1
|
||||||
memcpy(dp, line, ll); dp += ll;
|
memcpy(dp, line, ll); dp += ll;
|
||||||
}
|
}
|
||||||
dp += sprintf(dp, "E,%d,%d", i, total);
|
dp += sprintf(dp, "E,%d,%d", i, total);
|
||||||
@@ -237,9 +237,9 @@ void MyMesh::captureRx(const mesh::Packet* pkt) {
|
|||||||
// `rxlog [cursor]` -> paged dump of frames with seq > cursor (oldest first).
|
// `rxlog [cursor]` -> paged dump of frames with seq > cursor (oldest first).
|
||||||
// One text line per record: R,<seq>,<when>,<pkthash-hex>,<hdr-hex>,<snr*4>,<rssi>,<path-hex>
|
// One text line per record: R,<seq>,<when>,<pkthash-hex>,<hdr-hex>,<snr*4>,<rssi>,<path-hex>
|
||||||
// Trailer line: E,<last_returned_seq>,<oldest_seq_in_ring>,<newest_seq>
|
// Trailer line: E,<last_returned_seq>,<oldest_seq_in_ring>,<newest_seq>
|
||||||
void MyMesh::formatRxLogReply(char* reply, uint32_t cursor) {
|
void MyMesh::formatRxLogReply(char* reply, int max_len, uint32_t cursor) {
|
||||||
char* dp = reply;
|
char* dp = reply;
|
||||||
RxLogRec* recs[RXLOG_SIZE];
|
static RxLogRec* recs[RXLOG_SIZE]; // BSS, ne stack (512 ptrů = 2 KB; volá se jen z loop tasku)
|
||||||
int n = 0;
|
int n = 0;
|
||||||
uint32_t oldest = 0, newest = 0;
|
uint32_t oldest = 0, newest = 0;
|
||||||
for (int i = 0; i < RXLOG_SIZE; i++) {
|
for (int i = 0; i < RXLOG_SIZE; i++) {
|
||||||
@@ -264,7 +264,7 @@ void MyMesh::formatRxLogReply(char* reply, uint32_t cursor) {
|
|||||||
(unsigned long)r->pkt_hash, (unsigned)r->header,
|
(unsigned long)r->pkt_hash, (unsigned)r->header,
|
||||||
(int)r->snr, (int)r->rssi, pathhex);
|
(int)r->snr, (int)r->rssi, pathhex);
|
||||||
int ll = strlen(line);
|
int ll = strlen(line);
|
||||||
if (i > 0 && (dp - reply) + ll + 40 > 150) break; // room for trailer; always emit >=1
|
if (i > 0 && (dp - reply) + ll + 40 > max_len) break; // room for trailer; always emit >=1
|
||||||
memcpy(dp, line, ll); dp += ll;
|
memcpy(dp, line, ll); dp += ll;
|
||||||
last = r->seq;
|
last = r->seq;
|
||||||
}
|
}
|
||||||
@@ -1390,7 +1390,7 @@ void MyMesh::clearStats() {
|
|||||||
((SimpleMeshTables *)getTables())->resetStats();
|
((SimpleMeshTables *)getTables())->resetStats();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyMesh::handleCommand(uint32_t sender_timestamp, char *command, char *reply) {
|
void MyMesh::handleCommand(uint32_t sender_timestamp, char *command, char *reply, int reply_max) {
|
||||||
if (region_load_active) {
|
if (region_load_active) {
|
||||||
if (StrHelper::isBlank(command)) { // empty/blank line, signal to terminate 'load' operation
|
if (StrHelper::isBlank(command)) { // empty/blank line, signal to terminate 'load' operation
|
||||||
region_map = temp_map; // copy over the temp instance as new current map
|
region_map = temp_map; // copy over the temp instance as new current map
|
||||||
@@ -1478,15 +1478,17 @@ void MyMesh::handleCommand(uint32_t sender_timestamp, char *command, char *reply
|
|||||||
}
|
}
|
||||||
#if MAX_HEARD_NODES
|
#if MAX_HEARD_NODES
|
||||||
} else if (memcmp(command, "nodes", 5) == 0 && (command[5] == 0 || command[5] == ' ')) {
|
} else if (memcmp(command, "nodes", 5) == 0 && (command[5] == 0 || command[5] == ' ')) {
|
||||||
// analyzer: paged dump of heard repeaters/room servers (for a map/bridge)
|
// analyzer: paged dump of heard repeaters/room servers (for a map/bridge).
|
||||||
|
// Page size = caller's reply capacity: local console passes ~1000 (fewer BLE
|
||||||
|
// round trips), the mesh admin CLI keeps the default 150 (one LoRa packet).
|
||||||
uint16_t offset = (command[5] == ' ') ? (uint16_t) atoi(&command[6]) : 0;
|
uint16_t offset = (command[5] == ' ') ? (uint16_t) atoi(&command[6]) : 0;
|
||||||
formatNodesReply(reply, offset);
|
formatNodesReply(reply, reply_max, offset);
|
||||||
#endif
|
#endif
|
||||||
#if RXLOG_SIZE
|
#if RXLOG_SIZE
|
||||||
} else if (memcmp(command, "rxlog", 5) == 0 && (command[5] == 0 || command[5] == ' ')) {
|
} else if (memcmp(command, "rxlog", 5) == 0 && (command[5] == 0 || command[5] == ' ')) {
|
||||||
// analyzer: paged firehose of every frame heard, since <cursor> (0 = all)
|
// analyzer: paged firehose of every frame heard, since <cursor> (0 = all)
|
||||||
uint32_t cursor = (command[5] == ' ') ? (uint32_t) strtoul(&command[6], NULL, 10) : 0;
|
uint32_t cursor = (command[5] == ' ') ? (uint32_t) strtoul(&command[6], NULL, 10) : 0;
|
||||||
formatRxLogReply(reply, cursor);
|
formatRxLogReply(reply, reply_max, cursor);
|
||||||
#endif
|
#endif
|
||||||
} else{
|
} else{
|
||||||
#if defined(BLE_PIN_CODE) && defined(NRF52_PLATFORM)
|
#if defined(BLE_PIN_CODE) && defined(NRF52_PLATFORM)
|
||||||
|
|||||||
@@ -199,11 +199,11 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
|
|||||||
void putHeardNode(const mesh::Identity& id, uint32_t advert_timestamp, uint8_t type,
|
void putHeardNode(const mesh::Identity& id, uint32_t advert_timestamp, uint8_t type,
|
||||||
int32_t lat, int32_t lon, const char* name,
|
int32_t lat, int32_t lon, const char* name,
|
||||||
int8_t snr, int8_t rssi, const mesh::Packet* pkt);
|
int8_t snr, int8_t rssi, const mesh::Packet* pkt);
|
||||||
void formatNodesReply(char* reply, uint16_t offset);
|
void formatNodesReply(char* reply, int max_len, uint16_t offset);
|
||||||
#endif
|
#endif
|
||||||
#if RXLOG_SIZE
|
#if RXLOG_SIZE
|
||||||
void captureRx(const mesh::Packet* pkt);
|
void captureRx(const mesh::Packet* pkt);
|
||||||
void formatRxLogReply(char* reply, uint32_t cursor);
|
void formatRxLogReply(char* reply, int max_len, uint32_t cursor);
|
||||||
#endif
|
#endif
|
||||||
uint8_t handleLoginReq(const mesh::Identity& sender, const uint8_t* secret, uint32_t sender_timestamp, const uint8_t* data, bool is_flood);
|
uint8_t handleLoginReq(const mesh::Identity& sender, const uint8_t* secret, uint32_t sender_timestamp, const uint8_t* data, bool is_flood);
|
||||||
uint8_t handleAnonRegionsReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data);
|
uint8_t handleAnonRegionsReq(const mesh::Identity& sender, uint32_t sender_timestamp, const uint8_t* data);
|
||||||
@@ -308,7 +308,11 @@ public:
|
|||||||
void saveIdentity(const mesh::LocalIdentity& new_id) override;
|
void saveIdentity(const mesh::LocalIdentity& new_id) override;
|
||||||
void clearStats() override;
|
void clearStats() override;
|
||||||
|
|
||||||
void handleCommand(uint32_t sender_timestamp, char* command, char* reply);
|
// reply_max = usable reply capacity. Default 150 keeps the mesh admin CLI reply
|
||||||
|
// inside one LoRa packet; the local console (USB/BLE, big buffer) passes more so
|
||||||
|
// the paged analyzer replies (nodes/rxlog) can use big pages. Explicit parameter
|
||||||
|
// on purpose — a forged sender_timestamp must never be able to grow the reply.
|
||||||
|
void handleCommand(uint32_t sender_timestamp, char* command, char* reply, int reply_max = 150);
|
||||||
void loop();
|
void loop();
|
||||||
|
|
||||||
#if defined(WITH_BRIDGE)
|
#if defined(WITH_BRIDGE)
|
||||||
|
|||||||
@@ -28,8 +28,13 @@
|
|||||||
// no flush needed.
|
// no flush needed.
|
||||||
static void bleWriteAll(const char* s) {
|
static void bleWriteAll(const char* s) {
|
||||||
size_t n = strlen(s), i = 0; uint32_t stall = 0;
|
size_t n = strlen(s), i = 0; uint32_t stall = 0;
|
||||||
|
// chunk = ATT payload (MTU-3); bridge negotiates MTU 247 -> 244 B chunks.
|
||||||
|
// Fallback 20 B when MTU stayed at the 23 B default (unpaired phone etc.).
|
||||||
|
size_t maxchunk = 20;
|
||||||
|
BLEConnection* conn = Bluefruit.Connection(Bluefruit.connHandle());
|
||||||
|
if (conn && conn->getMtu() > 23) maxchunk = conn->getMtu() - 3;
|
||||||
while (i < n && Bluefruit.connected() && stall < 300) { // max ~0.9 s stall → bail
|
while (i < n && Bluefruit.connected() && stall < 300) { // max ~0.9 s stall → bail
|
||||||
size_t chunk = n - i; if (chunk > 20) chunk = 20;
|
size_t chunk = n - i; if (chunk > maxchunk) chunk = maxchunk;
|
||||||
size_t w = bleuart.write((const uint8_t*)(s + i), chunk);
|
size_t w = bleuart.write((const uint8_t*)(s + i), chunk);
|
||||||
if (w > 0) { i += w; stall = 0; }
|
if (w > 0) { i += w; stall = 0; }
|
||||||
else { stall++; delay(3); } // queue full -> wait a moment and retry
|
else { stall++; delay(3); } // queue full -> wait a moment and retry
|
||||||
@@ -342,8 +347,8 @@ void loop() {
|
|||||||
if (len > 0 && command[len - 1] == '\r') { // received complete line
|
if (len > 0 && command[len - 1] == '\r') { // received complete line
|
||||||
Serial.print('\n');
|
Serial.print('\n');
|
||||||
command[len - 1] = 0; // replace newline with C string null terminator
|
command[len - 1] = 0; // replace newline with C string null terminator
|
||||||
char reply[160];
|
static char reply[1032]; // big pages for paged analyzer replies (nodes/rxlog); BSS, ne stack
|
||||||
the_mesh.handleCommand(0, command, reply); // NOTE: there is no sender_timestamp via serial!
|
the_mesh.handleCommand(0, command, reply, (int)sizeof(reply) - 32); // NOTE: there is no sender_timestamp via serial!
|
||||||
if (reply[0]) {
|
if (reply[0]) {
|
||||||
Serial.print(" -> "); Serial.println(reply);
|
Serial.print(" -> "); Serial.println(reply);
|
||||||
#if defined(BLE_PIN_CODE) && defined(NRF52_PLATFORM)
|
#if defined(BLE_PIN_CODE) && defined(NRF52_PLATFORM)
|
||||||
|
|||||||
@@ -84,10 +84,16 @@ build_flags =
|
|||||||
; frame firehose over the text console for a BLE bridge/map. RAM-only, ~15 KB.
|
; frame firehose over the text console for a BLE bridge/map. RAM-only, ~15 KB.
|
||||||
; nodes [offset] -> heard repeater/room registry (identity, geo, SNR, path)
|
; nodes [offset] -> heard repeater/room registry (identity, geo, SNR, path)
|
||||||
; rxlog [cursor] -> circular log of every frame heard (type, path, SNR/RSSI)
|
; rxlog [cursor] -> circular log of every frame heard (type, path, SNR/RSSI)
|
||||||
; RXLOG_SIZE 96 -> 256 (~32 B/rec): daytime advert bursts overflowed the ring
|
; Sized from channel physics, not last week's traffic (so we stop re-raising):
|
||||||
; between BLE drains (~250 drops/h, meshcore_rxlog_dropped_total)
|
; RXLOG_SIZE 512 (~32 B/rec, 16 KB): ~2 min of a fully saturated SF8/62.5k
|
||||||
-D MAX_HEARD_NODES=48
|
; channel (~2-4 frames/s) or ~35 min of typical traffic -- covers BLE
|
||||||
-D RXLOG_SIZE=256
|
; outages; the fast big-page drain (~40+ rec/s) outruns the radio itself.
|
||||||
|
; MAX_HEARD_NODES 128 (~68 B/entry, 8.7 KB): the 48-slot registry filled in
|
||||||
|
; <2 h and churn evicted real neighbours (Kladno, ABC_10W_MKT) into the
|
||||||
|
; poorer `neighbors`-table fallback; 128 > distinct nodes heard per
|
||||||
|
; neighbour advert period even on inversion evenings.
|
||||||
|
-D MAX_HEARD_NODES=128
|
||||||
|
-D RXLOG_SIZE=512
|
||||||
; -D MESH_PACKET_LOGGING=1
|
; -D MESH_PACKET_LOGGING=1
|
||||||
build_src_filter = ${SenseCap_Solar.build_src_filter}
|
build_src_filter = ${SenseCap_Solar.build_src_filter}
|
||||||
+<../examples/simple_repeater/*.cpp>
|
+<../examples/simple_repeater/*.cpp>
|
||||||
|
|||||||
Reference in new issue
Block a user