commit
3633402e59
154 files changed
+4224
-898
No files matched your search
@@ -993,6 +993,8 @@ void MyMesh::begin() {
|
||||
_prefs.tx_power_dbm = constrain(_prefs.tx_power_dbm, -9, MAX_LORA_TX_POWER);
|
||||
_prefs.gps_enabled = constrain(_prefs.gps_enabled, 0, 1); // Ensure boolean 0 or 1
|
||||
_prefs.gps_interval = constrain(_prefs.gps_interval, 0, 86400); // Max 24 hours
|
||||
_prefs.adc_multiplier = constrain(_prefs.adc_multiplier, 0.0f, 10.0f);
|
||||
if (!board.setAdcMultiplier(_prefs.adc_multiplier)) _prefs.adc_multiplier = 0.0f;
|
||||
|
||||
_active_ble_pin = _prefs.ble_pin;
|
||||
|
||||
@@ -2093,6 +2095,11 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp, char*
|
||||
return true;
|
||||
}
|
||||
|
||||
if (_prefs.getGpsPrefs()->handleCommand(command, sensors, reply)) {
|
||||
if (_prefs.getGpsPrefs()->isDirty()) { savePrefs(); }
|
||||
return true;
|
||||
}
|
||||
|
||||
// hook for variant-specific CLI processing
|
||||
if (board.handleCommand(command, sender_timestamp, reply)) {
|
||||
if (_prefs.isDirty()) { savePrefs(); }
|
||||
@@ -2210,6 +2217,33 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp, char*
|
||||
return true;
|
||||
}
|
||||
|
||||
if (memcmp(command, "set adc.multiplier ", 19) == 0) { // same as CommonCLI
|
||||
float mult = atof(&command[19]);
|
||||
if (mult < 0.0f || mult > 10.0f) {
|
||||
strcpy(reply, "Error, must be from 0 to 10");
|
||||
} else if (board.setAdcMultiplier(mult)) {
|
||||
_prefs.adc_multiplier = mult;
|
||||
savePrefs();
|
||||
if (mult == 0.0f) {
|
||||
strcpy(reply, "OK - using default board multiplier");
|
||||
} else {
|
||||
sprintf(reply, "OK - multiplier set to %.3f", mult);
|
||||
}
|
||||
} else {
|
||||
strcpy(reply, "Error: unsupported");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (strcmp(command, "get adc.multiplier") == 0) {
|
||||
float mult = board.getAdcMultiplier();
|
||||
if (mult == 0.0f) {
|
||||
strcpy(reply, "Error: unsupported");
|
||||
} else {
|
||||
sprintf(reply, "> %.3f", mult);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strcmp(command, "get tz.offset") == 0) {
|
||||
float q = _prefs.tz_offset * 4;
|
||||
sprintf(reply, (q == (int)q && ((int)q & 1)) ? "> %.2f" : "> %.1f", _prefs.tz_offset);
|
||||
@@ -2286,6 +2320,18 @@ bool MyMesh::handleCommand(const char* command, uint32_t sender_timestamp, char*
|
||||
sprintf(reply, "> ui.nd_name is now %d", _prefs.ui_nd_name);
|
||||
return true;
|
||||
}
|
||||
if (memcmp(command, "set ui.gps_action", 17) == 0) {
|
||||
const char* v = &command[17];
|
||||
while (*v == ' ') v++;
|
||||
_prefs.ui_gps_action = (memcmp(v, "once", 4) == 0 || memcmp(v, "trigger", 7) == 0 || *v == '1') ? 1 : 0; // anything else: toggle
|
||||
savePrefs();
|
||||
sprintf(reply, "> now %s", _prefs.ui_gps_action ? "once" : "toggle");
|
||||
return true;
|
||||
}
|
||||
if (memcmp(command, "get ui.gps_action", 17) == 0) {
|
||||
sprintf(reply, "> %s", _prefs.ui_gps_action ? "once" : "toggle");
|
||||
return true;
|
||||
}
|
||||
if (memcmp(command, "get ui.show_clock", 17) == 0) {
|
||||
sprintf(reply, "> %d", _prefs.ui_show_clock);
|
||||
return true;
|
||||
|
||||
@@ -203,12 +203,13 @@ public:
|
||||
|
||||
#if ENV_INCLUDE_GPS == 1
|
||||
void applyGpsPrefs() {
|
||||
sensors.setSettingValue("gps", _prefs.gps_enabled ? "1" : "0");
|
||||
if (_prefs.gps_interval > 0) {
|
||||
char interval_str[12]; // Max: 24 hours = 86400 seconds (5 digits + null)
|
||||
sprintf(interval_str, "%u", _prefs.gps_interval);
|
||||
sensors.setSettingValue("gps_interval", interval_str);
|
||||
if (_prefs.gps_interval > 0 &&
|
||||
sensors.getSettingByKey("gps_interval") != nullptr) {
|
||||
char interval[11];
|
||||
snprintf(interval, sizeof(interval), "%lu", (unsigned long)_prefs.gps_interval);
|
||||
sensors.setSettingValue("gps_interval", interval);
|
||||
}
|
||||
_prefs.getGpsPrefs()->apply(sensors);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <cstdint> // For uint8_t, uint32_t
|
||||
#include <helpers/ConfigSerializer.h>
|
||||
#include <helpers/CommonRadioPrefs.h>
|
||||
#include <helpers/CommonGpsPrefs.h>
|
||||
#include <helpers/DynamicConfigSerializer.h>
|
||||
|
||||
#define TELEM_MODE_DENY 0
|
||||
@@ -35,6 +36,9 @@ public:
|
||||
uint8_t vibe_quiet = 0;
|
||||
uint8_t gps_enabled = 0; // GPS enabled flag (0=disabled, 1=enabled)
|
||||
uint32_t gps_interval = 0; // GPS read interval in seconds
|
||||
uint32_t gps_period = 0; // periodic acquisition interval in seconds
|
||||
int32_t gps_fence = -1; // GPS_GUARD fence in metres, 0 = off, -1 = build default
|
||||
uint8_t gps_guard = 1; // GPS_GUARD on/off
|
||||
uint8_t autoadd_config = 0; // bitmask for auto-add contacts config
|
||||
uint8_t rx_boosted_gain = 0; // SX126x RX boosted gain mode (0=power saving, 1=boosted)
|
||||
uint8_t radio_fem_rxgain = 0; // external LoRa FEM RX gain (LNA)
|
||||
@@ -48,6 +52,7 @@ public:
|
||||
char default_scope_name[31];
|
||||
uint8_t default_scope_key[16];
|
||||
float tz_offset = 0;
|
||||
float adc_multiplier = 0; // battery ADC multiplier, 0 = board default
|
||||
#ifdef ENABLE_WIFI_INTERFACE
|
||||
#ifndef WIFI_SSID
|
||||
#define WIFI_SSID ""
|
||||
@@ -85,6 +90,11 @@ public:
|
||||
uint8_t ui_auto_off_keep_msgs = 1;
|
||||
uint8_t ui_max_partial = EINK_MAX_PARTIAL_REFRESH;
|
||||
uint8_t ui_nd_name = 1;
|
||||
#ifdef PIN_GPS_SWITCH
|
||||
uint8_t ui_gps_action = 1;
|
||||
#else
|
||||
uint8_t ui_gps_action = 0;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
private:
|
||||
@@ -151,16 +161,36 @@ private:
|
||||
};
|
||||
RadioPrefs radio;
|
||||
|
||||
class GPSPrefs : public ConfigSerializer { // COPIED from CommonCLI (for now)
|
||||
class GPSPrefs : public CommonGpsPrefs {
|
||||
NodePrefs* _parent;
|
||||
protected:
|
||||
void structure() override {
|
||||
def("en", _parent->gps_enabled); // boolean
|
||||
def("int", _parent->gps_interval); // interval in seconds
|
||||
def("period", _parent->gps_period); // periodic acquisition interval in seconds
|
||||
def("adv_loc", _parent->advert_loc_policy);
|
||||
#ifdef GPS_GUARD
|
||||
def("fence", _parent->gps_fence);
|
||||
def("guard", _parent->gps_guard);
|
||||
#endif
|
||||
}
|
||||
public:
|
||||
GPSPrefs(NodePrefs* parent) : _parent(parent) { }
|
||||
bool isGpsEnabled() const override { return _parent->gps_enabled; }
|
||||
void setGpsEnabled(bool enabled) override { _parent->gps_enabled = enabled; markDirty(); }
|
||||
uint32_t getGpsPeriod() const override { return _parent->gps_period; }
|
||||
void setGpsPeriod(uint32_t seconds) override { _parent->gps_period = seconds; markDirty(); }
|
||||
bool getGuardFence(uint32_t& metres) const override {
|
||||
if (_parent->gps_fence < 0) return false;
|
||||
metres = (uint32_t)_parent->gps_fence;
|
||||
return true;
|
||||
}
|
||||
void setGuardFence(uint32_t metres) override { _parent->gps_fence = (int32_t)metres; markDirty(); }
|
||||
bool getGuardEnabled(bool& enabled) const override {
|
||||
enabled = _parent->gps_guard != 0;
|
||||
return true;
|
||||
}
|
||||
void setGuardEnabled(bool enabled) override { _parent->gps_guard = enabled ? 1 : 0; markDirty(); }
|
||||
};
|
||||
GPSPrefs gps;
|
||||
|
||||
@@ -194,6 +224,7 @@ private:
|
||||
def("tel_loc", _parent->telemetry_mode_loc);
|
||||
def("tel_env", _parent->telemetry_mode_env);
|
||||
def("tz_offset", _parent->tz_offset);
|
||||
def("adc_mult", _parent->adc_multiplier);
|
||||
}
|
||||
public:
|
||||
CompanionPrefs(NodePrefs* parent) : _parent(parent) { }
|
||||
@@ -231,6 +262,7 @@ private:
|
||||
def("off_blank", _parent->ui_auto_off_blank);
|
||||
def("off_keep_msgs", _parent->ui_auto_off_keep_msgs);
|
||||
def("nd_name", _parent->ui_nd_name);
|
||||
def("gps_act", _parent->ui_gps_action);
|
||||
}
|
||||
public:
|
||||
UI_Prefs(NodePrefs* parent) : _parent(parent) {}
|
||||
@@ -275,8 +307,9 @@ public:
|
||||
void setRepeatEn(bool en) { repeat.disable_fwd = en ? 0 : 1; }
|
||||
|
||||
CommonRadioPrefs* getRadioPrefs() { return &radio; }
|
||||
CommonGpsPrefs* getGpsPrefs() { return &gps; }
|
||||
KeyValueStore* getCustom() { return &custom; }
|
||||
|
||||
bool isDirty() const override { return ConfigSerializer::isDirty() || radio.isDirty() || custom.isDirty(); }
|
||||
void clearDirty() override { ConfigSerializer::clearDirty(); radio.clearDirty(); custom.clearDirty(); }
|
||||
bool isDirty() const override { return ConfigSerializer::isDirty() || radio.isDirty() || gps.isDirty() || custom.isDirty(); }
|
||||
void clearDirty() override { ConfigSerializer::clearDirty(); radio.clearDirty(); gps.clearDirty(); custom.clearDirty(); }
|
||||
};
|
||||
@@ -2,6 +2,11 @@
|
||||
#include <Mesh.h>
|
||||
#include "MyMesh.h"
|
||||
|
||||
#if defined(ENABLE_WIFI_INTERFACE) && defined(ENABLE_ESP_MDNS)
|
||||
#define HAS_ESP_MDNS
|
||||
#include <ESPmDNS.h>
|
||||
#endif
|
||||
|
||||
// Believe it or not, this std C function is busted on some platforms!
|
||||
static uint32_t _atoi(const char* sp) {
|
||||
uint32_t n = 0;
|
||||
@@ -132,6 +137,10 @@ void halt() {
|
||||
bool wifi_enabled = false; // set at boot from prefs; false also when the effective SSID is blank
|
||||
#endif
|
||||
|
||||
#if defined(DISPLAY_CLASS) && defined(EINK_REFRESH_LOOP)
|
||||
static void loopDuringDisplayRefresh();
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
board.begin();
|
||||
@@ -266,6 +275,33 @@ void setup() {
|
||||
interface_manager.addInterface(InterfaceType::Ethernet, ðernet_interface);
|
||||
#endif
|
||||
|
||||
#ifdef HAS_ESP_MDNS
|
||||
String nodeName = the_mesh.getNodeName();
|
||||
String sanitizedNodeName;
|
||||
sanitizedNodeName.reserve(nodeName.length());
|
||||
for (size_t i = 0; i < nodeName.length(); ++i) {
|
||||
const char c = nodeName[i];
|
||||
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
|
||||
(c >= '0' && c <= '9') || c == '-' || c == '_') {
|
||||
sanitizedNodeName += c;
|
||||
}
|
||||
}
|
||||
|
||||
String mdnsName = "meshcore_";
|
||||
mdnsName += sanitizedNodeName;
|
||||
if (!MDNS.begin(mdnsName.c_str())) {
|
||||
WIFI_DEBUG_PRINTLN("mDNS failed to start!");
|
||||
} else {
|
||||
MDNS.addService("meshcore", "tcp", TCP_PORT);
|
||||
MDNS.addServiceTxt("meshcore", "tcp", "node-name", the_mesh.getNodeName());
|
||||
MDNS.addServiceTxt("meshcore", "tcp", "firmware-version", FIRMWARE_VERSION);
|
||||
String protocol; protocol+=FIRMWARE_VER_CODE;
|
||||
MDNS.addServiceTxt("meshcore", "tcp", "protocol-version", protocol.c_str());
|
||||
MDNS.addServiceTxt("meshcore", "tcp", "build-date", __DATE__);
|
||||
MDNS.addServiceTxt("meshcore", "tcp", "build-time", __TIME__);
|
||||
}
|
||||
#endif
|
||||
|
||||
// add hardware serial interface
|
||||
#if defined(SERIAL_RX)
|
||||
companion_serial.setPins(SERIAL_RX, SERIAL_TX);
|
||||
@@ -284,15 +320,36 @@ void setup() {
|
||||
#ifdef DISPLAY_CLASS
|
||||
ui_task.begin(disp, &sensors, the_mesh.getNodePrefs()); // still want to pass this in as dependency, as prefs might be moved
|
||||
the_mesh.setListener(&ui_task);
|
||||
#ifdef EINK_REFRESH_LOOP
|
||||
if (disp != NULL) disp->setBusyHook(loopDuringDisplayRefresh);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
board.onBootComplete();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Work that must keep running even while the UI is blocked (e.g. by an e-ink refresh).
|
||||
// Called from loop() and from the display busy hook, so both always run the same set.
|
||||
static void loopCore() {
|
||||
the_mesh.loop();
|
||||
interface_manager.loop();
|
||||
sensors.loop();
|
||||
}
|
||||
|
||||
#if defined(DISPLAY_CLASS) && defined(EINK_REFRESH_LOOP)
|
||||
// Runs from inside the e-ink busy wait, so radio/BLE/sensors keep going during a panel refresh.
|
||||
// Must not touch the display: UI listener callbacks only update state and schedule the next frame.
|
||||
static void loopDuringDisplayRefresh() {
|
||||
static bool active = false;
|
||||
if (active) return;
|
||||
active = true;
|
||||
loopCore();
|
||||
active = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
void loop() {
|
||||
loopCore();
|
||||
#ifdef DISPLAY_CLASS
|
||||
ui_task.loop();
|
||||
#endif
|
||||
|
||||
@@ -86,6 +86,30 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
#if ENV_INCLUDE_GPS == 1
|
||||
// exact period with the largest unit that divides it: "30s", "5m", "2h"
|
||||
static void formatGpsPeriod(char* buf, size_t size, uint32_t seconds) {
|
||||
if (seconds % 3600 == 0) {
|
||||
snprintf(buf, size, "%luh", (unsigned long)(seconds / 3600));
|
||||
} else if (seconds % 60 == 0) {
|
||||
snprintf(buf, size, "%lum", (unsigned long)(seconds / 60));
|
||||
} else {
|
||||
snprintf(buf, size, "%lus", (unsigned long)seconds);
|
||||
}
|
||||
}
|
||||
|
||||
// age of the last fix, rounded down to a single unit: "45s", "12m", "3h"
|
||||
static void formatFixAge(char* buf, size_t size, uint32_t seconds) {
|
||||
if (seconds < 60) {
|
||||
snprintf(buf, size, "%lus", (unsigned long)seconds);
|
||||
} else if (seconds < 3600) {
|
||||
snprintf(buf, size, "%lum", (unsigned long)(seconds / 60));
|
||||
} else {
|
||||
snprintf(buf, size, "%luh", (unsigned long)(seconds / 3600));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
class HomeScreen : public UIScreen {
|
||||
enum HomePage {
|
||||
FIRST,
|
||||
@@ -418,16 +442,28 @@ public:
|
||||
char buf[50];
|
||||
int y = 18;
|
||||
bool gps_state = _task->getGPSState();
|
||||
#ifdef PIN_GPS_SWITCH
|
||||
bool hw_gps_state = digitalRead(PIN_GPS_SWITCH);
|
||||
if (gps_state != hw_gps_state) {
|
||||
strcpy(buf, gps_state ? "gps off(hw)" : "gps off(sw)");
|
||||
} else {
|
||||
strcpy(buf, gps_state ? "gps on" : "gps off");
|
||||
bool hw_gps_state = nmea != NULL && nmea->isHardwareEnabled();
|
||||
uint32_t period = nmea != NULL ? nmea->getGpsPeriod() : 0;
|
||||
char fix_buf[12] = "";
|
||||
if (nmea != NULL) {
|
||||
uint32_t fix_age = nmea->getLastFixAge();
|
||||
if (fix_age == UINT32_MAX) {
|
||||
strcpy(fix_buf, "no fix");
|
||||
} else {
|
||||
formatFixAge(fix_buf, sizeof(fix_buf), fix_age);
|
||||
}
|
||||
}
|
||||
if (nmea != NULL && nmea->hasHardwareEnableState() && gps_state != hw_gps_state) {
|
||||
strcpy(buf, gps_state ? "gps off(hw)" : "gps off(sw)");
|
||||
} else if (!gps_state) {
|
||||
strcpy(buf, "gps off");
|
||||
} else if (period == 0) {
|
||||
strcpy(buf, "gps on");
|
||||
} else {
|
||||
char per[12];
|
||||
formatGpsPeriod(per, sizeof(per), period);
|
||||
snprintf(buf, sizeof(buf), "%s (%s)", nmea != NULL && nmea->isActive() ? "active" : "sleep", per);
|
||||
}
|
||||
#else
|
||||
strcpy(buf, gps_state ? "gps on" : "gps off");
|
||||
#endif
|
||||
display.setColor(UIColor::primary_txt);
|
||||
display.drawTextLeftAlign(0, y, buf);
|
||||
if (nmea == NULL) {
|
||||
@@ -436,8 +472,7 @@ public:
|
||||
display.drawTextLeftAlign(0, y, "Can't access GPS");
|
||||
} else {
|
||||
display.setColor(UIColor::primary_txt);
|
||||
strcpy(buf, nmea->isValid()?"fix":"no fix");
|
||||
display.drawTextRightAlign(display.width()-1, y, buf);
|
||||
display.drawTextRightAlign(display.width()-1, y, fix_buf);
|
||||
y = y + 12;
|
||||
display.setColor(UIColor::secondary_txt);
|
||||
display.drawTextLeftAlign(0, y, "sat");
|
||||
@@ -626,7 +661,7 @@ public:
|
||||
}
|
||||
#if ENV_INCLUDE_GPS == 1
|
||||
if (c == KEY_ENTER && _page == HomePage::GPS) {
|
||||
_task->toggleGPS();
|
||||
if (_node_prefs->ui_gps_action == 1) _task->triggerGPS(); else _task->toggleGPS();
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
@@ -1245,16 +1280,14 @@ void UITask::toggleGPS() {
|
||||
for (int i = 0; i < num; i++) {
|
||||
if (strcmp(_sensors->getSettingName(i), "gps") == 0) {
|
||||
if (strcmp(_sensors->getSettingValue(i), "1") == 0) {
|
||||
_sensors->setSettingValue("gps", "0");
|
||||
_node_prefs->gps_enabled = 0;
|
||||
_node_prefs->getGpsPrefs()->setGpsEnabled(*_sensors, false);
|
||||
notify(UIEventType::ack);
|
||||
} else {
|
||||
_sensors->setSettingValue("gps", "1");
|
||||
_node_prefs->gps_enabled = 1;
|
||||
_node_prefs->getGpsPrefs()->setGpsEnabled(*_sensors, true);
|
||||
notify(UIEventType::ack);
|
||||
}
|
||||
the_mesh.savePrefs();
|
||||
showAlert(_node_prefs->gps_enabled ? "GPS: Enabled" : "GPS: Disabled", 800);
|
||||
showAlert(_node_prefs->getGpsPrefs()->isGpsEnabled() ? "GPS: Enabled" : "GPS: Disabled", 800);
|
||||
_next_refresh = 0;
|
||||
break;
|
||||
}
|
||||
@@ -1262,6 +1295,15 @@ void UITask::toggleGPS() {
|
||||
}
|
||||
}
|
||||
|
||||
void UITask::triggerGPS() {
|
||||
LocationProvider* location = _sensors != NULL ? _sensors->getLocationProvider() : NULL;
|
||||
if (location != NULL && !(location->hasHardwareEnableState() && !location->isHardwareEnabled())
|
||||
&& location->startOnce()) {
|
||||
notify(UIEventType::ack);
|
||||
}
|
||||
_next_refresh = 0;
|
||||
}
|
||||
|
||||
void UITask::toggleBuzzer() {
|
||||
// Toggle buzzer quiet mode
|
||||
#ifdef PIN_BUZZER
|
||||
|
||||
@@ -119,6 +119,7 @@ public:
|
||||
void toggleBuzzer();
|
||||
bool getGPSState();
|
||||
void toggleGPS();
|
||||
void triggerGPS();
|
||||
|
||||
// MyMesh::Listener
|
||||
void onMessageRecv(mesh::Packet *pkt, const ContactInfo &from, uint8_t txt_type, uint32_t sender_timestamp, const char* text) override;
|
||||
|
||||
@@ -609,14 +609,15 @@ void UITask::handleButtonQuadruplePress() {
|
||||
for (int i = 0; i < num; i++) {
|
||||
if (strcmp(_sensors->getSettingName(i), "gps") == 0) {
|
||||
if (strcmp(_sensors->getSettingValue(i), "1") == 0) {
|
||||
_sensors->setSettingValue("gps", "0");
|
||||
_node_prefs->getGpsPrefs()->setGpsEnabled(*_sensors, false);
|
||||
notify(UIEventType::ack);
|
||||
sprintf(_alert, "GPS: Disabled");
|
||||
} else {
|
||||
_sensors->setSettingValue("gps", "1");
|
||||
_node_prefs->getGpsPrefs()->setGpsEnabled(*_sensors, true);
|
||||
notify(UIEventType::ack);
|
||||
sprintf(_alert, "GPS: Enabled");
|
||||
}
|
||||
the_mesh.savePrefs();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,16 +254,16 @@ public:
|
||||
char buf[50];
|
||||
int y = 8;
|
||||
bool gps_state = _task->getGPSState();
|
||||
#ifdef PIN_GPS_SWITCH
|
||||
bool hw_gps_state = digitalRead(PIN_GPS_SWITCH);
|
||||
bool hw_gps_state = nmea != NULL && nmea->isHardwareEnabled();
|
||||
if (nmea != NULL && nmea->hasHardwareEnableState()) {
|
||||
if (gps_state != hw_gps_state) {
|
||||
strcpy(buf, gps_state ? "gps off(hw)" : "gps off(sw)");
|
||||
} else {
|
||||
strcpy(buf, gps_state ? "gps on" : "gps off");
|
||||
}
|
||||
#else
|
||||
} else {
|
||||
strcpy(buf, gps_state ? "gps on" : "gps off");
|
||||
#endif
|
||||
}
|
||||
display.setColor(UIColor::primary_txt);
|
||||
display.drawTextLeftAlign(0, y, buf);
|
||||
if (nmea == NULL) {
|
||||
@@ -833,16 +833,14 @@ void UITask::toggleGPS() {
|
||||
for (int i = 0; i < num; i++) {
|
||||
if (strcmp(_sensors->getSettingName(i), "gps") == 0) {
|
||||
if (strcmp(_sensors->getSettingValue(i), "1") == 0) {
|
||||
_sensors->setSettingValue("gps", "0");
|
||||
_node_prefs->gps_enabled = 0;
|
||||
_node_prefs->getGpsPrefs()->setGpsEnabled(*_sensors, false);
|
||||
notify(UIEventType::ack);
|
||||
} else {
|
||||
_sensors->setSettingValue("gps", "1");
|
||||
_node_prefs->gps_enabled = 1;
|
||||
_node_prefs->getGpsPrefs()->setGpsEnabled(*_sensors, true);
|
||||
notify(UIEventType::ack);
|
||||
}
|
||||
the_mesh.savePrefs();
|
||||
showAlert(_node_prefs->gps_enabled ? "GPS: Enabled" : "GPS: Disabled", 800);
|
||||
showAlert(_node_prefs->getGpsPrefs()->isGpsEnabled() ? "GPS: Enabled" : "GPS: Disabled", 800);
|
||||
_next_refresh = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
#include "MyMesh.h"
|
||||
#include <algorithm>
|
||||
#if REPEATER_HISTORY_SLOTS > 0
|
||||
#include <helpers/sensors/LPPDataHelpers.h>
|
||||
#endif
|
||||
|
||||
/* ------------------------------ Config -------------------------------- */
|
||||
|
||||
@@ -46,6 +49,9 @@
|
||||
#define REQ_TYPE_GET_STATUS 0x01 // same as _GET_STATS
|
||||
#define REQ_TYPE_KEEP_ALIVE 0x02
|
||||
#define REQ_TYPE_GET_TELEMETRY_DATA 0x03
|
||||
#if REPEATER_HISTORY_SLOTS > 0
|
||||
#define REQ_TYPE_GET_AVG_MIN_MAX 0x04
|
||||
#endif
|
||||
#define REQ_TYPE_GET_ACCESS_LIST 0x05
|
||||
#define REQ_TYPE_GET_NEIGHBOURS 0x06
|
||||
#define REQ_TYPE_GET_OWNER_INFO 0x07 // FIRMWARE_VER_LEVEL >= 2
|
||||
@@ -209,6 +215,7 @@ uint8_t MyMesh::handleAnonClockReq(const mesh::Identity& sender, uint32_t sender
|
||||
}
|
||||
|
||||
int MyMesh::handleRequest(ClientInfo *sender, uint32_t sender_timestamp, uint8_t *payload, size_t payload_len) {
|
||||
if (payload_len == 0) return 0;
|
||||
// uint32_t now = getRTCClock()->getCurrentTimeUnique();
|
||||
// memcpy(reply_data, &now, 4); // response packets always prefixed with timestamp
|
||||
memcpy(reply_data, &sender_timestamp, 4); // reflect sender_timestamp back in response packet (kind of like a 'tag')
|
||||
@@ -259,6 +266,48 @@ int MyMesh::handleRequest(ClientInfo *sender, uint32_t sender_timestamp, uint8_t
|
||||
memcpy(&reply_data[4], telemetry.getBuffer(), tlen);
|
||||
return 4 + tlen; // reply_len
|
||||
}
|
||||
#if REPEATER_HISTORY_SLOTS > 0
|
||||
if (payload[0] == REQ_TYPE_GET_AVG_MIN_MAX && payload_len >= 11 &&
|
||||
(sender->permissions & PERM_ACL_ROLE_MASK) >= PERM_ACL_READ_ONLY) {
|
||||
uint32_t start_secs_ago, end_secs_ago;
|
||||
memcpy(&start_secs_ago, &payload[1], 4);
|
||||
memcpy(&end_secs_ago, &payload[5], 4);
|
||||
MinMaxAvg data[8];
|
||||
int n = 0;
|
||||
if (payload[9] == 0 && payload[10] == 0) {
|
||||
uint32_t now_secs = uptime_millis / 1000;
|
||||
battery_history.calcMinMaxAvg(now_secs, start_secs_ago, end_secs_ago, &data[n++], HISTORY_BATTERY,
|
||||
LPP_VOLTAGE);
|
||||
noise_history.calcMinMaxAvg(now_secs, start_secs_ago, end_secs_ago, &data[n++], HISTORY_NOISE,
|
||||
LPP_ANALOG_INPUT);
|
||||
tx_history.calcMinMaxAvg(now_secs, start_secs_ago, end_secs_ago, &data[n++], HISTORY_TX,
|
||||
LPP_PERCENTAGE);
|
||||
rx_history.calcMinMaxAvg(now_secs, start_secs_ago, end_secs_ago, &data[n++], HISTORY_RX,
|
||||
LPP_PERCENTAGE);
|
||||
temperature_history.calcMinMaxAvg(now_secs, start_secs_ago, end_secs_ago, &data[n], HISTORY_TEMPERATURE,
|
||||
LPP_TEMPERATURE);
|
||||
// Unsupported temperature sensors and empty ranges have no encodable LPP value.
|
||||
if (!isnan(data[n]._avg)) n++;
|
||||
}
|
||||
uint8_t ofs = 4;
|
||||
uint32_t now = getRTCClock()->getCurrentTime();
|
||||
memcpy(&reply_data[ofs], &now, 4);
|
||||
ofs += 4;
|
||||
for (int i = 0; i < n; i++) {
|
||||
auto d = &data[i];
|
||||
if (isnan(d->_avg)) continue;
|
||||
reply_data[ofs++] = d->_channel;
|
||||
reply_data[ofs++] = d->_lpp_type;
|
||||
uint8_t sz = LPPData::getDataSize(d->_lpp_type);
|
||||
uint32_t mult = LPPData::getMultiplier(d->_lpp_type);
|
||||
bool is_signed = LPPData::isSigned(d->_lpp_type);
|
||||
ofs += LPPData::putFloat(&reply_data[ofs], d->_min, sz, mult, is_signed);
|
||||
ofs += LPPData::putFloat(&reply_data[ofs], d->_max, sz, mult, is_signed);
|
||||
ofs += LPPData::putFloat(&reply_data[ofs], d->_avg, sz, mult, is_signed);
|
||||
}
|
||||
return ofs;
|
||||
}
|
||||
#endif
|
||||
if (payload[0] == REQ_TYPE_GET_ACCESS_LIST && sender->isAdmin()) {
|
||||
uint8_t res1 = payload[1]; // reserved for future (extra query params)
|
||||
uint8_t res2 = payload[2];
|
||||
@@ -862,6 +911,13 @@ void MyMesh::sendNodeDiscoverReq() {
|
||||
MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondClock &ms, mesh::RNG &rng,
|
||||
mesh::RTCClock &rtc, mesh::MeshTables &tables)
|
||||
: mesh::Mesh(radio, ms, rng, rtc, *new StaticPoolPacketManager(32), tables),
|
||||
#if REPEATER_HISTORY_SLOTS > 0
|
||||
battery_history(REPEATER_HISTORY_SLOTS, REPEATER_HISTORY_INTERVAL_SECS),
|
||||
noise_history(REPEATER_HISTORY_SLOTS, REPEATER_HISTORY_INTERVAL_SECS),
|
||||
tx_history(REPEATER_HISTORY_SLOTS, REPEATER_HISTORY_INTERVAL_SECS),
|
||||
rx_history(REPEATER_HISTORY_SLOTS, REPEATER_HISTORY_INTERVAL_SECS),
|
||||
temperature_history(REPEATER_HISTORY_SLOTS, REPEATER_HISTORY_INTERVAL_SECS),
|
||||
#endif
|
||||
region_map(key_store), temp_map(key_store),
|
||||
_cli(board, rtc, sensors, region_map, acl, &_prefs, this),
|
||||
telemetry(MAX_PACKET_PAYLOAD - 4),
|
||||
@@ -876,6 +932,12 @@ MyMesh::MyMesh(mesh::MainBoard &board, mesh::Radio &radio, mesh::MillisecondCloc
|
||||
{
|
||||
last_millis = 0;
|
||||
uptime_millis = 0;
|
||||
#if REPEATER_HISTORY_SLOTS > 0
|
||||
history_last_secs = history_battery_secs = history_airtime_secs = 0;
|
||||
history_tx_millis = history_rx_millis = 0;
|
||||
history_battery_total = 0;
|
||||
history_battery_count = 0;
|
||||
#endif
|
||||
next_local_advert = next_flood_advert = 0;
|
||||
dirty_contacts_expiry = 0;
|
||||
set_radio_at = revert_radio_at = 0;
|
||||
@@ -1286,7 +1348,48 @@ void MyMesh::handleCommand(uint32_t sender_timestamp, char *command, char *reply
|
||||
}
|
||||
}
|
||||
|
||||
#if REPEATER_HISTORY_SLOTS > 0
|
||||
void MyMesh::recordHistory() {
|
||||
uint32_t now_secs = uptime_millis / 1000;
|
||||
// Average periodic reads without repeatedly enabling the battery divider.
|
||||
if (uint32_t(now_secs - history_battery_secs) >= 15) {
|
||||
history_battery_total += board.getBattMilliVolts();
|
||||
history_battery_count++;
|
||||
history_battery_secs = now_secs;
|
||||
}
|
||||
uint32_t elapsed_secs = now_secs - history_last_secs;
|
||||
if (elapsed_secs < REPEATER_HISTORY_INTERVAL_SECS) return;
|
||||
// Advance the sampling grid without accumulating loop delays or replaying missed slots.
|
||||
history_last_secs += (elapsed_secs / REPEATER_HISTORY_INTERVAL_SECS) * REPEATER_HISTORY_INTERVAL_SECS;
|
||||
uint32_t airtime_elapsed_secs = now_secs - history_airtime_secs;
|
||||
|
||||
if (history_battery_count > 0) {
|
||||
battery_history.recordData(history_last_secs, history_battery_total / history_battery_count / 1000.0f);
|
||||
}
|
||||
int noise_floor = _radio->getNoiseFloor();
|
||||
if (noise_floor != 0) noise_history.recordData(history_last_secs, noise_floor); // zero means uncalibrated
|
||||
uint32_t tx_millis = getTotalAirTime();
|
||||
uint32_t rx_millis = getReceiveAirTime();
|
||||
// Counters are milliseconds; unsigned subtraction also handles their wrap.
|
||||
tx_history.recordData(history_last_secs, uint32_t(tx_millis - history_tx_millis) / (airtime_elapsed_secs * 10.0f));
|
||||
rx_history.recordData(history_last_secs, uint32_t(rx_millis - history_rx_millis) / (airtime_elapsed_secs * 10.0f));
|
||||
temperature_history.recordData(history_last_secs, board.getMCUTemperature()); // ignores NaN
|
||||
history_airtime_secs = now_secs;
|
||||
history_tx_millis = tx_millis;
|
||||
history_rx_millis = rx_millis;
|
||||
history_battery_total = 0;
|
||||
history_battery_count = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
void MyMesh::loop() {
|
||||
// Update before dispatching requests, including across millis() wrap.
|
||||
uint32_t now = millis();
|
||||
uptime_millis += uint32_t(now - last_millis);
|
||||
last_millis = now;
|
||||
#if REPEATER_HISTORY_SLOTS > 0
|
||||
recordHistory();
|
||||
#endif
|
||||
#ifdef WITH_BRIDGE
|
||||
bridge.loop();
|
||||
#endif
|
||||
@@ -1324,11 +1427,6 @@ void MyMesh::loop() {
|
||||
acl.save(_fs);
|
||||
dirty_contacts_expiry = 0;
|
||||
}
|
||||
|
||||
// update uptime
|
||||
uint32_t now = millis();
|
||||
uptime_millis += now - last_millis;
|
||||
last_millis = now;
|
||||
}
|
||||
|
||||
// To check if there is pending work
|
||||
|
||||
@@ -37,6 +37,22 @@
|
||||
#include <helpers/RoutingPolicy.h>
|
||||
#include "RateLimiter.h"
|
||||
|
||||
#ifndef REPEATER_HISTORY_SLOTS
|
||||
#if defined(STM32_PLATFORM) || defined(RP2040_PLATFORM)
|
||||
#define REPEATER_HISTORY_SLOTS 0
|
||||
#else
|
||||
#define REPEATER_HISTORY_SLOTS 288
|
||||
#endif
|
||||
#endif
|
||||
#ifndef REPEATER_HISTORY_INTERVAL_SECS
|
||||
#define REPEATER_HISTORY_INTERVAL_SECS 300
|
||||
#endif
|
||||
|
||||
#if REPEATER_HISTORY_SLOTS > 0
|
||||
#include <helpers/TimeSeriesData.h>
|
||||
static_assert(REPEATER_HISTORY_INTERVAL_SECS > 0, "History interval must be positive");
|
||||
#endif
|
||||
|
||||
#ifdef WITH_BRIDGE
|
||||
extern AbstractBridge* bridge;
|
||||
#endif
|
||||
@@ -82,6 +98,16 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks {
|
||||
FILESYSTEM* _fs;
|
||||
uint32_t last_millis;
|
||||
uint64_t uptime_millis;
|
||||
#if REPEATER_HISTORY_SLOTS > 0
|
||||
// Dedicated history channels 200..204; environment telemetry occupies 1..17.
|
||||
enum { HISTORY_BATTERY = 200, HISTORY_NOISE, HISTORY_TX, HISTORY_RX, HISTORY_TEMPERATURE };
|
||||
TimeSeriesData battery_history, noise_history, tx_history, rx_history, temperature_history;
|
||||
uint32_t history_last_secs, history_battery_secs, history_airtime_secs;
|
||||
uint32_t history_tx_millis, history_rx_millis;
|
||||
float history_battery_total;
|
||||
uint32_t history_battery_count;
|
||||
void recordHistory();
|
||||
#endif
|
||||
unsigned long next_local_advert, next_flood_advert;
|
||||
bool _logging;
|
||||
NodePrefs _prefs;
|
||||
@@ -159,7 +185,14 @@ protected:
|
||||
|
||||
#if ENV_INCLUDE_GPS == 1
|
||||
void applyGpsPrefs() {
|
||||
sensors.setSettingValue("gps", _prefs.gps_enabled?"1":"0");
|
||||
if (sensors.getSettingByKey("gps_interval") != nullptr) {
|
||||
// gps_interval was introduced only for EnvironmentSensorManager
|
||||
// and has little interest ... kept only as a legacy
|
||||
char interval[11];
|
||||
snprintf(interval, sizeof(interval), "%lu", (unsigned long)_prefs.gps_interval);
|
||||
sensors.setSettingValue("gps_interval", interval);
|
||||
}
|
||||
_prefs.getGpsPrefs()->apply(sensors);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ mesh::Packet *MyMesh::createSelfAdvert() {
|
||||
}
|
||||
|
||||
File MyMesh::openAppend(const char *fname) {
|
||||
#if defined(NRF52_PLATFORM)
|
||||
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
|
||||
return _fs->open(fname, FILE_O_WRITE);
|
||||
#elif defined(RP2040_PLATFORM)
|
||||
return _fs->open(fname, "a");
|
||||
@@ -782,7 +782,7 @@ void MyMesh::applyTempRadioParams(float freq, float bw, uint8_t sf, uint8_t cr,
|
||||
}
|
||||
|
||||
bool MyMesh::formatFileSystem() {
|
||||
#if defined(NRF52_PLATFORM)
|
||||
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
|
||||
return InternalFS.format();
|
||||
#elif defined(RP2040_PLATFORM)
|
||||
return LittleFS.format();
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <Arduino.h> // needed for PlatformIO
|
||||
#include <Mesh.h>
|
||||
|
||||
#if defined(NRF52_PLATFORM)
|
||||
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
|
||||
#include <InternalFileSystem.h>
|
||||
#elif defined(RP2040_PLATFORM)
|
||||
#include <LittleFS.h>
|
||||
@@ -168,7 +168,14 @@ protected:
|
||||
|
||||
#if ENV_INCLUDE_GPS == 1
|
||||
void applyGpsPrefs() {
|
||||
sensors.setSettingValue("gps", _prefs.gps_enabled?"1":"0");
|
||||
if (sensors.getSettingByKey("gps_interval") != nullptr) {
|
||||
// gps_interval was introduced only for EnvironmentSensorManager
|
||||
// and has little interest ... kept only as a legacy
|
||||
char interval[11];
|
||||
snprintf(interval, sizeof(interval), "%lu", (unsigned long)_prefs.gps_interval);
|
||||
sensors.setSettingValue("gps_interval", interval);
|
||||
}
|
||||
_prefs.getGpsPrefs()->apply(sensors);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ void setup() {
|
||||
fast_rng.begin(radio_driver.getRngSeed());
|
||||
|
||||
FILESYSTEM* fs;
|
||||
#if defined(NRF52_PLATFORM)
|
||||
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
|
||||
InternalFS.begin();
|
||||
fs = &InternalFS;
|
||||
IdentityStore store(InternalFS, "");
|
||||
|
||||
@@ -789,7 +789,9 @@ SensorMesh::SensorMesh(mesh::MainBoard& board, mesh::Radio& radio, mesh::Millise
|
||||
{
|
||||
next_local_advert = next_flood_advert = 0;
|
||||
dirty_contacts_expiry = 0;
|
||||
last_read_time = 0;
|
||||
last_read_time = uint32_t(0) - SENSOR_READ_INTERVAL_SECS; // read immediately on the first loop
|
||||
last_millis = 0;
|
||||
uptime_millis = 0;
|
||||
num_alert_tasks = 0;
|
||||
set_radio_at = revert_radio_at = 0;
|
||||
recv_pkt_region = NULL;
|
||||
@@ -999,6 +1001,9 @@ bool SensorMesh::getGPS(uint8_t channel, float& lat, float& lon, float& alt) {
|
||||
}
|
||||
|
||||
void SensorMesh::loop() {
|
||||
uint32_t now = millis();
|
||||
uptime_millis += uint32_t(now - last_millis);
|
||||
last_millis = now;
|
||||
mesh::Mesh::loop();
|
||||
|
||||
if (next_flood_advert && millisHasNowPassed(next_flood_advert)) {
|
||||
@@ -1028,7 +1033,8 @@ void SensorMesh::loop() {
|
||||
}
|
||||
|
||||
uint32_t curr = getRTCClock()->getCurrentTime();
|
||||
if (curr >= last_read_time + SENSOR_READ_INTERVAL_SECS) {
|
||||
uint32_t uptime_secs = getUptimeSeconds();
|
||||
if (uint32_t(uptime_secs - last_read_time) >= SENSOR_READ_INTERVAL_SECS) {
|
||||
telemetry.reset();
|
||||
telemetry.addVoltage(TELEM_CHANNEL_SELF, (float)board.getBattMilliVolts() / 1000.0f);
|
||||
// query other sensors -- target specific
|
||||
@@ -1069,7 +1075,7 @@ void SensorMesh::loop() {
|
||||
|
||||
onSensorDataRead();
|
||||
|
||||
last_read_time = curr;
|
||||
last_read_time = uptime_secs;
|
||||
}
|
||||
|
||||
// check the alert send queue
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <Arduino.h> // needed for PlatformIO
|
||||
#include <Mesh.h>
|
||||
|
||||
#include "TimeSeriesData.h"
|
||||
#include <helpers/TimeSeriesData.h>
|
||||
|
||||
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
|
||||
#include <InternalFileSystem.h>
|
||||
@@ -88,6 +88,7 @@ public:
|
||||
void sendFloodReply(mesh::Packet* packet, unsigned long delay_millis, uint8_t path_hash_size);
|
||||
|
||||
protected:
|
||||
uint32_t getUptimeSeconds() const { return uptime_millis / 1000; }
|
||||
// current telemetry data queries
|
||||
float getVoltage(uint8_t channel) { return getTelemValue(channel, LPP_VOLTAGE); }
|
||||
float getCurrent(uint8_t channel) { return getTelemValue(channel, LPP_CURRENT); }
|
||||
@@ -154,6 +155,8 @@ private:
|
||||
RegionEntry* load_stack[8];
|
||||
TransportKey default_scope;
|
||||
uint32_t last_read_time;
|
||||
uint32_t last_millis;
|
||||
uint64_t uptime_millis;
|
||||
int matching_peer_indexes[MAX_SEARCH_RESULTS];
|
||||
int num_alert_tasks;
|
||||
Trigger* alert_tasks[MAX_CONCURRENT_ALERTS];
|
||||
@@ -173,7 +176,12 @@ private:
|
||||
|
||||
#if ENV_INCLUDE_GPS == 1
|
||||
void applyGpsPrefs() {
|
||||
sensors.setSettingValue("gps", _prefs.gps_enabled?"1":"0");
|
||||
if (sensors.getSettingByKey("gps_interval") != nullptr) {
|
||||
char interval[11];
|
||||
snprintf(interval, sizeof(interval), "%lu", (unsigned long)_prefs.gps_interval);
|
||||
sensors.setSettingValue("gps_interval", interval);
|
||||
}
|
||||
_prefs.getGpsPrefs()->apply(sensors);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
@@ -1,45 +0,0 @@
|
||||
#include "TimeSeriesData.h"
|
||||
|
||||
void TimeSeriesData::recordData(mesh::RTCClock* clock, float value) {
|
||||
uint32_t now = clock->getCurrentTime();
|
||||
if (now >= last_timestamp + interval_secs) {
|
||||
last_timestamp = now;
|
||||
|
||||
data[next] = value; // append to cycle table
|
||||
next = (next + 1) % num_slots;
|
||||
}
|
||||
}
|
||||
|
||||
void TimeSeriesData::calcMinMaxAvg(mesh::RTCClock* clock, uint32_t start_secs_ago, uint32_t end_secs_ago, MinMaxAvg* dest, uint8_t channel, uint8_t lpp_type) const {
|
||||
int i = next, n = num_slots;
|
||||
uint32_t ago = clock->getCurrentTime() - last_timestamp;
|
||||
int num_values = 0;
|
||||
float total = 0.0f;
|
||||
|
||||
dest->_channel = channel;
|
||||
dest->_lpp_type = lpp_type;
|
||||
|
||||
// start at most recet recording, back-track through to oldest
|
||||
while (n > 0) {
|
||||
n--;
|
||||
i = (i + num_slots - 1) % num_slots; // go back by one
|
||||
if (ago >= end_secs_ago && ago < start_secs_ago) { // filter by the desired time range
|
||||
float v = data[i];
|
||||
num_values++;
|
||||
total += v;
|
||||
if (num_values == 1) {
|
||||
dest->_max = dest->_min = v;
|
||||
} else {
|
||||
if (v < dest->_min) dest->_min = v;
|
||||
if (v > dest->_max) dest->_max = v;
|
||||
}
|
||||
}
|
||||
ago += interval_secs;
|
||||
}
|
||||
// calc average
|
||||
if (num_values > 0) {
|
||||
dest->_avg = total / num_values;
|
||||
} else {
|
||||
dest->_max = dest->_min = dest->_avg = NAN;
|
||||
}
|
||||
}
|
||||
@@ -1,29 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <Mesh.h>
|
||||
|
||||
struct MinMaxAvg {
|
||||
float _min, _max, _avg;
|
||||
uint8_t _lpp_type, _channel;
|
||||
};
|
||||
|
||||
class TimeSeriesData {
|
||||
float* data;
|
||||
int num_slots, next;
|
||||
uint32_t last_timestamp;
|
||||
uint32_t interval_secs;
|
||||
|
||||
public:
|
||||
TimeSeriesData(float* array, int num, uint32_t secs) : num_slots(num), data(array), last_timestamp(0), next(0), interval_secs(secs) {
|
||||
memset(data, 0, sizeof(float)*num);
|
||||
}
|
||||
TimeSeriesData(int num, uint32_t secs) : num_slots(num), last_timestamp(0), next(0), interval_secs(secs) {
|
||||
data = new float[num];
|
||||
memset(data, 0, sizeof(float)*num);
|
||||
}
|
||||
|
||||
void recordData(mesh::RTCClock* clock, float value);
|
||||
void calcMinMaxAvg(mesh::RTCClock* clock, uint32_t start_secs_ago, uint32_t end_secs_ago, MinMaxAvg* dest, uint8_t channel, uint8_t lpp_type) const;
|
||||
};
|
||||
|
||||
// Compatibility include for custom sensor sketches; implementation lives in src/helpers.
|
||||
#include <helpers/TimeSeriesData.h>
|
||||
@@ -21,13 +21,14 @@ protected:
|
||||
void onSensorDataRead() override {
|
||||
float batt_voltage = getVoltage(TELEM_CHANNEL_SELF);
|
||||
|
||||
battery_data.recordData(getRTCClock(), batt_voltage); // record battery
|
||||
battery_data.recordData(getUptimeSeconds(), batt_voltage); // record battery
|
||||
alertIf(batt_voltage < 3.4f, critical_batt, HIGH_PRI_ALERT, "Battery is critical!");
|
||||
alertIf(batt_voltage < 3.6f, low_batt, LOW_PRI_ALERT, "Battery is low");
|
||||
}
|
||||
|
||||
int querySeriesData(uint32_t start_secs_ago, uint32_t end_secs_ago, MinMaxAvg dest[], int max_num) override {
|
||||
battery_data.calcMinMaxAvg(getRTCClock(), start_secs_ago, end_secs_ago, &dest[0], TELEM_CHANNEL_SELF, LPP_VOLTAGE);
|
||||
battery_data.calcMinMaxAvg(getUptimeSeconds(), start_secs_ago, end_secs_ago, &dest[0], TELEM_CHANNEL_SELF,
|
||||
LPP_VOLTAGE);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user