mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-08 00:39:50 +03:00
Merge remote-tracking branch 'origin/flash_optimization' into dev #646
This commit is contained in:
149
src/emsesp.cpp
149
src/emsesp.cpp
@@ -190,7 +190,7 @@ void EMSESP::uart_init() {
|
||||
if (System::is_valid_gpio(rx_gpio) && System::is_valid_gpio(tx_gpio)) {
|
||||
EMSuart::start(tx_mode, rx_gpio, tx_gpio); // start UART
|
||||
} else {
|
||||
LOG_WARNING(F("Invalid UART Rx/Tx GPIOs. Check config."));
|
||||
LOG_WARNING("Invalid UART Rx/Tx GPIOs. Check config.");
|
||||
}
|
||||
|
||||
txservice_.start(); // sends out request to EMS bus for all devices
|
||||
@@ -234,42 +234,42 @@ void EMSESP::show_ems(uuid::console::Shell & shell) {
|
||||
// EMS bus information
|
||||
switch (bus_status()) {
|
||||
case BUS_STATUS_OFFLINE:
|
||||
shell.printfln(F("EMS Bus is disconnected."));
|
||||
shell.printfln("EMS Bus is disconnected.");
|
||||
break;
|
||||
case BUS_STATUS_TX_ERRORS:
|
||||
shell.printfln(F("EMS Bus is connected, but Tx is not stable."));
|
||||
shell.printfln("EMS Bus is connected, but Tx is not stable.");
|
||||
break;
|
||||
default:
|
||||
shell.printfln(F("EMS Bus is connected."));
|
||||
shell.printfln("EMS Bus is connected.");
|
||||
break;
|
||||
}
|
||||
|
||||
shell.println();
|
||||
|
||||
if (bus_status() != BUS_STATUS_OFFLINE) {
|
||||
shell.printfln(F("EMS Bus info:"));
|
||||
EMSESP::webSettingsService.read([&](WebSettings & settings) { shell.printfln(F(" Tx mode: %d"), settings.tx_mode); });
|
||||
shell.printfln(F(" Bus protocol: %s"), EMSbus::is_ht3() ? F("HT3") : F("Buderus"));
|
||||
shell.printfln(F(" #recognized EMS devices: %d"), EMSESP::emsdevices.size());
|
||||
shell.printfln(F(" #telegrams received: %d"), rxservice_.telegram_count());
|
||||
shell.printfln(F(" #read requests sent: %d"), txservice_.telegram_read_count());
|
||||
shell.printfln(F(" #write requests sent: %d"), txservice_.telegram_write_count());
|
||||
shell.printfln(F(" #incomplete telegrams: %d"), rxservice_.telegram_error_count());
|
||||
shell.printfln(F(" #read fails (after %d retries): %d"), TxService::MAXIMUM_TX_RETRIES, txservice_.telegram_read_fail_count());
|
||||
shell.printfln(F(" #write fails (after %d retries): %d"), TxService::MAXIMUM_TX_RETRIES, txservice_.telegram_write_fail_count());
|
||||
shell.printfln(F(" Rx line quality: %d%%"), rxservice_.quality());
|
||||
shell.printfln(F(" Tx line quality: %d%%"), (txservice_.read_quality() + txservice_.read_quality()) / 2);
|
||||
shell.printfln("EMS Bus info:");
|
||||
EMSESP::webSettingsService.read([&](WebSettings & settings) { shell.printfln(" Tx mode: %d", settings.tx_mode); });
|
||||
shell.printfln(" Bus protocol: %s", EMSbus::is_ht3() ? ("HT3") : ("Buderus"));
|
||||
shell.printfln(" #recognized EMS devices: %d", EMSESP::emsdevices.size());
|
||||
shell.printfln(" #telegrams received: %d", rxservice_.telegram_count());
|
||||
shell.printfln(" #read requests sent: %d", txservice_.telegram_read_count());
|
||||
shell.printfln(" #write requests sent: %d", txservice_.telegram_write_count());
|
||||
shell.printfln(" #incomplete telegrams: %d", rxservice_.telegram_error_count());
|
||||
shell.printfln((" #read fails (after %d retries): %d"), TxService::MAXIMUM_TX_RETRIES, txservice_.telegram_read_fail_count());
|
||||
shell.printfln((" #write fails (after %d retries): %d"), TxService::MAXIMUM_TX_RETRIES, txservice_.telegram_write_fail_count());
|
||||
shell.printfln(" Rx line quality: %d%%", rxservice_.quality());
|
||||
shell.printfln(" Tx line quality: %d%%", (txservice_.read_quality() + txservice_.read_quality()) / 2);
|
||||
shell.println();
|
||||
}
|
||||
|
||||
// Rx queue
|
||||
auto rx_telegrams = rxservice_.queue();
|
||||
if (rx_telegrams.empty()) {
|
||||
shell.printfln(F("Rx Queue is empty"));
|
||||
shell.printfln("Rx Queue is empty");
|
||||
} else {
|
||||
shell.printfln(F("Rx Queue (%ld telegram%s):"), rx_telegrams.size(), rx_telegrams.size() == 1 ? "" : "s");
|
||||
shell.printfln(("Rx Queue (%ld telegram%s):"), rx_telegrams.size(), rx_telegrams.size() == 1 ? "" : "s");
|
||||
for (const auto & it : rx_telegrams) {
|
||||
shell.printfln(F(" [%02d] %s"), it.id_, pretty_telegram(it.telegram_).c_str());
|
||||
shell.printfln(" [%02d] %s", it.id_, pretty_telegram(it.telegram_).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,20 +278,20 @@ void EMSESP::show_ems(uuid::console::Shell & shell) {
|
||||
// Tx queue
|
||||
auto tx_telegrams = txservice_.queue();
|
||||
if (tx_telegrams.empty()) {
|
||||
shell.printfln(F("Tx Queue is empty"));
|
||||
shell.printfln("Tx Queue is empty");
|
||||
} else {
|
||||
shell.printfln(F("Tx Queue (%ld telegram%s):"), tx_telegrams.size(), tx_telegrams.size() == 1 ? "" : "s");
|
||||
shell.printfln(("Tx Queue (%ld telegram%s):"), tx_telegrams.size(), tx_telegrams.size() == 1 ? "" : "s");
|
||||
|
||||
std::string op;
|
||||
for (const auto & it : tx_telegrams) {
|
||||
if ((it.telegram_->operation) == Telegram::Operation::TX_RAW) {
|
||||
op = read_flash_string(F("RAW "));
|
||||
op = "RAW ";
|
||||
} else if ((it.telegram_->operation) == Telegram::Operation::TX_READ) {
|
||||
op = read_flash_string(F("READ "));
|
||||
op = "READ ";
|
||||
} else if ((it.telegram_->operation) == Telegram::Operation::TX_WRITE) {
|
||||
op = read_flash_string(F("WRITE"));
|
||||
op = "WRITE";
|
||||
}
|
||||
shell.printfln(F(" [%02d%c] %s %s"), it.id_, ((it.retry_) ? '*' : ' '), op.c_str(), pretty_telegram(it.telegram_).c_str());
|
||||
shell.printfln(" [%02d%c] %s %s", it.id_, ((it.retry_) ? '*' : ' '), op.c_str(), pretty_telegram(it.telegram_).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,7 +301,7 @@ void EMSESP::show_ems(uuid::console::Shell & shell) {
|
||||
// show EMS device values to the shell console
|
||||
void EMSESP::show_device_values(uuid::console::Shell & shell) {
|
||||
if (emsdevices.empty()) {
|
||||
shell.printfln(F("No EMS devices detected."));
|
||||
shell.printfln("No EMS devices detected.");
|
||||
shell.println();
|
||||
return;
|
||||
}
|
||||
@@ -311,7 +311,7 @@ void EMSESP::show_device_values(uuid::console::Shell & shell) {
|
||||
for (const auto & emsdevice : emsdevices) {
|
||||
if (emsdevice && (emsdevice->device_type() == device_class.first)) {
|
||||
// print header
|
||||
shell.printfln(F("%s: %s (%d)"), emsdevice->device_type_name().c_str(), emsdevice->to_string().c_str(), emsdevice->count_entities());
|
||||
shell.printfln(("%s: %s (%d)"), emsdevice->device_type_name().c_str(), emsdevice->to_string().c_str(), emsdevice->count_entities());
|
||||
|
||||
DynamicJsonDocument doc(EMSESP_JSON_SIZE_XXLARGE_DYN); // use max size
|
||||
JsonObject json = doc.to<JsonObject>();
|
||||
@@ -359,14 +359,14 @@ void EMSESP::show_device_values(uuid::console::Shell & shell) {
|
||||
// show Dallas temperature sensors and Analog sensors
|
||||
void EMSESP::show_sensor_values(uuid::console::Shell & shell) {
|
||||
if (dallassensor_.have_sensors()) {
|
||||
shell.printfln(F("Temperature sensors:"));
|
||||
shell.printfln("Temperature sensors:");
|
||||
char s[10];
|
||||
char s2[10];
|
||||
uint8_t fahrenheit = EMSESP::system_.fahrenheit() ? 2 : 0;
|
||||
|
||||
for (const auto & sensor : dallassensor_.sensors()) {
|
||||
if (Helpers::hasValue(sensor.temperature_c)) {
|
||||
shell.printfln(F(" %s: %s%s °%c%s (offset %s, ID: %s)"),
|
||||
shell.printfln((" %s: %s%s °%c%s (offset %s, ID: %s)"),
|
||||
sensor.name().c_str(),
|
||||
COLOR_BRIGHT_GREEN,
|
||||
Helpers::render_value(s, sensor.temperature_c, 10, fahrenheit),
|
||||
@@ -375,10 +375,7 @@ void EMSESP::show_sensor_values(uuid::console::Shell & shell) {
|
||||
Helpers::render_value(s2, sensor.offset(), 10, fahrenheit),
|
||||
sensor.id().c_str());
|
||||
} else {
|
||||
shell.printfln(F(" %s (offset %s, ID: %s)"),
|
||||
sensor.name().c_str(),
|
||||
Helpers::render_value(s, sensor.offset(), 10, fahrenheit),
|
||||
sensor.id().c_str());
|
||||
shell.printfln((" %s (offset %s, ID: %s)"), sensor.name().c_str(), Helpers::render_value(s, sensor.offset(), 10, fahrenheit), sensor.id().c_str());
|
||||
}
|
||||
}
|
||||
shell.println();
|
||||
@@ -387,11 +384,11 @@ void EMSESP::show_sensor_values(uuid::console::Shell & shell) {
|
||||
if (analogsensor_.have_sensors()) {
|
||||
char s[10];
|
||||
char s2[10];
|
||||
shell.printfln(F("Analog sensors:"));
|
||||
shell.printfln("Analog sensors:");
|
||||
for (const auto & sensor : analogsensor_.sensors()) {
|
||||
switch (sensor.type()) {
|
||||
case AnalogSensor::AnalogType::ADC:
|
||||
shell.printfln(F(" %s: %s%s %s%s (Type: ADC, Factor: %s, Offset: %d)"),
|
||||
shell.printfln((" %s: %s%s %s%s (Type: ADC, Factor: %s, Offset: %d)"),
|
||||
sensor.name().c_str(),
|
||||
COLOR_BRIGHT_GREEN,
|
||||
Helpers::render_value(s, sensor.value(), 2),
|
||||
@@ -403,7 +400,7 @@ void EMSESP::show_sensor_values(uuid::console::Shell & shell) {
|
||||
default:
|
||||
// case AnalogSensor::AnalogType::DIGITAL_IN:
|
||||
// case AnalogSensor::AnalogType::COUNTER:
|
||||
shell.printfln(F(" %s: %s%d%s (Type: %s)"),
|
||||
shell.printfln((" %s: %s%d%s (Type: %s)"),
|
||||
sensor.name().c_str(),
|
||||
COLOR_BRIGHT_GREEN,
|
||||
(uint16_t)sensor.value(), // as int
|
||||
@@ -540,7 +537,7 @@ void EMSESP::publish_device_values(uint8_t device_type) {
|
||||
}
|
||||
if (need_publish) {
|
||||
if (doc.overflowed()) {
|
||||
LOG_WARNING(F("MQTT buffer overflow, please use individual topics"));
|
||||
LOG_WARNING("MQTT buffer overflow, please use individual topics");
|
||||
}
|
||||
Mqtt::publish(Mqtt::tag_to_topic(device_type, DeviceValueTAG::TAG_NONE), json);
|
||||
}
|
||||
@@ -625,9 +622,9 @@ bool EMSESP::get_device_value_info(JsonObject & root, const char * cmd, const in
|
||||
// search for recognized device_ids : Me, All, otherwise print hex value
|
||||
std::string EMSESP::device_tostring(const uint8_t device_id) {
|
||||
if ((device_id & 0x7F) == rxservice_.ems_bus_id()) {
|
||||
return read_flash_string(F("Me"));
|
||||
return "Me";
|
||||
} else if (device_id == 0x00) {
|
||||
return read_flash_string(F("All"));
|
||||
return "All";
|
||||
} else {
|
||||
char buffer[5];
|
||||
return Helpers::hextoa(buffer, device_id);
|
||||
@@ -672,14 +669,14 @@ std::string EMSESP::pretty_telegram(std::shared_ptr<const Telegram> telegram) {
|
||||
|
||||
// check for global/common types like Version & UBADevices
|
||||
if (telegram->type_id == EMSdevice::EMS_TYPE_VERSION) {
|
||||
type_name = read_flash_string(F("Version"));
|
||||
type_name = "Version";
|
||||
} else if (telegram->type_id == EMSdevice::EMS_TYPE_UBADevices) {
|
||||
type_name = read_flash_string(F("UBADevices"));
|
||||
type_name = "UBADevices";
|
||||
}
|
||||
|
||||
// if we don't know the type show
|
||||
if (type_name.empty()) {
|
||||
type_name = read_flash_string(F("?"));
|
||||
type_name = "?";
|
||||
}
|
||||
|
||||
std::string str;
|
||||
@@ -728,7 +725,7 @@ void EMSESP::process_UBADevices(std::shared_ptr<const Telegram> telegram) {
|
||||
// if we haven't already detected this device, request it's version details, unless its us (EMS-ESP)
|
||||
// when the version info is received, it will automagically add the device
|
||||
if ((device_id != EMSbus::ems_bus_id()) && !(EMSESP::device_exists(device_id))) {
|
||||
LOG_DEBUG(F("New EMS device detected with ID 0x%02X. Requesting version information."), device_id);
|
||||
LOG_DEBUG("New EMS device detected with ID 0x%02X. Requesting version information.", device_id);
|
||||
send_read_request(EMSdevice::EMS_TYPE_VERSION, device_id);
|
||||
}
|
||||
}
|
||||
@@ -788,7 +785,7 @@ void EMSESP::process_version(std::shared_ptr<const Telegram> telegram) {
|
||||
bool EMSESP::process_telegram(std::shared_ptr<const Telegram> telegram) {
|
||||
// if watching or reading...
|
||||
if ((telegram->type_id == read_id_) && (telegram->dest == txservice_.ems_bus_id())) {
|
||||
LOG_INFO(F("%s"), pretty_telegram(telegram).c_str());
|
||||
LOG_INFO("%s", pretty_telegram(telegram).c_str());
|
||||
if (Mqtt::send_response()) {
|
||||
publish_response(telegram);
|
||||
}
|
||||
@@ -800,18 +797,18 @@ bool EMSESP::process_telegram(std::shared_ptr<const Telegram> telegram) {
|
||||
} else if (watch() == WATCH_ON) {
|
||||
if ((watch_id_ == WATCH_ID_NONE) || (telegram->type_id == watch_id_)
|
||||
|| ((watch_id_ < 0x80) && ((telegram->src == watch_id_) || (telegram->dest == watch_id_)))) {
|
||||
LOG_NOTICE(F("%s"), pretty_telegram(telegram).c_str());
|
||||
LOG_NOTICE("%s", pretty_telegram(telegram).c_str());
|
||||
} else if (!trace_raw_) {
|
||||
LOG_TRACE(F("%s"), pretty_telegram(telegram).c_str());
|
||||
LOG_TRACE("%s", pretty_telegram(telegram).c_str());
|
||||
}
|
||||
} else if (!trace_raw_) {
|
||||
LOG_TRACE(F("%s"), pretty_telegram(telegram).c_str());
|
||||
LOG_TRACE("%s", pretty_telegram(telegram).c_str());
|
||||
}
|
||||
|
||||
// only process broadcast telegrams or ones sent to us on request
|
||||
// if ((telegram->dest != 0x00) && (telegram->dest != rxservice_.ems_bus_id())) {
|
||||
if (telegram->operation == Telegram::Operation::RX_READ) {
|
||||
// LOG_DEBUG(F("read telegram received, not processing"));
|
||||
// LOG_DEBUG("read telegram received, not processing");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -861,9 +858,9 @@ bool EMSESP::process_telegram(std::shared_ptr<const Telegram> telegram) {
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
LOG_DEBUG(F("No telegram type handler found for ID 0x%02X (src 0x%02X)"), telegram->type_id, telegram->src);
|
||||
LOG_DEBUG(("No telegram type handler found for ID 0x%02X (src 0x%02X)"), telegram->type_id, telegram->src);
|
||||
if (watch() == WATCH_UNKNOWN) {
|
||||
LOG_NOTICE(F("%s"), pretty_telegram(telegram).c_str());
|
||||
LOG_NOTICE("%s", pretty_telegram(telegram).c_str());
|
||||
}
|
||||
if (!wait_km_ && !knowndevice && (telegram->src != EMSbus::ems_bus_id()) && (telegram->message_length > 0)) {
|
||||
send_read_request(EMSdevice::EMS_TYPE_VERSION, telegram->src);
|
||||
@@ -887,12 +884,12 @@ bool EMSESP::device_exists(const uint8_t device_id) {
|
||||
// for each associated EMS device go and get its system information
|
||||
void EMSESP::show_devices(uuid::console::Shell & shell) {
|
||||
if (emsdevices.empty()) {
|
||||
shell.printfln(F("No EMS devices detected. Try using 'scan devices' from the ems menu."));
|
||||
shell.printfln("No EMS devices detected. Try using 'scan devices' from the ems menu.");
|
||||
shell.println();
|
||||
return;
|
||||
}
|
||||
|
||||
shell.printfln(F("These EMS devices are currently active:"));
|
||||
shell.printfln("These EMS devices are currently active:");
|
||||
shell.println();
|
||||
|
||||
// count the number of thermostats
|
||||
@@ -908,7 +905,7 @@ void EMSESP::show_devices(uuid::console::Shell & shell) {
|
||||
for (const auto & device_class : EMSFactory::device_handlers()) {
|
||||
for (const auto & emsdevice : emsdevices) {
|
||||
if (emsdevice && (emsdevice->device_type() == device_class.first)) {
|
||||
shell.printf(F("%s: %s"), emsdevice->device_type_name().c_str(), emsdevice->to_string().c_str());
|
||||
shell.printf("%s: %s", emsdevice->device_type_name().c_str(), emsdevice->to_string().c_str());
|
||||
shell.println();
|
||||
emsdevice->show_telegram_handlers(shell);
|
||||
|
||||
@@ -935,7 +932,7 @@ bool EMSESP::add_device(const uint8_t device_id, const uint8_t product_id, const
|
||||
if (product_id == 0) { // update only with valid product_id
|
||||
return true;
|
||||
}
|
||||
LOG_DEBUG(F("Updating details for already active deviceID 0x%02X"), device_id);
|
||||
LOG_DEBUG("Updating details for already active deviceID 0x%02X", device_id);
|
||||
emsdevice->product_id(product_id);
|
||||
emsdevice->version(version);
|
||||
// only set brand if it doesn't already exist
|
||||
@@ -945,7 +942,7 @@ bool EMSESP::add_device(const uint8_t device_id, const uint8_t product_id, const
|
||||
// find the name and flags in our database
|
||||
for (const auto & device : device_library_) {
|
||||
if (device.product_id == product_id && device.device_type == emsdevice->device_type()) {
|
||||
emsdevice->name(std::move(read_flash_string(device.name)));
|
||||
emsdevice->name(device.name);
|
||||
emsdevice->add_flags(device.flags);
|
||||
}
|
||||
}
|
||||
@@ -976,14 +973,13 @@ bool EMSESP::add_device(const uint8_t device_id, const uint8_t product_id, const
|
||||
|
||||
// if we don't recognize the productID report it and add as a generic device
|
||||
if (device_p == nullptr) {
|
||||
LOG_NOTICE(F("Unrecognized EMS device (deviceID 0x%02X, productID %d). Please report on GitHub."), device_id, product_id);
|
||||
std::string name("unknown");
|
||||
LOG_NOTICE(("Unrecognized EMS device (deviceID 0x%02X, productID %d). Please report on GitHub."), device_id, product_id);
|
||||
emsdevices.push_back(
|
||||
EMSFactory::add(DeviceType::GENERIC, device_id, product_id, version, name, DeviceFlags::EMS_DEVICE_FLAG_NONE, EMSdevice::Brand::NO_BRAND));
|
||||
EMSFactory::add(DeviceType::GENERIC, device_id, product_id, version, "unknown", DeviceFlags::EMS_DEVICE_FLAG_NONE, EMSdevice::Brand::NO_BRAND));
|
||||
return false; // not found
|
||||
}
|
||||
|
||||
auto name = read_flash_string(device_p->name);
|
||||
auto name = device_p->name;
|
||||
auto device_type = device_p->device_type;
|
||||
auto flags = device_p->flags;
|
||||
|
||||
@@ -1022,14 +1018,14 @@ bool EMSESP::add_device(const uint8_t device_id, const uint8_t product_id, const
|
||||
name = "generic boiler";
|
||||
device_type = DeviceType::BOILER;
|
||||
flags = DeviceFlags::EMS_DEVICE_FLAG_HEATPUMP;
|
||||
LOG_WARNING(F("Unknown EMS boiler. Using generic profile. Please report on GitHub."));
|
||||
LOG_WARNING("Unknown EMS boiler. Using generic profile. Please report on GitHub.");
|
||||
} else {
|
||||
LOG_WARNING(F("Unrecognized EMS device (device ID 0x%02X, no product ID). Please report on GitHub."), device_id);
|
||||
LOG_WARNING(("Unrecognized EMS device (device ID 0x%02X, no product ID). Please report on GitHub."), device_id);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
LOG_DEBUG(F("Adding new device %s (deviceID 0x%02X, productID %d, version %s)"), name.c_str(), device_id, product_id, version);
|
||||
LOG_DEBUG(("Adding new device %s (deviceID 0x%02X, productID %d, version %s)"), name, device_id, product_id, version);
|
||||
emsdevices.push_back(EMSFactory::add(device_type, device_id, product_id, version, name, flags, brand));
|
||||
|
||||
// assign a unique ID. Note that this is not actual unique after a restart as it's dependent on the order that devices are found
|
||||
@@ -1043,7 +1039,7 @@ bool EMSESP::add_device(const uint8_t device_id, const uint8_t product_id, const
|
||||
fetch_device_values(device_id); // go and fetch its data
|
||||
|
||||
// Print to LOG showing we've added a new device
|
||||
LOG_INFO(F("Recognized new %s with deviceID 0x%02X"), EMSdevice::device_type_2_device_name(device_type).c_str(), device_id);
|
||||
LOG_INFO("Recognized new %s with deviceID 0x%02X", EMSdevice::device_type_2_device_name(device_type).c_str(), device_id);
|
||||
|
||||
// add command commands for all devices, except for connect, controller and gateway
|
||||
if ((device_type == DeviceType::CONNECT) || (device_type == DeviceType::CONTROLLER) || (device_type == DeviceType::GATEWAY)) {
|
||||
@@ -1059,7 +1055,7 @@ bool EMSESP::add_device(const uint8_t device_id, const uint8_t product_id, const
|
||||
F_(info_cmd));
|
||||
Command::add(
|
||||
device_type,
|
||||
F("values"),
|
||||
("values"),
|
||||
[device_type](const char * value, const int8_t id, JsonObject & output) {
|
||||
return command_info(device_type, output, id, EMSdevice::OUTPUT_TARGET::API_SHORTNAMES); // HIDDEN command showing short names, used in e.g. /api/boiler
|
||||
},
|
||||
@@ -1178,7 +1174,7 @@ void EMSESP::incoming_telegram(uint8_t * data, const uint8_t length) {
|
||||
Roomctrl::check((data[1] ^ 0x80 ^ rxservice_.ems_mask()), data);
|
||||
#ifdef EMSESP_UART_DEBUG
|
||||
// get_uptime is only updated once per loop, does not give the right time
|
||||
LOG_TRACE(F("[UART_DEBUG] Echo after %d ms: %s"), ::millis() - rx_time_, Helpers::data_to_hex(data, length).c_str());
|
||||
LOG_TRACE("[UART_DEBUG] Echo after %d ms: %s", ::millis() - rx_time_, Helpers::data_to_hex(data, length).c_str());
|
||||
#endif
|
||||
// add to RxQueue for log/watch
|
||||
rxservice_.add(data, length);
|
||||
@@ -1194,14 +1190,14 @@ void EMSESP::incoming_telegram(uint8_t * data, const uint8_t length) {
|
||||
// if we're waiting on a Write operation, we want a single byte 1 or 4
|
||||
if ((tx_state == Telegram::Operation::TX_WRITE) && (length == 1)) {
|
||||
if (first_value == TxService::TX_WRITE_SUCCESS) {
|
||||
LOG_DEBUG(F("Last Tx write successful"));
|
||||
LOG_DEBUG("Last Tx write successful");
|
||||
txservice_.increment_telegram_write_count(); // last tx/write was confirmed ok
|
||||
txservice_.send_poll(); // close the bus
|
||||
publish_id_ = txservice_.post_send_query(); // follow up with any post-read if set
|
||||
txservice_.reset_retry_count();
|
||||
tx_successful = true;
|
||||
} else if (first_value == TxService::TX_WRITE_FAIL) {
|
||||
LOG_ERROR(F("Last Tx write rejected by host"));
|
||||
LOG_ERROR("Last Tx write rejected by host");
|
||||
txservice_.send_poll(); // close the bus
|
||||
txservice_.reset_retry_count();
|
||||
}
|
||||
@@ -1210,7 +1206,7 @@ void EMSESP::incoming_telegram(uint8_t * data, const uint8_t length) {
|
||||
uint8_t src = data[0];
|
||||
uint8_t dest = data[1];
|
||||
if (txservice_.is_last_tx(src, dest)) {
|
||||
LOG_DEBUG(F("Last Tx read successful"));
|
||||
LOG_DEBUG("Last Tx read successful");
|
||||
txservice_.increment_telegram_read_count();
|
||||
txservice_.send_poll(); // close the bus
|
||||
txservice_.reset_retry_count();
|
||||
@@ -1252,11 +1248,11 @@ void EMSESP::incoming_telegram(uint8_t * data, const uint8_t length) {
|
||||
#ifdef EMSESP_UART_DEBUG
|
||||
char s[4];
|
||||
if (first_value & 0x80) {
|
||||
LOG_TRACE(F("[UART_DEBUG] next Poll %s after %d ms"), Helpers::hextoa(s, first_value), ::millis() - rx_time_);
|
||||
LOG_TRACE("[UART_DEBUG] next Poll %s after %d ms", Helpers::hextoa(s, first_value), ::millis() - rx_time_);
|
||||
// time measurement starts here, use millis because get_uptime is only updated once per loop
|
||||
rx_time_ = ::millis();
|
||||
} else {
|
||||
LOG_TRACE(F("[UART_DEBUG] Poll ack %s after %d ms"), Helpers::hextoa(s, first_value), ::millis() - rx_time_);
|
||||
LOG_TRACE("[UART_DEBUG] Poll ack %s after %d ms", Helpers::hextoa(s, first_value), ::millis() - rx_time_);
|
||||
}
|
||||
#endif
|
||||
// check for poll to us, if so send top message from Tx queue immediately and quit
|
||||
@@ -1268,7 +1264,7 @@ void EMSESP::incoming_telegram(uint8_t * data, const uint8_t length) {
|
||||
return;
|
||||
} else {
|
||||
#ifdef EMSESP_UART_DEBUG
|
||||
LOG_TRACE(F("[UART_DEBUG] Reply after %d ms: %s"), ::millis() - rx_time_, Helpers::data_to_hex(data, length).c_str());
|
||||
LOG_TRACE("[UART_DEBUG] Reply after %d ms: %s", ::millis() - rx_time_, Helpers::data_to_hex(data, length).c_str());
|
||||
#endif
|
||||
Roomctrl::check((data[1] ^ 0x80 ^ rxservice_.ems_mask()), data); // check if there is a message for the roomcontroller
|
||||
|
||||
@@ -1293,14 +1289,14 @@ void EMSESP::start() {
|
||||
webLogService.begin(); // start web log service. now we can start capturing logs to the web log
|
||||
|
||||
#ifdef EMSESP_DEBUG
|
||||
LOG_NOTICE(F("System is running in Debug mode"));
|
||||
LOG_NOTICE("System is running in Debug mode");
|
||||
#endif
|
||||
|
||||
LOG_INFO(F("Last system reset reason Core0: %s, Core1: %s"), system_.reset_reason(0).c_str(), system_.reset_reason(1).c_str());
|
||||
LOG_INFO("Last system reset reason Core0: %s, Core1: %s", system_.reset_reason(0).c_str(), system_.reset_reason(1).c_str());
|
||||
|
||||
// do any system upgrades
|
||||
if (system_.check_upgrade()) {
|
||||
LOG_INFO(F("System needs a restart to apply new settings. Please wait."));
|
||||
LOG_INFO("System needs a restart to apply new settings. Please wait.");
|
||||
system_.system_restart();
|
||||
};
|
||||
|
||||
@@ -1316,7 +1312,7 @@ void EMSESP::start() {
|
||||
// start all the EMS-ESP services
|
||||
mqtt_.start(); // mqtt init
|
||||
system_.start(); // starts commands, led, adc, button, network, syslog & uart
|
||||
LOG_INFO(F("Starting EMS-ESP version %s (hostname: %s)"), EMSESP_APP_VERSION, system_.hostname().c_str()); // welcome message
|
||||
LOG_INFO(("Starting EMS-ESP version %s (hostname: %s)"), EMSESP_APP_VERSION, system_.hostname().c_str()); // welcome message
|
||||
|
||||
shower_.start(); // initialize shower timer and shower alert
|
||||
dallassensor_.start(); // Dallas external sensors
|
||||
@@ -1327,7 +1323,7 @@ void EMSESP::start() {
|
||||
device_library_ = {
|
||||
#include "device_library.h"
|
||||
};
|
||||
LOG_INFO(F("Loaded EMS device library (%d records)"), device_library_.size());
|
||||
LOG_INFO(("Loaded EMS device library (%d records)"), device_library_.size());
|
||||
|
||||
#if defined(EMSESP_STANDALONE)
|
||||
Mqtt::on_connect(); // simulate an MQTT connection
|
||||
@@ -1344,6 +1340,7 @@ void EMSESP::scheduled_fetch_values() {
|
||||
last_fetch_ = uuid::get_uptime();
|
||||
no = 1;
|
||||
}
|
||||
|
||||
if (txservice_.tx_queue_empty()) {
|
||||
uint8_t i = 0;
|
||||
for (const auto & emsdevice : emsdevices) {
|
||||
|
||||
Reference in New Issue
Block a user