Code hardening: introduce const keyword
This commit is contained in:
parent
83ca402306
commit
31e56f6c2b
@ -14,7 +14,7 @@ private:
|
|||||||
void onMqttStatus(AsyncWebServerRequest* request);
|
void onMqttStatus(AsyncWebServerRequest* request);
|
||||||
void onMqttAdminGet(AsyncWebServerRequest* request);
|
void onMqttAdminGet(AsyncWebServerRequest* request);
|
||||||
void onMqttAdminPost(AsyncWebServerRequest* request);
|
void onMqttAdminPost(AsyncWebServerRequest* request);
|
||||||
String getRootCaCertInfo(char* cert);
|
String getRootCaCertInfo(const char* cert);
|
||||||
|
|
||||||
AsyncWebServer* _server;
|
AsyncWebServer* _server;
|
||||||
};
|
};
|
||||||
@ -1,6 +1,6 @@
|
|||||||
#include "crc.h"
|
#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;
|
uint8_t crc = CRC8_INIT;
|
||||||
for (uint8_t i = 0; i < len; i++) {
|
for (uint8_t i = 0; i < len; i++) {
|
||||||
@ -12,7 +12,7 @@ uint8_t crc8(uint8_t buf[], uint8_t len)
|
|||||||
return crc;
|
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;
|
uint16_t crc = start;
|
||||||
uint8_t shift = 0;
|
uint8_t shift = 0;
|
||||||
@ -29,7 +29,7 @@ uint16_t crc16(uint8_t buf[], uint8_t len, uint16_t start)
|
|||||||
return crc;
|
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;
|
uint16_t crc = crcIn;
|
||||||
uint8_t idx, val = buf[(startBit >> 3)];
|
uint8_t idx, val = buf[(startBit >> 3)];
|
||||||
|
|||||||
@ -8,6 +8,6 @@
|
|||||||
#define CRC16_MODBUS_POLYNOM 0xA001
|
#define CRC16_MODBUS_POLYNOM 0xA001
|
||||||
#define CRC16_NRF24_POLYNOM 0x1021
|
#define CRC16_NRF24_POLYNOM 0x1021
|
||||||
|
|
||||||
uint8_t crc8(uint8_t buf[], uint8_t len);
|
uint8_t crc8(const uint8_t buf[], uint8_t len);
|
||||||
uint16_t crc16(uint8_t buf[], uint8_t len, uint16_t start = 0xffff);
|
uint16_t crc16(const 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);
|
uint16_t crc16nrf24(const uint8_t buf[], uint16_t lenBits, uint16_t startBit = 0, uint16_t crcIn = 0xffff);
|
||||||
|
|||||||
@ -46,7 +46,7 @@ void MqttHassPublishingClass::publishConfig()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CONFIG_T& config = Configuration.get();
|
const CONFIG_T& config = Configuration.get();
|
||||||
|
|
||||||
// Loop all inverters
|
// Loop all inverters
|
||||||
for (uint8_t i = 0; i < Hoymiles.getNumInverters(); i++) {
|
for (uint8_t i = 0; i < Hoymiles.getNumInverters(); i++) {
|
||||||
|
|||||||
@ -19,7 +19,7 @@ void MqttPublishingClass::loop()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CONFIG_T& config = Configuration.get();
|
const CONFIG_T& config = Configuration.get();
|
||||||
|
|
||||||
if (millis() - _lastPublish > (config.Mqtt_PublishInterval * 1000)) {
|
if (millis() - _lastPublish > (config.Mqtt_PublishInterval * 1000)) {
|
||||||
MqttSettings.publish("dtu/uptime", String(millis() / 1000));
|
MqttSettings.publish("dtu/uptime", String(millis() / 1000));
|
||||||
|
|||||||
@ -30,7 +30,7 @@ void MqttSettingsClass::NetworkEvent(network_event event)
|
|||||||
void MqttSettingsClass::onMqttConnect(bool sessionPresent)
|
void MqttSettingsClass::onMqttConnect(bool sessionPresent)
|
||||||
{
|
{
|
||||||
Serial.println(F("Connected to MQTT."));
|
Serial.println(F("Connected to MQTT."));
|
||||||
CONFIG_T& config = Configuration.get();
|
const CONFIG_T& config = Configuration.get();
|
||||||
publish(config.Mqtt_LwtTopic, config.Mqtt_LwtValue_Online);
|
publish(config.Mqtt_LwtTopic, config.Mqtt_LwtValue_Online);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ void MqttSettingsClass::performConnect()
|
|||||||
if (NetworkSettings.isConnected() && Configuration.get().Mqtt_Enabled) {
|
if (NetworkSettings.isConnected() && Configuration.get().Mqtt_Enabled) {
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
Serial.println(F("Connecting to MQTT..."));
|
Serial.println(F("Connecting to MQTT..."));
|
||||||
CONFIG_T& config = Configuration.get();
|
const CONFIG_T& config = Configuration.get();
|
||||||
willTopic = getPrefix() + config.Mqtt_LwtTopic;
|
willTopic = getPrefix() + config.Mqtt_LwtTopic;
|
||||||
clientId = NetworkSettings.getApName();
|
clientId = NetworkSettings.getApName();
|
||||||
if (config.Mqtt_Tls) {
|
if (config.Mqtt_Tls) {
|
||||||
@ -95,7 +95,7 @@ void MqttSettingsClass::performConnect()
|
|||||||
|
|
||||||
void MqttSettingsClass::performDisconnect()
|
void MqttSettingsClass::performDisconnect()
|
||||||
{
|
{
|
||||||
CONFIG_T& config = Configuration.get();
|
const CONFIG_T& config = Configuration.get();
|
||||||
publish(config.Mqtt_LwtTopic, config.Mqtt_LwtValue_Offline);
|
publish(config.Mqtt_LwtTopic, config.Mqtt_LwtValue_Offline);
|
||||||
mqttClient->disconnect();
|
mqttClient->disconnect();
|
||||||
}
|
}
|
||||||
@ -146,7 +146,7 @@ void MqttSettingsClass::createMqttClientObject()
|
|||||||
{
|
{
|
||||||
if (mqttClient != nullptr)
|
if (mqttClient != nullptr)
|
||||||
delete mqttClient;
|
delete mqttClient;
|
||||||
CONFIG_T& config = Configuration.get();
|
const CONFIG_T& config = Configuration.get();
|
||||||
if (config.Mqtt_Tls) {
|
if (config.Mqtt_Tls) {
|
||||||
mqttClient = static_cast<MqttClient*>(new espMqttClientSecure);
|
mqttClient = static_cast<MqttClient*>(new espMqttClientSecure);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -26,7 +26,7 @@ void WebApiDtuClass::onDtuAdminGet(AsyncWebServerRequest* request)
|
|||||||
{
|
{
|
||||||
AsyncJsonResponse* response = new AsyncJsonResponse();
|
AsyncJsonResponse* response = new AsyncJsonResponse();
|
||||||
JsonObject root = response->getRoot();
|
JsonObject root = response->getRoot();
|
||||||
CONFIG_T& config = Configuration.get();
|
const CONFIG_T& config = Configuration.get();
|
||||||
|
|
||||||
// DTU Serial is read as HEX
|
// DTU Serial is read as HEX
|
||||||
char buffer[sizeof(uint64_t) * 8 + 1];
|
char buffer[sizeof(uint64_t) * 8 + 1];
|
||||||
|
|||||||
@ -32,7 +32,7 @@ void WebApiInverterClass::onInverterList(AsyncWebServerRequest* request)
|
|||||||
JsonObject root = response->getRoot();
|
JsonObject root = response->getRoot();
|
||||||
JsonArray data = root.createNestedArray(F("inverter"));
|
JsonArray data = root.createNestedArray(F("inverter"));
|
||||||
|
|
||||||
CONFIG_T& config = Configuration.get();
|
const CONFIG_T& config = Configuration.get();
|
||||||
|
|
||||||
for (uint8_t i = 0; i < INV_MAX_COUNT; i++) {
|
for (uint8_t i = 0; i < INV_MAX_COUNT; i++) {
|
||||||
if (config.Inverter[i].Serial > 0) {
|
if (config.Inverter[i].Serial > 0) {
|
||||||
|
|||||||
@ -29,7 +29,7 @@ void WebApiMqttClass::onMqttStatus(AsyncWebServerRequest* request)
|
|||||||
{
|
{
|
||||||
AsyncJsonResponse* response = new AsyncJsonResponse(false, MQTT_JSON_DOC_SIZE);
|
AsyncJsonResponse* response = new AsyncJsonResponse(false, MQTT_JSON_DOC_SIZE);
|
||||||
JsonObject root = response->getRoot();
|
JsonObject root = response->getRoot();
|
||||||
CONFIG_T& config = Configuration.get();
|
const CONFIG_T& config = Configuration.get();
|
||||||
|
|
||||||
root[F("mqtt_enabled")] = config.Mqtt_Enabled;
|
root[F("mqtt_enabled")] = config.Mqtt_Enabled;
|
||||||
root[F("mqtt_hostname")] = config.Mqtt_Hostname;
|
root[F("mqtt_hostname")] = config.Mqtt_Hostname;
|
||||||
@ -56,7 +56,7 @@ void WebApiMqttClass::onMqttAdminGet(AsyncWebServerRequest* request)
|
|||||||
{
|
{
|
||||||
AsyncJsonResponse* response = new AsyncJsonResponse(false, MQTT_JSON_DOC_SIZE);
|
AsyncJsonResponse* response = new AsyncJsonResponse(false, MQTT_JSON_DOC_SIZE);
|
||||||
JsonObject root = response->getRoot();
|
JsonObject root = response->getRoot();
|
||||||
CONFIG_T& config = Configuration.get();
|
const CONFIG_T& config = Configuration.get();
|
||||||
|
|
||||||
root[F("mqtt_enabled")] = config.Mqtt_Enabled;
|
root[F("mqtt_enabled")] = config.Mqtt_Enabled;
|
||||||
root[F("mqtt_hostname")] = config.Mqtt_Hostname;
|
root[F("mqtt_hostname")] = config.Mqtt_Hostname;
|
||||||
@ -267,7 +267,7 @@ void WebApiMqttClass::onMqttAdminPost(AsyncWebServerRequest* request)
|
|||||||
MqttHassPublishing.forceUpdate();
|
MqttHassPublishing.forceUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
String WebApiMqttClass::getRootCaCertInfo(char* cert)
|
String WebApiMqttClass::getRootCaCertInfo(const char* cert)
|
||||||
{
|
{
|
||||||
char rootCaCertInfo[1024] = "";
|
char rootCaCertInfo[1024] = "";
|
||||||
|
|
||||||
|
|||||||
@ -53,7 +53,7 @@ void WebApiNetworkClass::onNetworkAdminGet(AsyncWebServerRequest* request)
|
|||||||
{
|
{
|
||||||
AsyncJsonResponse* response = new AsyncJsonResponse();
|
AsyncJsonResponse* response = new AsyncJsonResponse();
|
||||||
JsonObject root = response->getRoot();
|
JsonObject root = response->getRoot();
|
||||||
CONFIG_T& config = Configuration.get();
|
const CONFIG_T& config = Configuration.get();
|
||||||
|
|
||||||
root[F("hostname")] = config.WiFi_Hostname;
|
root[F("hostname")] = config.WiFi_Hostname;
|
||||||
root[F("dhcp")] = config.WiFi_Dhcp;
|
root[F("dhcp")] = config.WiFi_Dhcp;
|
||||||
|
|||||||
@ -28,7 +28,7 @@ void WebApiNtpClass::onNtpStatus(AsyncWebServerRequest* request)
|
|||||||
{
|
{
|
||||||
AsyncJsonResponse* response = new AsyncJsonResponse();
|
AsyncJsonResponse* response = new AsyncJsonResponse();
|
||||||
JsonObject root = response->getRoot();
|
JsonObject root = response->getRoot();
|
||||||
CONFIG_T& config = Configuration.get();
|
const CONFIG_T& config = Configuration.get();
|
||||||
|
|
||||||
root[F("ntp_server")] = config.Ntp_Server;
|
root[F("ntp_server")] = config.Ntp_Server;
|
||||||
root[F("ntp_timezone")] = config.Ntp_Timezone;
|
root[F("ntp_timezone")] = config.Ntp_Timezone;
|
||||||
@ -52,7 +52,7 @@ void WebApiNtpClass::onNtpAdminGet(AsyncWebServerRequest* request)
|
|||||||
{
|
{
|
||||||
AsyncJsonResponse* response = new AsyncJsonResponse();
|
AsyncJsonResponse* response = new AsyncJsonResponse();
|
||||||
JsonObject root = response->getRoot();
|
JsonObject root = response->getRoot();
|
||||||
CONFIG_T& config = Configuration.get();
|
const CONFIG_T& config = Configuration.get();
|
||||||
|
|
||||||
root[F("ntp_server")] = config.Ntp_Server;
|
root[F("ntp_server")] = config.Ntp_Server;
|
||||||
root[F("ntp_timezone")] = config.Ntp_Timezone;
|
root[F("ntp_timezone")] = config.Ntp_Timezone;
|
||||||
|
|||||||
@ -78,7 +78,7 @@ void setup()
|
|||||||
|
|
||||||
// Initialize inverter communication
|
// Initialize inverter communication
|
||||||
Serial.print(F("Initialize Hoymiles interface... "));
|
Serial.print(F("Initialize Hoymiles interface... "));
|
||||||
CONFIG_T& config = Configuration.get();
|
const CONFIG_T& config = Configuration.get();
|
||||||
Hoymiles.init();
|
Hoymiles.init();
|
||||||
|
|
||||||
Serial.println(F(" Setting radio PA level... "));
|
Serial.println(F(" Setting radio PA level... "));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user