Add packed noise-floor telemetry history for both radio profiles

This commit is contained in:
mikecarper committed 2026-10-22 16:50:31 -07:00
1 parent 52a36c89dc
commit f4ade738df
32 files changed
+2520 -53

No files matched your search

+54 -2
View File
@@ -245,6 +245,8 @@ static const uint8_t TELEMETRY_HISTORY_TX_MAX_DAYS = 30U;
static const uint8_t TELEMETRY_HISTORY_TX_TEMPERATURE = 1U;
static const uint8_t TELEMETRY_HISTORY_TX_VOLTAGE = 2U;
static const uint8_t TELEMETRY_HISTORY_TX_EXTERNAL_VOLTAGE = 4U;
static const uint8_t TELEMETRY_HISTORY_TX_NOISE = 8U;
static const uint8_t TELEMETRY_HISTORY_TX_NOISE2 = 16U;
#endif
#define CLOCK_SYNC_VALID_YEARS 10
@@ -12270,6 +12272,9 @@ void MyMesh::handleCommand(uint32_t sender_timestamp, ClientInfo* sender, char *
while (*command == ' ') command++; // skip leading spaces
#if MESH_ENABLE_TELEMETRY_HISTORY
const bool prefixed_reply = strlen(command) > 4 && command[2] == '|';
#endif
if (strlen(command) > 4 && command[2] == '|') { // optional prefix (for companion radio CLI)
memcpy(reply, command, 3); // reflect the prefix back
reply += 3;
@@ -12309,6 +12314,17 @@ void MyMesh::handleCommand(uint32_t sender_timestamp, ClientInfo* sender, char *
#endif
#if MESH_ENABLE_TELEMETRY_HISTORY
const char* noise_commands[] = {"get telemetry.noise", "get telemetry.noise2"};
for (uint8_t profile = 0; profile < 2; ++profile) {
const size_t length = strlen(noise_commands[profile]);
if (strncmp(command, noise_commands[profile], length) == 0
&& (command[length] == 0 || command[length] == ' ')) {
if (sender != NULL && !sender->isAdmin()) strcpy(reply, "Err - not permitted");
else noise_floor_history.formatPageReply(profile, command + length, reply,
prefixed_reply ? 157 : 160, !prefixed_reply);
return;
}
}
const char* telemetry_args = NULL;
mesh::TelemetryHistory::Series telemetry_series =
mesh::TelemetryHistory::SERIES_TEMPERATURE;
@@ -12351,6 +12367,10 @@ void MyMesh::handleCommand(uint32_t sender_timestamp, ClientInfo* sender, char *
}
telemetry_history_tx_pending = TELEMETRY_HISTORY_TX_TEMPERATURE
| TELEMETRY_HISTORY_TX_VOLTAGE;
if (noise_floor_history.sampleCount(0) != 0)
telemetry_history_tx_pending |= TELEMETRY_HISTORY_TX_NOISE;
if (isDualRadioActive() && noise_floor_history.sampleCount(1) != 0)
telemetry_history_tx_pending |= TELEMETRY_HISTORY_TX_NOISE2;
const uint8_t external_channels =
external_voltage_history.populatedChannelCount();
if (external_channels != 0) {
@@ -12371,8 +12391,10 @@ void MyMesh::handleCommand(uint32_t sender_timestamp, ClientInfo* sender, char *
const unsigned external_packets = (unsigned)external_channels
* external_voltage_history.binaryChunkCount();
snprintf(reply, 160,
"OK - telemetry.tx queued temp=%u volt=%u i2c=%u/%u",
sent, sent, (unsigned)external_channels, external_packets);
"OK - telemetry.tx queued temp=%u volt=%u i2c=%u/%u noise=%u/%u",
sent, sent, (unsigned)external_channels, external_packets,
(telemetry_history_tx_pending & TELEMETRY_HISTORY_TX_NOISE) != 0,
(telemetry_history_tx_pending & TELEMETRY_HISTORY_TX_NOISE2) != 0);
return;
}
@@ -13326,6 +13348,18 @@ bool MyMesh::sendTelemetryHistorySnapshot(
return sendDirect(packet, data_path, data_path_len);
}
bool MyMesh::sendNoiseFloorHistorySnapshot(uint8_t profile) {
const uint8_t* data_path = NULL;
uint8_t data_path_len = OUT_PATH_UNKNOWN;
if (!_cli.getDataTxPath(data_path, data_path_len)) return false;
uint8_t payload[mesh::NoiseFloorHistory::BINARY_PAYLOAD_SIZE];
const size_t length = noise_floor_history.formatBinarySnapshot(
profile, self_id.pub_key, payload, sizeof(payload));
if (length <= mesh::NoiseFloorHistory::BINARY_HEADER_SIZE) return false;
mesh::Packet* packet = createRawData(payload, length);
return packet != NULL && sendDirect(packet, data_path, data_path_len);
}
bool MyMesh::sendExternalVoltageHistorySnapshot(uint8_t channel_index,
uint8_t chunk_index) {
const uint8_t* data_path = NULL;
@@ -13369,6 +13403,10 @@ void MyMesh::serviceTelemetryHistoryTx() {
telemetry_history_tx_resume_uptime = 0;
telemetry_history_tx_pending = TELEMETRY_HISTORY_TX_TEMPERATURE
| TELEMETRY_HISTORY_TX_VOLTAGE;
if (noise_floor_history.sampleCount(0) != 0)
telemetry_history_tx_pending |= TELEMETRY_HISTORY_TX_NOISE;
if (isDualRadioActive() && noise_floor_history.sampleCount(1) != 0)
telemetry_history_tx_pending |= TELEMETRY_HISTORY_TX_NOISE2;
if (external_voltage_history.populatedChannelCount() != 0) {
telemetry_history_tx_pending |= TELEMETRY_HISTORY_TX_EXTERNAL_VOLTAGE;
}
@@ -13392,6 +13430,14 @@ void MyMesh::serviceTelemetryHistoryTx() {
telemetry_history_tx_pending &=
(uint8_t)~TELEMETRY_HISTORY_TX_VOLTAGE;
}
} else if ((telemetry_history_tx_pending & TELEMETRY_HISTORY_TX_NOISE) != 0) {
sent = noise_floor_history.sampleCount(0) == 0
|| sendNoiseFloorHistorySnapshot(0);
if (sent) telemetry_history_tx_pending &= (uint8_t)~TELEMETRY_HISTORY_TX_NOISE;
} else if ((telemetry_history_tx_pending & TELEMETRY_HISTORY_TX_NOISE2) != 0) {
sent = !isDualRadioActive() || noise_floor_history.sampleCount(1) == 0
|| sendNoiseFloorHistorySnapshot(1);
if (sent) telemetry_history_tx_pending &= (uint8_t)~TELEMETRY_HISTORY_TX_NOISE2;
} else if ((telemetry_history_tx_pending
& TELEMETRY_HISTORY_TX_EXTERNAL_VOLTAGE) != 0) {
const uint8_t channel_count =
@@ -13443,6 +13489,11 @@ void MyMesh::serviceTelemetryHistoryTx() {
}
}
void MyMesh::sampleNoiseFloorHistory() {
noise_floor_sampler.poll(*_radio, noise_floor_history,
rtc_clock.getCurrentTime(), millis());
}
void MyMesh::sampleTelemetryHistory() {
const uint32_t now = rtc_clock.getCurrentTime();
if (!telemetry_history.sampleDue(now)) return;
@@ -13516,6 +13567,7 @@ void __attribute__((noinline)) MyMesh::servicePostMeshLoop() {
#endif
checkRxInactivityWatchdog();
#if MESH_ENABLE_TELEMETRY_HISTORY
sampleNoiseFloorHistory();
sampleTelemetryHistory();
serviceTelemetryHistoryTx();
#endif
+5
View File
@@ -126,6 +126,7 @@
#if MESH_ENABLE_TELEMETRY_HISTORY
#include <helpers/ExternalVoltageHistory.h>
#include <helpers/TelemetryHistory.h>
#include <helpers/NoiseFloorHistorySampler.h>
#endif
#include <helpers/TxtDataHelpers.h>
#include <helpers/RegionMap.h>
@@ -575,6 +576,8 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks
#if MESH_ENABLE_TELEMETRY_HISTORY
mesh::TelemetryHistory telemetry_history;
mesh::ExternalVoltageHistory external_voltage_history;
mesh::NoiseFloorHistory noise_floor_history;
mesh::NoiseFloorHistorySampler noise_floor_sampler;
bool telemetry_history_tx_prefs_healthy;
bool telemetry_history_tx_enabled;
uint8_t telemetry_history_tx_interval_days;
@@ -859,6 +862,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks
void servicePostMeshLoop();
#if MESH_ENABLE_TELEMETRY_HISTORY
void sampleTelemetryHistory();
void sampleNoiseFloorHistory();
#if MESH_ENABLE_TELEMETRY_GPS_HISTORY
uint8_t resizeTelemetryGpsDays(uint8_t requested_days);
#endif
@@ -866,6 +870,7 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks
bool saveTelemetryHistoryTxPrefs();
void serviceTelemetryHistoryTx();
bool sendTelemetryHistorySnapshot(mesh::TelemetryHistory::Series series);
bool sendNoiseFloorHistorySnapshot(uint8_t profile);
bool sendExternalVoltageHistorySnapshot(uint8_t channel_index,
uint8_t chunk_index);
void formatTelemetryHistoryTxStatus(char* reply, size_t reply_size) const;
+25 -4
View File
@@ -3649,7 +3649,18 @@ void MyMesh::onUserGpioTimerCompleted(uint8_t pin, uint8_t state,
#endif
#if MESH_ENABLE_TELEMETRY_HISTORY
bool MyMesh::handleTelemetryHistoryCommand(const char* command, char* reply) {
bool MyMesh::handleTelemetryHistoryCommand(const char* command, char* reply,
size_t reply_capacity, bool include_prompt) {
const char* noise_commands[] = {"get telemetry.noise", "get telemetry.noise2"};
for (uint8_t profile = 0; profile < 2; ++profile) {
const size_t length = strlen(noise_commands[profile]);
if (strncmp(command, noise_commands[profile], length) == 0
&& (command[length] == 0 || command[length] == ' ')) {
noise_floor_history.formatPageReply(profile, command + length, reply,
reply_capacity, include_prompt);
return true;
}
}
static const char temperature_command[] = "get telemetry.temp";
static const char battery_command[] = "get telemetry.volt";
static const char external_voltage_command[] =
@@ -3663,7 +3674,7 @@ bool MyMesh::handleTelemetryHistoryCommand(const char* command, char* reply) {
&& (command[sizeof(external_voltage_command) - 1U] == 0
|| command[sizeof(external_voltage_command) - 1U] == ' ')) {
external_voltage_history.formatPageReply(
command + sizeof(external_voltage_command) - 1U, reply, 160);
command + sizeof(external_voltage_command) - 1U, reply, reply_capacity);
return true;
}
@@ -3691,10 +3702,15 @@ bool MyMesh::handleTelemetryHistoryCommand(const char* command, char* reply) {
}
if (args == NULL) return false;
telemetry_history.formatPageReply(series, args, reply, 160);
telemetry_history.formatPageReply(series, args, reply, reply_capacity);
return true;
}
void MyMesh::sampleNoiseFloorHistory() {
noise_floor_sampler.poll(*_radio, noise_floor_history,
getRTCClock()->getCurrentTime(), millis());
}
void MyMesh::sampleTelemetryHistory() {
const uint32_t now = getRTCClock()->getCurrentTime();
if (!telemetry_history.sampleDue(now)) return;
@@ -3803,6 +3819,9 @@ void MyMesh::handleCommand(uint32_t sender_timestamp, char *command, char *reply
while (*command == ' ')
command++; // skip leading spaces
#if MESH_ENABLE_TELEMETRY_HISTORY
const bool prefixed_reply = strlen(command) > 4 && command[2] == '|';
#endif
if (strlen(command) > 4 && command[2] == '|') { // optional prefix (for companion radio CLI)
memcpy(reply, command, 3); // reflect the prefix back
reply += 3;
@@ -3840,7 +3859,8 @@ void MyMesh::handleCommand(uint32_t sender_timestamp, char *command, char *reply
#endif
#if MESH_ENABLE_TELEMETRY_HISTORY
if (handleTelemetryHistoryCommand(command, reply)) return;
if (handleTelemetryHistoryCommand(command, reply,
prefixed_reply ? 157 : 160, !prefixed_reply)) return;
#endif
// handle ACL related commands
@@ -4000,6 +4020,7 @@ void MyMesh::loop() {
#endif
_clock_sync.loop();
#if MESH_ENABLE_TELEMETRY_HISTORY
sampleNoiseFloorHistory();
sampleTelemetryHistory();
#endif
#ifdef WITH_MQTT_BRIDGE
+6 -1
View File
@@ -66,6 +66,7 @@ namespace mesh { class RoomJsonWriter; }
#if MESH_ENABLE_TELEMETRY_HISTORY
#include <helpers/ExternalVoltageHistory.h>
#include <helpers/TelemetryHistory.h>
#include <helpers/NoiseFloorHistorySampler.h>
#endif
#ifdef WITH_MQTT_BRIDGE
@@ -253,6 +254,8 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks,
#if MESH_ENABLE_TELEMETRY_HISTORY
mesh::TelemetryHistory telemetry_history;
mesh::ExternalVoltageHistory external_voltage_history;
mesh::NoiseFloorHistory noise_floor_history;
mesh::NoiseFloorHistorySampler noise_floor_sampler;
#endif
RegionEntry* load_stack[8];
RegionEntry* recv_pkt_region;
@@ -493,8 +496,10 @@ protected:
bool sendFloodReply(mesh::Packet* packet, unsigned long delay_millis, uint8_t path_hash_size);
#if MESH_ENABLE_TELEMETRY_HISTORY
bool handleTelemetryHistoryCommand(const char* command, char* reply);
bool handleTelemetryHistoryCommand(const char* command, char* reply,
size_t reply_capacity = 160, bool include_prompt = true);
void sampleTelemetryHistory();
void sampleNoiseFloorHistory();
#endif
public: