Browse Source

system: rework stability counter

- remove public function from the header
- initial log for both states, log counted number
- fixup terminal reset triggering unstable state
dev
Maxim Prokhorov 3 years ago
parent
commit
474f0e9369
3 changed files with 37 additions and 40 deletions
  1. +34
    -37
      code/espurna/system.cpp
  2. +0
    -1
      code/espurna/system.h
  3. +3
    -2
      code/espurna/terminal.cpp

+ 34
- 37
code/espurna/system.cpp View File

@ -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


+ 0
- 1
code/espurna/system.h View File

@ -146,7 +146,6 @@ uint32_t systemResetReason();
uint8_t systemStabilityCounter();
void systemStabilityCounter(uint8_t count);
void systemCheck(bool stable);
bool systemCheck();
void customResetReason(CustomResetReason reason);


+ 3
- 2
code/espurna/terminal.cpp View File

@ -348,10 +348,11 @@ void _terminalInitCommands() {
});
terminalRegisterCommand(F("RESET"), [](const terminal::CommandContext& ctx) {
auto count = 1;
if (ctx.argc == 2) {
auto arg = ctx.argv[1].toInt();
count = ctx.argv[1].toInt();
if (arg < SYSTEM_CHECK_MAX) {
systemStabilityCounter(arg);
systemStabilityCounter(count);
}
}


Loading…
Cancel
Save