Merge branch 'dev' into double-acks

This commit is contained in:
Scott Powell 2025-07-12 10:36:03 +10:00
commit d84feacc60
26 changed files with 699 additions and 17 deletions

View file

@ -45,6 +45,7 @@
#define CMD_GET_CUSTOM_VARS 40
#define CMD_SET_CUSTOM_VAR 41
#define CMD_GET_ADVERT_PATH 42
#define CMD_GET_TUNING_PARAMS 43
#define RESP_CODE_OK 0
#define RESP_CODE_ERR 1
@ -69,6 +70,7 @@
#define RESP_CODE_SIGNATURE 20
#define RESP_CODE_CUSTOM_VARS 21
#define RESP_CODE_ADVERT_PATH 22
#define RESP_CODE_TUNING_PARAMS 23
#define SEND_TIMEOUT_BASE_MILLIS 500
#define FLOOD_SEND_TIMEOUT_FACTOR 16.0f
@ -1016,6 +1018,13 @@ void MyMesh::handleCmdFrame(size_t len) {
_prefs.airtime_factor = ((float)af) / 1000.0f;
savePrefs();
writeOKFrame();
} else if (cmd_frame[0] == CMD_GET_TUNING_PARAMS) {
uint32_t rx = _prefs.rx_delay_base * 1000, af = _prefs.airtime_factor * 1000;
int i = 0;
out_frame[i++] = RESP_CODE_TUNING_PARAMS;
memcpy(&out_frame[i], &rx, 4); i += 4;
memcpy(&out_frame[i], &af, 4); i += 4;
_serial->writeFrame(out_frame, i);
} else if (cmd_frame[0] == CMD_SET_OTHER_PARAMS) {
_prefs.manual_add_contacts = cmd_frame[1];
if (len >= 3) {

View file

@ -332,13 +332,14 @@ void SensorMesh::applyContactPermissions(const uint8_t* pubkey, uint16_t perms)
dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY); // trigger saveContacts()
}
void SensorMesh::sendAlert(const char* text) {
void SensorMesh::sendAlert(AlertPriority pri, const char* text) {
int text_len = strlen(text);
uint16_t pri_mask = (pri == HIGH_PRI_ALERT) ? PERM_RECV_ALERTS_HI : PERM_RECV_ALERTS_LO;
// send text message to all contacts with RECV_ALERT permission
for (int i = 0; i < num_contacts; i++) {
auto c = &contacts[i];
if ((c->permissions & PERM_RECV_ALERTS) == 0) continue; // contact does NOT want alerts
if ((c->permissions & pri_mask) == 0) continue; // contact does NOT want alert
uint8_t data[MAX_PACKET_PAYLOAD];
uint32_t now = getRTCClock()->getCurrentTimeUnique(); // need different timestamp per packet
@ -360,12 +361,12 @@ void SensorMesh::sendAlert(const char* text) {
}
}
void SensorMesh::alertIf(bool condition, Trigger& t, const char* text) {
void SensorMesh::alertIf(bool condition, Trigger& t, AlertPriority pri, const char* text) {
if (condition) {
if (!t.triggered) {
t.triggered = true;
t.time = getRTCClock()->getCurrentTime();
sendAlert(text);
sendAlert(pri, text);
}
} else {
if (t.triggered) {
@ -422,7 +423,7 @@ uint8_t SensorMesh::handleLoginReq(const mesh::Identity& sender, const uint8_t*
MESH_DEBUG_PRINTLN("Login success!");
client->last_timestamp = sender_timestamp;
client->last_activity = getRTCClock()->getCurrentTime();
client->permissions = PERM_IS_ADMIN | PERM_RECV_ALERTS;
client->permissions = PERM_IS_ADMIN | PERM_RECV_ALERTS_HI | PERM_RECV_ALERTS_LO; // initially opt-in to receive alerts (can opt out)
memcpy(client->shared_secret, secret, PUB_KEY_SIZE);
dirty_contacts_expiry = futureMillis(LAZY_CONTACTS_WRITE_DELAY);

View file

@ -26,7 +26,8 @@
#define PERM_IS_ADMIN 0x8000
#define PERM_GET_TELEMETRY 0x0001
#define PERM_GET_MIN_MAX_AVG 0x0002
#define PERM_RECV_ALERTS 0x0100
#define PERM_RECV_ALERTS_LO 0x0100 // low priority alerts
#define PERM_RECV_ALERTS_HI 0x0200 // high priority alerts
struct ContactInfo {
mesh::Identity id;
@ -104,8 +105,8 @@ protected:
Trigger() { triggered = false; time = 0; }
};
void alertIf(bool condition, Trigger& t, const char* text);
enum AlertPriority { LOW_PRI_ALERT, HIGH_PRI_ALERT };
void alertIf(bool condition, Trigger& t, AlertPriority pri, const char* text);
virtual void onSensorDataRead() = 0; // for app to implement
virtual int querySeriesData(uint32_t start_secs_ago, uint32_t end_secs_ago, MinMaxAvg dest[], int max_num) = 0; // for app to implement
@ -145,6 +146,6 @@ private:
ContactInfo* putContact(const mesh::Identity& id);
void applyContactPermissions(const uint8_t* pubkey, uint16_t perms);
void sendAlert(const char* text);
void sendAlert(AlertPriority pri, const char* text);
};

View file

@ -22,7 +22,7 @@ protected:
float batt_voltage = getVoltage(TELEM_CHANNEL_SELF);
battery_data.recordData(getRTCClock(), batt_voltage); // record battery
alertIf(batt_voltage < 3.4f, low_batt, "Battery low!");
alertIf(batt_voltage < 3.4f, low_batt, HIGH_PRI_ALERT, "Battery low!");
}
int querySeriesData(uint32_t start_secs_ago, uint32_t end_secs_ago, MinMaxAvg dest[], int max_num) override {