Introduce several const statements
This commit is contained in:
parent
e0c07b9bcf
commit
8b5d406a4f
@ -14,7 +14,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
void generateJsonResponse(JsonVariant& root);
|
void generateJsonResponse(JsonVariant& root);
|
||||||
void addField(JsonObject& root, uint8_t idx, std::shared_ptr<InverterAbstract> inv, ChannelType_t type, ChannelNum_t channel, FieldId_t fieldId, String topic = "");
|
void addField(JsonObject& root, uint8_t idx, std::shared_ptr<InverterAbstract> inv, ChannelType_t type, ChannelNum_t channel, FieldId_t fieldId, String topic = "");
|
||||||
void addTotalField(JsonObject& root, String name, float value, String unit, uint8_t digits);
|
void addTotalField(JsonObject& root, const String& name, float value, const String& unit, uint8_t digits);
|
||||||
void onLivedataStatus(AsyncWebServerRequest* request);
|
void onLivedataStatus(AsyncWebServerRequest* request);
|
||||||
void onWebsocketEvent(AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data, size_t len);
|
void onWebsocketEvent(AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data, size_t len);
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2022 Thomas Basler and others
|
* Copyright (C) 2022-2023 Thomas Basler and others
|
||||||
*/
|
*/
|
||||||
#include "Hoymiles.h"
|
#include "Hoymiles.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
@ -126,7 +126,7 @@ void HoymilesClass::loop()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Perform housekeeping of all inverters on day change
|
// Perform housekeeping of all inverters on day change
|
||||||
int8_t currentWeekDay = Utils::getWeekDay();
|
const int8_t currentWeekDay = Utils::getWeekDay();
|
||||||
static int8_t lastWeekDay = -1;
|
static int8_t lastWeekDay = -1;
|
||||||
if (lastWeekDay == -1) {
|
if (lastWeekDay == -1) {
|
||||||
lastWeekDay = currentWeekDay;
|
lastWeekDay = currentWeekDay;
|
||||||
@ -198,7 +198,7 @@ std::shared_ptr<InverterAbstract> HoymilesClass::getInverterBySerial(uint64_t se
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<InverterAbstract> HoymilesClass::getInverterByFragment(fragment_t* fragment)
|
std::shared_ptr<InverterAbstract> HoymilesClass::getInverterByFragment(const fragment_t* fragment)
|
||||||
{
|
{
|
||||||
if (fragment->len <= 4) {
|
if (fragment->len <= 4) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|||||||
@ -26,7 +26,7 @@ public:
|
|||||||
std::shared_ptr<InverterAbstract> addInverter(const char* name, uint64_t serial);
|
std::shared_ptr<InverterAbstract> addInverter(const char* name, uint64_t serial);
|
||||||
std::shared_ptr<InverterAbstract> getInverterByPos(uint8_t pos);
|
std::shared_ptr<InverterAbstract> getInverterByPos(uint8_t pos);
|
||||||
std::shared_ptr<InverterAbstract> getInverterBySerial(uint64_t serial);
|
std::shared_ptr<InverterAbstract> getInverterBySerial(uint64_t serial);
|
||||||
std::shared_ptr<InverterAbstract> getInverterByFragment(fragment_t* fragment);
|
std::shared_ptr<InverterAbstract> getInverterByFragment(const fragment_t* fragment);
|
||||||
void removeInverterBySerial(uint64_t serial);
|
void removeInverterBySerial(uint64_t serial);
|
||||||
size_t getNumInverters();
|
size_t getNumInverters();
|
||||||
|
|
||||||
|
|||||||
@ -28,7 +28,7 @@ serial_u HoymilesRadio::convertSerialToRadioId(serial_u serial)
|
|||||||
return radioId;
|
return radioId;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HoymilesRadio::checkFragmentCrc(fragment_t* fragment)
|
bool HoymilesRadio::checkFragmentCrc(const fragment_t* fragment)
|
||||||
{
|
{
|
||||||
uint8_t crc = crc8(fragment->fragment, fragment->len - 1);
|
uint8_t crc = crc8(fragment->fragment, fragment->len - 1);
|
||||||
return (crc == fragment->fragment[fragment->len - 1]);
|
return (crc == fragment->fragment[fragment->len - 1]);
|
||||||
|
|||||||
@ -31,7 +31,7 @@ protected:
|
|||||||
static serial_u convertSerialToRadioId(serial_u serial);
|
static serial_u convertSerialToRadioId(serial_u serial);
|
||||||
void dumpBuf(const uint8_t buf[], uint8_t len, bool appendNewline = true);
|
void dumpBuf(const uint8_t buf[], uint8_t len, bool appendNewline = true);
|
||||||
|
|
||||||
bool checkFragmentCrc(fragment_t* fragment);
|
bool checkFragmentCrc(const fragment_t* fragment);
|
||||||
virtual void sendEsbPacket(CommandAbstract* cmd) = 0;
|
virtual void sendEsbPacket(CommandAbstract* cmd) = 0;
|
||||||
void sendRetransmitPacket(uint8_t fragment_id);
|
void sendRetransmitPacket(uint8_t fragment_id);
|
||||||
void sendLastPacketAgain();
|
void sendLastPacketAgain();
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2022 Thomas Basler and others
|
* Copyright (C) 2022-2023 Thomas Basler and others
|
||||||
*/
|
*/
|
||||||
#include "MultiDataCommand.h"
|
#include "MultiDataCommand.h"
|
||||||
#include "crc.h"
|
#include "crc.h"
|
||||||
@ -88,7 +88,7 @@ bool MultiDataCommand::handleResponse(InverterAbstract* inverter, fragment_t fra
|
|||||||
|
|
||||||
void MultiDataCommand::udpateCRC()
|
void MultiDataCommand::udpateCRC()
|
||||||
{
|
{
|
||||||
uint16_t crc = crc16(&_payload[10], 14); // From data_type till password
|
const uint16_t crc = crc16(&_payload[10], 14); // From data_type till password
|
||||||
_payload[24] = (uint8_t)(crc >> 8);
|
_payload[24] = (uint8_t)(crc >> 8);
|
||||||
_payload[25] = (uint8_t)(crc);
|
_payload[25] = (uint8_t)(crc);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2022 Thomas Basler and others
|
* Copyright (C) 2022-2023 Thomas Basler and others
|
||||||
*/
|
*/
|
||||||
#include "RealTimeRunDataCommand.h"
|
#include "RealTimeRunDataCommand.h"
|
||||||
#include "Hoymiles.h"
|
#include "Hoymiles.h"
|
||||||
@ -29,8 +29,8 @@ bool RealTimeRunDataCommand::handleResponse(InverterAbstract* inverter, fragment
|
|||||||
// Check if at least all required bytes are received
|
// Check if at least all required bytes are received
|
||||||
// In case of low power in the inverter it occours that some incomplete fragments
|
// In case of low power in the inverter it occours that some incomplete fragments
|
||||||
// with a valid CRC are received.
|
// with a valid CRC are received.
|
||||||
uint8_t fragmentsSize = getTotalFragmentSize(fragment, max_fragment_id);
|
const uint8_t fragmentsSize = getTotalFragmentSize(fragment, max_fragment_id);
|
||||||
uint8_t expectedSize = inverter->Statistics()->getExpectedByteCount();
|
const uint8_t expectedSize = inverter->Statistics()->getExpectedByteCount();
|
||||||
if (fragmentsSize < expectedSize) {
|
if (fragmentsSize < expectedSize) {
|
||||||
Hoymiles.getMessageOutput()->printf("ERROR in %s: Received fragment size: %d, min expected size: %d\r\n",
|
Hoymiles.getMessageOutput()->printf("ERROR in %s: Received fragment size: %d, min expected size: %d\r\n",
|
||||||
getCommandName().c_str(), fragmentsSize, expectedSize);
|
getCommandName().c_str(), fragmentsSize, expectedSize);
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2022 Thomas Basler and others
|
* Copyright (C) 2022-2023 Thomas Basler and others
|
||||||
*/
|
*/
|
||||||
#include "SystemConfigParaCommand.h"
|
#include "SystemConfigParaCommand.h"
|
||||||
#include "Hoymiles.h"
|
#include "Hoymiles.h"
|
||||||
@ -29,8 +29,8 @@ bool SystemConfigParaCommand::handleResponse(InverterAbstract* inverter, fragmen
|
|||||||
// Check if at least all required bytes are received
|
// Check if at least all required bytes are received
|
||||||
// In case of low power in the inverter it occours that some incomplete fragments
|
// In case of low power in the inverter it occours that some incomplete fragments
|
||||||
// with a valid CRC are received.
|
// with a valid CRC are received.
|
||||||
uint8_t fragmentsSize = getTotalFragmentSize(fragment, max_fragment_id);
|
const uint8_t fragmentsSize = getTotalFragmentSize(fragment, max_fragment_id);
|
||||||
uint8_t expectedSize = inverter->SystemConfigPara()->getExpectedByteCount();
|
const uint8_t expectedSize = inverter->SystemConfigPara()->getExpectedByteCount();
|
||||||
if (fragmentsSize < expectedSize) {
|
if (fragmentsSize < expectedSize) {
|
||||||
Hoymiles.getMessageOutput()->printf("ERROR in %s: Received fragment size: %d, min expected size: %d\r\n",
|
Hoymiles.getMessageOutput()->printf("ERROR in %s: Received fragment size: %d, min expected size: %d\r\n",
|
||||||
getCommandName().c_str(), fragmentsSize, expectedSize);
|
getCommandName().c_str(), fragmentsSize, expectedSize);
|
||||||
|
|||||||
@ -216,13 +216,13 @@ void AlarmLogParser::setMessageType(AlarmMessageType_t type)
|
|||||||
|
|
||||||
void AlarmLogParser::getLogEntry(uint8_t entryId, AlarmLogEntry_t* entry, AlarmMessageLocale_t locale)
|
void AlarmLogParser::getLogEntry(uint8_t entryId, AlarmLogEntry_t* entry, AlarmMessageLocale_t locale)
|
||||||
{
|
{
|
||||||
uint8_t entryStartOffset = 2 + entryId * ALARM_LOG_ENTRY_SIZE;
|
const uint8_t entryStartOffset = 2 + entryId * ALARM_LOG_ENTRY_SIZE;
|
||||||
|
|
||||||
int timezoneOffset = getTimezoneOffset();
|
const int timezoneOffset = getTimezoneOffset();
|
||||||
|
|
||||||
HOY_SEMAPHORE_TAKE();
|
HOY_SEMAPHORE_TAKE();
|
||||||
|
|
||||||
uint32_t wcode = (uint16_t)_payloadAlarmLog[entryStartOffset] << 8 | _payloadAlarmLog[entryStartOffset + 1];
|
const uint32_t wcode = (uint16_t)_payloadAlarmLog[entryStartOffset] << 8 | _payloadAlarmLog[entryStartOffset + 1];
|
||||||
uint32_t startTimeOffset = 0;
|
uint32_t startTimeOffset = 0;
|
||||||
if (((wcode >> 13) & 0x01) == 1) {
|
if (((wcode >> 13) & 0x01) == 1) {
|
||||||
startTimeOffset = 12 * 60 * 60;
|
startTimeOffset = 12 * 60 * 60;
|
||||||
|
|||||||
@ -116,7 +116,7 @@ void DevInfoParser::setLastUpdateSimple(uint32_t lastUpdate)
|
|||||||
uint16_t DevInfoParser::getFwBuildVersion()
|
uint16_t DevInfoParser::getFwBuildVersion()
|
||||||
{
|
{
|
||||||
HOY_SEMAPHORE_TAKE();
|
HOY_SEMAPHORE_TAKE();
|
||||||
uint16_t ret = (((uint16_t)_payloadDevInfoAll[0]) << 8) | _payloadDevInfoAll[1];
|
const uint16_t ret = (((uint16_t)_payloadDevInfoAll[0]) << 8) | _payloadDevInfoAll[1];
|
||||||
HOY_SEMAPHORE_GIVE();
|
HOY_SEMAPHORE_GIVE();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -140,19 +140,16 @@ time_t DevInfoParser::getFwBuildDateTime()
|
|||||||
uint16_t DevInfoParser::getFwBootloaderVersion()
|
uint16_t DevInfoParser::getFwBootloaderVersion()
|
||||||
{
|
{
|
||||||
HOY_SEMAPHORE_TAKE();
|
HOY_SEMAPHORE_TAKE();
|
||||||
uint16_t ret = (((uint16_t)_payloadDevInfoAll[8]) << 8) | _payloadDevInfoAll[9];
|
const uint16_t ret = (((uint16_t)_payloadDevInfoAll[8]) << 8) | _payloadDevInfoAll[9];
|
||||||
HOY_SEMAPHORE_GIVE();
|
HOY_SEMAPHORE_GIVE();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t DevInfoParser::getHwPartNumber()
|
uint32_t DevInfoParser::getHwPartNumber()
|
||||||
{
|
{
|
||||||
uint16_t hwpn_h;
|
|
||||||
uint16_t hwpn_l;
|
|
||||||
|
|
||||||
HOY_SEMAPHORE_TAKE();
|
HOY_SEMAPHORE_TAKE();
|
||||||
hwpn_h = (((uint16_t)_payloadDevInfoSimple[2]) << 8) | _payloadDevInfoSimple[3];
|
const uint16_t hwpn_h = (((uint16_t)_payloadDevInfoSimple[2]) << 8) | _payloadDevInfoSimple[3];
|
||||||
hwpn_l = (((uint16_t)_payloadDevInfoSimple[4]) << 8) | _payloadDevInfoSimple[5];
|
const uint16_t hwpn_l = (((uint16_t)_payloadDevInfoSimple[4]) << 8) | _payloadDevInfoSimple[5];
|
||||||
HOY_SEMAPHORE_GIVE();
|
HOY_SEMAPHORE_GIVE();
|
||||||
|
|
||||||
return ((uint32_t)hwpn_h << 16) | ((uint32_t)hwpn_l);
|
return ((uint32_t)hwpn_h << 16) | ((uint32_t)hwpn_l);
|
||||||
@ -169,7 +166,7 @@ String DevInfoParser::getHwVersion()
|
|||||||
|
|
||||||
uint16_t DevInfoParser::getMaxPower()
|
uint16_t DevInfoParser::getMaxPower()
|
||||||
{
|
{
|
||||||
uint8_t idx = getDevIdx();
|
const uint8_t idx = getDevIdx();
|
||||||
if (idx == 0xff) {
|
if (idx == 0xff) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -178,7 +175,7 @@ uint16_t DevInfoParser::getMaxPower()
|
|||||||
|
|
||||||
String DevInfoParser::getHwModelName()
|
String DevInfoParser::getHwModelName()
|
||||||
{
|
{
|
||||||
uint8_t idx = getDevIdx();
|
const uint8_t idx = getDevIdx();
|
||||||
if (idx == 0xff) {
|
if (idx == 0xff) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@ -187,7 +184,7 @@ String DevInfoParser::getHwModelName()
|
|||||||
|
|
||||||
bool DevInfoParser::containsValidData()
|
bool DevInfoParser::containsValidData()
|
||||||
{
|
{
|
||||||
time_t t = getFwBuildDateTime();
|
const time_t t = getFwBuildDateTime();
|
||||||
|
|
||||||
struct tm info;
|
struct tm info;
|
||||||
localtime_r(&t, &info);
|
localtime_r(&t, &info);
|
||||||
|
|||||||
@ -144,15 +144,13 @@ fieldSettings_t* StatisticsParser::getSettingByChannelField(ChannelType_t type,
|
|||||||
float StatisticsParser::getChannelFieldValue(ChannelType_t type, ChannelNum_t channel, FieldId_t fieldId)
|
float StatisticsParser::getChannelFieldValue(ChannelType_t type, ChannelNum_t channel, FieldId_t fieldId)
|
||||||
{
|
{
|
||||||
const byteAssign_t* pos = getAssignmentByChannelField(type, channel, fieldId);
|
const byteAssign_t* pos = getAssignmentByChannelField(type, channel, fieldId);
|
||||||
fieldSettings_t* setting = getSettingByChannelField(type, channel, fieldId);
|
|
||||||
|
|
||||||
if (pos == NULL) {
|
if (pos == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t ptr = pos->start;
|
uint8_t ptr = pos->start;
|
||||||
uint8_t end = ptr + pos->num;
|
const uint8_t end = ptr + pos->num;
|
||||||
uint16_t div = pos->div;
|
const uint16_t div = pos->div;
|
||||||
|
|
||||||
if (CMD_CALC != div) {
|
if (CMD_CALC != div) {
|
||||||
// Value is a static value
|
// Value is a static value
|
||||||
@ -174,6 +172,8 @@ float StatisticsParser::getChannelFieldValue(ChannelType_t type, ChannelNum_t ch
|
|||||||
}
|
}
|
||||||
|
|
||||||
result /= static_cast<float>(div);
|
result /= static_cast<float>(div);
|
||||||
|
|
||||||
|
const fieldSettings_t* setting = getSettingByChannelField(type, channel, fieldId);
|
||||||
if (setting != NULL && _statisticLength > 0) {
|
if (setting != NULL && _statisticLength > 0) {
|
||||||
result += setting->offset;
|
result += setting->offset;
|
||||||
}
|
}
|
||||||
@ -189,20 +189,19 @@ float StatisticsParser::getChannelFieldValue(ChannelType_t type, ChannelNum_t ch
|
|||||||
bool StatisticsParser::setChannelFieldValue(ChannelType_t type, ChannelNum_t channel, FieldId_t fieldId, float value)
|
bool StatisticsParser::setChannelFieldValue(ChannelType_t type, ChannelNum_t channel, FieldId_t fieldId, float value)
|
||||||
{
|
{
|
||||||
const byteAssign_t* pos = getAssignmentByChannelField(type, channel, fieldId);
|
const byteAssign_t* pos = getAssignmentByChannelField(type, channel, fieldId);
|
||||||
fieldSettings_t* setting = getSettingByChannelField(type, channel, fieldId);
|
|
||||||
|
|
||||||
if (pos == NULL) {
|
if (pos == NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t ptr = pos->start + pos->num - 1;
|
uint8_t ptr = pos->start + pos->num - 1;
|
||||||
uint8_t end = pos->start;
|
const uint8_t end = pos->start;
|
||||||
uint16_t div = pos->div;
|
const uint16_t div = pos->div;
|
||||||
|
|
||||||
if (CMD_CALC == div) {
|
if (CMD_CALC == div) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fieldSettings_t* setting = getSettingByChannelField(type, channel, fieldId);
|
||||||
if (setting != NULL) {
|
if (setting != NULL) {
|
||||||
value -= setting->offset;
|
value -= setting->offset;
|
||||||
}
|
}
|
||||||
@ -260,7 +259,7 @@ uint8_t StatisticsParser::getChannelFieldDigits(ChannelType_t type, ChannelNum_t
|
|||||||
|
|
||||||
float StatisticsParser::getChannelFieldOffset(ChannelType_t type, ChannelNum_t channel, FieldId_t fieldId)
|
float StatisticsParser::getChannelFieldOffset(ChannelType_t type, ChannelNum_t channel, FieldId_t fieldId)
|
||||||
{
|
{
|
||||||
fieldSettings_t* setting = getSettingByChannelField(type, channel, fieldId);
|
const fieldSettings_t* setting = getSettingByChannelField(type, channel, fieldId);
|
||||||
if (setting != NULL) {
|
if (setting != NULL) {
|
||||||
return setting->offset;
|
return setting->offset;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -196,7 +196,7 @@ void WebApiWsLiveClass::addField(JsonObject& root, uint8_t idx, std::shared_ptr<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebApiWsLiveClass::addTotalField(JsonObject& root, String name, float value, String unit, uint8_t digits)
|
void WebApiWsLiveClass::addTotalField(JsonObject& root, const String& name, float value, const String& unit, uint8_t digits)
|
||||||
{
|
{
|
||||||
root[name]["v"] = value;
|
root[name]["v"] = value;
|
||||||
root[name]["u"] = unit;
|
root[name]["u"] = unit;
|
||||||
|
|||||||
@ -68,7 +68,7 @@ void setup()
|
|||||||
MessageOutput.print("migrated... ");
|
MessageOutput.print("migrated... ");
|
||||||
Configuration.migrate();
|
Configuration.migrate();
|
||||||
}
|
}
|
||||||
CONFIG_T& config = Configuration.get();
|
auto& config = Configuration.get();
|
||||||
MessageOutput.println("done");
|
MessageOutput.println("done");
|
||||||
|
|
||||||
// Load PinMapping
|
// Load PinMapping
|
||||||
@ -78,7 +78,7 @@ void setup()
|
|||||||
} else {
|
} else {
|
||||||
MessageOutput.print("using default config ");
|
MessageOutput.print("using default config ");
|
||||||
}
|
}
|
||||||
const PinMapping_t& pin = PinMapping.get();
|
const auto& pin = PinMapping.get();
|
||||||
MessageOutput.println("done");
|
MessageOutput.println("done");
|
||||||
|
|
||||||
// Initialize WiFi
|
// Initialize WiFi
|
||||||
@ -137,7 +137,7 @@ void setup()
|
|||||||
MessageOutput.print("Check for default DTU serial... ");
|
MessageOutput.print("Check for default DTU serial... ");
|
||||||
if (config.Dtu.Serial == DTU_SERIAL) {
|
if (config.Dtu.Serial == DTU_SERIAL) {
|
||||||
MessageOutput.print("generate serial based on ESP chip id: ");
|
MessageOutput.print("generate serial based on ESP chip id: ");
|
||||||
uint64_t dtuId = Utils::generateDtuSerial();
|
const uint64_t dtuId = Utils::generateDtuSerial();
|
||||||
MessageOutput.printf("%0x%08x... ",
|
MessageOutput.printf("%0x%08x... ",
|
||||||
((uint32_t)((dtuId >> 32) & 0xFFFFFFFF)),
|
((uint32_t)((dtuId >> 32) & 0xFFFFFFFF)),
|
||||||
((uint32_t)(dtuId & 0xFFFFFFFF)));
|
((uint32_t)(dtuId & 0xFFFFFFFF)));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user