diff --git a/Software/Software.ino b/Software/Software.ino index aed22338..a9debf20 100644 --- a/Software/Software.ino +++ b/Software/Software.ino @@ -86,8 +86,8 @@ float charger_stat_LVvol = 0; int64_t core_task_time_us; MyTimer core_task_timer_10s(INTERVAL_10_S); -int64_t mqtt_task_time_us; -MyTimer mqtt_task_timer_10s(INTERVAL_10_S); +int64_t connectivity_task_time_us; +MyTimer connectivity_task_timer_10s(INTERVAL_10_S); MyTimer loop_task_timer_10s(INTERVAL_10_S); @@ -116,7 +116,7 @@ unsigned long timeSpentInFaultedMode = 0; #endif TaskHandle_t main_loop_task; -TaskHandle_t mqtt_loop_task; +TaskHandle_t connectivity_loop_task; // Initialization void setup() { @@ -125,11 +125,9 @@ void setup() { init_stored_settings(); #ifdef WEBSERVER - init_webserver(); - init_mDNS(); #ifdef MQTT - xTaskCreatePinnedToCore((TaskFunction_t)&mqtt_loop, "mqtt_loop", 4096, &mqtt_task_time_us, TASK_CONNECTIVITY_PRIO, - &mqtt_loop_task, WIFI_CORE); + xTaskCreatePinnedToCore((TaskFunction_t)&connectivity_loop, "connectivity_loop", 4096, &connectivity_task_time_us, + TASK_CONNECTIVITY_PRIO, &connectivity_loop_task, WIFI_CORE); #endif #endif @@ -170,25 +168,33 @@ void loop() { #endif } +#ifdef WEBSERVER #ifdef MQTT -void mqtt_loop(void* task_time_us) { - // Init MQTT +void connectivity_loop(void* task_time_us) { + // Init + init_webserver(); + init_mDNS(); init_mqtt(); while (true) { + START_TIME_MEASUREMENT(wifi); + wifi_monitor(); + END_TIME_MEASUREMENT_MAX(wifi, datalayer.system.status.wifi_task_10s_max_us); START_TIME_MEASUREMENT(mqtt); mqtt_loop(); END_TIME_MEASUREMENT_MAX(mqtt, datalayer.system.status.mqtt_task_10s_max_us); #ifdef FUNCTION_TIME_MEASUREMENT - if (mqtt_task_timer_10s.elapsed()) { + if (connectivity_task_timer_10s.elapsed()) { datalayer.system.status.mqtt_task_10s_max_us = 0; + datalayer.system.status.wifi_task_10s_max_us = 0; } #endif delay(1); } } #endif +#endif void core_loop(void* task_time_us) { TickType_t xLastWakeTime = xTaskGetTickCount(); @@ -211,10 +217,9 @@ void core_loop(void* task_time_us) { #endif END_TIME_MEASUREMENT_MAX(comm, datalayer.system.status.time_comm_us); #ifdef WEBSERVER - START_TIME_MEASUREMENT(wifi_ota); - wifi_monitor(); + START_TIME_MEASUREMENT(ota); ElegantOTA.loop(); - END_TIME_MEASUREMENT_MAX(wifi_ota, datalayer.system.status.time_wifi_us); + END_TIME_MEASUREMENT_MAX(ota, datalayer.system.status.time_ota_us); #endif START_TIME_MEASUREMENT(time_10ms); @@ -262,13 +267,13 @@ void core_loop(void* task_time_us) { datalayer.system.status.time_snap_10ms_us = datalayer.system.status.time_10ms_us; datalayer.system.status.time_snap_5s_us = datalayer.system.status.time_5s_us; datalayer.system.status.time_snap_cantx_us = datalayer.system.status.time_cantx_us; - datalayer.system.status.time_snap_wifi_us = datalayer.system.status.time_wifi_us; + datalayer.system.status.time_snap_ota_us = datalayer.system.status.time_ota_us; } datalayer.system.status.core_task_max_us = MAX(datalayer.system.status.core_task_10s_max_us, datalayer.system.status.core_task_max_us); if (core_task_timer_10s.elapsed()) { - datalayer.system.status.time_wifi_us = 0; + datalayer.system.status.time_ota_us = 0; datalayer.system.status.time_comm_us = 0; datalayer.system.status.time_10ms_us = 0; datalayer.system.status.time_5s_us = 0; diff --git a/Software/src/battery/BMW-I3-BATTERY.cpp b/Software/src/battery/BMW-I3-BATTERY.cpp index 646fafa9..526bfbd8 100644 --- a/Software/src/battery/BMW-I3-BATTERY.cpp +++ b/Software/src/battery/BMW-I3-BATTERY.cpp @@ -687,6 +687,8 @@ void send_can_battery() { // Check if sending of CAN messages has been delayed too much. if ((currentMillis - previousMillis20 >= INTERVAL_20_MS_DELAYED) && (currentMillis > BOOTUP_TIME)) { set_event(EVENT_CAN_OVERRUN, (currentMillis - previousMillis20)); + } else { + clear_event(EVENT_CAN_OVERRUN); } previousMillis20 = currentMillis; diff --git a/Software/src/battery/BYD-ATTO-3-BATTERY.cpp b/Software/src/battery/BYD-ATTO-3-BATTERY.cpp index 4c80263c..2aeb702f 100644 --- a/Software/src/battery/BYD-ATTO-3-BATTERY.cpp +++ b/Software/src/battery/BYD-ATTO-3-BATTERY.cpp @@ -264,6 +264,8 @@ void send_can_battery() { // Check if sending of CAN messages has been delayed too much. if ((currentMillis - previousMillis50 >= INTERVAL_50_MS_DELAYED) && (currentMillis > BOOTUP_TIME)) { set_event(EVENT_CAN_OVERRUN, (currentMillis - previousMillis50)); + } else { + clear_event(EVENT_CAN_OVERRUN); } previousMillis50 = currentMillis; diff --git a/Software/src/battery/CHADEMO-BATTERY.cpp b/Software/src/battery/CHADEMO-BATTERY.cpp index cb9f7ce8..27df46f6 100644 --- a/Software/src/battery/CHADEMO-BATTERY.cpp +++ b/Software/src/battery/CHADEMO-BATTERY.cpp @@ -689,6 +689,8 @@ void send_can_battery() { // Check if sending of CAN messages has been delayed too much. if ((currentMillis - previousMillis100 >= INTERVAL_100_MS_DELAYED) && (currentMillis > BOOTUP_TIME)) { set_event(EVENT_CAN_OVERRUN, (currentMillis - previousMillis100)); + } else { + clear_event(EVENT_CAN_OVERRUN); } previousMillis100 = currentMillis; diff --git a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp index 11a86f40..a0f4ce5d 100644 --- a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp +++ b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp @@ -188,6 +188,8 @@ void send_can_battery() { // Check if sending of CAN messages has been delayed too much. if ((currentMillis - previousMillis100 >= INTERVAL_100_MS_DELAYED) && (currentMillis > BOOTUP_TIME)) { set_event(EVENT_CAN_OVERRUN, (currentMillis - previousMillis100)); + } else { + clear_event(EVENT_CAN_OVERRUN); } previousMillis100 = currentMillis; diff --git a/Software/src/battery/KIA-E-GMP-BATTERY.cpp b/Software/src/battery/KIA-E-GMP-BATTERY.cpp index 97f05fb1..713a1219 100644 --- a/Software/src/battery/KIA-E-GMP-BATTERY.cpp +++ b/Software/src/battery/KIA-E-GMP-BATTERY.cpp @@ -377,6 +377,8 @@ void send_can_battery() { // Check if sending of CAN messages has been delayed too much. if ((currentMillis - previousMillis500ms >= INTERVAL_500_MS_DELAYED) && (currentMillis > BOOTUP_TIME)) { set_event(EVENT_CAN_OVERRUN, (currentMillis - previousMillis500ms)); + } else { + clear_event(EVENT_CAN_OVERRUN); } previousMillis500ms = currentMillis; // Section added to close contractor diff --git a/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp b/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp index a4aa647d..1105c077 100644 --- a/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp +++ b/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp @@ -525,6 +525,8 @@ void send_can_battery() { // Check if sending of CAN messages has been delayed too much. if ((currentMillis - previousMillis10 >= INTERVAL_10_MS_DELAYED) && (currentMillis > BOOTUP_TIME)) { set_event(EVENT_CAN_OVERRUN, (currentMillis - previousMillis10)); + } else { + clear_event(EVENT_CAN_OVERRUN); } previousMillis10 = currentMillis; diff --git a/Software/src/battery/MG-5-BATTERY.cpp b/Software/src/battery/MG-5-BATTERY.cpp index 766f0e0d..d8bfeb83 100644 --- a/Software/src/battery/MG-5-BATTERY.cpp +++ b/Software/src/battery/MG-5-BATTERY.cpp @@ -125,6 +125,8 @@ void send_can_battery() { // Check if sending of CAN messages has been delayed too much. if ((currentMillis - previousMillis10 >= INTERVAL_10_MS_DELAYED) && (currentMillis > BOOTUP_TIME)) { set_event(EVENT_CAN_OVERRUN, (currentMillis - previousMillis10)); + } else { + clear_event(EVENT_CAN_OVERRUN); } previousMillis10 = currentMillis; diff --git a/Software/src/battery/NISSAN-LEAF-BATTERY.cpp b/Software/src/battery/NISSAN-LEAF-BATTERY.cpp index 0f1ef624..ea77a6d7 100644 --- a/Software/src/battery/NISSAN-LEAF-BATTERY.cpp +++ b/Software/src/battery/NISSAN-LEAF-BATTERY.cpp @@ -559,6 +559,8 @@ void send_can_battery() { // Check if sending of CAN messages has been delayed too much. if ((currentMillis - previousMillis10 >= INTERVAL_10_MS_DELAYED) && (currentMillis > BOOTUP_TIME)) { set_event(EVENT_CAN_OVERRUN, (currentMillis - previousMillis10)); + } else { + clear_event(EVENT_CAN_OVERRUN); } previousMillis10 = currentMillis; diff --git a/Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp b/Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp index db3abadd..56371598 100644 --- a/Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp +++ b/Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp @@ -123,6 +123,8 @@ void send_can_battery() { // Check if sending of CAN messages has been delayed too much. if ((currentMillis - previousMillis10 >= INTERVAL_10_MS_DELAYED) && (currentMillis > BOOTUP_TIME)) { set_event(EVENT_CAN_OVERRUN, (currentMillis - previousMillis10)); + } else { + clear_event(EVENT_CAN_OVERRUN); } previousMillis10 = currentMillis; diff --git a/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp b/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp index 47490030..8378a774 100644 --- a/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp +++ b/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp @@ -568,6 +568,8 @@ the first, for a few cycles, then stop all messages which causes the contactor // Check if sending of CAN messages has been delayed too much. if ((currentMillis - previousMillis30 >= INTERVAL_30_MS_DELAYED) && (currentMillis > BOOTUP_TIME)) { set_event(EVENT_CAN_OVERRUN, (currentMillis - previousMillis30)); + } else { + clear_event(EVENT_CAN_OVERRUN); } previousMillis30 = currentMillis; diff --git a/Software/src/battery/VOLVO-SPA-BATTERY.cpp b/Software/src/battery/VOLVO-SPA-BATTERY.cpp index 94a14a3e..62b393ab 100644 --- a/Software/src/battery/VOLVO-SPA-BATTERY.cpp +++ b/Software/src/battery/VOLVO-SPA-BATTERY.cpp @@ -331,6 +331,8 @@ void send_can_battery() { // Check if sending of CAN messages has been delayed too much. if ((currentMillis - previousMillis100 >= INTERVAL_100_MS_DELAYED) && (currentMillis > BOOTUP_TIME)) { set_event(EVENT_CAN_OVERRUN, (currentMillis - previousMillis100)); + } else { + clear_event(EVENT_CAN_OVERRUN); } previousMillis100 = currentMillis; diff --git a/Software/src/datalayer/datalayer.h b/Software/src/datalayer/datalayer.h index d3716711..675b6e92 100644 --- a/Software/src/datalayer/datalayer.h +++ b/Software/src/datalayer/datalayer.h @@ -113,13 +113,15 @@ typedef struct { int64_t core_task_max_us = 0; /** Core task measurement variable, reset each 10 seconds */ int64_t core_task_10s_max_us = 0; - /** MQTT task measurement variable, reset each 10 seconds */ + /** MQTT sub-task measurement variable, reset each 10 seconds */ int64_t mqtt_task_10s_max_us = 0; + /** Wifi sub-task measurement variable, reset each 10 seconds */ + int64_t wifi_task_10s_max_us = 0; /** loop() task measurement variable, reset each 10 seconds */ int64_t loop_task_10s_max_us = 0; - /** OTA/Wifi handling function measurement variable */ - int64_t time_wifi_us = 0; + /** OTA handling function measurement variable */ + int64_t time_ota_us = 0; /** CAN RX or serial link function measurement variable */ int64_t time_comm_us = 0; /** 10 ms function measurement variable */ @@ -130,9 +132,9 @@ typedef struct { int64_t time_cantx_us = 0; /** Function measurement snapshot variable. - * This will show the performance of OTA/Wifi handling when the total time reached a new worst case + * This will show the performance of OTA handling when the total time reached a new worst case */ - int64_t time_snap_wifi_us = 0; + int64_t time_snap_ota_us = 0; /** Function measurement snapshot variable. * This will show the performance of CAN RX or serial link when the total time reached a new worst case */ diff --git a/Software/src/devboard/webserver/webserver.cpp b/Software/src/devboard/webserver/webserver.cpp index 827a236b..a8db9987 100644 --- a/Software/src/devboard/webserver/webserver.cpp +++ b/Software/src/devboard/webserver/webserver.cpp @@ -386,7 +386,12 @@ String processor(const String& var) { // Load information content += "