Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix static code analysis warnings #93

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Hoymiles/src/Hoymiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class HoymilesClass {
std::vector<std::shared_ptr<InverterAbstract>> _inverters;
std::unique_ptr<HoymilesRadio> _radio;

uint32_t _pollInterval;
uint32_t _pollInterval = 0;
uint32_t _lastPoll = 0;
};

Expand Down
6 changes: 3 additions & 3 deletions lib/Hoymiles/src/HoymilesRadio.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ class HoymilesRadio {
std::unique_ptr<SPIClass> _hspi;
std::unique_ptr<RF24> _radio;
uint8_t _rxChLst[5] = { 3, 23, 40, 61, 75 };
uint8_t _rxChIdx;
uint8_t _rxChIdx = 0;

uint8_t _txChLst[5] = { 3, 23, 40, 61, 75 };
uint8_t _txChIdx;
uint8_t _txChIdx = 0;

volatile bool _packetReceived;
volatile bool _packetReceived = false;

CircularBuffer<fragment_t, FRAGMENT_BUFFER_SIZE> _rxBuffer;
TimeoutHelper _rxTimeout;
Expand Down
2 changes: 1 addition & 1 deletion lib/Hoymiles/src/commands/AlarmDataCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ class AlarmDataCommand : public MultiDataCommand {
public:
AlarmDataCommand(uint64_t target_address = 0, uint64_t router_address = 0, time_t time = 0);

virtual bool handleResponse(InverterAbstract* inverter, fragment_t fragment[], uint8_t max_fragment_id);
virtual bool handleResponse(InverterAbstract* inverter, fragment_t fragment[], uint8_t max_fragment_id) override;
};
2 changes: 1 addition & 1 deletion lib/Hoymiles/src/commands/DevInfoAllCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ class DevInfoAllCommand : public MultiDataCommand {
public:
DevInfoAllCommand(uint64_t target_address = 0, uint64_t router_address = 0, time_t time = 0);

virtual bool handleResponse(InverterAbstract* inverter, fragment_t fragment[], uint8_t max_fragment_id);
virtual bool handleResponse(InverterAbstract* inverter, fragment_t fragment[], uint8_t max_fragment_id) override;
};
2 changes: 1 addition & 1 deletion lib/Hoymiles/src/commands/DevInfoSampleCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ class DevInfoSampleCommand : public MultiDataCommand {
public:
DevInfoSampleCommand(uint64_t target_address = 0, uint64_t router_address = 0, time_t time = 0);

virtual bool handleResponse(InverterAbstract* inverter, fragment_t fragment[], uint8_t max_fragment_id);
virtual bool handleResponse(InverterAbstract* inverter, fragment_t fragment[], uint8_t max_fragment_id) override;
};
4 changes: 2 additions & 2 deletions lib/Hoymiles/src/commands/MultiDataCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class MultiDataCommand : public CommandAbstract {
void setTime(time_t time);
time_t getTime();

CommandAbstract* getRequestFrameCommand(uint8_t frame_no);
CommandAbstract* getRequestFrameCommand(uint8_t frame_no) override;

virtual bool handleResponse(InverterAbstract* inverter, fragment_t fragment[], uint8_t max_fragment_id);
virtual bool handleResponse(InverterAbstract* inverter, fragment_t fragment[], uint8_t max_fragment_id) override;

protected:
void setDataType(uint8_t data_type);
Expand Down
2 changes: 1 addition & 1 deletion lib/Hoymiles/src/commands/RealTimeRunDataCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ class RealTimeRunDataCommand : public MultiDataCommand {
public:
RealTimeRunDataCommand(uint64_t target_address = 0, uint64_t router_address = 0, time_t time = 0);

virtual bool handleResponse(InverterAbstract* inverter, fragment_t fragment[], uint8_t max_fragment_id);
virtual bool handleResponse(InverterAbstract* inverter, fragment_t fragment[], uint8_t max_fragment_id) override;
};
2 changes: 1 addition & 1 deletion lib/Hoymiles/src/commands/RequestFrameCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ class RequestFrameCommand : public SingleDataCommand {
void setFrameNo(uint8_t frame_no);
uint8_t getFrameNo();

virtual bool handleResponse(InverterAbstract* inverter, fragment_t fragment[], uint8_t max_fragment_id);
virtual bool handleResponse(InverterAbstract* inverter, fragment_t fragment[], uint8_t max_fragment_id) override;
};
8 changes: 4 additions & 4 deletions lib/Hoymiles/src/crc.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "crc.h"

uint8_t crc8(uint8_t buf[], uint8_t len)
uint8_t crc8(const uint8_t buf[], uint8_t len)
{
uint8_t crc = CRC8_INIT;
for (uint8_t i = 0; i < len; i++) {
Expand All @@ -12,10 +12,10 @@ uint8_t crc8(uint8_t buf[], uint8_t len)
return crc;
}

uint16_t crc16(uint8_t buf[], uint8_t len, uint16_t start)
uint16_t crc16(const uint8_t buf[], uint8_t len, uint16_t start)
{
uint16_t crc = start;
uint8_t shift = 0;
uint8_t shift;

for (uint8_t i = 0; i < len; i++) {
crc = crc ^ buf[i];
Expand All @@ -29,7 +29,7 @@ uint16_t crc16(uint8_t buf[], uint8_t len, uint16_t start)
return crc;
}

uint16_t crc16nrf24(uint8_t buf[], uint16_t lenBits, uint16_t startBit, uint16_t crcIn)
uint16_t crc16nrf24(const uint8_t buf[], uint16_t lenBits, uint16_t startBit, uint16_t crcIn)
{
uint16_t crc = crcIn;
uint8_t idx, val = buf[(startBit >> 3)];
Expand Down
6 changes: 3 additions & 3 deletions lib/Hoymiles/src/crc.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
#define CRC16_MODBUS_POLYNOM 0xA001
#define CRC16_NRF24_POLYNOM 0x1021

uint8_t crc8(uint8_t buf[], uint8_t len);
uint16_t crc16(uint8_t buf[], uint8_t len, uint16_t start = 0xffff);
uint16_t crc16nrf24(uint8_t buf[], uint16_t lenBits, uint16_t startBit = 0, uint16_t crcIn = 0xffff);
uint8_t crc8(const uint8_t buf[], uint8_t len);
uint16_t crc16(const uint8_t buf[], uint8_t len, uint16_t start = 0xffff);
uint16_t crc16nrf24(const uint8_t buf[], uint16_t lenBits, uint16_t startBit = 0, uint16_t crcIn = 0xffff);
6 changes: 3 additions & 3 deletions lib/Hoymiles/src/inverters/HM_1CH.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ class HM_1CH : public HM_Abstract {
public:
HM_1CH(uint64_t serial);
static bool isValidSerial(uint64_t serial);
String typeName();
const byteAssign_t* getByteAssignment();
const uint8_t getAssignmentCount();
String typeName() override;
const byteAssign_t* getByteAssignment() override;
const uint8_t getAssignmentCount() override;

private:
const byteAssign_t byteAssignment[17] = {
Expand Down
6 changes: 3 additions & 3 deletions lib/Hoymiles/src/inverters/HM_2CH.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ class HM_2CH : public HM_Abstract {
public:
HM_2CH(uint64_t serial);
static bool isValidSerial(uint64_t serial);
String typeName();
const byteAssign_t* getByteAssignment();
const uint8_t getAssignmentCount();
String typeName() override;
const byteAssign_t* getByteAssignment() override;
const uint8_t getAssignmentCount() override;

private:
const byteAssign_t byteAssignment[23] = {
Expand Down
6 changes: 3 additions & 3 deletions lib/Hoymiles/src/inverters/HM_4CH.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ class HM_4CH : public HM_Abstract {
public:
HM_4CH(uint64_t serial);
static bool isValidSerial(uint64_t serial);
String typeName();
const byteAssign_t* getByteAssignment();
const uint8_t getAssignmentCount();
String typeName() override;
const byteAssign_t* getByteAssignment() override;
const uint8_t getAssignmentCount() override;

private:
const byteAssign_t byteAssignment[36] = {
Expand Down
6 changes: 3 additions & 3 deletions lib/Hoymiles/src/inverters/HM_Abstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
class HM_Abstract : public InverterAbstract {
public:
HM_Abstract(uint64_t serial);
bool sendStatsRequest(HoymilesRadio* radio);
bool sendAlarmLogRequest(HoymilesRadio* radio);
bool sendDevInfoRequest(HoymilesRadio* radio);
bool sendStatsRequest(HoymilesRadio* radio) override;
bool sendAlarmLogRequest(HoymilesRadio* radio) override;
bool sendDevInfoRequest(HoymilesRadio* radio) override;

private:
uint8_t _lastAlarmLogCnt = 0;
Expand Down
2 changes: 1 addition & 1 deletion lib/Hoymiles/src/inverters/InverterAbstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class InverterAbstract {

private:
serial_u _serial;
char _name[MAX_NAME_LENGTH];
char _name[MAX_NAME_LENGTH] = {};
fragment_t _rxFragmentBuffer[MAX_RF_FRAGMENT_COUNT];
uint8_t _rxFragmentMaxPacketId = 0;
uint8_t _rxFragmentLastPacketId = 0;
Expand Down
4 changes: 2 additions & 2 deletions lib/Hoymiles/src/parser/AlarmLogParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ void AlarmLogParser::getLogEntry(uint8_t entryId, AlarmLogEntry_t* entry)

uint32_t wcode = (uint16_t)_payloadAlarmLog[entryStartOffset] << 8 | _payloadAlarmLog[entryStartOffset + 1];
uint32_t startTimeOffset = 0;
if ((wcode >> 13) & 0x01 == 1) {
if (((wcode >> 13) & 0x01) == 1) {
startTimeOffset = 12 * 60 * 60;
}

uint32_t endTimeOffset = 0;
if ((wcode >> 12) & 0x01 == 1) {
if (((wcode >> 12) & 0x01) == 1) {
endTimeOffset = 12 * 60 * 60;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Hoymiles/src/parser/AlarmLogParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ class AlarmLogParser : public Parser {
private:
static int getTimezoneOffset();

uint8_t _payloadAlarmLog[ALARM_LOG_ENTRY_SIZE * ALARM_LOG_ENTRY_COUNT];
uint8_t _alarmLogLength;
uint8_t _payloadAlarmLog[ALARM_LOG_ENTRY_SIZE * ALARM_LOG_ENTRY_COUNT] = {};
uint8_t _alarmLogLength = 0;
};
8 changes: 4 additions & 4 deletions lib/Hoymiles/src/parser/DevInfoParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class DevInfoParser : public Parser {
uint32_t _lastUpdateAll = 0;
uint32_t _lastUpdateSample = 0;

uint8_t _payloadDevInfoAll[DEV_INFO_SIZE];
uint8_t _devInfoAllLength;
uint8_t _payloadDevInfoAll[DEV_INFO_SIZE] = {};
uint8_t _devInfoAllLength = 0;

uint8_t _payloadDevInfoSample[DEV_INFO_SIZE];
uint8_t _devInfoSampleLength;
uint8_t _payloadDevInfoSample[DEV_INFO_SIZE] = {};
uint8_t _devInfoSampleLength = 0;
};
6 changes: 3 additions & 3 deletions lib/Hoymiles/src/parser/StatisticsParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ class StatisticsParser : public Parser {
void setChannelMaxPower(uint8_t channel, uint16_t power);

private:
uint8_t _payloadStatistic[STATISTIC_PACKET_SIZE];
uint8_t _statisticLength;
uint16_t _chanMaxPower[CH4];
uint8_t _payloadStatistic[STATISTIC_PACKET_SIZE] = {};
uint8_t _statisticLength = 0;
uint16_t _chanMaxPower[CH4] = {};

const byteAssign_t* _byteAssignment;
uint8_t _byteAssignmentCount;
Expand Down
2 changes: 1 addition & 1 deletion src/MqttHassPublishing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void MqttHassPublishingClass::publishField(std::shared_ptr<InverterAbstract> inv
}

char serial[sizeof(uint64_t) * 8 + 1];
sprintf(serial, "%0lx%08lx",
sprintf(serial, "%0x%08x",
((uint32_t)((inv->serial() >> 32) & 0xFFFFFFFF)),
((uint32_t)(inv->serial() & 0xFFFFFFFF)));

Expand Down
4 changes: 2 additions & 2 deletions src/MqttPublishing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void MqttPublishingClass::loop()
auto inv = Hoymiles.getInverterByPos(i);

char buffer[sizeof(uint64_t) * 8 + 1];
sprintf(buffer, "%0lx%08lx",
sprintf(buffer, "%0x%08x",
((uint32_t)((inv->serial() >> 32) & 0xFFFFFFFF)),
((uint32_t)(inv->serial() & 0xFFFFFFFF)));
String subtopic = String(buffer);
Expand Down Expand Up @@ -94,7 +94,7 @@ String MqttPublishingClass::getTopic(std::shared_ptr<InverterAbstract> inv, uint
}

char buffer[sizeof(uint64_t) * 8 + 1];
sprintf(buffer, "%0lx%08lx",
sprintf(buffer, "%0x%08x",
((uint32_t)((inv->serial() >> 32) & 0xFFFFFFFF)),
((uint32_t)(inv->serial() & 0xFFFFFFFF)));
String invSerial = String(buffer);
Expand Down
2 changes: 1 addition & 1 deletion src/WebApi_devinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void WebApiDevInfoClass::onDevInfoStatus(AsyncWebServerRequest* request)

// Inverter Serial is read as HEX
char buffer[sizeof(uint64_t) * 8 + 1];
sprintf(buffer, "%0lx%08lx",
sprintf(buffer, "%0x%08x",
((uint32_t)((inv->serial() >> 32) & 0xFFFFFFFF)),
((uint32_t)(inv->serial() & 0xFFFFFFFF)));

Expand Down
2 changes: 1 addition & 1 deletion src/WebApi_dtu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void WebApiDtuClass::onDtuAdminGet(AsyncWebServerRequest* request)

// DTU Serial is read as HEX
char buffer[sizeof(uint64_t) * 8 + 1];
sprintf(buffer, "%0lx%08lx",
sprintf(buffer, "%0ux%08ux",
((uint32_t)((config.Dtu_Serial >> 32) & 0xFFFFFFFF)),
((uint32_t)(config.Dtu_Serial & 0xFFFFFFFF)));
root[F("dtu_serial")] = buffer;
Expand Down
2 changes: 1 addition & 1 deletion src/WebApi_eventlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void WebApiEventlogClass::onEventlogStatus(AsyncWebServerRequest* request)

// Inverter Serial is read as HEX
char buffer[sizeof(uint64_t) * 8 + 1];
sprintf(buffer, "%0lx%08lx",
sprintf(buffer, "%0x%08x",
((uint32_t)((inv->serial() >> 32) & 0xFFFFFFFF)),
((uint32_t)(inv->serial() & 0xFFFFFFFF)));

Expand Down
2 changes: 1 addition & 1 deletion src/WebApi_inverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void WebApiInverterClass::onInverterList(AsyncWebServerRequest* request)

// Inverter Serial is read as HEX
char buffer[sizeof(uint64_t) * 8 + 1];
sprintf(buffer, "%0lx%08lx",
sprintf(buffer, "%0x%08x",
((uint32_t)((config.Inverter[i].Serial >> 32) & 0xFFFFFFFF)),
((uint32_t)(config.Inverter[i].Serial & 0xFFFFFFFF)));
obj[F("serial")] = buffer;
Expand Down
2 changes: 1 addition & 1 deletion src/WebApi_ws_live.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void WebApiWsLiveClass::generateJsonResponse(JsonVariant& root)
auto inv = Hoymiles.getInverterByPos(i);

char buffer[sizeof(uint64_t) * 8 + 1];
sprintf(buffer, "%0lx%08lx",
sprintf(buffer, "%0x%08x",
((uint32_t)((inv->serial() >> 32) & 0xFFFFFFFF)),
((uint32_t)(inv->serial() & 0xFFFFFFFF)));

Expand Down