Tune keymind repeater behavior
This commit is contained in:
1 parent
7473719b92
commit
48ac725d76
24 files changed
+2885
-155
No files matched your search
+85
-24
@@ -28,6 +28,41 @@ static uint8_t decodeTraceHashSize(uint8_t flags, uint8_t route_bytes) {
|
||||
return size_linear;
|
||||
}
|
||||
|
||||
static uint8_t getTraceRemainingHops(const Packet* packet) {
|
||||
if (packet == NULL || packet->payload_len < 9) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t route_bytes = packet->payload_len - 9;
|
||||
uint8_t hash_size = decodeTraceHashSize(packet->payload[8], route_bytes);
|
||||
if (hash_size == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t route_hops = route_bytes / hash_size;
|
||||
if (packet->path_len >= route_hops) {
|
||||
return 0;
|
||||
}
|
||||
return route_hops - packet->path_len;
|
||||
}
|
||||
|
||||
static uint8_t getTraceDirectPriority(const Packet* packet) {
|
||||
uint8_t remaining_hops = getTraceRemainingHops(packet);
|
||||
if (remaining_hops == 0) {
|
||||
return 5;
|
||||
}
|
||||
if (remaining_hops <= 4) {
|
||||
return 1;
|
||||
}
|
||||
if (remaining_hops <= 8) {
|
||||
return 2;
|
||||
}
|
||||
if (remaining_hops <= 12) {
|
||||
return 3;
|
||||
}
|
||||
return 5;
|
||||
}
|
||||
|
||||
void Mesh::begin() {
|
||||
for (int i = 0; i < MAX_DIRECT_RETRY_SLOTS; i++) {
|
||||
_direct_retries[i].packet = NULL;
|
||||
@@ -39,6 +74,7 @@ void Mesh::begin() {
|
||||
_direct_retries[i].retry_attempts_sent = 0;
|
||||
memset(_direct_retries[i].next_hop_hash, 0, sizeof(_direct_retries[i].next_hop_hash));
|
||||
_direct_retries[i].next_hop_hash_len = 0;
|
||||
_direct_retries[i].payload_type = 0;
|
||||
_direct_retries[i].priority = 0;
|
||||
_direct_retries[i].progress_marker = 0;
|
||||
_direct_retries[i].expect_path_growth = false;
|
||||
@@ -78,8 +114,12 @@ void Mesh::loop() {
|
||||
uint32_t elapsed_millis = _direct_retries[i].retry_started_at == 0
|
||||
? 0
|
||||
: (uint32_t)(_ms->getMillis() - _direct_retries[i].retry_started_at);
|
||||
onDirectRetryEvent("failed_all_tries", _direct_retries[i].packet, elapsed_millis, _direct_retries[i].retry_attempts_sent);
|
||||
onDirectRetryEvent("failure", _direct_retries[i].packet, elapsed_millis, _direct_retries[i].retry_attempts_sent);
|
||||
onDirectRetryEvent("failed_all_tries", _direct_retries[i].packet, elapsed_millis, _direct_retries[i].retry_attempts_sent,
|
||||
_direct_retries[i].next_hop_hash, _direct_retries[i].next_hop_hash_len,
|
||||
_direct_retries[i].payload_type);
|
||||
onDirectRetryEvent("failure", _direct_retries[i].packet, elapsed_millis, _direct_retries[i].retry_attempts_sent,
|
||||
_direct_retries[i].next_hop_hash, _direct_retries[i].next_hop_hash_len,
|
||||
_direct_retries[i].payload_type);
|
||||
onDirectRetryFailed(_direct_retries[i].next_hop_hash, _direct_retries[i].next_hop_hash_len);
|
||||
clearDirectRetrySlot(i);
|
||||
continue;
|
||||
@@ -230,9 +270,10 @@ DispatcherAction Mesh::onRecvPacket(Packet* pkt) {
|
||||
// append SNR (Not hash!)
|
||||
pkt->path[pkt->path_len++] = (int8_t) (pkt->getSNR()*4);
|
||||
|
||||
uint8_t pri = getTraceDirectPriority(pkt);
|
||||
uint32_t d = getDirectRetransmitDelay(pkt);
|
||||
maybeScheduleDirectRetry(pkt, 5);
|
||||
return ACTION_RETRANSMIT_DELAYED(5, d); // schedule with priority 5 (for now), maybe make configurable?
|
||||
maybeScheduleDirectRetry(pkt, pri);
|
||||
return ACTION_RETRANSMIT_DELAYED(pri, d);
|
||||
}
|
||||
}
|
||||
return ACTION_RELEASE;
|
||||
@@ -589,6 +630,7 @@ void Mesh::clearDirectRetrySlot(int idx) {
|
||||
_direct_retries[idx].retry_attempts_sent = 0;
|
||||
memset(_direct_retries[idx].next_hop_hash, 0, sizeof(_direct_retries[idx].next_hop_hash));
|
||||
_direct_retries[idx].next_hop_hash_len = 0;
|
||||
_direct_retries[idx].payload_type = 0;
|
||||
_direct_retries[idx].priority = 0;
|
||||
_direct_retries[idx].progress_marker = 0;
|
||||
_direct_retries[idx].expect_path_growth = false;
|
||||
@@ -641,7 +683,9 @@ bool Mesh::cancelDirectRetryOnEcho(const Packet* packet) {
|
||||
uint8_t retry_attempt = _direct_retries[i].waiting_final_echo
|
||||
? _direct_retries[i].retry_attempts_sent
|
||||
: _direct_retries[i].retry_attempts_sent + 1;
|
||||
onDirectRetryEvent("good", _direct_retries[i].packet, echo_millis, retry_attempt);
|
||||
onDirectRetryEvent("good", _direct_retries[i].packet, echo_millis, retry_attempt,
|
||||
_direct_retries[i].next_hop_hash, _direct_retries[i].next_hop_hash_len,
|
||||
_direct_retries[i].payload_type);
|
||||
if (_direct_retries[i].queued) {
|
||||
for (int j = 0; j < _mgr->getOutboundTotal(); j++) {
|
||||
if (_mgr->getOutboundByIdx(j) == _direct_retries[i].packet) {
|
||||
@@ -661,7 +705,8 @@ bool Mesh::cancelDirectRetryOnEcho(const Packet* packet) {
|
||||
uint32_t echo_millis = _direct_retries[i].echo_wait_started_at == 0
|
||||
? 0
|
||||
: (uint32_t)(_ms->getMillis() - _direct_retries[i].echo_wait_started_at);
|
||||
onDirectRetryEvent("good", _direct_retries[i].trigger_packet, echo_millis, _direct_retries[i].retry_attempts_sent + 1);
|
||||
onDirectRetryEvent("good", _direct_retries[i].trigger_packet, echo_millis, _direct_retries[i].retry_attempts_sent + 1,
|
||||
_direct_retries[i].next_hop_hash, _direct_retries[i].next_hop_hash_len);
|
||||
clearDirectRetrySlot(i);
|
||||
}
|
||||
cleared = true;
|
||||
@@ -682,7 +727,8 @@ void Mesh::armDirectRetryOnSendComplete(const Packet* packet) {
|
||||
uint32_t elapsed_millis = _direct_retries[i].retry_started_at == 0
|
||||
? 0
|
||||
: (uint32_t)(_ms->getMillis() - _direct_retries[i].retry_started_at);
|
||||
onDirectRetryEvent("resent", packet, elapsed_millis, _direct_retries[i].retry_attempts_sent + 1);
|
||||
onDirectRetryEvent("resent", packet, elapsed_millis, _direct_retries[i].retry_attempts_sent + 1,
|
||||
_direct_retries[i].next_hop_hash, _direct_retries[i].next_hop_hash_len);
|
||||
_direct_retries[i].echo_wait_started_at = _ms->getMillis();
|
||||
_direct_retries[i].retry_attempts_sent++;
|
||||
uint8_t max_attempts = getDirectRetryMaxAttempts(packet);
|
||||
@@ -703,8 +749,10 @@ void Mesh::armDirectRetryOnSendComplete(const Packet* packet) {
|
||||
|
||||
Packet* retry = obtainNewPacket();
|
||||
if (retry == NULL) {
|
||||
onDirectRetryEvent("dropped_no_packet", packet, elapsed_millis, _direct_retries[i].retry_attempts_sent + 1);
|
||||
onDirectRetryEvent("failure", packet, elapsed_millis, _direct_retries[i].retry_attempts_sent + 1);
|
||||
onDirectRetryEvent("dropped_no_packet", packet, elapsed_millis, _direct_retries[i].retry_attempts_sent + 1,
|
||||
_direct_retries[i].next_hop_hash, _direct_retries[i].next_hop_hash_len);
|
||||
onDirectRetryEvent("failure", packet, elapsed_millis, _direct_retries[i].retry_attempts_sent + 1,
|
||||
_direct_retries[i].next_hop_hash, _direct_retries[i].next_hop_hash_len);
|
||||
clearDirectRetrySlot(i);
|
||||
continue;
|
||||
}
|
||||
@@ -719,10 +767,13 @@ void Mesh::armDirectRetryOnSendComplete(const Packet* packet) {
|
||||
_direct_retries[i].retry_delay = retry_delay;
|
||||
_direct_retries[i].retry_at = futureMillis(retry_delay);
|
||||
_direct_retries[i].waiting_final_echo = false;
|
||||
onDirectRetryEvent("queued", retry, retry_delay, retry_attempt);
|
||||
onDirectRetryEvent("queued", retry, retry_delay, retry_attempt,
|
||||
_direct_retries[i].next_hop_hash, _direct_retries[i].next_hop_hash_len);
|
||||
} else {
|
||||
onDirectRetryEvent("dropped_queue_full", retry, retry_delay, retry_attempt);
|
||||
onDirectRetryEvent("failure", retry, elapsed_millis, retry_attempt);
|
||||
onDirectRetryEvent("dropped_queue_full", retry, retry_delay, retry_attempt,
|
||||
_direct_retries[i].next_hop_hash, _direct_retries[i].next_hop_hash_len);
|
||||
onDirectRetryEvent("failure", retry, elapsed_millis, retry_attempt,
|
||||
_direct_retries[i].next_hop_hash, _direct_retries[i].next_hop_hash_len);
|
||||
releasePacket(retry);
|
||||
clearDirectRetrySlot(i);
|
||||
}
|
||||
@@ -737,8 +788,10 @@ void Mesh::armDirectRetryOnSendComplete(const Packet* packet) {
|
||||
// Allocate the retry packet only after TX-complete so busy repeaters do not reserve pool slots early.
|
||||
Packet* retry = obtainNewPacket();
|
||||
if (retry == NULL) {
|
||||
onDirectRetryEvent("dropped_no_packet", packet, _direct_retries[i].retry_delay, 1);
|
||||
onDirectRetryEvent("failure", packet, 0, 1);
|
||||
onDirectRetryEvent("dropped_no_packet", packet, _direct_retries[i].retry_delay, 1,
|
||||
_direct_retries[i].next_hop_hash, _direct_retries[i].next_hop_hash_len);
|
||||
onDirectRetryEvent("failure", packet, 0, 1,
|
||||
_direct_retries[i].next_hop_hash, _direct_retries[i].next_hop_hash_len);
|
||||
clearDirectRetrySlot(i);
|
||||
continue;
|
||||
}
|
||||
@@ -757,10 +810,13 @@ void Mesh::armDirectRetryOnSendComplete(const Packet* packet) {
|
||||
_direct_retries[i].retry_at = futureMillis(_direct_retries[i].retry_delay);
|
||||
_direct_retries[i].retry_started_at = now;
|
||||
_direct_retries[i].echo_wait_started_at = now;
|
||||
onDirectRetryEvent("queued", retry, _direct_retries[i].retry_delay, 1);
|
||||
onDirectRetryEvent("queued", retry, _direct_retries[i].retry_delay, 1,
|
||||
_direct_retries[i].next_hop_hash, _direct_retries[i].next_hop_hash_len);
|
||||
} else {
|
||||
onDirectRetryEvent("dropped_queue_full", retry, _direct_retries[i].retry_delay, 1);
|
||||
onDirectRetryEvent("failure", retry, 0, 1);
|
||||
onDirectRetryEvent("dropped_queue_full", retry, _direct_retries[i].retry_delay, 1,
|
||||
_direct_retries[i].next_hop_hash, _direct_retries[i].next_hop_hash_len);
|
||||
onDirectRetryEvent("failure", retry, 0, 1,
|
||||
_direct_retries[i].next_hop_hash, _direct_retries[i].next_hop_hash_len);
|
||||
releasePacket(retry);
|
||||
clearDirectRetrySlot(i);
|
||||
}
|
||||
@@ -776,16 +832,20 @@ void Mesh::clearPendingDirectRetryOnSendFail(const Packet* packet) {
|
||||
if (_direct_retries[i].queued) {
|
||||
if (_direct_retries[i].packet == packet) {
|
||||
// The queued retry itself failed; Dispatcher will release it after this hook.
|
||||
onDirectRetryEvent("dropped_send_fail", packet, 0, _direct_retries[i].retry_attempts_sent + 1);
|
||||
onDirectRetryEvent("failure", packet, 0, _direct_retries[i].retry_attempts_sent + 1);
|
||||
onDirectRetryEvent("dropped_send_fail", packet, 0, _direct_retries[i].retry_attempts_sent + 1,
|
||||
_direct_retries[i].next_hop_hash, _direct_retries[i].next_hop_hash_len);
|
||||
onDirectRetryEvent("failure", packet, 0, _direct_retries[i].retry_attempts_sent + 1,
|
||||
_direct_retries[i].next_hop_hash, _direct_retries[i].next_hop_hash_len);
|
||||
clearDirectRetrySlot(i);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (_direct_retries[i].trigger_packet == packet) {
|
||||
onDirectRetryEvent("dropped_send_fail", packet, 0, 1);
|
||||
onDirectRetryEvent("failure", packet, 0, 1);
|
||||
onDirectRetryEvent("dropped_send_fail", packet, 0, 1,
|
||||
_direct_retries[i].next_hop_hash, _direct_retries[i].next_hop_hash_len);
|
||||
onDirectRetryEvent("failure", packet, 0, 1,
|
||||
_direct_retries[i].next_hop_hash, _direct_retries[i].next_hop_hash_len);
|
||||
clearDirectRetrySlot(i);
|
||||
}
|
||||
}
|
||||
@@ -922,8 +982,8 @@ void Mesh::maybeScheduleDirectRetry(const Packet* packet, uint8_t priority) {
|
||||
}
|
||||
}
|
||||
if (slot_idx < 0) {
|
||||
onDirectRetryEvent("dropped_no_slot", packet, 0, 0);
|
||||
onDirectRetryEvent("failure", packet, 0, 0);
|
||||
onDirectRetryEvent("dropped_no_slot", packet, 0, 0, next_hop_hash, next_hop_hash_len);
|
||||
onDirectRetryEvent("failure", packet, 0, 0, next_hop_hash, next_hop_hash_len);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -940,6 +1000,7 @@ void Mesh::maybeScheduleDirectRetry(const Packet* packet, uint8_t priority) {
|
||||
memset(_direct_retries[slot_idx].next_hop_hash, 0, sizeof(_direct_retries[slot_idx].next_hop_hash));
|
||||
memcpy(_direct_retries[slot_idx].next_hop_hash, next_hop_hash, next_hop_hash_len);
|
||||
_direct_retries[slot_idx].next_hop_hash_len = next_hop_hash_len;
|
||||
_direct_retries[slot_idx].payload_type = packet->getPayloadType();
|
||||
_direct_retries[slot_idx].priority = priority;
|
||||
_direct_retries[slot_idx].progress_marker = progress_marker;
|
||||
_direct_retries[slot_idx].expect_path_growth = expect_path_growth;
|
||||
@@ -1496,7 +1557,7 @@ void Mesh::sendDirect(Packet* packet, const uint8_t* path, uint8_t path_len, uin
|
||||
packet->payload_len += path_len;
|
||||
|
||||
packet->path_len = 0;
|
||||
pri = 5; // maybe make this configurable
|
||||
pri = getTraceDirectPriority(packet);
|
||||
} else {
|
||||
packet->path_len = Packet::copyPath(packet->path, path, path_len);
|
||||
if (packet->getPayloadType() == PAYLOAD_TYPE_PATH) {
|
||||
|
||||
+4
-1
@@ -48,6 +48,7 @@ class Mesh : public Dispatcher {
|
||||
uint8_t retry_key[MAX_HASH_SIZE];
|
||||
uint8_t next_hop_hash[MAX_HASH_SIZE];
|
||||
uint8_t next_hop_hash_len;
|
||||
uint8_t payload_type;
|
||||
uint8_t priority;
|
||||
uint8_t progress_marker;
|
||||
bool expect_path_growth;
|
||||
@@ -201,7 +202,9 @@ protected:
|
||||
/**
|
||||
* \brief Optional hook for logging direct-retry lifecycle events.
|
||||
*/
|
||||
virtual void onDirectRetryEvent(const char* event, const Packet* packet, uint32_t delay_millis, uint8_t retry_attempt) { }
|
||||
virtual void onDirectRetryEvent(const char* event, const Packet* packet, uint32_t delay_millis, uint8_t retry_attempt,
|
||||
const uint8_t* target_hash = NULL, uint8_t target_hash_len = 0,
|
||||
int16_t payload_type = -1) { }
|
||||
|
||||
/**
|
||||
* \brief Optional hook for link-quality feedback when all direct-retry attempts fail.
|
||||
|
||||
@@ -64,12 +64,14 @@ public:
|
||||
virtual uint8_t getStartupReason() const = 0;
|
||||
virtual bool getBootloaderVersion(char* version, size_t max_len) { return false; }
|
||||
virtual bool startOTAUpdate(const char* id, char reply[]) { return false; } // not supported
|
||||
virtual bool stopOTAUpdate(char reply[]) { return false; } // not supported
|
||||
virtual bool setLoRaFemLnaEnabled(bool enable) { return false; }
|
||||
virtual bool canControlLoRaFemLna() const { return false; }
|
||||
virtual bool isLoRaFemLnaEnabled() const { return false; }
|
||||
|
||||
// Power management interface (boards with power management override these)
|
||||
virtual bool isExternalPowered() { return false; }
|
||||
virtual bool isUsbDataConnected() { return false; }
|
||||
virtual uint16_t getBootVoltage() { return 0; }
|
||||
virtual uint32_t getResetReason() const { return 0; }
|
||||
virtual const char* getResetReasonString(uint32_t reason) { return "Not available"; }
|
||||
|
||||
+483
-12
@@ -95,6 +95,150 @@ static bool looksUnsignedInteger(const char* s) {
|
||||
return saw_digit;
|
||||
}
|
||||
|
||||
static bool parseUint8Strict(const char* value, uint8_t min_value, uint8_t max_value, uint8_t& result) {
|
||||
if (value == NULL || *value == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint16_t parsed = 0;
|
||||
const char* sp = value;
|
||||
while (*sp) {
|
||||
if (*sp < '0' || *sp > '9') {
|
||||
return false;
|
||||
}
|
||||
parsed = (uint16_t)((parsed * 10) + (*sp - '0'));
|
||||
if (parsed > max_value) {
|
||||
return false;
|
||||
}
|
||||
sp++;
|
||||
}
|
||||
if (parsed < min_value) {
|
||||
return false;
|
||||
}
|
||||
result = (uint8_t)parsed;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool bwMatches(float bw, float allowed) {
|
||||
float diff = bw - allowed;
|
||||
if (diff < 0.0f) diff = -diff;
|
||||
return diff <= 0.001f;
|
||||
}
|
||||
|
||||
static bool isValidLoRaBandwidth(float bw) {
|
||||
#if defined(USE_LR1110)
|
||||
return bwMatches(bw, 62.5f)
|
||||
|| bwMatches(bw, 125.0f)
|
||||
|| bwMatches(bw, 250.0f)
|
||||
|| bwMatches(bw, 500.0f);
|
||||
#elif defined(USE_LLCC68) || defined(USE_SX1272)
|
||||
return bwMatches(bw, 125.0f)
|
||||
|| bwMatches(bw, 250.0f)
|
||||
|| bwMatches(bw, 500.0f);
|
||||
#else
|
||||
return bwMatches(bw, 7.8f)
|
||||
|| bwMatches(bw, 10.4f)
|
||||
|| bwMatches(bw, 15.6f)
|
||||
|| bwMatches(bw, 20.8f)
|
||||
|| bwMatches(bw, 31.25f)
|
||||
|| bwMatches(bw, 41.7f)
|
||||
|| bwMatches(bw, 62.5f)
|
||||
|| bwMatches(bw, 125.0f)
|
||||
|| bwMatches(bw, 250.0f)
|
||||
|| bwMatches(bw, 500.0f);
|
||||
#endif
|
||||
}
|
||||
|
||||
static float defaultLoRaBandwidth() {
|
||||
#ifdef LORA_BW
|
||||
if (isValidLoRaBandwidth((float)LORA_BW)) {
|
||||
return (float)LORA_BW;
|
||||
}
|
||||
#endif
|
||||
return 125.0f;
|
||||
}
|
||||
|
||||
static const char* skipSpacesConst(const char* s) {
|
||||
while (s != NULL && *s == ' ') s++;
|
||||
return s;
|
||||
}
|
||||
|
||||
static bool parseUint32Strict(const char* s, uint32_t& out) {
|
||||
if (!looksUnsignedInteger(s)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint64_t n = 0;
|
||||
s = skipSpacesConst(s);
|
||||
while (*s >= '0' && *s <= '9') {
|
||||
n = (n * 10) + (uint32_t)(*s - '0');
|
||||
if (n > 0xFFFFFFFFULL) {
|
||||
return false;
|
||||
}
|
||||
s++;
|
||||
}
|
||||
out = (uint32_t)n;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int countSeparatedParts(const char* s, char separator) {
|
||||
if (s == NULL || *s == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int count = 1;
|
||||
while (*s) {
|
||||
if (*s++ == separator) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static bool parseScheduledRadioArgs(const char* args, bool temporary, float& freq, float& bw,
|
||||
uint8_t& sf, uint8_t& cr, uint32_t& start_time,
|
||||
uint32_t& end_time) {
|
||||
const int expected_parts = temporary ? 6 : 5;
|
||||
args = skipSpacesConst(args);
|
||||
if (countSeparatedParts(args, ',') != expected_parts) {
|
||||
return false;
|
||||
}
|
||||
char local[96];
|
||||
if (strlen(args) >= sizeof(local)) {
|
||||
return false;
|
||||
}
|
||||
StrHelper::strncpy(local, args, sizeof(local));
|
||||
const char* parts[6];
|
||||
int num = mesh::Utils::parseTextParts(local, parts, expected_parts, ',');
|
||||
if (num != expected_parts) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t sf_u32 = 0;
|
||||
uint32_t cr_u32 = 0;
|
||||
if (!looksNumeric(parts[0]) || !looksNumeric(parts[1])
|
||||
|| !parseUint32Strict(parts[2], sf_u32)
|
||||
|| !parseUint32Strict(parts[3], cr_u32)
|
||||
|| !parseUint32Strict(parts[4], start_time)) {
|
||||
return false;
|
||||
}
|
||||
if (sf_u32 > 255 || cr_u32 > 255) {
|
||||
return false;
|
||||
}
|
||||
|
||||
freq = atof(parts[0]);
|
||||
bw = atof(parts[1]);
|
||||
sf = (uint8_t)sf_u32;
|
||||
cr = (uint8_t)cr_u32;
|
||||
if (temporary && !parseUint32Strict(parts[5], end_time)) {
|
||||
return false;
|
||||
}
|
||||
if (!temporary) {
|
||||
end_time = 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static int16_t parseSnrDbX4(const char* s) {
|
||||
float db = atof(s);
|
||||
return (int16_t)(db * 4.0f + (db >= 0.0f ? 0.5f : -0.5f));
|
||||
@@ -124,6 +268,93 @@ static void markDirectRetryPrefsValid(NodePrefs* prefs) {
|
||||
prefs->direct_retry_prefs_magic[1] = DIRECT_RETRY_PREFS_MAGIC_1;
|
||||
}
|
||||
|
||||
static void applyFloodRetryPreset(NodePrefs* prefs, uint8_t preset) {
|
||||
if (preset == RETRY_PRESET_INFRA) {
|
||||
prefs->flood_retry_attempts = FLOOD_RETRY_INFRA_COUNT;
|
||||
prefs->flood_retry_max_path = FLOOD_RETRY_INFRA_MAX_PATH;
|
||||
} else if (preset == RETRY_PRESET_MOBILE) {
|
||||
prefs->flood_retry_attempts = FLOOD_RETRY_MOBILE_COUNT;
|
||||
prefs->flood_retry_max_path = FLOOD_RETRY_MOBILE_MAX_PATH;
|
||||
} else {
|
||||
prefs->flood_retry_attempts = FLOOD_RETRY_ROOFTOP_COUNT;
|
||||
prefs->flood_retry_max_path = FLOOD_RETRY_ROOFTOP_MAX_PATH;
|
||||
}
|
||||
}
|
||||
|
||||
static bool parseFloodRetryPathGate(const char* value, uint8_t& path_gate) {
|
||||
if (value == NULL) {
|
||||
return false;
|
||||
}
|
||||
if (strcmp(value, "off") == 0 || strcmp(value, "disabled") == 0 || strcmp(value, "disable") == 0) {
|
||||
path_gate = FLOOD_RETRY_PATH_GATE_DISABLED;
|
||||
return true;
|
||||
}
|
||||
return parseUint8Strict(value, 0, 63, path_gate);
|
||||
}
|
||||
|
||||
static void formatFloodRetryPathGate(char* dest, uint8_t path_gate) {
|
||||
if (path_gate == FLOOD_RETRY_PATH_GATE_DISABLED) {
|
||||
strcpy(dest, "off");
|
||||
} else {
|
||||
sprintf(dest, "%u", (unsigned int)path_gate);
|
||||
}
|
||||
}
|
||||
|
||||
static void formatFloodRetryPrefixList(char* dest, const uint8_t prefixes[][FLOOD_RETRY_PREFIX_LEN],
|
||||
uint8_t max_prefixes) {
|
||||
char* out = dest;
|
||||
bool first = true;
|
||||
for (int i = 0; i < max_prefixes; i++) {
|
||||
const uint8_t* prefix = prefixes[i];
|
||||
if (prefix[0] == 0 && prefix[1] == 0 && prefix[2] == 0) {
|
||||
continue;
|
||||
}
|
||||
if (!first) {
|
||||
*out++ = ',';
|
||||
}
|
||||
mesh::Utils::toHex(out, prefix, FLOOD_RETRY_PREFIX_LEN);
|
||||
out += FLOOD_RETRY_PREFIX_LEN * 2;
|
||||
first = false;
|
||||
}
|
||||
*out = 0;
|
||||
}
|
||||
|
||||
static bool parseFloodRetryPrefixList(uint8_t dest[][FLOOD_RETRY_PREFIX_LEN], uint8_t max_prefixes, const char* value) {
|
||||
if (max_prefixes > FLOOD_RETRY_LIST_PREFIXES) {
|
||||
return false;
|
||||
}
|
||||
uint8_t parsed[FLOOD_RETRY_LIST_PREFIXES][FLOOD_RETRY_PREFIX_LEN];
|
||||
memset(parsed, 0, sizeof(parsed));
|
||||
if (value == NULL || value[0] == 0 || strcmp(value, "none") == 0 || strcmp(value, "off") == 0) {
|
||||
memcpy(dest, parsed, max_prefixes * FLOOD_RETRY_PREFIX_LEN);
|
||||
return true;
|
||||
}
|
||||
|
||||
char local[FLOOD_RETRY_LIST_TEXT_MAX];
|
||||
StrHelper::strncpy(local, value, sizeof(local));
|
||||
const char* parts[FLOOD_RETRY_LIST_PREFIXES + 1];
|
||||
int num = mesh::Utils::parseTextParts(local, parts, FLOOD_RETRY_LIST_PREFIXES + 1);
|
||||
if (num > max_prefixes) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < num; i++) {
|
||||
if (strlen(parts[i]) != FLOOD_RETRY_PREFIX_LEN * 2) {
|
||||
return false;
|
||||
}
|
||||
for (int j = 0; j < FLOOD_RETRY_PREFIX_LEN * 2; j++) {
|
||||
if (!mesh::Utils::isHexChar(parts[i][j])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!mesh::Utils::fromHex(parsed[i], FLOOD_RETRY_PREFIX_LEN, parts[i])
|
||||
|| (parsed[i][0] == 0 && parsed[i][1] == 0 && parsed[i][2] == 0)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
memcpy(dest, parsed, max_prefixes * FLOOD_RETRY_PREFIX_LEN);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void applyDirectRetryPreset(NodePrefs* prefs, uint8_t preset) {
|
||||
prefs->retry_preset = preset;
|
||||
if (preset == RETRY_PRESET_INFRA) {
|
||||
@@ -143,6 +374,7 @@ static void applyDirectRetryPreset(NodePrefs* prefs, uint8_t preset) {
|
||||
prefs->direct_retry_step_ms = DIRECT_RETRY_ROOFTOP_STEP_MS;
|
||||
prefs->direct_retry_snr_margin_x4 = DIRECT_RETRY_ROOFTOP_MARGIN_X4;
|
||||
}
|
||||
applyFloodRetryPreset(prefs, prefs->retry_preset);
|
||||
markDirectRetryPrefsValid(prefs);
|
||||
}
|
||||
|
||||
@@ -154,6 +386,7 @@ static void setDefaultDirectRetryPrefs(NodePrefs* prefs) {
|
||||
prefs->direct_retry_cr7_snr_x4 = DIRECT_RETRY_CR7_MIN_SNR_X4_DEFAULT;
|
||||
prefs->direct_retry_cr8_snr_x4 = DIRECT_RETRY_CR8_MAX_SNR_X4_DEFAULT;
|
||||
prefs->direct_retry_enabled = 1;
|
||||
prefs->direct_retry_recent_enabled = DIRECT_RETRY_RECENT_DEFAULT;
|
||||
markDirectRetryPrefsValid(prefs);
|
||||
}
|
||||
|
||||
@@ -280,7 +513,48 @@ void CommonCLI::loadPrefsInt(FILESYSTEM* fs, const char* filename) {
|
||||
file.read((uint8_t *)&_prefs->direct_retry_enabled, sizeof(_prefs->direct_retry_enabled)); // 307
|
||||
file.read((uint8_t *)&_prefs->direct_retry_cr_enabled, sizeof(_prefs->direct_retry_cr_enabled)); // 308
|
||||
file.read((uint8_t *)&_prefs->direct_retry_prefs_magic, sizeof(_prefs->direct_retry_prefs_magic)); // 309
|
||||
// next: 311
|
||||
memset(_prefs->flood_retry_prefixes, 0, sizeof(_prefs->flood_retry_prefixes));
|
||||
_prefs->flood_retry_bridge_enabled = 0;
|
||||
memset(_prefs->flood_retry_bridge_buckets, 0, sizeof(_prefs->flood_retry_bridge_buckets));
|
||||
memset(_prefs->flood_retry_ignore_prefixes, 0, sizeof(_prefs->flood_retry_ignore_prefixes));
|
||||
_prefs->flood_retry_advert_enabled = FLOOD_RETRY_ADVERT_DEFAULT;
|
||||
_prefs->battery_alert_enabled = 0;
|
||||
_prefs->battery_alert_low_percent = BATTERY_ALERT_LOW_PERCENT_DEFAULT;
|
||||
_prefs->battery_alert_critical_percent = BATTERY_ALERT_CRITICAL_PERCENT_DEFAULT;
|
||||
_prefs->direct_retry_recent_enabled = DIRECT_RETRY_RECENT_DEFAULT;
|
||||
bool has_flood_retry_prefs = file.available() >= 2;
|
||||
if (has_flood_retry_prefs) {
|
||||
file.read((uint8_t *)&_prefs->flood_retry_attempts, sizeof(_prefs->flood_retry_attempts)); // 311
|
||||
file.read((uint8_t *)&_prefs->flood_retry_max_path, sizeof(_prefs->flood_retry_max_path)); // 312
|
||||
if (file.available() >= (int)sizeof(_prefs->flood_retry_prefixes)) {
|
||||
file.read((uint8_t *)&_prefs->flood_retry_prefixes[0][0], sizeof(_prefs->flood_retry_prefixes));
|
||||
}
|
||||
if (file.available() >= (int)sizeof(_prefs->flood_retry_bridge_enabled)) {
|
||||
file.read((uint8_t *)&_prefs->flood_retry_bridge_enabled, sizeof(_prefs->flood_retry_bridge_enabled));
|
||||
}
|
||||
if (file.available() >= (int)sizeof(_prefs->flood_retry_bridge_buckets)) {
|
||||
file.read((uint8_t *)&_prefs->flood_retry_bridge_buckets[0][0][0], sizeof(_prefs->flood_retry_bridge_buckets));
|
||||
}
|
||||
if (file.available() >= (int)sizeof(_prefs->flood_retry_ignore_prefixes)) {
|
||||
file.read((uint8_t *)&_prefs->flood_retry_ignore_prefixes[0][0], sizeof(_prefs->flood_retry_ignore_prefixes));
|
||||
}
|
||||
if (file.available() >= (int)sizeof(_prefs->flood_retry_advert_enabled)) {
|
||||
file.read((uint8_t *)&_prefs->flood_retry_advert_enabled, sizeof(_prefs->flood_retry_advert_enabled));
|
||||
}
|
||||
if (file.available() >= (int)sizeof(_prefs->battery_alert_enabled)) {
|
||||
file.read((uint8_t *)&_prefs->battery_alert_enabled, sizeof(_prefs->battery_alert_enabled));
|
||||
}
|
||||
if (file.available() >= (int)sizeof(_prefs->battery_alert_low_percent)) {
|
||||
file.read((uint8_t *)&_prefs->battery_alert_low_percent, sizeof(_prefs->battery_alert_low_percent));
|
||||
}
|
||||
if (file.available() >= (int)sizeof(_prefs->battery_alert_critical_percent)) {
|
||||
file.read((uint8_t *)&_prefs->battery_alert_critical_percent, sizeof(_prefs->battery_alert_critical_percent));
|
||||
}
|
||||
if (file.available() >= (int)sizeof(_prefs->direct_retry_recent_enabled)) {
|
||||
file.read((uint8_t *)&_prefs->direct_retry_recent_enabled, sizeof(_prefs->direct_retry_recent_enabled));
|
||||
}
|
||||
}
|
||||
// next: 672
|
||||
|
||||
// sanitise bad pref values
|
||||
_prefs->rx_delay_base = constrain(_prefs->rx_delay_base, 0, 20.0f);
|
||||
@@ -288,7 +562,7 @@ void CommonCLI::loadPrefsInt(FILESYSTEM* fs, const char* filename) {
|
||||
_prefs->direct_tx_delay_factor = constrain(_prefs->direct_tx_delay_factor, 0, 2.0f);
|
||||
_prefs->airtime_factor = constrain(_prefs->airtime_factor, 0, 9.0f);
|
||||
_prefs->freq = constrain(_prefs->freq, 150.0f, 2500.0f);
|
||||
_prefs->bw = constrain(_prefs->bw, 7.8f, 500.0f);
|
||||
_prefs->bw = isValidLoRaBandwidth(_prefs->bw) ? _prefs->bw : defaultLoRaBandwidth();
|
||||
_prefs->sf = constrain(_prefs->sf, 5, 12);
|
||||
_prefs->cr = constrain(_prefs->cr, 5, 8);
|
||||
_prefs->tx_power_dbm = constrain(_prefs->tx_power_dbm, -9, 30);
|
||||
@@ -315,6 +589,13 @@ void CommonCLI::loadPrefsInt(FILESYSTEM* fs, const char* filename) {
|
||||
_prefs->cad_enabled = constrain(_prefs->cad_enabled, 0, 1); // boolean
|
||||
if (!directRetryPrefsValid(_prefs)) {
|
||||
setDefaultDirectRetryPrefs(_prefs);
|
||||
memset(_prefs->flood_retry_prefixes, 0, sizeof(_prefs->flood_retry_prefixes));
|
||||
_prefs->flood_retry_bridge_enabled = 0;
|
||||
memset(_prefs->flood_retry_bridge_buckets, 0, sizeof(_prefs->flood_retry_bridge_buckets));
|
||||
memset(_prefs->flood_retry_ignore_prefixes, 0, sizeof(_prefs->flood_retry_ignore_prefixes));
|
||||
_prefs->flood_retry_advert_enabled = FLOOD_RETRY_ADVERT_DEFAULT;
|
||||
} else if (!has_flood_retry_prefs) {
|
||||
applyFloodRetryPreset(_prefs, _prefs->retry_preset);
|
||||
}
|
||||
if (_prefs->retry_preset > RETRY_PRESET_MOBILE && _prefs->retry_preset != RETRY_PRESET_CUSTOM) {
|
||||
_prefs->retry_preset = RETRY_PRESET_CUSTOM;
|
||||
@@ -325,6 +606,20 @@ void CommonCLI::loadPrefsInt(FILESYSTEM* fs, const char* filename) {
|
||||
_prefs->direct_retry_snr_margin_x4 = constrain(_prefs->direct_retry_snr_margin_x4, 0, 160);
|
||||
_prefs->direct_retry_enabled = constrain(_prefs->direct_retry_enabled, 0, 1);
|
||||
_prefs->direct_retry_cr_enabled = constrain(_prefs->direct_retry_cr_enabled, 0, 1);
|
||||
_prefs->flood_retry_attempts = constrain(_prefs->flood_retry_attempts, 0, 15);
|
||||
if (_prefs->flood_retry_max_path != FLOOD_RETRY_PATH_GATE_DISABLED) {
|
||||
_prefs->flood_retry_max_path = constrain(_prefs->flood_retry_max_path, 0, 63);
|
||||
}
|
||||
_prefs->flood_retry_bridge_enabled = constrain(_prefs->flood_retry_bridge_enabled, 0, 1);
|
||||
_prefs->flood_retry_advert_enabled = constrain(_prefs->flood_retry_advert_enabled, 0, 1);
|
||||
_prefs->battery_alert_enabled = constrain(_prefs->battery_alert_enabled, 0, 1);
|
||||
_prefs->direct_retry_recent_enabled = constrain(_prefs->direct_retry_recent_enabled, 0, 1);
|
||||
if (_prefs->battery_alert_low_percent < 1
|
||||
|| _prefs->battery_alert_low_percent > 100
|
||||
|| _prefs->battery_alert_critical_percent >= _prefs->battery_alert_low_percent) {
|
||||
_prefs->battery_alert_low_percent = BATTERY_ALERT_LOW_PERCENT_DEFAULT;
|
||||
_prefs->battery_alert_critical_percent = BATTERY_ALERT_CRITICAL_PERCENT_DEFAULT;
|
||||
}
|
||||
|
||||
file.close();
|
||||
}
|
||||
@@ -405,7 +700,18 @@ void CommonCLI::savePrefs(FILESYSTEM* fs) {
|
||||
file.write((uint8_t *)&_prefs->direct_retry_enabled, sizeof(_prefs->direct_retry_enabled)); // 307
|
||||
file.write((uint8_t *)&_prefs->direct_retry_cr_enabled, sizeof(_prefs->direct_retry_cr_enabled)); // 308
|
||||
file.write((uint8_t *)&_prefs->direct_retry_prefs_magic, sizeof(_prefs->direct_retry_prefs_magic)); // 309
|
||||
// next: 311
|
||||
file.write((uint8_t *)&_prefs->flood_retry_attempts, sizeof(_prefs->flood_retry_attempts)); // 311
|
||||
file.write((uint8_t *)&_prefs->flood_retry_max_path, sizeof(_prefs->flood_retry_max_path)); // 312
|
||||
file.write((uint8_t *)&_prefs->flood_retry_prefixes[0][0], sizeof(_prefs->flood_retry_prefixes)); // 313
|
||||
file.write((uint8_t *)&_prefs->flood_retry_bridge_enabled, sizeof(_prefs->flood_retry_bridge_enabled));
|
||||
file.write((uint8_t *)&_prefs->flood_retry_bridge_buckets[0][0][0], sizeof(_prefs->flood_retry_bridge_buckets));
|
||||
file.write((uint8_t *)&_prefs->flood_retry_ignore_prefixes[0][0], sizeof(_prefs->flood_retry_ignore_prefixes));
|
||||
file.write((uint8_t *)&_prefs->flood_retry_advert_enabled, sizeof(_prefs->flood_retry_advert_enabled));
|
||||
file.write((uint8_t *)&_prefs->battery_alert_enabled, sizeof(_prefs->battery_alert_enabled));
|
||||
file.write((uint8_t *)&_prefs->battery_alert_low_percent, sizeof(_prefs->battery_alert_low_percent));
|
||||
file.write((uint8_t *)&_prefs->battery_alert_critical_percent, sizeof(_prefs->battery_alert_critical_percent));
|
||||
file.write((uint8_t *)&_prefs->direct_retry_recent_enabled, sizeof(_prefs->direct_retry_recent_enabled));
|
||||
// next: 672
|
||||
|
||||
file.close();
|
||||
}
|
||||
@@ -466,10 +772,14 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, char* command, char* re
|
||||
} else {
|
||||
strcpy(reply, "ERR: clock cannot go backwards");
|
||||
}
|
||||
} else if (memcmp(command, "start ota", 9) == 0) {
|
||||
} else if (memcmp(command, "start ota", 9) == 0 && (command[9] == 0 || command[9] == ' ')) {
|
||||
if (!_board->startOTAUpdate(_prefs->node_name, reply)) {
|
||||
strcpy(reply, "Error");
|
||||
}
|
||||
} else if (memcmp(command, "stop ota", 8) == 0 && (command[8] == 0 || command[8] == ' ')) {
|
||||
if (!_board->stopOTAUpdate(reply)) {
|
||||
strcpy(reply, "Error");
|
||||
}
|
||||
} else if (memcmp(command, "clock", 5) == 0) {
|
||||
uint32_t now = getRTCClock()->getCurrentTime();
|
||||
DateTime dt = DateTime(now);
|
||||
@@ -507,7 +817,7 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, char* command, char* re
|
||||
uint8_t sf = num > 2 ? atoi(parts[2]) : 0;
|
||||
uint8_t cr = num > 3 ? atoi(parts[3]) : 0;
|
||||
int temp_timeout_mins = num > 4 ? atoi(parts[4]) : 0;
|
||||
if (freq >= 150.0f && freq <= 2500.0f && sf >= 5 && sf <= 12 && cr >= 5 && cr <= 8 && bw >= 7.0f && bw <= 500.0f && temp_timeout_mins > 0) {
|
||||
if (freq >= 150.0f && freq <= 2500.0f && sf >= 5 && sf <= 12 && cr >= 5 && cr <= 8 && isValidLoRaBandwidth(bw) && temp_timeout_mins > 0) {
|
||||
_callbacks->applyTempRadioParams(freq, bw, sf, cr, temp_timeout_mins);
|
||||
sprintf(reply, "OK - temp params for %d mins", temp_timeout_mins);
|
||||
} else {
|
||||
@@ -529,6 +839,8 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, char* command, char* re
|
||||
handleGetCmd(sender_timestamp, command, reply);
|
||||
} else if (memcmp(command, "set ", 4) == 0) {
|
||||
handleSetCmd(sender_timestamp, command, reply);
|
||||
} else if (memcmp(command, "del ", 4) == 0) {
|
||||
handleDelCmd(command, reply);
|
||||
} else if (sender_timestamp == 0 && strcmp(command, "erase") == 0) {
|
||||
bool s = _callbacks->formatFileSystem();
|
||||
sprintf(reply, "File system erase: %s", s ? "OK" : "Err");
|
||||
@@ -663,13 +975,21 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, char* command, char* re
|
||||
#endif
|
||||
} else if (memcmp(command, "powersaving on", 14) == 0) {
|
||||
#if defined(NRF52_PLATFORM)
|
||||
_prefs->powersaving_enabled = 1;
|
||||
savePrefs();
|
||||
strcpy(reply, "on - Immediate effect");
|
||||
if (sender_timestamp == 0 || _board->isUsbDataConnected()) {
|
||||
strcpy(reply, "Error: USB serial connected");
|
||||
} else {
|
||||
_prefs->powersaving_enabled = 1;
|
||||
savePrefs();
|
||||
strcpy(reply, "on - Immediate effect");
|
||||
}
|
||||
#elif defined(ESP32) && !defined(WITH_BRIDGE)
|
||||
_prefs->powersaving_enabled = 1;
|
||||
savePrefs();
|
||||
strcpy(reply, "on - After 2 minutes");
|
||||
if (sender_timestamp == 0 || _board->isUsbDataConnected()) {
|
||||
strcpy(reply, "Error: USB serial connected");
|
||||
} else {
|
||||
_prefs->powersaving_enabled = 1;
|
||||
savePrefs();
|
||||
strcpy(reply, "on - After 2 minutes");
|
||||
}
|
||||
#elif defined(WITH_BRIDGE)
|
||||
strcpy(reply, "Bridge not supported");
|
||||
#else
|
||||
@@ -862,7 +1182,7 @@ void CommonCLI::handleSetCmd(uint32_t sender_timestamp, char* command, char* rep
|
||||
float bw = num > 1 ? strtof(parts[1], nullptr) : 0.0f;
|
||||
uint8_t sf = num > 2 ? atoi(parts[2]) : 0;
|
||||
uint8_t cr = num > 3 ? atoi(parts[3]) : 0;
|
||||
if (freq >= 150.0f && freq <= 2500.0f && sf >= 5 && sf <= 12 && cr >= 5 && cr <= 8 && bw >= 7.0f && bw <= 500.0f) {
|
||||
if (freq >= 150.0f && freq <= 2500.0f && sf >= 5 && sf <= 12 && cr >= 5 && cr <= 8 && isValidLoRaBandwidth(bw)) {
|
||||
_prefs->sf = sf;
|
||||
_prefs->cr = cr;
|
||||
_prefs->freq = freq;
|
||||
@@ -872,6 +1192,28 @@ void CommonCLI::handleSetCmd(uint32_t sender_timestamp, char* command, char* rep
|
||||
} else {
|
||||
strcpy(reply, "Error, invalid radio params");
|
||||
}
|
||||
} else if (memcmp(config, "radioat ", 8) == 0) {
|
||||
float freq, bw;
|
||||
uint8_t sf, cr;
|
||||
uint32_t start_time, end_time;
|
||||
if (!parseScheduledRadioArgs(&config[8], false, freq, bw, sf, cr, start_time, end_time)) {
|
||||
strcpy(reply, "Error, use: set radioat f,bw,sf,cr,start");
|
||||
} else if (freq < 150.0f || freq > 2500.0f || sf < 5 || sf > 12 || cr < 5 || cr > 8 || !isValidLoRaBandwidth(bw)) {
|
||||
strcpy(reply, "Error, invalid radio params");
|
||||
} else {
|
||||
_callbacks->addScheduledRadioParams(false, freq, bw, sf, cr, start_time, end_time, reply);
|
||||
}
|
||||
} else if (memcmp(config, "tempradioat ", 12) == 0) {
|
||||
float freq, bw;
|
||||
uint8_t sf, cr;
|
||||
uint32_t start_time, end_time;
|
||||
if (!parseScheduledRadioArgs(&config[12], true, freq, bw, sf, cr, start_time, end_time)) {
|
||||
strcpy(reply, "Error, use: set tempradioat f,bw,sf,cr,start,end");
|
||||
} else if (freq < 150.0f || freq > 2500.0f || sf < 5 || sf > 12 || cr < 5 || cr > 8 || !isValidLoRaBandwidth(bw)) {
|
||||
strcpy(reply, "Error, invalid radio params");
|
||||
} else {
|
||||
_callbacks->addScheduledRadioParams(true, freq, bw, sf, cr, start_time, end_time, reply);
|
||||
}
|
||||
} else if (memcmp(config, "lat ", 4) == 0) {
|
||||
_prefs->node_lat = atof(&config[4]);
|
||||
savePrefs();
|
||||
@@ -955,6 +1297,18 @@ void CommonCLI::handleSetCmd(uint32_t sender_timestamp, char* command, char* rep
|
||||
} else {
|
||||
strcpy(reply, "Error, must be on or off");
|
||||
}
|
||||
} else if (memcmp(config, "direct.retry.heard ", 19) == 0) {
|
||||
if (strcmp(&config[19], "on") == 0) {
|
||||
_prefs->direct_retry_recent_enabled = 1;
|
||||
savePrefs();
|
||||
strcpy(reply, "OK");
|
||||
} else if (strcmp(&config[19], "off") == 0) {
|
||||
_prefs->direct_retry_recent_enabled = 0;
|
||||
savePrefs();
|
||||
strcpy(reply, "OK");
|
||||
} else {
|
||||
strcpy(reply, "Error, must be on or off");
|
||||
}
|
||||
} else if (memcmp(config, "direct.retry.margin ", 20) == 0) {
|
||||
if (!looksNumeric(&config[20])) {
|
||||
strcpy(reply, "Error, must be 0-40 dB");
|
||||
@@ -999,6 +1353,81 @@ void CommonCLI::handleSetCmd(uint32_t sender_timestamp, char* command, char* rep
|
||||
} else {
|
||||
strcpy(reply, "Error, must be 0-5000 ms");
|
||||
}
|
||||
} else if (memcmp(config, "flood.retry.count ", 18) == 0) {
|
||||
int attempts = looksUnsignedInteger(&config[18]) ? _atoi(&config[18]) : -1;
|
||||
if (attempts >= 0 && attempts <= 15) {
|
||||
_prefs->flood_retry_attempts = (uint8_t)attempts;
|
||||
_prefs->retry_preset = RETRY_PRESET_CUSTOM;
|
||||
savePrefs();
|
||||
strcpy(reply, "OK");
|
||||
} else {
|
||||
strcpy(reply, "Error, must be 0-15");
|
||||
}
|
||||
} else if (memcmp(config, "flood.retry.path ", 17) == 0) {
|
||||
uint8_t path_gate;
|
||||
if (parseFloodRetryPathGate(&config[17], path_gate)) {
|
||||
_prefs->flood_retry_max_path = path_gate;
|
||||
_prefs->retry_preset = RETRY_PRESET_CUSTOM;
|
||||
savePrefs();
|
||||
strcpy(reply, "OK");
|
||||
} else {
|
||||
strcpy(reply, "Error, must be 0-63 or off");
|
||||
}
|
||||
} else if (memcmp(config, "flood.retry.prefixes ", 21) == 0) {
|
||||
if (parseFloodRetryPrefixList(_prefs->flood_retry_prefixes, FLOOD_RETRY_PREFIX_SLOTS, &config[21])) {
|
||||
savePrefs();
|
||||
strcpy(reply, "OK");
|
||||
} else {
|
||||
sprintf(reply, "Error, use up to %u comma-separated 3-byte hex prefixes",
|
||||
(unsigned int)FLOOD_RETRY_PREFIX_SLOTS);
|
||||
}
|
||||
} else if (memcmp(config, "flood.retry.ignore ", 19) == 0) {
|
||||
if (parseFloodRetryPrefixList(_prefs->flood_retry_ignore_prefixes,
|
||||
FLOOD_RETRY_IGNORE_PREFIXES, &config[19])) {
|
||||
savePrefs();
|
||||
strcpy(reply, "OK");
|
||||
} else {
|
||||
sprintf(reply, "Error, use up to %u comma-separated 3-byte hex prefixes",
|
||||
(unsigned int)FLOOD_RETRY_IGNORE_PREFIXES);
|
||||
}
|
||||
} else if (memcmp(config, "flood.retry.advert ", 19) == 0) {
|
||||
if (strcmp(&config[19], "on") == 0) {
|
||||
_prefs->flood_retry_advert_enabled = 1;
|
||||
savePrefs();
|
||||
strcpy(reply, "OK");
|
||||
} else if (strcmp(&config[19], "off") == 0) {
|
||||
_prefs->flood_retry_advert_enabled = 0;
|
||||
savePrefs();
|
||||
strcpy(reply, "OK");
|
||||
} else {
|
||||
strcpy(reply, "Error, must be on or off");
|
||||
}
|
||||
} else if (memcmp(config, "flood.retry.bridge ", 19) == 0) {
|
||||
if (strcmp(&config[19], "on") == 0) {
|
||||
_prefs->flood_retry_bridge_enabled = 1;
|
||||
savePrefs();
|
||||
strcpy(reply, "OK");
|
||||
} else if (strcmp(&config[19], "off") == 0) {
|
||||
_prefs->flood_retry_bridge_enabled = 0;
|
||||
savePrefs();
|
||||
strcpy(reply, "OK");
|
||||
} else {
|
||||
strcpy(reply, "Error, must be on or off");
|
||||
}
|
||||
} else if (memcmp(config, "flood.retry.bucket ", 19) == 0) {
|
||||
const char* params = &config[19];
|
||||
uint8_t bucket = atoi(params);
|
||||
const char* list = strchr(params, ' ');
|
||||
if (bucket < 1 || bucket > FLOOD_RETRY_BRIDGE_BUCKETS || list == NULL || *(list + 1) == 0) {
|
||||
sprintf(reply, "Error, usage: set flood.retry.bucket <1-%d> <prefixes|none>", FLOOD_RETRY_BRIDGE_BUCKETS);
|
||||
} else if (parseFloodRetryPrefixList(_prefs->flood_retry_bridge_buckets[bucket - 1],
|
||||
FLOOD_RETRY_BUCKET_PREFIXES, list + 1)) {
|
||||
savePrefs();
|
||||
strcpy(reply, "OK");
|
||||
} else {
|
||||
sprintf(reply, "Error, use up to %u comma-separated 3-byte hex prefixes",
|
||||
(unsigned int)FLOOD_RETRY_BUCKET_PREFIXES);
|
||||
}
|
||||
} else if (memcmp(config, "direct.retry.cr ", 16) == 0) {
|
||||
if (strcmp(&config[16], "off") == 0) {
|
||||
_prefs->direct_retry_cr_enabled = 0;
|
||||
@@ -1234,6 +1663,10 @@ void CommonCLI::handleGetCmd(uint32_t sender_timestamp, char* command, char* rep
|
||||
} else {
|
||||
sprintf(reply, "> %s", _board->isLoRaFemLnaEnabled() ? "on" : "off");
|
||||
}
|
||||
} else if (memcmp(config, "tempradioat", 11) == 0 && (config[11] == 0 || config[11] == ' ')) {
|
||||
_callbacks->formatScheduledRadioParams(true, skipSpacesConst(&config[11]), reply);
|
||||
} else if (memcmp(config, "radioat", 7) == 0 && (config[7] == 0 || config[7] == ' ')) {
|
||||
_callbacks->formatScheduledRadioParams(false, skipSpacesConst(&config[7]), reply);
|
||||
} else if (memcmp(config, "radio", 5) == 0) {
|
||||
char freq[16], bw[16];
|
||||
strcpy(freq, StrHelper::ftoa(_prefs->freq));
|
||||
@@ -1255,6 +1688,8 @@ void CommonCLI::handleGetCmd(uint32_t sender_timestamp, char* command, char* rep
|
||||
sprintf(reply, "> %s", retryPresetName(_prefs->retry_preset));
|
||||
} else if (memcmp(config, "direct.retry", 12) == 0 && (config[12] == 0 || config[12] == ' ')) {
|
||||
sprintf(reply, "> %s", _prefs->direct_retry_enabled ? "on" : "off");
|
||||
} else if (memcmp(config, "direct.retry.heard", 18) == 0) {
|
||||
sprintf(reply, "> %s", _prefs->direct_retry_recent_enabled ? "on" : "off");
|
||||
} else if (memcmp(config, "direct.retry.margin", 19) == 0) {
|
||||
char margin[12];
|
||||
formatSnrDbX4(margin, sizeof(margin), _prefs->direct_retry_snr_margin_x4);
|
||||
@@ -1265,6 +1700,30 @@ void CommonCLI::handleGetCmd(uint32_t sender_timestamp, char* command, char* rep
|
||||
sprintf(reply, "> %d", (uint32_t)_prefs->direct_retry_base_ms);
|
||||
} else if (memcmp(config, "direct.retry.step", 17) == 0) {
|
||||
sprintf(reply, "> %d", (uint32_t)_prefs->direct_retry_step_ms);
|
||||
} else if (memcmp(config, "flood.retry.count", 17) == 0) {
|
||||
sprintf(reply, "> %d", (uint32_t)_prefs->flood_retry_attempts);
|
||||
} else if (memcmp(config, "flood.retry.path", 16) == 0) {
|
||||
char path_gate[8];
|
||||
formatFloodRetryPathGate(path_gate, _prefs->flood_retry_max_path);
|
||||
sprintf(reply, "> %s", path_gate);
|
||||
} else if (memcmp(config, "flood.retry.prefixes", 20) == 0) {
|
||||
formatFloodRetryPrefixList(tmp, _prefs->flood_retry_prefixes, FLOOD_RETRY_PREFIX_SLOTS);
|
||||
sprintf(reply, "> %s", tmp[0] ? tmp : "none");
|
||||
} else if (memcmp(config, "flood.retry.ignore", 18) == 0) {
|
||||
formatFloodRetryPrefixList(tmp, _prefs->flood_retry_ignore_prefixes, FLOOD_RETRY_IGNORE_PREFIXES);
|
||||
sprintf(reply, "> %s", tmp[0] ? tmp : "none");
|
||||
} else if (memcmp(config, "flood.retry.advert", 18) == 0) {
|
||||
sprintf(reply, "> %s", _prefs->flood_retry_advert_enabled ? "on" : "off");
|
||||
} else if (memcmp(config, "flood.retry.bridge", 18) == 0) {
|
||||
sprintf(reply, "> %s", _prefs->flood_retry_bridge_enabled ? "on" : "off");
|
||||
} else if (memcmp(config, "flood.retry.bucket.", 19) == 0) {
|
||||
uint8_t bucket = atoi(&config[19]);
|
||||
if (bucket >= 1 && bucket <= FLOOD_RETRY_BRIDGE_BUCKETS) {
|
||||
formatFloodRetryPrefixList(tmp, _prefs->flood_retry_bridge_buckets[bucket - 1], FLOOD_RETRY_BUCKET_PREFIXES);
|
||||
sprintf(reply, "> %s", tmp[0] ? tmp : "none");
|
||||
} else {
|
||||
sprintf(reply, "Error, bucket 1-%d", FLOOD_RETRY_BRIDGE_BUCKETS);
|
||||
}
|
||||
} else if (memcmp(config, "direct.retry.cr", 15) == 0) {
|
||||
if (!_prefs->direct_retry_cr_enabled) {
|
||||
strcpy(reply, "> off");
|
||||
@@ -1398,6 +1857,18 @@ void CommonCLI::handleGetCmd(uint32_t sender_timestamp, char* command, char* rep
|
||||
}
|
||||
}
|
||||
|
||||
void CommonCLI::handleDelCmd(char* command, char* reply) {
|
||||
const char* config = &command[4];
|
||||
if (memcmp(config, "tempradioat", 11) == 0 && (config[11] == 0 || config[11] == ' ')) {
|
||||
_callbacks->deleteScheduledRadioParams(true, skipSpacesConst(&config[11]), reply);
|
||||
} else if (memcmp(config, "radioat", 7) == 0 && (config[7] == 0 || config[7] == ' ')) {
|
||||
_callbacks->deleteScheduledRadioParams(false, skipSpacesConst(&config[7]), reply);
|
||||
} else {
|
||||
strcpy(reply, "unknown del: ");
|
||||
StrHelper::strncpy(&reply[13], config, 160 - 14);
|
||||
}
|
||||
}
|
||||
|
||||
static char* skipSpaces(char* s) {
|
||||
while (*s == ' ') s++;
|
||||
return s;
|
||||
|
||||
+73
-1
@@ -38,6 +38,45 @@
|
||||
#define DIRECT_RETRY_MOBILE_COUNT 15
|
||||
#define DIRECT_RETRY_MOBILE_STEP_MS 50
|
||||
#define DIRECT_RETRY_MOBILE_MARGIN_X4 0
|
||||
#define DIRECT_RETRY_RECENT_DEFAULT 1
|
||||
|
||||
#define FLOOD_RETRY_INFRA_COUNT 1
|
||||
#define FLOOD_RETRY_INFRA_MAX_PATH 1
|
||||
|
||||
#define FLOOD_RETRY_ROOFTOP_COUNT 3
|
||||
#define FLOOD_RETRY_ROOFTOP_MAX_PATH 2
|
||||
|
||||
#define FLOOD_RETRY_MOBILE_COUNT 15
|
||||
#define FLOOD_RETRY_MOBILE_MAX_PATH 1
|
||||
#define FLOOD_RETRY_ADVERT_DEFAULT 0
|
||||
|
||||
#define BATTERY_ALERT_LOW_PERCENT_DEFAULT 20
|
||||
#define BATTERY_ALERT_CRITICAL_PERCENT_DEFAULT 10
|
||||
|
||||
#ifndef FLOOD_RETRY_PREFIX_SLOTS
|
||||
#define FLOOD_RETRY_PREFIX_SLOTS 8
|
||||
#endif
|
||||
#ifndef FLOOD_RETRY_PREFIX_LEN
|
||||
#define FLOOD_RETRY_PREFIX_LEN 3
|
||||
#endif
|
||||
#ifndef FLOOD_RETRY_BRIDGE_BUCKETS
|
||||
#define FLOOD_RETRY_BRIDGE_BUCKETS 6
|
||||
#endif
|
||||
#ifndef FLOOD_RETRY_BUCKET_PREFIXES
|
||||
#define FLOOD_RETRY_BUCKET_PREFIXES 17
|
||||
#endif
|
||||
#ifndef FLOOD_RETRY_IGNORE_PREFIXES
|
||||
#define FLOOD_RETRY_IGNORE_PREFIXES 8
|
||||
#endif
|
||||
#ifndef FLOOD_RETRY_LIST_PREFIXES
|
||||
#define FLOOD_RETRY_LIST_PREFIXES ((FLOOD_RETRY_IGNORE_PREFIXES > FLOOD_RETRY_BUCKET_PREFIXES) ? FLOOD_RETRY_IGNORE_PREFIXES : FLOOD_RETRY_BUCKET_PREFIXES)
|
||||
#endif
|
||||
#ifndef FLOOD_RETRY_LIST_TEXT_MAX
|
||||
#define FLOOD_RETRY_LIST_TEXT_MAX (FLOOD_RETRY_LIST_PREFIXES * FLOOD_RETRY_PREFIX_LEN * 2 + FLOOD_RETRY_LIST_PREFIXES)
|
||||
#endif
|
||||
#ifndef COMMON_CLI_TMP_LEN
|
||||
#define COMMON_CLI_TMP_LEN ((FLOOD_RETRY_LIST_TEXT_MAX > (PRV_KEY_SIZE * 2 + 4)) ? FLOOD_RETRY_LIST_TEXT_MAX : (PRV_KEY_SIZE * 2 + 4))
|
||||
#endif
|
||||
|
||||
#define DIRECT_RETRY_CR4_MIN_SNR_X4_DEFAULT 40
|
||||
#define DIRECT_RETRY_CR5_MIN_SNR_X4_DEFAULT 30
|
||||
@@ -106,6 +145,17 @@ struct NodePrefs { // persisted to file
|
||||
uint8_t direct_retry_enabled;
|
||||
uint8_t direct_retry_cr_enabled;
|
||||
uint8_t direct_retry_prefs_magic[2];
|
||||
uint8_t flood_retry_attempts;
|
||||
uint8_t flood_retry_max_path;
|
||||
uint8_t flood_retry_prefixes[FLOOD_RETRY_PREFIX_SLOTS][FLOOD_RETRY_PREFIX_LEN];
|
||||
uint8_t flood_retry_bridge_enabled;
|
||||
uint8_t flood_retry_bridge_buckets[FLOOD_RETRY_BRIDGE_BUCKETS][FLOOD_RETRY_BUCKET_PREFIXES][FLOOD_RETRY_PREFIX_LEN];
|
||||
uint8_t flood_retry_ignore_prefixes[FLOOD_RETRY_IGNORE_PREFIXES][FLOOD_RETRY_PREFIX_LEN];
|
||||
uint8_t flood_retry_advert_enabled;
|
||||
uint8_t battery_alert_enabled;
|
||||
uint8_t battery_alert_low_percent;
|
||||
uint8_t battery_alert_critical_percent;
|
||||
uint8_t direct_retry_recent_enabled;
|
||||
};
|
||||
|
||||
class CommonCLICallbacks {
|
||||
@@ -145,6 +195,27 @@ public:
|
||||
virtual void saveIdentity(const mesh::LocalIdentity& new_id) = 0;
|
||||
virtual void clearStats() = 0;
|
||||
virtual void applyTempRadioParams(float freq, float bw, uint8_t sf, uint8_t cr, int timeout_mins) = 0;
|
||||
virtual void addScheduledRadioParams(bool temporary, float freq, float bw, uint8_t sf, uint8_t cr,
|
||||
uint32_t start_time, uint32_t end_time, char* reply) {
|
||||
(void)temporary;
|
||||
(void)freq;
|
||||
(void)bw;
|
||||
(void)sf;
|
||||
(void)cr;
|
||||
(void)start_time;
|
||||
(void)end_time;
|
||||
strcpy(reply, "Error: unsupported");
|
||||
}
|
||||
virtual void formatScheduledRadioParams(bool temporary, const char* selector, char* reply) {
|
||||
(void)temporary;
|
||||
(void)selector;
|
||||
strcpy(reply, "Error: unsupported");
|
||||
}
|
||||
virtual void deleteScheduledRadioParams(bool temporary, const char* selector, char* reply) {
|
||||
(void)temporary;
|
||||
(void)selector;
|
||||
strcpy(reply, "Error: unsupported");
|
||||
}
|
||||
|
||||
virtual void startRegionsLoad() {
|
||||
// no op by default
|
||||
@@ -177,7 +248,7 @@ class CommonCLI {
|
||||
SensorManager* _sensors;
|
||||
RegionMap* _region_map;
|
||||
ClientACL* _acl;
|
||||
char tmp[PRV_KEY_SIZE*2 + 4];
|
||||
char tmp[COMMON_CLI_TMP_LEN];
|
||||
|
||||
mesh::RTCClock* getRTCClock() { return _rtc; }
|
||||
void savePrefs();
|
||||
@@ -186,6 +257,7 @@ class CommonCLI {
|
||||
void handleRegionCmd(char* command, char* reply);
|
||||
void handleGetCmd(uint32_t sender_timestamp, char* command, char* reply);
|
||||
void handleSetCmd(uint32_t sender_timestamp, char* command, char* reply);
|
||||
void handleDelCmd(char* command, char* reply);
|
||||
|
||||
public:
|
||||
CommonCLI(mesh::MainBoard& board, mesh::RTCClock& rtc, SensorManager& sensors, RegionMap& region_map, ClientACL& acl, NodePrefs* prefs, CommonCLICallbacks* callbacks)
|
||||
|
||||
@@ -13,6 +13,12 @@
|
||||
|
||||
bool ESP32Board::startOTAUpdate(const char* id, char reply[]) {
|
||||
inhibit_sleep = true; // prevent sleep during OTA
|
||||
|
||||
if (ota_server != nullptr) {
|
||||
sprintf(reply, "Started: http://%s/update", WiFi.softAPIP().toString().c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
WiFi.softAP("MeshCore-OTA", NULL);
|
||||
|
||||
sprintf(reply, "Started: http://%s/update", WiFi.softAPIP().toString().c_str());
|
||||
@@ -23,18 +29,36 @@ bool ESP32Board::startOTAUpdate(const char* id, char reply[]) {
|
||||
static char home_buf[90];
|
||||
sprintf(home_buf, "<H2>Hi! I am a MeshCore Repeater. ID: %s</H2>", id);
|
||||
|
||||
AsyncWebServer* server = new AsyncWebServer(80);
|
||||
ota_server = new AsyncWebServer(80);
|
||||
|
||||
server->on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||
ota_server->on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||
request->send(200, "text/html", home_buf);
|
||||
});
|
||||
server->on("/log", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||
ota_server->on("/log", HTTP_GET, [](AsyncWebServerRequest *request) {
|
||||
request->send(SPIFFS, "/packet_log", "text/plain");
|
||||
});
|
||||
|
||||
AsyncElegantOTA.setID(id_buf);
|
||||
AsyncElegantOTA.begin(server); // Start ElegantOTA
|
||||
server->begin();
|
||||
AsyncElegantOTA.begin(ota_server); // Start ElegantOTA
|
||||
ota_server->begin();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ESP32Board::stopOTAUpdate(char reply[]) {
|
||||
if (ota_server == nullptr) {
|
||||
strcpy(reply, "OK - OTA not running");
|
||||
return true;
|
||||
}
|
||||
|
||||
ota_server->end();
|
||||
delete ota_server;
|
||||
ota_server = nullptr;
|
||||
WiFi.softAPdisconnect(true);
|
||||
inhibit_sleep = false;
|
||||
|
||||
strcpy(reply, "OK - OTA stopped");
|
||||
MESH_DEBUG_PRINTLN("stopOTAUpdate: %s", reply);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -43,6 +67,10 @@ bool ESP32Board::startOTAUpdate(const char* id, char reply[]) {
|
||||
bool ESP32Board::startOTAUpdate(const char* id, char reply[]) {
|
||||
return false; // not supported
|
||||
}
|
||||
|
||||
bool ESP32Board::stopOTAUpdate(char reply[]) {
|
||||
return false; // not supported
|
||||
}
|
||||
#endif
|
||||
|
||||
void ESP32Board::powerOff() {
|
||||
|
||||
@@ -16,10 +16,13 @@
|
||||
#include "esp_system.h"
|
||||
#include <driver/rtc_io.h>
|
||||
|
||||
class AsyncWebServer;
|
||||
|
||||
class ESP32Board : public mesh::MainBoard {
|
||||
protected:
|
||||
uint8_t startup_reason;
|
||||
bool inhibit_sleep = false;
|
||||
AsyncWebServer* ota_server = nullptr;
|
||||
static inline portMUX_TYPE sleepMux = portMUX_INITIALIZER_UNLOCKED;
|
||||
|
||||
public:
|
||||
@@ -155,6 +158,15 @@ public:
|
||||
}
|
||||
|
||||
bool startOTAUpdate(const char* id, char reply[]) override;
|
||||
bool stopOTAUpdate(char reply[]) override;
|
||||
|
||||
bool isUsbDataConnected() override {
|
||||
#if defined(ARDUINO_USB_CDC_ON_BOOT) && ARDUINO_USB_CDC_ON_BOOT
|
||||
return (bool)Serial;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void setInhibitSleep(bool inhibit) {
|
||||
inhibit_sleep = inhibit;
|
||||
|
||||
+67
-15
@@ -3,18 +3,33 @@
|
||||
#include <target.h>
|
||||
|
||||
#include <bluefruit.h>
|
||||
#include "ble_gap.h"
|
||||
#include "ble_hci.h"
|
||||
#include <nrf_soc.h>
|
||||
|
||||
static BLEDfu bledfu;
|
||||
static uint16_t ota_conn_handle = BLE_CONN_HANDLE_INVALID;
|
||||
static bool ota_active = false;
|
||||
static bool ota_ble_started = false;
|
||||
|
||||
static void format_ota_reply(char reply[]) {
|
||||
uint8_t mac_addr[6];
|
||||
memset(mac_addr, 0, sizeof(mac_addr));
|
||||
Bluefruit.getAddr(mac_addr);
|
||||
sprintf(reply, "OK - mac: %02X:%02X:%02X:%02X:%02X:%02X", mac_addr[5], mac_addr[4], mac_addr[3],
|
||||
mac_addr[2], mac_addr[1], mac_addr[0]);
|
||||
}
|
||||
|
||||
static void connect_callback(uint16_t conn_handle) {
|
||||
(void)conn_handle;
|
||||
ota_conn_handle = conn_handle;
|
||||
MESH_DEBUG_PRINTLN("BLE client connected");
|
||||
}
|
||||
|
||||
static void disconnect_callback(uint16_t conn_handle, uint8_t reason) {
|
||||
(void)conn_handle;
|
||||
(void)reason;
|
||||
if (ota_conn_handle == conn_handle) {
|
||||
ota_conn_handle = BLE_CONN_HANDLE_INVALID;
|
||||
}
|
||||
|
||||
MESH_DEBUG_PRINTLN("BLE client disconnected");
|
||||
}
|
||||
@@ -252,6 +267,14 @@ bool NRF52Board::isExternalPowered() {
|
||||
}
|
||||
}
|
||||
|
||||
bool NRF52Board::isUsbDataConnected() {
|
||||
#ifdef USE_TINYUSB
|
||||
return Serial.dtr();
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void NRF52Board::sleep(uint32_t secs) {
|
||||
// Clear FPU interrupt flags to avoid insomnia
|
||||
// see errata 87 for details https://docs.nordicsemi.com/bundle/errata_nRF52840_Rev3/page/ERR/nRF52840/Rev3/latest/anomaly_840_87.html
|
||||
@@ -349,13 +372,27 @@ bool NRF52Board::getBootloaderVersion(char* out, size_t max_len) {
|
||||
}
|
||||
|
||||
bool NRF52Board::startOTAUpdate(const char *id, char reply[]) {
|
||||
// Config the peripheral connection with maximum bandwidth
|
||||
// more SRAM required by SoftDevice
|
||||
// Note: All config***() function must be called before begin()
|
||||
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);
|
||||
Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16);
|
||||
(void)id;
|
||||
|
||||
if (ota_active) {
|
||||
format_ota_reply(reply);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!ota_ble_started) {
|
||||
// Config the peripheral connection with maximum bandwidth
|
||||
// more SRAM required by SoftDevice
|
||||
// Note: All config***() function must be called before begin()
|
||||
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);
|
||||
Bluefruit.configPrphConn(92, BLE_GAP_EVENT_LENGTH_MIN, 16, 16);
|
||||
|
||||
Bluefruit.begin(1, 0);
|
||||
ota_ble_started = true;
|
||||
|
||||
// To be consistent OTA DFU should be added first if it exists
|
||||
bledfu.begin();
|
||||
}
|
||||
|
||||
Bluefruit.begin(1, 0);
|
||||
// Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4
|
||||
Bluefruit.setTxPower(4);
|
||||
// Set the BLE device name
|
||||
@@ -364,8 +401,8 @@ bool NRF52Board::startOTAUpdate(const char *id, char reply[]) {
|
||||
Bluefruit.Periph.setConnectCallback(connect_callback);
|
||||
Bluefruit.Periph.setDisconnectCallback(disconnect_callback);
|
||||
|
||||
// To be consistent OTA DFU should be added first if it exists
|
||||
bledfu.begin();
|
||||
Bluefruit.Advertising.clearData();
|
||||
Bluefruit.ScanResponse.clearData();
|
||||
|
||||
// Set up and start advertising
|
||||
// Advertising packet
|
||||
@@ -387,12 +424,27 @@ bool NRF52Board::startOTAUpdate(const char *id, char reply[]) {
|
||||
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
|
||||
Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds
|
||||
|
||||
uint8_t mac_addr[6];
|
||||
memset(mac_addr, 0, sizeof(mac_addr));
|
||||
Bluefruit.getAddr(mac_addr);
|
||||
sprintf(reply, "OK - mac: %02X:%02X:%02X:%02X:%02X:%02X", mac_addr[5], mac_addr[4], mac_addr[3],
|
||||
mac_addr[2], mac_addr[1], mac_addr[0]);
|
||||
ota_active = true;
|
||||
format_ota_reply(reply);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool NRF52Board::stopOTAUpdate(char reply[]) {
|
||||
if (!ota_active) {
|
||||
strcpy(reply, "OK - OTA not running");
|
||||
return true;
|
||||
}
|
||||
|
||||
Bluefruit.Advertising.restartOnDisconnect(false);
|
||||
Bluefruit.Advertising.stop();
|
||||
if (ota_conn_handle != BLE_CONN_HANDLE_INVALID) {
|
||||
sd_ble_gap_disconnect(ota_conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
|
||||
ota_conn_handle = BLE_CONN_HANDLE_INVALID;
|
||||
}
|
||||
ota_active = false;
|
||||
|
||||
strcpy(reply, "OK - OTA stopped");
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
@@ -53,8 +53,10 @@ public:
|
||||
virtual void powerOff() override;
|
||||
virtual bool getBootloaderVersion(char* version, size_t max_len) override;
|
||||
virtual bool startOTAUpdate(const char *id, char reply[]) override;
|
||||
virtual bool stopOTAUpdate(char reply[]) override;
|
||||
virtual void sleep(uint32_t secs) override;
|
||||
bool isExternalPowered() override;
|
||||
bool isUsbDataConnected() override;
|
||||
|
||||
#ifdef NRF52_POWER_MANAGEMENT
|
||||
uint16_t getBootVoltage() override { return boot_voltage_mv; }
|
||||
@@ -77,4 +79,4 @@ public:
|
||||
NRF52BoardDCDC() {}
|
||||
virtual void begin() override;
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,6 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <Mesh.h>
|
||||
#if ARDUINO
|
||||
#include <Arduino.h>
|
||||
#endif
|
||||
|
||||
#ifdef ESP32
|
||||
#include <FS.h>
|
||||
@@ -26,6 +29,7 @@ public:
|
||||
uint8_t prefix[MAX_ROUTE_HASH_BYTES];
|
||||
uint8_t prefix_len;
|
||||
int8_t snr_x4;
|
||||
uint32_t last_heard_millis;
|
||||
};
|
||||
|
||||
private:
|
||||
@@ -194,7 +198,10 @@ public:
|
||||
uint32_t getNumDirectDups() const { return _direct_dups; }
|
||||
uint32_t getNumFloodDups() const { return _flood_dups; }
|
||||
|
||||
bool setRecentRepeater(const uint8_t* prefix, uint8_t prefix_len, int8_t snr_x4) {
|
||||
bool setRecentRepeater(const uint8_t* prefix, uint8_t prefix_len, int8_t snr_x4,
|
||||
bool snr_locked = false, bool bypass_allow_filter = false) {
|
||||
(void)snr_locked;
|
||||
(void)bypass_allow_filter;
|
||||
if (prefix == NULL || prefix_len == 0) {
|
||||
return false;
|
||||
}
|
||||
@@ -211,6 +218,11 @@ public:
|
||||
continue;
|
||||
}
|
||||
existing.snr_x4 = weightedSnrX4RoundUp(existing.snr_x4, snr_x4);
|
||||
#if ARDUINO
|
||||
existing.last_heard_millis = millis();
|
||||
#else
|
||||
existing.last_heard_millis = 0;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -222,15 +234,19 @@ public:
|
||||
}
|
||||
}
|
||||
if (slot_idx < 0) {
|
||||
// Table is full: evict the weakest observed SNR entry.
|
||||
// Table is full: evict the oldest heard entry.
|
||||
slot_idx = 0;
|
||||
int8_t min_snr_x4 = _recent_repeaters[0].snr_x4;
|
||||
#if ARDUINO
|
||||
uint32_t now = millis();
|
||||
uint32_t oldest_age = (uint32_t)(now - _recent_repeaters[0].last_heard_millis);
|
||||
for (int i = 1; i < MAX_RECENT_REPEATERS; i++) {
|
||||
if (_recent_repeaters[i].snr_x4 < min_snr_x4) {
|
||||
min_snr_x4 = _recent_repeaters[i].snr_x4;
|
||||
uint32_t age = (uint32_t)(now - _recent_repeaters[i].last_heard_millis);
|
||||
if (age > oldest_age) {
|
||||
oldest_age = age;
|
||||
slot_idx = i;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
RecentRepeaterInfo& slot = _recent_repeaters[slot_idx];
|
||||
@@ -238,6 +254,11 @@ public:
|
||||
memcpy(slot.prefix, prefix, prefix_len);
|
||||
slot.prefix_len = prefix_len;
|
||||
slot.snr_x4 = snr_x4;
|
||||
#if ARDUINO
|
||||
slot.last_heard_millis = millis();
|
||||
#else
|
||||
slot.last_heard_millis = 0;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
bool decrementRecentRepeaterSnrX4(const uint8_t* prefix, uint8_t prefix_len, uint8_t amount_x4 = 1) {
|
||||
|
||||
@@ -4,6 +4,10 @@
|
||||
#include "RadioLibWrappers.h"
|
||||
#include "LR11x0Reset.h"
|
||||
|
||||
#ifndef USE_LR1110
|
||||
#define USE_LR1110
|
||||
#endif
|
||||
|
||||
class CustomLR1110Wrapper : public RadioLibWrapper {
|
||||
public:
|
||||
CustomLR1110Wrapper(CustomLR1110& radio, mesh::MainBoard& board) : RadioLibWrapper(radio, board) { }
|
||||
|
||||
Reference in new issue
Block a user