Skip to content

Commit

Permalink
0.8.74
Browse files Browse the repository at this point in the history
* reduced cppcheck linter warnings significantly
  • Loading branch information
lumapu committed Feb 5, 2024
1 parent 6b5435a commit 3740a09
Show file tree
Hide file tree
Showing 31 changed files with 375 additions and 413 deletions.
3 changes: 3 additions & 0 deletions src/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Development Changes

## 0.8.74 - 2024-02-05
* reduced cppcheck linter warnings significantly

## 0.8.73 - 2024-02-03
* fix nullpointer during communication #1401
* added `max_power` to MqTT total values #1375
Expand Down
15 changes: 7 additions & 8 deletions src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@


//-----------------------------------------------------------------------------
app::app() : ah::Scheduler {} {}
app::app() : ah::Scheduler {} {
memset(mVersion, 0, sizeof(char) * 12);
memset(mVersionModules, 0, sizeof(char) * 12);
}


//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -228,7 +231,6 @@ void app::updateNtp(void) {
onceAt(std::bind(&app::tickMidnight, this), midTrig, "midNi");

if (mConfig->sys.schedReboot) {
uint32_t localTime = gTimezone.toLocal(mTimestamp);
uint32_t rebootTrig = gTimezone.toUTC(localTime - (localTime % 86400) + 86410); // reboot 10 secs after midnght
if (rebootTrig <= mTimestamp) { //necessary for times other than midnight to prevent reboot loop
rebootTrig += 86400;
Expand Down Expand Up @@ -301,9 +303,8 @@ void app::tickIVCommunication(void) {
bool zeroValues = false;
uint32_t nxtTrig = 0;

Inverter<> *iv;
for(uint8_t i = 0; i < MAX_NUM_INVERTERS; i ++) {
iv = mSys.getInverterByPos(i);
Inverter<> *iv = mSys.getInverterByPos(i);
if(NULL == iv)
continue;

Expand Down Expand Up @@ -390,10 +391,9 @@ void app::tickMidnight(void) {

// clear max values
if(mConfig->inst.rstMaxValsMidNight) {
uint8_t pos;
record_t<> *rec = iv->getRecordStruct(RealTimeRunData_Debug);
for(uint8_t i = 0; i <= iv->channels; i++) {
pos = iv->getPosByChFld(i, FLD_MP, rec);
uint8_t pos = iv->getPosByChFld(i, FLD_MP, rec);
iv->setValue(pos, rec, 0.0f);
}
}
Expand Down Expand Up @@ -592,9 +592,8 @@ void app::updateLed(void) {
uint8_t led_on = (mConfig->led.high_active) ? (mConfig->led.luminance) : (255-mConfig->led.luminance);

if (mConfig->led.led[0] != DEF_PIN_OFF) {
Inverter<> *iv;
for (uint8_t id = 0; id < mSys.getNumInverters(); id++) {
iv = mSys.getInverterByPos(id);
Inverter<> *iv = mSys.getInverterByPos(id);
if (NULL != iv) {
if (iv->isProducing()) {
// turn on when at least one inverter is producing
Expand Down
100 changes: 50 additions & 50 deletions src/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class app : public IApp, public ah::Scheduler {
void handleIntr(void) {
mNrfRadio.handleIntr();
}
void* getRadioObj(bool nrf) {
void* getRadioObj(bool nrf) override {
if(nrf)
return (void*)&mNrfRadio;
else {
Expand All @@ -108,19 +108,19 @@ class app : public IApp, public ah::Scheduler {
}
#endif

uint32_t getUptime() {
uint32_t getUptime() override {
return Scheduler::getUptime();
}

uint32_t getTimestamp() {
uint32_t getTimestamp() override {
return Scheduler::mTimestamp;
}

uint64_t getTimestampMs() {
uint64_t getTimestampMs() override {
return ((uint64_t)Scheduler::mTimestamp * 1000) + ((uint64_t)millis() - (uint64_t)Scheduler::mTsMillis) % 1000;
}

bool saveSettings(bool reboot) {
bool saveSettings(bool reboot) override {
mShowRebootRequest = true; // only message on index, no reboot
mSavePending = true;
mSaveReboot = reboot;
Expand All @@ -131,7 +131,7 @@ class app : public IApp, public ah::Scheduler {
return true;
}

void initInverter(uint8_t id) {
void initInverter(uint8_t id) override {
mSys.addInverter(id, [this](Inverter<> *iv) {
if((IV_MI == iv->ivGen) || (IV_HM == iv->ivGen))
iv->radio = &mNrfRadio;
Expand All @@ -142,104 +142,104 @@ class app : public IApp, public ah::Scheduler {
});
}

bool readSettings(const char *path) {
bool readSettings(const char *path) override {
return mSettings.readSettings(path);
}

bool eraseSettings(bool eraseWifi = false) {
return mSettings.eraseSettings(eraseWifi);
}

bool getSavePending() {
bool getSavePending() override {
return mSavePending;
}

bool getLastSaveSucceed() {
bool getLastSaveSucceed() override {
return mSettings.getLastSaveSucceed();
}

bool getShouldReboot() {
bool getShouldReboot() override {
return mSaveReboot;
}

#if !defined(ETHERNET)
void scanAvailNetworks() {
void scanAvailNetworks() override {
mWifi.scanAvailNetworks();
}

bool getAvailNetworks(JsonObject obj) {
bool getAvailNetworks(JsonObject obj) override {
return mWifi.getAvailNetworks(obj);
}

void setupStation(void) {
void setupStation(void) override {
mWifi.setupStation();
}

void setStopApAllowedMode(bool allowed) {
void setStopApAllowedMode(bool allowed) override {
mWifi.setStopApAllowedMode(allowed);
}

String getStationIp(void) {
String getStationIp(void) override {
return mWifi.getStationIp();
}

bool getWasInCh12to14(void) const {
bool getWasInCh12to14(void) const override {
return mWifi.getWasInCh12to14();
}

#endif /* !defined(ETHERNET) */

void setRebootFlag() {
void setRebootFlag() override {
once(std::bind(&app::tickReboot, this), 3, "rboot");
}

const char *getVersion() {
const char *getVersion() override {
return mVersion;
}

const char *getVersionModules() {
const char *getVersionModules() override {
return mVersionModules;
}

uint32_t getSunrise() {
uint32_t getSunrise() override {
return mSunrise;
}

uint32_t getSunset() {
uint32_t getSunset() override {
return mSunset;
}

bool getSettingsValid() {
bool getSettingsValid() override {
return mSettings.getValid();
}

bool getRebootRequestState() {
bool getRebootRequestState() override {
return mShowRebootRequest;
}

void setMqttDiscoveryFlag() {
void setMqttDiscoveryFlag() override {
#if defined(ENABLE_MQTT)
once(std::bind(&PubMqttType::sendDiscoveryConfig, &mMqtt), 1, "disCf");
#endif
}

bool getMqttIsConnected() {
bool getMqttIsConnected() override {
#if defined(ENABLE_MQTT)
return mMqtt.isConnected();
#else
return false;
#endif
}

uint32_t getMqttTxCnt() {
uint32_t getMqttTxCnt() override {
#if defined(ENABLE_MQTT)
return mMqtt.getTxCnt();
#else
return 0;
#endif
}

uint32_t getMqttRxCnt() {
uint32_t getMqttRxCnt() override {
#if defined(ENABLE_MQTT)
return mMqtt.getRxCnt();
#else
Expand Down Expand Up @@ -267,11 +267,11 @@ class app : public IApp, public ah::Scheduler {
return mProtection->isProtected(clientIp);
}

bool getNrfEnabled(void) {
bool getNrfEnabled(void) override {
return mConfig->nrf.enabled;
}

bool getCmtEnabled(void) {
bool getCmtEnabled(void) override {
return mConfig->cmt.enabled;
}

Expand All @@ -283,19 +283,19 @@ class app : public IApp, public ah::Scheduler {
return mConfig->cmt.pinIrq;
}

uint32_t getTimezoneOffset() {
uint32_t getTimezoneOffset() override {
return mApi.getTimezoneOffset();
}

void getSchedulerInfo(uint8_t *max) {
void getSchedulerInfo(uint8_t *max) override {
getStat(max);
}

void getSchedulerNames(void) {
void getSchedulerNames(void) override {
printSchedulers();
}

void setTimestamp(uint32_t newTime) {
void setTimestamp(uint32_t newTime) override {
DPRINT(DBG_DEBUG, F("setTimestamp: "));
DBGPRINTLN(String(newTime));
if(0 == newTime)
Expand All @@ -310,15 +310,15 @@ class app : public IApp, public ah::Scheduler {
Scheduler::setTimestamp(newTime);
}

uint16_t getHistoryValue(uint8_t type, uint16_t i) {
uint16_t getHistoryValue(uint8_t type, uint16_t i) override {
#if defined(ENABLE_HISTORY)
return mHistory.valueAt((HistoryStorageType)type, i);
#else
return 0;
#endif
}

uint16_t getHistoryMaxDay() {
uint16_t getHistoryMaxDay() override {
#if defined(ENABLE_HISTORY)
return mHistory.getMaximumDay();
#else
Expand Down Expand Up @@ -372,11 +372,11 @@ class app : public IApp, public ah::Scheduler {
void tickNtpUpdate(void);
#if defined(ETHERNET)
void onNtpUpdate(bool gotTime);
bool mNtpReceived;
bool mNtpReceived = false;
#endif /* defined(ETHERNET) */
void updateNtp(void);

void triggerTickSend() {
void triggerTickSend() override {
once(std::bind(&app::tickSend, this), 0, "tSend");
}

Expand All @@ -395,7 +395,7 @@ class app : public IApp, public ah::Scheduler {
HmRadio<> mNrfRadio;
Communication mCommunication;

bool mShowRebootRequest;
bool mShowRebootRequest = false;

#if defined(ETHERNET)
ahoyeth mEth;
Expand All @@ -404,7 +404,7 @@ class app : public IApp, public ah::Scheduler {
#endif /* defined(ETHERNET) */
WebType mWeb;
RestApiType mApi;
Protection *mProtection;
Protection *mProtection = nullptr;
#ifdef ENABLE_SYSLOG
DbgSyslog mDbgSyslog;
#endif
Expand All @@ -421,26 +421,26 @@ class app : public IApp, public ah::Scheduler {
char mVersion[12];
char mVersionModules[12];
settings mSettings;
settings_t *mConfig;
bool mSavePending;
bool mSaveReboot;
settings_t *mConfig = nullptr;
bool mSavePending = false;
bool mSaveReboot = false;

uint8_t mSendLastIvId;
bool mSendFirst;
bool mAllIvNotAvail;
uint8_t mSendLastIvId = 0;
bool mSendFirst = false;
bool mAllIvNotAvail = false;

bool mNetworkConnected;
bool mNetworkConnected = false;

// mqtt
#if defined(ENABLE_MQTT)
PubMqttType mMqtt;
#endif /*ENABLE_MQTT*/
bool mMqttReconnect;
bool mMqttEnabled;
bool mMqttReconnect = false;
bool mMqttEnabled = false;

// sun
int32_t mCalculatedTimezoneOffset;
uint32_t mSunrise, mSunset;
int32_t mCalculatedTimezoneOffset = 0;
uint32_t mSunrise = 0, mSunset = 0;

// plugins
#if defined(PLUGIN_DISPLAY)
Expand Down
7 changes: 4 additions & 3 deletions src/config/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <Arduino.h>
#include <ArduinoJson.h>
#include <algorithm>
#include <LittleFS.h>

#include "../defines.h"
Expand Down Expand Up @@ -206,7 +207,7 @@ typedef struct {
class settings {
public:
settings() {
mLastSaveSucceed = false;
std::fill(reinterpret_cast<char*>(&mCfg), reinterpret_cast<char*>(&mCfg) + sizeof(mCfg), 0);
}

void setup() {
Expand Down Expand Up @@ -377,7 +378,7 @@ class settings {
memcpy(&tmp, &mCfg.sys, sizeof(cfgSys_t));
}
// erase all settings and reset to default
memset(&mCfg, 0, sizeof(settings_t));
std::fill(reinterpret_cast<char*>(&mCfg), reinterpret_cast<char*>(&mCfg) + sizeof(mCfg), 0);
mCfg.sys.protectionMask = DEF_PROT_INDEX | DEF_PROT_LIVE | DEF_PROT_SERIAL | DEF_PROT_SETUP
| DEF_PROT_UPDATE | DEF_PROT_SYSTEM | DEF_PROT_API | DEF_PROT_MQTT | DEF_PROT_HISTORY;
mCfg.sys.darkMode = false;
Expand Down Expand Up @@ -847,7 +848,7 @@ class settings {
#endif

settings_t mCfg;
bool mLastSaveSucceed;
bool mLastSaveSucceed = 0;
};

#endif /*__SETTINGS_H__*/
Loading

0 comments on commit 3740a09

Please sign in to comment.