|
|
@ -164,43 +164,45 @@ void _systemRtcmemResetReason(CustomResetReason reason) { |
|
|
|
//
|
|
|
|
// An unstable system will only have serial access, WiFi in AP mode and OTA
|
|
|
|
|
|
|
|
bool _systemStable = true; |
|
|
|
|
|
|
|
void systemCheck(bool stable) { |
|
|
|
uint8_t value = 0; |
|
|
|
|
|
|
|
if (stable) { |
|
|
|
value = 0; |
|
|
|
DEBUG_MSG_P(PSTR("[MAIN] System OK\n")); |
|
|
|
} else { |
|
|
|
if (!rtcmemStatus()) { |
|
|
|
systemStabilityCounter(1); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
value = systemStabilityCounter(); |
|
|
|
constexpr unsigned char _systemCheckMin() { |
|
|
|
return 0u; |
|
|
|
} |
|
|
|
|
|
|
|
if (++value > SYSTEM_CHECK_MAX) { |
|
|
|
_systemStable = false; |
|
|
|
value = SYSTEM_CHECK_MAX; |
|
|
|
DEBUG_MSG_P(PSTR("[MAIN] System UNSTABLE\n")); |
|
|
|
} |
|
|
|
} |
|
|
|
constexpr unsigned char _systemCheckMax() { |
|
|
|
return SYSTEM_CHECK_MAX; |
|
|
|
} |
|
|
|
|
|
|
|
systemStabilityCounter(value); |
|
|
|
constexpr unsigned long _systemCheckTime() { |
|
|
|
return SYSTEM_CHECK_TIME; |
|
|
|
} |
|
|
|
|
|
|
|
bool systemCheck() { |
|
|
|
return _systemStable; |
|
|
|
static_assert(_systemCheckMax() > 0, ""); |
|
|
|
|
|
|
|
Ticker _system_stable_timer; |
|
|
|
bool _system_stable { true }; |
|
|
|
|
|
|
|
void _systemStabilityInit() { |
|
|
|
auto count = rtcmemStatus() ? systemStabilityCounter() : 1u; |
|
|
|
|
|
|
|
_system_stable = (count < _systemCheckMax()); |
|
|
|
DEBUG_MSG_P(PSTR("[MAIN] System %s\n"), _system_stable ? "OK" : "UNSTABLE"); |
|
|
|
|
|
|
|
_system_stable_timer.once_ms_scheduled(_systemCheckTime(), []() { |
|
|
|
DEBUG_MSG_P(PSTR("[MAIN] System stability counter %hhu / %hhu\n"), |
|
|
|
_systemCheckMin(), _systemCheckMax()); |
|
|
|
systemStabilityCounter(_systemCheckMin()); |
|
|
|
}); |
|
|
|
|
|
|
|
auto next = count + 1u; |
|
|
|
count = next > _systemCheckMax() |
|
|
|
? count |
|
|
|
: next; |
|
|
|
|
|
|
|
systemStabilityCounter(count); |
|
|
|
} |
|
|
|
|
|
|
|
void _systemCheckLoop() { |
|
|
|
static bool checked = false; |
|
|
|
if (!checked && (millis() > SYSTEM_CHECK_TIME)) { |
|
|
|
// Flag system as stable
|
|
|
|
systemCheck(true); |
|
|
|
checked = true; |
|
|
|
} |
|
|
|
bool systemCheck() { |
|
|
|
return _system_stable; |
|
|
|
} |
|
|
|
|
|
|
|
#endif
|
|
|
@ -536,10 +538,6 @@ void systemLoop() { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
#if SYSTEM_CHECK_ENABLED
|
|
|
|
_systemCheckLoop(); |
|
|
|
#endif
|
|
|
|
|
|
|
|
_systemUpdateLoadAverage(); |
|
|
|
} |
|
|
|
|
|
|
@ -573,9 +571,8 @@ void systemSetup() { |
|
|
|
SPIFFS.begin(); |
|
|
|
#endif
|
|
|
|
|
|
|
|
// Question system stability
|
|
|
|
#if SYSTEM_CHECK_ENABLED
|
|
|
|
systemCheck(false); |
|
|
|
_systemStabilityInit(); |
|
|
|
#endif
|
|
|
|
|
|
|
|
#if WEB_SUPPORT
|
|
|
|