mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
code optimizations based on static analysis checks
This commit is contained in:
@@ -736,6 +736,8 @@ void Boiler::show_values(uuid::console::Shell & shell) {
|
||||
shell.println();
|
||||
return;
|
||||
}
|
||||
|
||||
// ww
|
||||
print_value_json(shell, F("wWSelTemp"), nullptr, F_(wWSelTemp), F_(degrees), json);
|
||||
print_value_json(shell, F("wWSetTemp"), nullptr, F_(wWSetTemp), F_(degrees), json);
|
||||
print_value_json(shell, F("wWDisinfectionTemp"), nullptr, F_(wWDisinfectionTemp), F_(degrees), json);
|
||||
|
||||
@@ -33,7 +33,7 @@ void Connect::device_info_web(JsonArray & root) {
|
||||
|
||||
// display all values into the shell console
|
||||
void Connect::show_values(uuid::console::Shell & shell) {
|
||||
// EMSdevice::show_values(shell); // always call this to show header
|
||||
EMSdevice::show_values(shell); // always call this to show header
|
||||
}
|
||||
|
||||
// publish values via MQTT
|
||||
|
||||
@@ -33,7 +33,7 @@ void Controller::device_info_web(JsonArray & root) {
|
||||
|
||||
// display all values into the shell console
|
||||
void Controller::show_values(uuid::console::Shell & shell) {
|
||||
// EMSdevice::show_values(shell); // always call this to show header
|
||||
EMSdevice::show_values(shell); // always call this to show header
|
||||
}
|
||||
|
||||
// publish values via MQTT
|
||||
|
||||
@@ -33,7 +33,7 @@ void Generic::device_info_web(JsonArray & root) {
|
||||
|
||||
// display all values into the shell console
|
||||
void Generic::show_values(uuid::console::Shell & shell) {
|
||||
// EMSdevice::show_values(shell); // always call this to show header
|
||||
EMSdevice::show_values(shell); // always call this to show header
|
||||
}
|
||||
|
||||
// publish values via MQTT
|
||||
|
||||
@@ -34,8 +34,8 @@ Switch::Switch(uint8_t device_type, uint8_t device_id, uint8_t product_id, const
|
||||
register_telegram_type(0x9B, F("WM10SetMessage"), false, [&](std::shared_ptr<const Telegram> t) { process_WM10SetMessage(t); });
|
||||
}
|
||||
|
||||
// fetch the values into a JSON document for display in the web
|
||||
void Switch::device_info_web(JsonArray & root) {
|
||||
// fetch the values into a JSON document
|
||||
StaticJsonDocument<EMSESP_MAX_JSON_SIZE_SMALL> doc;
|
||||
JsonObject json = doc.to<JsonObject>();
|
||||
if (export_values(json)) {
|
||||
@@ -47,8 +47,6 @@ void Switch::device_info_web(JsonArray & root) {
|
||||
|
||||
// display all values into the shell console
|
||||
void Switch::show_values(uuid::console::Shell & shell) {
|
||||
// EMSdevice::show_values(shell); // always call this to show header
|
||||
// fetch the values into a JSON document
|
||||
StaticJsonDocument<EMSESP_MAX_JSON_SIZE_SMALL> doc;
|
||||
JsonObject json = doc.to<JsonObject>();
|
||||
if (export_values(json)) {
|
||||
@@ -66,6 +64,7 @@ void Switch::publish_values(JsonObject & json, bool force) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
StaticJsonDocument<EMSESP_MAX_JSON_SIZE_SMALL> doc;
|
||||
JsonObject json_data = doc.to<JsonObject>();
|
||||
if (export_values(json_data)) {
|
||||
|
||||
@@ -413,7 +413,7 @@ void EMSdevice::print_value_json(uuid::console::Shell & shell,
|
||||
shell.println();
|
||||
}
|
||||
|
||||
// print value to shell from the json doc into a name/value pair
|
||||
// create json key/value pair
|
||||
void EMSdevice::print_value_json(JsonArray & root,
|
||||
const __FlashStringHelper * key,
|
||||
const __FlashStringHelper * prefix,
|
||||
|
||||
@@ -108,9 +108,9 @@ void EMSESP::scan_devices() {
|
||||
* we send to right device and match all reads to 0x18
|
||||
*/
|
||||
uint8_t EMSESP::check_master_device(const uint8_t device_id, const uint16_t type_id, const bool read) {
|
||||
uint16_t mon_id[4] = {0x02A5, 0x02A6, 0x02A7, 0x02A8};
|
||||
uint16_t set_id[4] = {0x02B9, 0x02BA, 0x02BB, 0x02BC};
|
||||
if (actual_master_thermostat_ == 0x18) {
|
||||
uint16_t mon_id[4] = {0x02A5, 0x02A6, 0x02A7, 0x02A8};
|
||||
uint16_t set_id[4] = {0x02B9, 0x02BA, 0x02BB, 0x02BC};
|
||||
for (uint8_t i = 0; i < 4; i++) {
|
||||
if (type_id == mon_id[i] || type_id == set_id[i]) {
|
||||
if (read) {
|
||||
@@ -121,6 +121,7 @@ uint8_t EMSESP::check_master_device(const uint8_t device_id, const uint16_t type
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return device_id;
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ char * Helpers::itoa(char * result, int32_t value, const uint8_t base) {
|
||||
return result;
|
||||
}
|
||||
|
||||
char * ptr = result, *ptr1 = result, tmp_char;
|
||||
char * ptr = result, *ptr1 = result;
|
||||
int16_t tmp_value;
|
||||
|
||||
do {
|
||||
@@ -97,6 +97,7 @@ char * Helpers::itoa(char * result, int32_t value, const uint8_t base) {
|
||||
}
|
||||
|
||||
*ptr-- = '\0';
|
||||
char tmp_char;
|
||||
while (ptr1 < ptr) {
|
||||
tmp_char = *ptr;
|
||||
*ptr-- = *ptr1;
|
||||
@@ -136,7 +137,7 @@ char * Helpers::render_boolean(char * result, bool value) {
|
||||
}
|
||||
|
||||
// depending on format render a number or a string
|
||||
char * Helpers::render_enum(char * result, const std::vector<const __FlashStringHelper *> value, const uint8_t no) {
|
||||
char * Helpers::render_enum(char * result, const std::vector<const __FlashStringHelper *> &value, const uint8_t no) {
|
||||
if (no >= value.size()) {
|
||||
return nullptr; // out of bounds
|
||||
}
|
||||
@@ -459,7 +460,7 @@ bool Helpers::value2bool(const char * v, bool & value) {
|
||||
}
|
||||
|
||||
// checks to see if a string is member of a vector and return the index, also allow true/false for on/off
|
||||
bool Helpers::value2enum(const char * v, uint8_t & value, const std::vector<const __FlashStringHelper *> strs) {
|
||||
bool Helpers::value2enum(const char * v, uint8_t & value, const std::vector<const __FlashStringHelper *> &strs) {
|
||||
if ((v == nullptr) || (strlen(v) == 0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ class Helpers {
|
||||
static char * render_value(char * result, const int16_t value, const uint8_t format);
|
||||
static char * render_value(char * result, const char * value, uint8_t format);
|
||||
static char * render_boolean(char * result, bool value);
|
||||
static char * render_enum(char * result, const std::vector<const __FlashStringHelper *> value, const uint8_t no);
|
||||
static char * render_enum(char * result, const std::vector<const __FlashStringHelper *> & value, const uint8_t no);
|
||||
|
||||
static char * hextoa(char * result, const uint8_t value);
|
||||
static std::string data_to_hex(const uint8_t * data, const uint8_t length);
|
||||
@@ -63,7 +63,7 @@ class Helpers {
|
||||
static bool value2float(const char * v, float & value);
|
||||
static bool value2bool(const char * v, bool & value);
|
||||
static bool value2string(const char * v, std::string & value);
|
||||
static bool value2enum(const char * v, uint8_t & value, const std::vector<const __FlashStringHelper *> strs);
|
||||
static bool value2enum(const char * v, uint8_t & value, const std::vector<const __FlashStringHelper *> & strs);
|
||||
|
||||
static void bool_format(uint8_t bool_format) {
|
||||
bool_format_ = bool_format;
|
||||
|
||||
@@ -434,14 +434,13 @@ void System::led_monitor() {
|
||||
// Low quality: 30% ~= -85dBm
|
||||
// Unusable quality: 8% ~= -96dBm
|
||||
int8_t System::wifi_quality() {
|
||||
#ifndef EMSESP_STANDALONE
|
||||
#ifdef EMSESP_STANDALONE
|
||||
return 100;
|
||||
#else
|
||||
if (WiFi.status() != WL_CONNECTED) {
|
||||
return -1;
|
||||
}
|
||||
int32_t dBm = WiFi.RSSI();
|
||||
#else
|
||||
int32_t dBm = -70;
|
||||
#endif
|
||||
if (dBm <= -100) {
|
||||
return 0;
|
||||
}
|
||||
@@ -450,6 +449,7 @@ int8_t System::wifi_quality() {
|
||||
return 100;
|
||||
}
|
||||
return 2 * (dBm + 100);
|
||||
#endif
|
||||
}
|
||||
|
||||
// print users to console
|
||||
@@ -750,9 +750,9 @@ bool System::check_upgrade() {
|
||||
|
||||
Serial.begin(115200);
|
||||
|
||||
bool failed = false;
|
||||
File file;
|
||||
JsonObject network, general, mqtt, custom_settings;
|
||||
bool failed = false;
|
||||
File file;
|
||||
JsonObject network, general, mqtt, custom_settings;
|
||||
StaticJsonDocument<EMSESP_MAX_JSON_SIZE_LARGE> doc;
|
||||
|
||||
// open the system settings:
|
||||
|
||||
@@ -41,7 +41,6 @@ bool EMSuart::sending_ = false;
|
||||
// Important: must not use ICACHE_FLASH_ATTR
|
||||
//
|
||||
void ICACHE_RAM_ATTR EMSuart::emsuart_rx_intr_handler(void * para) {
|
||||
static uint8_t length = 0;
|
||||
static uint8_t uart_buffer[EMS_MAXBUFFERSIZE + 2];
|
||||
|
||||
if (USIS(EMSUART_UART) & ((1 << UIBD))) { // BREAK detection = End of EMS data block
|
||||
@@ -49,8 +48,10 @@ void ICACHE_RAM_ATTR EMSuart::emsuart_rx_intr_handler(void * para) {
|
||||
if (sending_) { // irq tx_mode is interrupted by <brk>, should never happen
|
||||
drop_next_rx = true; // we have trash in buffer
|
||||
}
|
||||
USIC(EMSUART_UART) = (1 << UIBD); // INT clear the BREAK detect interrupt
|
||||
length = 0;
|
||||
|
||||
USIC(EMSUART_UART) = (1 << UIBD); // INT clear the BREAK detect interrupt
|
||||
static uint8_t length = 0;
|
||||
|
||||
while ((USS(EMSUART_UART) >> USRXC) & 0x0FF) { // read fifo into buffer
|
||||
uint8_t rx = USF(EMSUART_UART);
|
||||
if (length < EMS_MAXBUFFERSIZE) {
|
||||
@@ -61,14 +62,17 @@ void ICACHE_RAM_ATTR EMSuart::emsuart_rx_intr_handler(void * para) {
|
||||
drop_next_rx = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!drop_next_rx) {
|
||||
if (uart_buffer[length - 1]) { // check if last byte is break
|
||||
length++;
|
||||
}
|
||||
|
||||
pEMSRxBuf->length = length;
|
||||
os_memcpy((void *)pEMSRxBuf->buffer, (void *)&uart_buffer, pEMSRxBuf->length); // copy data into transfer buffer, including the BRK 0x00 at the end
|
||||
system_os_post(EMSUART_recvTaskPrio, 0, 0); // call emsuart_recvTask() at next opportunity
|
||||
}
|
||||
|
||||
drop_next_rx = false;
|
||||
sending_ = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user