Merge bench/rf-cmd into main
tth-docs / site (push) Successful in 20s
pub-release / release (push) Failing after 13m45s

This commit is contained in:
tth committed 2026-12-04 19:18:14 +01:00
commit 171d350c16
4 files changed
+85

No files matched your search

+68
View File
@@ -1568,6 +1568,11 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc
set_radio_at = revert_radio_at = 0;
_logging = false;
region_load_active = false;
#ifdef BENCH_RF_CMD
bench_tx_left = bench_tx_seq = bench_tx_gap = bench_tx_jitter = 0;
bench_tx_next = 0;
bench_tx_len = 0;
#endif
recv_pkt_region = NULL;
#if MAX_NEIGHBOURS
@@ -2026,6 +2031,49 @@ void MyMesh::handleCommand(uint32_t sender_timestamp, char *command, char *reply
__builtin_trap(); // UDF -> UsageFault, escalates to HardFault
}
#endif
#ifdef BENCH_RF_CMD
// Bench only (-D BENCH_RF_CMD), local console only: RX-loss tests of rxps (#46).
// bench preamble <symbols>|0 transmit with this preamble (0 = the SF's default)
// bench tx <count> <len> <gap ms> [jitter ms] zero-hop RAW_CUSTOM train
// bench tx progress; bench tx stop
if (sender_timestamp == 0 && strncmp(command, "bench ", 6) == 0) {
const char* a = command + 6;
if (strncmp(a, "preamble ", 9) == 0) {
int n = atoi(a + 9);
if (n < 0 || n > 1024) { strcpy(reply, "Error: bench preamble <0-1024>"); return; }
int16_t st = radio_driver.benchSetPreamble((uint16_t) n);
sprintf(reply, "%s - bench preamble %d (radiolib %d)", st == 0 ? "OK" : "Err", n, (int) st);
return;
}
if (strcmp(a, "tx") == 0) {
sprintf(reply, "> bench tx left %lu, sent seq %lu, len %u, gap %lu+%lu ms",
(unsigned long) bench_tx_left, (unsigned long) bench_tx_seq, (unsigned) bench_tx_len,
(unsigned long) bench_tx_gap, (unsigned long) bench_tx_jitter);
return;
}
if (strcmp(a, "tx stop") == 0) {
bench_tx_left = 0;
strcpy(reply, "OK - bench tx stopped");
return;
}
if (strncmp(a, "tx ", 3) == 0) {
unsigned long cnt = 0, len = 0, gap = 0, jit = 0;
int got = sscanf(a + 3, "%lu %lu %lu %lu", &cnt, &len, &gap, &jit);
if (got < 3 || len < 8 || len > MAX_PACKET_PAYLOAD || gap < 100) {
strcpy(reply, "Error: bench tx <count> <len 8-184> <gap ms>=100> [jitter ms]");
return;
}
bench_tx_left = cnt;
bench_tx_seq = 0;
bench_tx_len = (uint8_t) len;
bench_tx_gap = gap;
bench_tx_jitter = got >= 4 ? jit : 0;
bench_tx_next = millis();
sprintf(reply, "OK - bench tx %lu x %lu B every %lu+%lu ms", cnt, len, gap, (unsigned long) bench_tx_jitter);
return;
}
}
#endif
const char* cmd = command;
cli_args::stripPrefix(cmd, reply, &reply_max);
@@ -2150,12 +2198,32 @@ void MyMesh::handleCommand(uint32_t sender_timestamp, char *command, char *reply
}
}
#ifdef BENCH_RF_CMD
void MyMesh::benchTxLoop() {
if (bench_tx_left == 0 || !millisHasNowPassed(bench_tx_next)) return;
uint8_t data[MAX_PACKET_PAYLOAD];
memcpy(data, &bench_tx_seq, 4); // receivers can count gaps from the sequence
getRNG()->random(&data[4], bench_tx_len - 4); // unique packet hash every time
mesh::Packet* pkt = createRawData(data, bench_tx_len);
if (pkt) {
sendZeroHop(pkt);
bench_tx_seq++;
bench_tx_left--;
}
uint32_t jit = bench_tx_jitter ? getRNG()->nextInt(0, bench_tx_jitter + 1) : 0;
bench_tx_next = futureMillis(bench_tx_gap + jit);
}
#endif
void MyMesh::loop() {
#ifdef WITH_BRIDGE
bridge.loop();
#endif
mesh::Mesh::loop();
#ifdef BENCH_RF_CMD
benchTxLoop();
#endif
// Fairness limiter refilling. The `else if` chain keeps the three timers from
// aligning on one loop pass; each adds ONE token per bucket per interval.