Delay displayed radio preamble advice for two minutes
This commit is contained in:
1 parent
64a928d18f
commit
97be2b9b21
7 files changed
+244
-11
No files matched your search
+23
-1
@@ -55,6 +55,7 @@ class RadioProfiles {
|
||||
// the self-tested, guarded switch time in the idle-scan timing model.
|
||||
static constexpr uint32_t LoopBudgetUs = 0;
|
||||
static constexpr uint8_t SwitchTestSamplesPerDirection = 4;
|
||||
static constexpr uint32_t SwitchRecommendationWindowMs = 120000;
|
||||
|
||||
struct ChirpTiming {
|
||||
bool valid = false;
|
||||
@@ -83,20 +84,41 @@ class RadioProfiles {
|
||||
uint32_t longest_switch_us = 0;
|
||||
uint32_t switch_test_max_us[2] = {};
|
||||
uint8_t switch_test_samples[2] = {};
|
||||
uint32_t switch_runtime_started_ms = 0;
|
||||
bool switch_runtime_started = false;
|
||||
bool switch_runtime_ready = false;
|
||||
|
||||
void resetSwitchTest() {
|
||||
switch_test_max_us[0] = switch_test_max_us[1] = 0;
|
||||
switch_test_samples[0] = switch_test_samples[1] = 0;
|
||||
switch_runtime_started_ms = 0;
|
||||
switch_runtime_started = switch_runtime_ready = false;
|
||||
}
|
||||
void sampleSwitch(uint8_t from, uint8_t to, uint32_t elapsed_us) {
|
||||
void sampleSwitch(uint8_t from, uint8_t to, uint32_t elapsed_us, uint32_t now_ms = 0) {
|
||||
if (!enabled() || from > 1 || to > 1 || from == to || !elapsed_us) return;
|
||||
if (switch_test_samples[from] < SwitchTestSamplesPerDirection) ++switch_test_samples[from];
|
||||
if (elapsed_us > switch_test_max_us[from]) switch_test_max_us[from] = elapsed_us;
|
||||
// Delay only the displayed recommendation. Startup readiness, guarded
|
||||
// maxima, automatic preambles and scanner behavior remain unchanged.
|
||||
if (!switch_runtime_started) {
|
||||
switch_runtime_started = true;
|
||||
switch_runtime_started_ms = now_ms;
|
||||
}
|
||||
if (switchTestReady()
|
||||
&& uint32_t(now_ms - switch_runtime_started_ms) >= SwitchRecommendationWindowMs)
|
||||
switch_runtime_ready = true;
|
||||
}
|
||||
bool switchTestReady() const {
|
||||
return switch_test_samples[0] >= SwitchTestSamplesPerDirection
|
||||
&& switch_test_samples[1] >= SwitchTestSamplesPerDirection;
|
||||
}
|
||||
bool recommendationReady() const { return switch_runtime_ready; }
|
||||
uint32_t recommendationRemainingMs(uint32_t now_ms) const {
|
||||
if (recommendationReady()) return 0;
|
||||
if (!switch_runtime_started) return SwitchRecommendationWindowMs;
|
||||
const uint32_t elapsed = now_ms - switch_runtime_started_ms;
|
||||
return elapsed < SwitchRecommendationWindowMs ? SwitchRecommendationWindowMs - elapsed : 0;
|
||||
}
|
||||
uint32_t switchBudgetUs() const {
|
||||
const uint32_t observed = switch_test_max_us[0] > switch_test_max_us[1]
|
||||
? switch_test_max_us[0] : switch_test_max_us[1];
|
||||
|
||||
@@ -630,9 +630,11 @@ void RadioProfileCLI::appendPrimaryChirpWarning(char* reply, size_t capacity, ui
|
||||
|
||||
void RadioProfileCLI::appendChirpWarning(char* reply, size_t capacity, const RadioProfiles& preview) {
|
||||
if (!capacity || !preview.enabled()) return;
|
||||
if (!preview.switchTestReady()) {
|
||||
if (!preview.recommendationReady()) {
|
||||
const size_t used = strlen(reply);
|
||||
if (used < capacity) snprintf(reply + used, capacity - used, "; timing self-test pending");
|
||||
if (used < capacity) snprintf(reply + used, capacity - used,
|
||||
"; timing self-test pending; wait=%lus",
|
||||
(unsigned long)((preview.recommendationRemainingMs(millis()) + 999) / 1000));
|
||||
return;
|
||||
}
|
||||
const auto timing = preview.chirpTiming();
|
||||
@@ -761,10 +763,12 @@ bool RadioProfileCLI::handle(const char* command, char* reply, size_t capacity,
|
||||
const auto& p = *radio_->profiles();
|
||||
const auto t = p.chirpTiming();
|
||||
if (!p.enabled()) snprintf(reply, capacity, "> off");
|
||||
else if (!p.switchTestReady()) snprintf(reply, capacity,
|
||||
"> timing self-test pending; test=%u/%u,%u/%u; provisional preamble=%u,%u",
|
||||
else if (!p.recommendationReady()) snprintf(reply, capacity,
|
||||
"> timing self-test pending; test=%u/%u,%u/%u; wait=%lus; provisional switch=%luus preamble=%u,%u",
|
||||
p.switch_test_samples[0], RadioProfiles::SwitchTestSamplesPerDirection,
|
||||
p.switch_test_samples[1], RadioProfiles::SwitchTestSamplesPerDirection,
|
||||
(unsigned long)((p.recommendationRemainingMs(millis()) + 999) / 1000),
|
||||
(unsigned long)p.switchBudgetUs(),
|
||||
radio_->profilePreamble(0), radio_->profilePreamble(1));
|
||||
else if (!t.valid) snprintf(reply, capacity, "Error: timing unavailable");
|
||||
else {
|
||||
@@ -823,7 +827,7 @@ bool RadioProfileCLI::handle(const char* command, char* reply, size_t capacity,
|
||||
if (used < capacity) snprintf(reply + used, capacity - used, "; test=%u/%u,%u/%u%s budget=%luus",
|
||||
p.switch_test_samples[0], RadioProfiles::SwitchTestSamplesPerDirection,
|
||||
p.switch_test_samples[1], RadioProfiles::SwitchTestSamplesPerDirection,
|
||||
p.switchTestReady() ? " ready" : " pending", (unsigned long)p.switchBudgetUs());
|
||||
p.recommendationReady() ? " ready" : " pending", (unsigned long)p.switchBudgetUs());
|
||||
appendChirpWarning(reply, capacity, p);
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -562,7 +562,7 @@ mesh::RadioParamApplyResult RadioLibWrapper::tuneProfile(uint8_t profile) {
|
||||
// then continue raising the observed maximum as later good hops run.
|
||||
// Deferred and rolled-back operations are not samples.
|
||||
if (applied && resume && old_profile != profile) {
|
||||
_profiles.sampleSwitch(old_profile, profile, elapsed);
|
||||
_profiles.sampleSwitch(old_profile, profile, elapsed, millis());
|
||||
}
|
||||
return applied ? mesh::RadioParamApplyResult::APPLIED : mesh::RadioParamApplyResult::FAILED;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user