fix: harden firmware builds and runtime reliability
This commit is contained in:
1 parent
66c9e3f73b
commit
bd3a94bddb
71 files changed
+2102
-466
No files matched your search
@@ -1,6 +1,9 @@
|
||||
#include "MyMesh.h"
|
||||
#include <helpers/radiolib/RxBoostedGainDefaults.h>
|
||||
#include <helpers/CLICommandUtils.h>
|
||||
#if MESH_PACKET_LOGGING
|
||||
#include <helpers/SerialPacketLog.h>
|
||||
#endif
|
||||
#if MESH_ENABLE_ROOM_FLOOD_RULE_ENGINE
|
||||
#include <helpers/FloodFilterPolicy.h>
|
||||
#endif
|
||||
@@ -265,12 +268,10 @@ int MyMesh::handleRequest(ClientInfo *sender, uint32_t sender_timestamp, uint8_t
|
||||
void MyMesh::logRxRaw(float snr, float rssi, const uint8_t raw[], int len) {
|
||||
#if MESH_PACKET_LOGGING
|
||||
if (mesh::isUsbLoggingEnabled()) {
|
||||
// Logging builds prefer backpressure over silently losing a packet record.
|
||||
Stream& logging_port = mesh::usbLoggingPort();
|
||||
logging_port.print(getLogDateTime());
|
||||
logging_port.print(" RAW: ");
|
||||
mesh::Utils::printHex(logging_port, raw, len);
|
||||
logging_port.println();
|
||||
mesh::SerialLogLine<> line;
|
||||
line.printf("%s RAW: ", getLogDateTime());
|
||||
line.hex(raw, len);
|
||||
line.flush(mesh::usbLoggingPort());
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -770,7 +771,8 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
|
||||
if (neighbor_discover_active && i >= NEIGHBOR_DISCOVER_PEER_BASE) {
|
||||
int oi = i - NEIGHBOR_DISCOVER_PEER_BASE;
|
||||
if (type == PAYLOAD_TYPE_RESPONSE && oi >= 0 && oi < neighbor_discover_count) {
|
||||
handleNeighborDiscoverResponse(oi, data, len);
|
||||
handleNeighborDiscoverResponse(
|
||||
oi, data, len, packet->getSNR(), packet->getRSSI());
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -786,7 +788,8 @@ void MyMesh::onPeerDataRecv(mesh::Packet *packet, uint8_t type, int sender_idx,
|
||||
if (neighbor_discover_active && type == PAYLOAD_TYPE_RESPONSE) {
|
||||
for (int oi = 0; oi < neighbor_discover_count; oi++) {
|
||||
if (client->id.matches(neighbor_discover[oi].id)
|
||||
&& handleNeighborDiscoverResponse(oi, data, len)) {
|
||||
&& handleNeighborDiscoverResponse(
|
||||
oi, data, len, packet->getSNR(), packet->getRSSI())) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1051,7 +1054,7 @@ void MyMesh::onAdvertRecv(mesh::Packet* packet, const mesh::Identity& id,
|
||||
if (packet->getPathHashCount() == 0 && !is_share) {
|
||||
AdvertDataParser parser(app_data, app_data_len);
|
||||
if (parser.isValid() && parser.getType() == ADV_TYPE_REPEATER) {
|
||||
putNeighbour(id, timestamp, packet->getSNR());
|
||||
putNeighbour(id, timestamp, packet->getSNR(), packet->getRSSI());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1066,7 +1069,8 @@ void MyMesh::onGroupPacketRecv(mesh::Packet* packet) {
|
||||
#define CTL_TYPE_NODE_DISCOVER_REQ 0x80
|
||||
#define CTL_TYPE_NODE_DISCOVER_RESP 0x90
|
||||
|
||||
void MyMesh::putNeighbour(const mesh::Identity &id, uint32_t timestamp, float snr) {
|
||||
void MyMesh::putNeighbour(const mesh::Identity &id, uint32_t timestamp, float snr,
|
||||
int16_t rssi) {
|
||||
// find existing neighbour, else use least recently updated
|
||||
uint32_t oldest_timestamp = 0xFFFFFFFF;
|
||||
NeighbourInfo *neighbour = &neighbours[0];
|
||||
@@ -1089,6 +1093,7 @@ void MyMesh::putNeighbour(const mesh::Identity &id, uint32_t timestamp, float sn
|
||||
neighbour->advert_timestamp = timestamp;
|
||||
neighbour->heard_timestamp = getRTCClock()->getCurrentTime();
|
||||
neighbour->snr = (int8_t)(snr * 4);
|
||||
neighbour->rssi = rssi;
|
||||
}
|
||||
|
||||
void MyMesh::onControlDataRecv(mesh::Packet* packet) {
|
||||
@@ -1120,7 +1125,8 @@ void MyMesh::onControlDataRecv(mesh::Packet* packet) {
|
||||
if (id.matches(self_id)) {
|
||||
return;
|
||||
}
|
||||
putNeighbour(id, getRTCClock()->getCurrentTime(), packet->getSNR());
|
||||
putNeighbour(id, getRTCClock()->getCurrentTime(), packet->getSNR(),
|
||||
packet->getRSSI());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2712,6 +2718,7 @@ bool MyMesh::completeNeighborDiscoverEntry() {
|
||||
entry.status == ND_RESPONDED ? "responded"
|
||||
: (entry.status == ND_SEND_FAILED ? "send_failed" : "timeout")
|
||||
};
|
||||
measured.rssi = entry.rssi;
|
||||
size_t added = MQTTMessageBuilder::measureNeighborsMessageEntry(measured);
|
||||
if (neighbor_discover_publish_count > 0) added++; // array comma
|
||||
|
||||
@@ -2730,7 +2737,9 @@ bool MyMesh::completeNeighborDiscoverEntry() {
|
||||
|
||||
// Match a RESPONSE against the pending overlay entry by tag; copy its scope
|
||||
// string (payload after the 8-byte {tag}{clock} header) into the entry.
|
||||
bool MyMesh::handleNeighborDiscoverResponse(int overlay_idx, const uint8_t* data, size_t len) {
|
||||
bool MyMesh::handleNeighborDiscoverResponse(int overlay_idx,
|
||||
const uint8_t* data, size_t len,
|
||||
float snr, int16_t rssi) {
|
||||
if (overlay_idx < 0 || overlay_idx >= neighbor_discover_count) return false;
|
||||
NeighborDiscoverEntry& entry = neighbor_discover[overlay_idx];
|
||||
if (entry.status != ND_PENDING || len < 8) return false;
|
||||
@@ -2747,18 +2756,23 @@ bool MyMesh::handleNeighborDiscoverResponse(int overlay_idx, const uint8_t* data
|
||||
entry.scopes[scope_len] = 0;
|
||||
entry.status = ND_RESPONDED;
|
||||
// A zero-hop reply is proof we heard this neighbour now, so re-stamp both the
|
||||
// snapshot and the live table; a stamp taken before time sync heals here.
|
||||
// snapshot and live table with this packet's measurements. A stamp taken
|
||||
// before time sync also heals here.
|
||||
entry.heard_timestamp = getRTCClock()->getCurrentTime();
|
||||
touchNeighbourHeard(entry.id, entry.heard_timestamp);
|
||||
entry.snr = (int8_t)(snr * 4);
|
||||
entry.rssi = rssi;
|
||||
touchNeighbourHeard(entry.id, entry.heard_timestamp, snr, rssi);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Refresh a live neighbour's heard time only: a scope reply carries no advert
|
||||
// timestamp or SNR to update.
|
||||
void MyMesh::touchNeighbourHeard(const mesh::Identity& id, uint32_t heard_timestamp) {
|
||||
void MyMesh::touchNeighbourHeard(const mesh::Identity& id,
|
||||
uint32_t heard_timestamp, float snr,
|
||||
int16_t rssi) {
|
||||
for (int i = 0; i < MAX_NEIGHBOURS; i++) {
|
||||
if (id.matches(neighbours[i].id)) {
|
||||
neighbours[i].heard_timestamp = heard_timestamp;
|
||||
neighbours[i].snr = (int8_t)(snr * 4);
|
||||
neighbours[i].rssi = rssi;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -2880,6 +2894,7 @@ void MyMesh::finishNeighborDiscover() {
|
||||
mesh::Utils::toHex(hex, entry.id.pub_key, PUB_KEY_SIZE);
|
||||
entries[i].pubkey_hex = hex;
|
||||
entries[i].snr = entry.snr / 4.0f;
|
||||
entries[i].rssi = entry.rssi;
|
||||
bool heard_known = neighborHeardAgeUsable(entry.heard_timestamp, now_secs);
|
||||
entries[i].heard_unknown = !heard_known;
|
||||
entries[i].heard_secs_ago = heard_known ? (now_secs - entry.heard_timestamp) : 0;
|
||||
@@ -3023,6 +3038,7 @@ bool MyMesh::startNeighborDiscover(char* reply) {
|
||||
entry.id = neighbours[i].id;
|
||||
entry.heard_timestamp = neighbours[i].heard_timestamp;
|
||||
entry.snr = neighbours[i].snr;
|
||||
entry.rssi = neighbours[i].rssi;
|
||||
entry.scopes[0] = 0;
|
||||
entry.tag = 0;
|
||||
entry.status = ND_UNSENT;
|
||||
|
||||
Reference in new issue
Block a user