From 275eaa9be8569536f9e50ac3ccd1ba054862348a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20=C3=96ster?= Date: Fri, 24 Jan 2025 18:40:08 +0300 Subject: [PATCH] Improvement: Replace use of deprecated functions and improve compilation warnings (#817) * Change deprecated Send_P to send function * Fix compilation warnings in Wifi files * Change warnings into compilation errors * Add -Wall -Wextra -Wpedantic -Werror to github actions --- .github/workflows/compile-all-batteries.yml | 2 +- ...all-combinations-part1-batteries-A-to-M.yml | 2 +- ...all-combinations-part2-batteries-N-to-Z.yml | 2 +- .github/workflows/compile-all-hardware.yml | 2 +- .github/workflows/compile-all-inverters.yml | 2 +- Software/src/devboard/webserver/webserver.cpp | 18 +++++++++--------- Software/src/devboard/wifi/wifi.cpp | 10 +++++----- Software/src/devboard/wifi/wifi.h | 10 +++++----- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/.github/workflows/compile-all-batteries.yml b/.github/workflows/compile-all-batteries.yml index a3e2d7df7..f4be1c58b 100644 --- a/.github/workflows/compile-all-batteries.yml +++ b/.github/workflows/compile-all-batteries.yml @@ -112,4 +112,4 @@ jobs: # in the build matrix, and using build flags to define the # battery and inverter set in the build matrix. - name: Compile Sketch - run: arduino-cli compile --fqbn ${{ matrix.fqbn }} --build-property "build.extra_flags=-Wall -DESP32 -D${{ matrix.battery}} -D${{ matrix.inverter}} -D${{ matrix.hardware}}" ./Software + run: arduino-cli compile --fqbn ${{ matrix.fqbn }} --build-property "build.extra_flags=-Wall -Wextra -Wpedantic -Werror -DESP32 -D${{ matrix.battery}} -D${{ matrix.inverter}} -D${{ matrix.hardware}}" ./Software diff --git a/.github/workflows/compile-all-combinations-part1-batteries-A-to-M.yml b/.github/workflows/compile-all-combinations-part1-batteries-A-to-M.yml index 2aed0464a..1606e334e 100644 --- a/.github/workflows/compile-all-combinations-part1-batteries-A-to-M.yml +++ b/.github/workflows/compile-all-combinations-part1-batteries-A-to-M.yml @@ -118,4 +118,4 @@ jobs: # in the build matrix, and using build flags to define the # battery and inverter set in the build matrix. - name: Compile Sketch - run: arduino-cli compile --fqbn ${{ matrix.fqbn }} --build-property "build.extra_flags=-Wall -DESP32 -D${{ matrix.battery}} -D${{ matrix.inverter}} -D${{ matrix.hardware}}" ./Software + run: arduino-cli compile --fqbn ${{ matrix.fqbn }} --build-property "build.extra_flags=-Wall -Wextra -Wpedantic -Werror -DESP32 -D${{ matrix.battery}} -D${{ matrix.inverter}} -D${{ matrix.hardware}}" ./Software diff --git a/.github/workflows/compile-all-combinations-part2-batteries-N-to-Z.yml b/.github/workflows/compile-all-combinations-part2-batteries-N-to-Z.yml index c1233dd04..8a4f76e2b 100644 --- a/.github/workflows/compile-all-combinations-part2-batteries-N-to-Z.yml +++ b/.github/workflows/compile-all-combinations-part2-batteries-N-to-Z.yml @@ -118,4 +118,4 @@ jobs: # in the build matrix, and using build flags to define the # battery and inverter set in the build matrix. - name: Compile Sketch - run: arduino-cli compile --fqbn ${{ matrix.fqbn }} --build-property "build.extra_flags=-Wall -DESP32 -D${{ matrix.battery}} -D${{ matrix.inverter}} -D${{ matrix.hardware}}" ./Software + run: arduino-cli compile --fqbn ${{ matrix.fqbn }} --build-property "build.extra_flags=-Wall -Wextra -Wpedantic -Werror -DESP32 -D${{ matrix.battery}} -D${{ matrix.inverter}} -D${{ matrix.hardware}}" ./Software diff --git a/.github/workflows/compile-all-hardware.yml b/.github/workflows/compile-all-hardware.yml index 473e0fb2f..e55aeb32f 100644 --- a/.github/workflows/compile-all-hardware.yml +++ b/.github/workflows/compile-all-hardware.yml @@ -90,4 +90,4 @@ jobs: # in the build matrix, and using build flags to define the # battery and inverter set in the build matrix. - name: Compile Sketch - run: arduino-cli compile --fqbn ${{ matrix.fqbn }} --build-property "build.extra_flags=-Wall -DESP32 -D${{ matrix.battery}} -D${{ matrix.inverter}} -D${{ matrix.hardware}}" ./Software + run: arduino-cli compile --fqbn ${{ matrix.fqbn }} --build-property "build.extra_flags=-Wall -Wextra -Wpedantic -Werror -DESP32 -D${{ matrix.battery}} -D${{ matrix.inverter}} -D${{ matrix.hardware}}" ./Software diff --git a/.github/workflows/compile-all-inverters.yml b/.github/workflows/compile-all-inverters.yml index 62e2a2173..ad46efc88 100644 --- a/.github/workflows/compile-all-inverters.yml +++ b/.github/workflows/compile-all-inverters.yml @@ -105,4 +105,4 @@ jobs: # in the build matrix, and using build flags to define the # battery and inverter set in the build matrix. - name: Compile Sketch - run: arduino-cli compile --fqbn ${{ matrix.fqbn }} --build-property "build.extra_flags=-Wall -DESP32 -D${{ matrix.battery}} -D${{ matrix.inverter}} -D${{ matrix.hardware}}" ./Software + run: arduino-cli compile --fqbn ${{ matrix.fqbn }} --build-property "build.extra_flags=-Wall -Wextra -Wpedantic -Werror -DESP32 -D${{ matrix.battery}} -D${{ matrix.inverter}} -D${{ matrix.hardware}}" ./Software diff --git a/Software/src/devboard/webserver/webserver.cpp b/Software/src/devboard/webserver/webserver.cpp index 976696ebe..acfa55c29 100644 --- a/Software/src/devboard/webserver/webserver.cpp +++ b/Software/src/devboard/webserver/webserver.cpp @@ -37,26 +37,26 @@ void init_webserver() { server.on("/GetFirmwareInfo", HTTP_GET, [](AsyncWebServerRequest* request) { if (WEBSERVER_AUTH_REQUIRED && !request->authenticate(http_username, http_password)) return request->requestAuthentication(); - request->send_P(200, "application/json", get_firmware_info_html, get_firmware_info_processor); + request->send(200, "application/json", get_firmware_info_html, get_firmware_info_processor); }); // Route for root / web page server.on("/", HTTP_GET, [](AsyncWebServerRequest* request) { if (WEBSERVER_AUTH_REQUIRED && !request->authenticate(http_username, http_password)) return request->requestAuthentication(); - request->send_P(200, "text/html", index_html, processor); + request->send(200, "text/html", index_html, processor); }); // Route for going to settings web page server.on("/settings", HTTP_GET, [](AsyncWebServerRequest* request) { if (WEBSERVER_AUTH_REQUIRED && !request->authenticate(http_username, http_password)) return request->requestAuthentication(); - request->send_P(200, "text/html", index_html, settings_processor); + request->send(200, "text/html", index_html, settings_processor); }); // Route for going to advanced battery info web page server.on("/advanced", HTTP_GET, [](AsyncWebServerRequest* request) { - request->send_P(200, "text/html", index_html, advanced_battery_processor); + request->send(200, "text/html", index_html, advanced_battery_processor); }); // Route for going to CAN logging web page @@ -76,7 +76,7 @@ void init_webserver() { // Define the handler to stop can logging server.on("/stop_can_logging", HTTP_GET, [](AsyncWebServerRequest* request) { datalayer.system.info.can_logging_active = false; - request->send_P(200, "text/plain", "Logging stopped"); + request->send(200, "text/plain", "Logging stopped"); }); #ifndef LOG_CAN_TO_SD @@ -119,7 +119,7 @@ void init_webserver() { // Define the handler to delete can log server.on("/delete_can_log", HTTP_GET, [](AsyncWebServerRequest* request) { delete_can_log(); - request->send_P(200, "text/plain", "Log file deleted"); + request->send(200, "text/plain", "Log file deleted"); }); #endif @@ -127,7 +127,7 @@ void init_webserver() { // Define the handler to delete log file server.on("/delete_log", HTTP_GET, [](AsyncWebServerRequest* request) { delete_log(); - request->send_P(200, "text/plain", "Log file deleted"); + request->send(200, "text/plain", "Log file deleted"); }); // Define the handler to export debug log @@ -171,14 +171,14 @@ void init_webserver() { server.on("/cellmonitor", HTTP_GET, [](AsyncWebServerRequest* request) { if (WEBSERVER_AUTH_REQUIRED && !request->authenticate(http_username, http_password)) return request->requestAuthentication(); - request->send_P(200, "text/html", index_html, cellmonitor_processor); + request->send(200, "text/html", index_html, cellmonitor_processor); }); // Route for going to event log web page server.on("/events", HTTP_GET, [](AsyncWebServerRequest* request) { if (WEBSERVER_AUTH_REQUIRED && !request->authenticate(http_username, http_password)) return request->requestAuthentication(); - request->send_P(200, "text/html", index_html, events_processor); + request->send(200, "text/html", index_html, events_processor); }); // Route for clearing all events diff --git a/Software/src/devboard/wifi/wifi.cpp b/Software/src/devboard/wifi/wifi.cpp index c158b52ad..fa8f41ef1 100644 --- a/Software/src/devboard/wifi/wifi.cpp +++ b/Software/src/devboard/wifi/wifi.cpp @@ -108,7 +108,7 @@ void wifi_monitor() { } // Function to force a full reconnect to Wi-Fi -static void FullReconnectToWiFi() { +void FullReconnectToWiFi() { // Increase the current reconnect interval if it's not at the maximum if (current_full_reconnect_interval + STEP_WIFI_FULL_RECONNECT_INTERVAL <= MAX_WIFI_FULL_RECONNECT_INTERVAL) { @@ -120,7 +120,7 @@ static void FullReconnectToWiFi() { } // Function to handle Wi-Fi connection -static void connectToWiFi() { +void connectToWiFi() { if (WiFi.status() != WL_CONNECTED) { lastReconnectAttempt = millis(); // Reset the reconnect attempt timer #ifdef DEBUG_LOG @@ -135,7 +135,7 @@ static void connectToWiFi() { } // Event handler for successful Wi-Fi connection -static void onWifiConnect(WiFiEvent_t event, WiFiEventInfo_t info) { +void onWifiConnect(WiFiEvent_t event, WiFiEventInfo_t info) { clear_event(EVENT_WIFI_DISCONNECT); set_event(EVENT_WIFI_CONNECT, 0); connected_once = true; @@ -153,7 +153,7 @@ static void onWifiConnect(WiFiEvent_t event, WiFiEventInfo_t info) { } // Event handler for Wi-Fi Got IP -static void onWifiGotIP(WiFiEvent_t event, WiFiEventInfo_t info) { +void onWifiGotIP(WiFiEvent_t event, WiFiEventInfo_t info) { //clear disconnects events if we got a IP clear_event(EVENT_WIFI_DISCONNECT); #ifdef DEBUG_LOG @@ -164,7 +164,7 @@ static void onWifiGotIP(WiFiEvent_t event, WiFiEventInfo_t info) { } // Event handler for Wi-Fi disconnection -static void onWifiDisconnect(WiFiEvent_t event, WiFiEventInfo_t info) { +void onWifiDisconnect(WiFiEvent_t event, WiFiEventInfo_t info) { if (connected_once) set_event(EVENT_WIFI_DISCONNECT, 0); #ifdef DEBUG_LOG diff --git a/Software/src/devboard/wifi/wifi.h b/Software/src/devboard/wifi/wifi.h index 0cf37b236..bed27416b 100644 --- a/Software/src/devboard/wifi/wifi.h +++ b/Software/src/devboard/wifi/wifi.h @@ -17,11 +17,11 @@ extern const char* passwordAP; void init_WiFi(); void wifi_monitor(); -static void connectToWiFi(); -static void FullReconnectToWiFi(); -static void onWifiConnect(WiFiEvent_t event, WiFiEventInfo_t info); -static void onWifiDisconnect(WiFiEvent_t event, WiFiEventInfo_t info); -static void onWifiGotIP(WiFiEvent_t event, WiFiEventInfo_t info); +void connectToWiFi(); +void FullReconnectToWiFi(); +void onWifiConnect(WiFiEvent_t event, WiFiEventInfo_t info); +void onWifiDisconnect(WiFiEvent_t event, WiFiEventInfo_t info); +void onWifiGotIP(WiFiEvent_t event, WiFiEventInfo_t info); #ifdef WIFIAP void init_WiFi_AP();