From 7ee1f992cb4d3c59a9b7f1fdb5f4d797f4a24085 Mon Sep 17 00:00:00 2001 From: lumapu Date: Tue, 2 Apr 2024 13:09:19 +0200 Subject: [PATCH] 0.8.103 * fix cppcheck warnings * changed MqTT retained flags of some topics --- src/CHANGES.md | 2 ++ src/app.cpp | 17 +++++++++-------- src/app.h | 2 +- src/defines.h | 2 +- src/network/AhoyWifiEsp32.h | 10 ---------- src/publisher/pubMqtt.h | 4 ++-- src/publisher/pubMqttIvData.h | 2 -- src/web/RestApi.h | 2 +- 8 files changed, 16 insertions(+), 25 deletions(-) diff --git a/src/CHANGES.md b/src/CHANGES.md index 3705c785..73c5c5d4 100644 --- a/src/CHANGES.md +++ b/src/CHANGES.md @@ -4,6 +4,8 @@ * merge PR: fix: get refresh property from object #1552 * merge PR: fix typos and spelling in Github Issue template #1550 * merge PR: shorten last cmt waiting time #1549 +* fix cppcheck warnings +* changed MqTT retained flags of some topics ## 0.8.102 - 2024-04-01 * fix NTP for `opendtufusion` #1542 diff --git a/src/app.cpp b/src/app.cpp index 5166c035..f22e6906 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -56,9 +56,9 @@ void app::setup() { #ifdef ETHERNET delay(1000); - mNetwork = (AhoyNetwork*) new AhoyEthernet(); + mNetwork = static_cast(new AhoyEthernet()); #else - mNetwork = (AhoyNetwork*) new AhoyWifi(); + mNetwork = static_cast(new AhoyWifi()); #endif // ETHERNET mNetwork->setup(mConfig, &mTimestamp, [this](bool gotIp) { this->onNetwork(gotIp); }, [this](bool gotTime) { this->onNtpUpdate(gotTime); }); mNetwork->begin(); @@ -403,7 +403,8 @@ void app::tickSend(void) { for (uint8_t i = 0; i < MAX_NUM_INVERTERS; i++) { Inverter<> *iv = mSys.getInverterByPos(i); - sendIv(iv); + if(!sendIv(iv)) + notAvail = false; } if(mAllIvNotAvail != notAvail) @@ -415,22 +416,22 @@ void app::tickSend(void) { //----------------------------------------------------------------------------- bool app::sendIv(Inverter<> *iv) { - bool notAvail = true; if(NULL == iv) - return notAvail; + return true; if(!iv->config->enabled) - return notAvail; + return true; if(!iv->commEnabled) { DPRINT_IVID(DBG_INFO, iv->id); DBGPRINTLN(F("no communication to the inverter (night time)")); - return notAvail; + return true; } if(!iv->radio->isChipConnected()) - return notAvail; + return true; + bool notAvail = true; if(InverterStatus::OFF != iv->status) notAvail = false; diff --git a/src/app.h b/src/app.h index 8fe9420d..2fc37ea8 100644 --- a/src/app.h +++ b/src/app.h @@ -414,7 +414,7 @@ class app : public IApp, public ah::Scheduler { bool mShowRebootRequest = false; - AhoyNetwork *mNetwork; + AhoyNetwork *mNetwork = nullptr; WebType mWeb; RestApiType mApi; Protection *mProtection = nullptr; diff --git a/src/defines.h b/src/defines.h index ab7c860b..502568a8 100644 --- a/src/defines.h +++ b/src/defines.h @@ -13,7 +13,7 @@ //------------------------------------- #define VERSION_MAJOR 0 #define VERSION_MINOR 8 -#define VERSION_PATCH 102 +#define VERSION_PATCH 103 //------------------------------------- typedef struct { uint8_t ch; diff --git a/src/network/AhoyWifiEsp32.h b/src/network/AhoyWifiEsp32.h index 41956dfc..a3bbb9cf 100644 --- a/src/network/AhoyWifiEsp32.h +++ b/src/network/AhoyWifiEsp32.h @@ -68,16 +68,6 @@ class AhoyWifi : public AhoyNetwork { String getIp(void) override { return WiFi.localIP().toString(); } - - private: - void sortRSSI(int *sort, int n) { - for (int i = 0; i < n; i++) - sort[i] = i; - for (int i = 0; i < n; i++) - for (int j = i + 1; j < n; j++) - if (WiFi.RSSI(sort[j]) > WiFi.RSSI(sort[i])) - std::swap(sort[i], sort[j]); - } }; #endif /*ESP32 & !ETHERNET*/ diff --git a/src/publisher/pubMqtt.h b/src/publisher/pubMqtt.h index 2d393b8b..35dc2b71 100644 --- a/src/publisher/pubMqtt.h +++ b/src/publisher/pubMqtt.h @@ -251,8 +251,8 @@ class PubMqtt { void onConnect(bool sessionPreset) { DPRINTLN(DBG_INFO, F("MQTT connected")); - publish(subtopics[MQTT_VERSION], mVersion, true); - publish(subtopics[MQTT_DEVICE], mDevName, true); + publish(subtopics[MQTT_VERSION], mVersion, false); + publish(subtopics[MQTT_DEVICE], mDevName, false); publish(subtopics[MQTT_IP_ADDR], mApp->getIp().c_str(), true); tickerMinute(); publish(mLwtTopic.data(), mqttStr[MQTT_STR_LWT_CONN], true, false); diff --git a/src/publisher/pubMqttIvData.h b/src/publisher/pubMqttIvData.h index 6ddd63a9..cd212aa4 100644 --- a/src/publisher/pubMqttIvData.h +++ b/src/publisher/pubMqttIvData.h @@ -187,7 +187,6 @@ class PubMqttIvData { static_cast(mIv->getChannelFieldValue(CH0, FLD_FW_BUILD_MONTH_DAY, rec)), static_cast(mIv->getChannelFieldValue(CH0, FLD_FW_BUILD_HOUR_MINUTE, rec)), static_cast(mIv->getChannelFieldValue(CH0, FLD_BOOTLOADER_VER, rec))); - retained = true; } else if(InverterDevInform_Simple == mCmd) { snprintf(mSubTopic.data(), mSubTopic.size(), "%s/hardware", mIv->config->name); snprintf(mVal.data(), mVal.size(), "{\"part\":%d,\"version\":\"%d\",\"grid_profile_code\":%d,\"grid_profile_version\":%d}", @@ -195,7 +194,6 @@ class PubMqttIvData { static_cast(mIv->getChannelFieldValue(CH0, FLD_HW_VERSION, rec)), static_cast(mIv->getChannelFieldValue(CH0, FLD_GRID_PROFILE_CODE, rec)), static_cast(mIv->getChannelFieldValue(CH0, FLD_GRID_PROFILE_VERSION, rec))); - retained = true; } else { snprintf(mSubTopic.data(), mSubTopic.size(), "%s/ch%d/%s", mIv->config->name, rec->assign[mPos].ch, fields[rec->assign[mPos].fieldId]); snprintf(mVal.data(), mVal.size(), "%g", ah::round3(mIv->getValue(mPos, rec))); diff --git a/src/web/RestApi.h b/src/web/RestApi.h index a9756944..665a3333 100644 --- a/src/web/RestApi.h +++ b/src/web/RestApi.h @@ -166,7 +166,7 @@ class RestApi { #else DynamicJsonDocument json(12000); // does this work? I have no ESP32 :-( #endif - DeserializationError err = deserializeJson(json, (const char *)mTmpBuf, mTmpSize); + DeserializationError err = deserializeJson(json, static_cast(mTmpBuf, mTmpSize)); json.shrinkToFit(); JsonObject obj = json.as();