From 77b5e934a337129717003b5270fc3750488feb76 Mon Sep 17 00:00:00 2001 From: proddy Date: Sun, 15 Sep 2024 18:09:15 +0200 Subject: [PATCH] tidy up EMSESP_DEBUG --- Makefile | 5 +++-- lib/framework/FSPersistence.h | 28 ++++++++++++------------ lib/framework/MqttSettingsService.cpp | 6 +---- lib/framework/NetworkSettingsService.cpp | 5 ++--- src/console.cpp | 2 +- src/emsdevice.cpp | 4 ++-- src/telegram.h | 22 ++----------------- src/web/WebSettingsService.cpp | 6 ++--- src/web/WebStatusService.cpp | 4 ++-- 9 files changed, 30 insertions(+), 52 deletions(-) diff --git a/Makefile b/Makefile index 54137f214..96d80f59a 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,9 @@ # This is mainly used to generate the .o files for SonarQube analysis # -NUMJOBS=${NUMJOBS:-" -j2 "} -MAKEFLAGS+="j " +# NUMJOBS=${NUMJOBS:-" -j10 "} +# MAKEFLAGS+="j " + #---------------------------------------------------------------------- # Project Structure #---------------------------------------------------------------------- diff --git a/lib/framework/FSPersistence.h b/lib/framework/FSPersistence.h index 7478e4886..299d943c2 100644 --- a/lib/framework/FSPersistence.h +++ b/lib/framework/FSPersistence.h @@ -26,11 +26,11 @@ class FSPersistence { if (error == DeserializationError::Ok && jsonDocument.is()) { JsonObject jsonObject = jsonDocument.as(); _statefulService->updateWithoutPropagation(jsonObject, _stateUpdater); -#ifdef EMSESP_DEBUG - Serial.println(); - Serial.printf("Reading settings from %s ", _filePath); - serializeJson(jsonDocument, Serial); - Serial.println(); +#if defined(EMSESP_DEBUG) + // Serial.println(); + // Serial.printf("Reading settings from %s ", _filePath); + // serializeJson(jsonDocument, Serial); + // Serial.println(); #endif settingsFile.close(); return; @@ -40,10 +40,10 @@ class FSPersistence { // If we reach here we have not been successful in loading the config, // hard-coded emergency defaults are now applied. -#ifdef EMSESP_DEBUG - Serial.println(); - Serial.printf("Applying defaults to %s", _filePath); - Serial.println(); +#if defined(EMSESP_DEBUG) + // Serial.println(); + // Serial.printf("Applying defaults to %s", _filePath); + // Serial.println(); #endif applyDefaults(); writeToFS(); // added to make sure the initial file is created @@ -74,11 +74,11 @@ class FSPersistence { } // serialize the data to the file -#ifdef EMSESP_DEBUG - Serial.println(); - Serial.printf("Writing settings to %s ", _filePath); - serializeJson(jsonDocument, Serial); - Serial.println(); +#if defined(EMSESP_DEBUG) + // Serial.println(); + // Serial.printf("Writing settings to %s ", _filePath); + // serializeJson(jsonDocument, Serial); + // Serial.println(); #endif serializeJson(jsonDocument, settingsFile); settingsFile.close(); diff --git a/lib/framework/MqttSettingsService.cpp b/lib/framework/MqttSettingsService.cpp index 15a235f11..198e845f8 100644 --- a/lib/framework/MqttSettingsService.cpp +++ b/lib/framework/MqttSettingsService.cpp @@ -133,11 +133,7 @@ MqttClient * MqttSettingsService::getMqttClient() { void MqttSettingsService::onMqttConnect(bool sessionPresent) { (void)sessionPresent; - // _disconnectedAt = 0; emsesp::EMSESP::mqtt_.on_connect(); -#ifdef EMSESP_DEBUG - emsesp::EMSESP::logger().debug("Connected to MQTT, %s", (sessionPresent) ? ("with persistent session") : ("without persistent session")); -#endif } void MqttSettingsService::onMqttDisconnect(espMqttClientTypes::DisconnectReason reason) { @@ -190,7 +186,7 @@ bool MqttSettingsService::configureMqtt() { _reconfigureMqtt = false; #ifndef TASMOTA_SDK if (_state.enableTLS) { -#if EMSESP_DEBUG +#if defined(EMSESP_DEBUG) emsesp::EMSESP::logger().debug("Start secure MQTT with rootCA"); #endif static_cast(_mqttClient)->setServer(_state.host.c_str(), _state.port); diff --git a/lib/framework/NetworkSettingsService.cpp b/lib/framework/NetworkSettingsService.cpp index 48c779217..e9000e566 100644 --- a/lib/framework/NetworkSettingsService.cpp +++ b/lib/framework/NetworkSettingsService.cpp @@ -180,9 +180,8 @@ void NetworkSettingsService::setWiFiPowerOnRSSI() { else if (min_tx_pwr > 20) p = WIFI_POWER_5dBm; -#ifdef EMSESP_DEBUG - uint8_t set_power = min_tx_pwr / 10; // this is the recommended power setting to use - emsesp::EMSESP::logger().debug("Recommended WiFi Tx Power (set_power %d, new power %d, rssi %d, threshold %d)", set_power, p, rssi, threshold); +#if defined(EMSESP_DEBUG) + // emsesp::EMSESP::logger().debug("Recommended WiFi Tx Power (set_power %d, new power %d, rssi %d, threshold %d)", min_tx_pwr / 10, p, rssi, threshold); #endif if (!WiFi.setTxPower(p)) { diff --git a/src/console.cpp b/src/console.cpp index 786ac9f8e..b4cb59254 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -686,7 +686,7 @@ void EMSESPShell::end_of_transmission() { void EMSESPShell::main_help_function(Shell & shell, const std::vector & arguments) { shell.println(); -#ifndef EMSESP_DEBUG +#if defined(EMSESP_DEBUG) shell.printfln("%s%sEMS-ESP version %s%s", COLOR_BRIGHT_GREEN, COLOR_BOLD_ON, EMSESP_APP_VERSION, COLOR_RESET); #else shell.printfln("%s%sEMS-ESP version %s%s (DEBUG)", COLOR_BRIGHT_GREEN, COLOR_BOLD_ON, EMSESP_APP_VERSION, COLOR_RESET); diff --git a/src/emsdevice.cpp b/src/emsdevice.cpp index fdfef14ac..2c3f5e841 100644 --- a/src/emsdevice.cpp +++ b/src/emsdevice.cpp @@ -1682,8 +1682,8 @@ bool EMSdevice::generate_values(JsonObject output, const int8_t tag_filter, cons // do not overwrite if (json.containsKey(name)) { -#ifdef EMSESP_DEBUG - EMSESP::logger().debug("double json key: %s", name); +#if defined(EMSESP_DEBUG) + EMSESP::logger().debug("warning: double json key: %s", name); #endif continue; } diff --git a/src/telegram.h b/src/telegram.h index e6e54283b..c18dabe9c 100644 --- a/src/telegram.h +++ b/src/telegram.h @@ -132,19 +132,6 @@ class Telegram { // check for out of bounds, if so don't modify the value auto msg_size = (index - this->offset + num_bytes - 1); -#ifdef EMSESP_DEBUG -// Serial.print(" index: "); -// Serial.print(index); -// Serial.print(" offset: "); -// Serial.print(offset); -// Serial.print(" index: "); -// Serial.print(" message_length: "); -// Serial.print(this->message_length); -// Serial.print(" msg_size: "); -// Serial.print(msg_size); -// Serial.println(); -#endif - if ((index < this->offset) || (msg_size >= this->message_length) || (msg_size > EMS_MAX_TELEGRAM_MESSAGE_LENGTH)) { return false; } @@ -443,13 +430,8 @@ class TxService : public EMSbus { return tx_telegrams_.empty(); } -#if defined(EMSESP_DEBUG) - static constexpr uint8_t MAXIMUM_TX_RETRIES = 0; // when compiled with EMSESP_DEBUG don't retry -#else - static constexpr uint8_t MAXIMUM_TX_RETRIES = 3; -#endif - - static constexpr uint32_t POST_SEND_DELAY = 2000; + static constexpr uint8_t MAXIMUM_TX_RETRIES = 3; + static constexpr uint32_t POST_SEND_DELAY = 2000; private: std::deque tx_telegrams_; // the Tx queue diff --git a/src/web/WebSettingsService.cpp b/src/web/WebSettingsService.cpp index 23c964cf3..6be813006 100644 --- a/src/web/WebSettingsService.cpp +++ b/src/web/WebSettingsService.cpp @@ -93,7 +93,7 @@ StateUpdateResult WebSettings::update(JsonObject root, WebSettings & settings) { bool psram = false; #endif -#ifdef EMSESP_DEBUG +#if defined(EMSESP_DEBUG) EMSESP::logger().debug("NVS boot value=[%s], board profile=[%s], EMSESP_DEFAULT_BOARD_PROFILE=[%s]", EMSESP::nvs_.getString("boot").c_str(), root["board_profile"] | "", @@ -111,7 +111,7 @@ StateUpdateResult WebSettings::update(JsonObject root, WebSettings & settings) { if (!EMSESP::system_.getBBQKeesGatewayDetails().isEmpty()) { String nvs_boot = EMSESP::nvs_.getString("boot"); if (!nvs_boot.isEmpty()) { -#ifdef EMSESP_DEBUG +#if defined(EMSESP_DEBUG) EMSESP::logger().debug("Overriding board profile with NVS boot value %s"); #endif settings.board_profile = nvs_boot; @@ -145,7 +145,7 @@ StateUpdateResult WebSettings::update(JsonObject root, WebSettings & settings) { // still don't have a valid board profile. Let's see if we can determine one if (settings.board_profile == "default") { -#ifdef EMSESP_DEBUG +#if defined(EMSESP_DEBUG) EMSESP::logger().debug("Trying to detect board and set board profile..."); #endif diff --git a/src/web/WebStatusService.cpp b/src/web/WebStatusService.cpp index 96777a91e..503bf1a94 100644 --- a/src/web/WebStatusService.cpp +++ b/src/web/WebStatusService.cpp @@ -82,7 +82,7 @@ void WebStatusService::systemStatus(AsyncWebServerRequest * request) { #endif } -#ifdef EMSESP_DEBUG +#if defined(EMSESP_DEBUG) #ifdef EMSESP_TEST root["build_flags"] = "DEBUG,TEST"; #else @@ -155,7 +155,7 @@ void WebStatusService::checkUpgrade(AsyncWebServerRequest * request, JsonVariant const std::string latest_version = json["version"] | EMSESP_APP_VERSION; version::Semver200_version this_version(latest_version); -#ifdef EMSESP_DEBUG +#if defined(EMSESP_DEBUG) emsesp::EMSESP::logger().debug("Checking for upgrade: %s > %s", EMSESP_APP_VERSION, latest_version.c_str()); #endif