Browse Source

Build setting to disable system check

fastled
Xose Pérez 7 years ago
parent
commit
84fc259a6f
5 changed files with 43 additions and 17 deletions
  1. +7
    -3
      code/espurna/config/general.h
  2. +8
    -0
      code/espurna/debug.ino
  3. +10
    -11
      code/espurna/espurna.ino
  4. +15
    -2
      code/espurna/utils.ino
  5. +3
    -1
      code/espurna/wifi.ino

+ 7
- 3
code/espurna/config/general.h View File

@ -82,11 +82,15 @@
#endif #endif
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// CRASH
// SYSTEM CHECK
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
#define CRASH_SAFE_TIME 60000 // The system is considered stable after these many millis
#define CRASH_COUNT_MAX 5 // After this many crashes on boot
#ifndef SYSTEM_CHECK_ENABLED
#define SYSTEM_CHECK_ENABLED 1 // Enable crash check by default
#endif
#define SYSTEM_CHECK_TIME 60000 // The system is considered stable after these many millis
#define SYSTEM_CHECK_MAX 5 // After this many crashes on boot
// the system is flagged as unstable // the system is flagged as unstable
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------


+ 8
- 0
code/espurna/debug.ino View File

@ -33,7 +33,9 @@ void debugSend(const char * format, ...) {
#endif #endif
#if DEBUG_UDP_SUPPORT #if DEBUG_UDP_SUPPORT
#if SYSTEM_CHECK_ENABLED
if (systemCheck()) { if (systemCheck()) {
#endif
udpDebug.beginPacket(DEBUG_UDP_IP, DEBUG_UDP_PORT); udpDebug.beginPacket(DEBUG_UDP_IP, DEBUG_UDP_PORT);
udpDebug.write(buffer); udpDebug.write(buffer);
if (len > DEBUG_MESSAGE_MAX_LENGTH) { if (len > DEBUG_MESSAGE_MAX_LENGTH) {
@ -41,7 +43,9 @@ void debugSend(const char * format, ...) {
} }
udpDebug.endPacket(); udpDebug.endPacket();
delay(1); delay(1);
#if SYSTEM_CHECK_ENABLED
} }
#endif
#endif #endif
#if DEBUG_TELNET_SUPPORT #if DEBUG_TELNET_SUPPORT
@ -70,7 +74,9 @@ void debugSend_P(PGM_P format, ...) {
#endif #endif
#if DEBUG_UDP_SUPPORT #if DEBUG_UDP_SUPPORT
#if SYSTEM_CHECK_ENABLED
if (systemCheck()) { if (systemCheck()) {
#endif
udpDebug.beginPacket(DEBUG_UDP_IP, DEBUG_UDP_PORT); udpDebug.beginPacket(DEBUG_UDP_IP, DEBUG_UDP_PORT);
udpDebug.write(buffer); udpDebug.write(buffer);
if (len > DEBUG_MESSAGE_MAX_LENGTH) { if (len > DEBUG_MESSAGE_MAX_LENGTH) {
@ -78,7 +84,9 @@ void debugSend_P(PGM_P format, ...) {
} }
udpDebug.endPacket(); udpDebug.endPacket();
delay(1); delay(1);
#if SYSTEM_CHECK_ENABLED
} }
#endif
#endif #endif
#if DEBUG_TELNET_SUPPORT #if DEBUG_TELNET_SUPPORT


+ 10
- 11
code/espurna/espurna.ino View File

@ -53,14 +53,6 @@ void hardwareSetup() {
void hardwareLoop() { void hardwareLoop() {
// System check
static bool checked = false;
if (!checked && (millis() > CRASH_SAFE_TIME)) {
// Check system as stable
systemCheck(true);
checked = true;
}
// Heartbeat // Heartbeat
static unsigned long last_uptime = 0; static unsigned long last_uptime = 0;
if ((millis() - last_uptime > HEARTBEAT_INTERVAL) || (last_uptime == 0)) { if ((millis() - last_uptime > HEARTBEAT_INTERVAL) || (last_uptime == 0)) {
@ -225,7 +217,9 @@ void setup() {
hardwareSetup(); hardwareSetup();
// Question system stability // Question system stability
systemCheck(false);
#if SYSTEM_CHECK_ENABLED
systemCheck(false);
#endif
// Show welcome message and system configuration // Show welcome message and system configuration
welcome(); welcome();
@ -243,7 +237,9 @@ void setup() {
#endif #endif
// Do not run the next services if system is flagged stable // Do not run the next services if system is flagged stable
if (!systemCheck()) return;
#if SYSTEM_CHECK_ENABLED
if (!systemCheck()) return;
#endif
#if WEB_SUPPORT #if WEB_SUPPORT
webSetup(); webSetup();
@ -316,7 +312,10 @@ void loop() {
otaLoop(); otaLoop();
// Do not run the next services if system is flagged stable // Do not run the next services if system is flagged stable
if (!systemCheck()) return;
#if SYSTEM_CHECK_ENABLED
systemCheckLoop();
if (!systemCheck()) return;
#endif
#if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE #if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE
lightLoop(); lightLoop();


+ 15
- 2
code/espurna/utils.ino View File

@ -141,9 +141,11 @@ unsigned char customReset() {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#if SYSTEM_CHECK_ENABLED
// Call this method on boot with start=true to increase the crash counter // Call this method on boot with start=true to increase the crash counter
// Call it again once the system is stable to decrease the counter // Call it again once the system is stable to decrease the counter
// If the counter reaches CRASH_COUNT_MAX then the system is flagged as unstable
// If the counter reaches SYSTEM_CHECK_MAX then the system is flagged as unstable
// setting _systemOK = false; // setting _systemOK = false;
// //
// An unstable system will only have serial access, WiFi in AP mode and OTA // An unstable system will only have serial access, WiFi in AP mode and OTA
@ -156,7 +158,7 @@ void systemCheck(bool stable) {
value = 0; value = 0;
DEBUG_MSG_P(PSTR("[MAIN] System OK\n")); DEBUG_MSG_P(PSTR("[MAIN] System OK\n"));
} else { } else {
if (++value > CRASH_COUNT_MAX) {
if (++value > SYSTEM_CHECK_MAX) {
_systemStable = false; _systemStable = false;
value = 0; value = 0;
DEBUG_MSG_P(PSTR("[MAIN] System UNSTABLE\n")); DEBUG_MSG_P(PSTR("[MAIN] System UNSTABLE\n"));
@ -170,6 +172,17 @@ bool systemCheck() {
return _systemStable; return _systemStable;
} }
void systemCheckLoop() {
static bool checked = false;
if (!checked && (millis() > SYSTEM_CHECK_TIME)) {
// Check system as stable
systemCheck(true);
checked = true;
}
}
#endif
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
char * ltrim(char * s) { char * ltrim(char * s) {


+ 3
- 1
code/espurna/wifi.ino View File

@ -66,7 +66,9 @@ void wifiConfigure() {
jw.cleanNetworks(); jw.cleanNetworks();
// If system is flagged unstable we do not init wifi networks // If system is flagged unstable we do not init wifi networks
if (!systemCheck()) return;
#if SYSTEM_CHECK_ENABLED
if (!systemCheck()) return;
#endif
int i; int i;
for (i = 0; i< WIFI_MAX_NETWORKS; i++) { for (i = 0; i< WIFI_MAX_NETWORKS; i++) {


Loading…
Cancel
Save