diff --git a/src/boiler.cpp b/src/boiler.cpp index d6edcb6c8..5d03e02a0 100644 --- a/src/boiler.cpp +++ b/src/boiler.cpp @@ -49,6 +49,8 @@ Boiler::Boiler(uint8_t device_type, int8_t device_id, uint8_t product_id, const LOG_DEBUG(F("Registering new Boiler with device ID 0x%02X"), device_id); // the telegram handlers... + register_telegram_type(0x10, F("UBAErrorMessage1"), false, nullptr); + register_telegram_type(0x11, F("UBAErrorMessage2"), false, nullptr); register_telegram_type(0x18, F("UBAMonitorFast"), false, std::bind(&Boiler::process_UBAMonitorFast, this, _1)); register_telegram_type(0x19, F("UBAMonitorSlow"), true, std::bind(&Boiler::process_UBAMonitorSlow, this, _1)); register_telegram_type(0x34, F("UBAMonitorWW"), false, std::bind(&Boiler::process_UBAMonitorWW, this, _1)); diff --git a/src/emsesp.cpp b/src/emsesp.cpp index 49aa3a772..2bb15bbdd 100644 --- a/src/emsesp.cpp +++ b/src/emsesp.cpp @@ -584,9 +584,11 @@ void EMSESP::incoming_telegram(uint8_t * data, const uint8_t length) { txservice_.send_poll(); // close the bus txservice_.post_send_query(); // follow up with any post-read tx_successful = true; + txservice_.reset_retry_count(); } else if (first_value == TxService::TX_WRITE_FAIL) { LOG_ERROR(F("Last Tx write rejected by host")); txservice_.send_poll(); // close the bus + txservice_.reset_retry_count(); } } else { // got a telegram with data in it. See if the src/dest matches that from the last one we sent @@ -597,6 +599,7 @@ void EMSESP::incoming_telegram(uint8_t * data, const uint8_t length) { LOG_DEBUG(F("Last Tx read successful")); txservice_.increment_telegram_read_count(); txservice_.send_poll(); // close the bus + txservice_.reset_retry_count(); tx_successful = true; } } @@ -605,6 +608,9 @@ void EMSESP::incoming_telegram(uint8_t * data, const uint8_t length) { if (!tx_successful) { // the telegram we got wasn't what we had requested // So re-send the last Tx and increment retry count +#ifdef EMSESP_DEBUG + LOG_DEBUG(F("send: %s, received: %s"), txservice_.last_tx_to_string().c_str(), Helpers::data_to_hex(data, length).c_str()); +#endif uint8_t retries = txservice_.retry_tx(); // returns 0 if exceeded count if (retries) { LOG_ERROR(F("Last Tx operation failed. Retrying #%d..."), retries); @@ -810,8 +816,8 @@ void EMSESP::start() { }; system_.start(); - console_.start(); network_.start(); + console_.start(); sensors_.start(); rxservice_.start(); txservice_.start(); diff --git a/src/sensors.cpp b/src/sensors.cpp index 554c005d5..d9457ee93 100644 --- a/src/sensors.cpp +++ b/src/sensors.cpp @@ -60,6 +60,7 @@ void Sensors::loop() { if (time_now - last_activity_ >= READ_INTERVAL_MS) { // LOG_DEBUG(F("Read sensor temperature")); // uncomment for debug if (bus_.reset()) { + yield(); bus_.skip(); bus_.write(CMD_CONVERT_TEMP); @@ -151,18 +152,17 @@ float Sensors::get_temperature_c(const uint8_t addr[]) { LOG_ERROR(F("Bus reset failed before reading scratchpad from %s"), Device(addr).to_string().c_str()); return NAN; } - + yield(); uint8_t scratchpad[SCRATCHPAD_LEN] = {0}; - bus_.select(addr); bus_.write(CMD_READ_SCRATCHPAD); bus_.read_bytes(scratchpad, SCRATCHPAD_LEN); - + yield(); if (!bus_.reset()) { LOG_ERROR(F("Bus reset failed after reading scratchpad from %s"), Device(addr).to_string().c_str()); return NAN; } - + yield(); if (bus_.crc8(scratchpad, SCRATCHPAD_LEN - 1) != scratchpad[SCRATCHPAD_LEN - 1]) { LOG_WARNING(F("Invalid scratchpad CRC: %02X%02X%02X%02X%02X%02X%02X%02X%02X from device %s"), scratchpad[0], diff --git a/src/telegram.cpp b/src/telegram.cpp index 3187a64cd..95807e678 100644 --- a/src/telegram.cpp +++ b/src/telegram.cpp @@ -489,6 +489,8 @@ void TxService::send_telegram(const QueuedTxTelegram & tx_telegram) { if (status != EMS_TX_STATUS_OK) { LOG_ERROR(F("Failed to transmit Tx via UART. Error: %s"), status == EMS_TX_WTD_TIMEOUT ? F("Timeout") : F("BRK")); + tx_waiting(false); // nothing send, tx not in wait state + return; } tx_waiting(true); // tx now in a wait state diff --git a/src/uart/emsuart_esp32.cpp b/src/uart/emsuart_esp32.cpp index 11ac5dc05..7cef6668b 100644 --- a/src/uart/emsuart_esp32.cpp +++ b/src/uart/emsuart_esp32.cpp @@ -32,9 +32,6 @@ static intr_handle_t uart_handle; static RingbufHandle_t buf_handle = NULL; static bool drop_next_rx = true; static uint8_t tx_mode_ = 0xFF; -static uint32_t emsRxTime; - -#define EMS_RX_TO_TX_TIMEOUT 20 /* * Task to handle the incoming data @@ -72,7 +69,6 @@ void IRAM_ATTR EMSuart::emsuart_rx_intr_handler(void * para) { if ((!drop_next_rx) && ((length == 2) || (length > 4))) { int baseType = 0; xRingbufferSendFromISR(buf_handle, rxbuf, length - 1, &baseType); - emsRxTime = millis(); } drop_next_rx = false; } @@ -103,7 +99,7 @@ void EMSuart::start(uint8_t tx_mode) { drop_next_rx = true; buf_handle = xRingbufferCreate(128, RINGBUF_TYPE_NOSPLIT); ESP_ERROR_CHECK(uart_isr_register(EMSUART_UART, emsuart_rx_intr_handler, NULL, ESP_INTR_FLAG_IRAM, &uart_handle)); - xTaskCreate(emsuart_recvTask, "emsuart_recvTask", 2048, NULL, 12, NULL); + xTaskCreate(emsuart_recvTask, "emsuart_recvTask", 2048, NULL, configMAX_PRIORITIES -1, NULL); EMS_UART.int_ena.brk_det = 1; // activate only break } @@ -139,9 +135,6 @@ void EMSuart::send_poll(uint8_t data) { * returns code, 1=success */ EMSUART_STATUS EMSuart::transmit(uint8_t * buf, uint8_t len) { - if (millis() - emsRxTime > EMS_RX_TO_TX_TIMEOUT) { - return EMS_TX_WTD_TIMEOUT; - } if (len > 0) { for (uint8_t i = 0; i < len; i++) { EMS_UART.fifo.rw_byte = buf[i]; diff --git a/src/uart/emsuart_esp8266.cpp b/src/uart/emsuart_esp8266.cpp index 7b12cf72f..ae317922d 100644 --- a/src/uart/emsuart_esp8266.cpp +++ b/src/uart/emsuart_esp8266.cpp @@ -24,8 +24,10 @@ namespace emsesp { -os_event_t recvTaskQueue[EMSUART_recvTaskQueueLen]; // our Rx queue +MAKE_PSTR(logger_name, "emsuart") +uuid::log::Logger EMSuart::logger_{F_(logger_name), uuid::log::Facility::CONSOLE}; +os_event_t recvTaskQueue[EMSUART_recvTaskQueueLen]; // our Rx queue EMSuart::EMSRxBuf_t * pEMSRxBuf; EMSuart::EMSRxBuf_t * paEMSRxBuf[EMS_MAXBUFFERS]; uint8_t emsRxBufIdx = 0; @@ -34,8 +36,6 @@ uint8_t tx_mode_ = 0xFF; bool drop_next_rx = true; uint32_t emsRxTime; -#define EMS_RX_TO_TX_TIMEOUT 20 - // // Main interrupt handler // Important: must not use ICACHE_FLASH_ATTR @@ -46,7 +46,7 @@ void ICACHE_RAM_ATTR EMSuart::emsuart_rx_intr_handler(void * para) { if (USIS(EMSUART_UART) & ((1 << UIBD))) { // BREAK detection = End of EMS data block length = 0; - while ((USS(EMSUART_UART) >> USRXC) & 0xFF) { // read fifo into buffer + while ((USS(EMSUART_UART) >> USRXC) & 0x0FF) { // read fifo into buffer uint8_t rx = USF(EMSUART_UART); if (length < EMS_MAXBUFFERSIZE) { uart_buffer[length++] = rx; @@ -59,7 +59,7 @@ void ICACHE_RAM_ATTR EMSuart::emsuart_rx_intr_handler(void * para) { if (!drop_next_rx) { 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 - emsRxTime = millis(); + emsRxTime = uuid::get_uptime(); } drop_next_rx = false; system_os_post(EMSUART_recvTaskPrio, 0, 0); // call emsuart_recvTask() at next opportunity @@ -249,9 +249,12 @@ EMSUART_STATUS ICACHE_FLASH_ATTR EMSuart::transmit(uint8_t * buf, uint8_t len) { if (len == 0) { return EMS_TX_STATUS_OK; // nothing to send } - if (millis() > (emsRxTime + EMS_RX_TO_TX_TIMEOUT)) { // send allowed within 20 ms - return EMS_TX_WTD_TIMEOUT; - } +#ifdef EMSESP_DEBUG + LOG_INFO(F("UART Responsetime: %d ms"),uuid::get_uptime() - emsRxTime); +#endif + // if ((uuid::get_uptime() - emsRxTime) > EMS_RX_TO_TX_TIMEOUT)) { // send allowed within 20 ms + // return EMS_TX_WTD_TIMEOUT; + // } // new code from Michael. See https://github.com/proddy/EMS-ESP/issues/380 if (tx_mode_ == EMS_TXMODE_NEW) { diff --git a/src/uart/emsuart_esp8266.h b/src/uart/emsuart_esp8266.h index d0b7eec99..81a2009ec 100644 --- a/src/uart/emsuart_esp8266.h +++ b/src/uart/emsuart_esp8266.h @@ -22,6 +22,7 @@ #include #include +#include #define EMSUART_UART 0 // UART 0 #define EMSUART_CONFIG 0x1C // 8N1 (8 bits, no stop bits, 1 parity) @@ -30,7 +31,7 @@ #define EMS_MAXBUFFERS 3 // buffers for circular filling to avoid collisions #define EMS_MAXBUFFERSIZE 33 // max size of the buffer. EMS packets are max 32 bytes, plus extra 2 for BRKs -#define EMSUART_recvTaskPrio 1 // 0, 1 or 2. 0 being the lowest +#define EMSUART_recvTaskPrio 2 // 0, 1 or 2. 0 being the lowest #define EMSUART_recvTaskQueueLen 10 // number of queued Rx triggers #define EMS_TXMODE_DEFAULT 1 @@ -47,7 +48,7 @@ #define EMSUART_TX_LAG 8 #define EMSUART_BUSY_WAIT (EMSUART_BIT_TIME / 8) #define EMS_TX_TO_CHARS (2 + 20) -#define EMS_TX_TO_COUNT ((EMS_TX_TO_CHARS)*8*10) +#define EMS_TX_TO_COUNT ((EMS_TX_TO_CHARS)*8) namespace emsesp { @@ -74,9 +75,10 @@ class EMSuart { } EMSRxBuf_t; private: + // static constexpr uint32_t EMS_RX_TO_TX_TIMEOUT = 20; + static uuid::log::Logger logger_; static void ICACHE_RAM_ATTR emsuart_rx_intr_handler(void * para); static void ICACHE_FLASH_ATTR emsuart_recvTask(os_event_t * events); - static void ICACHE_FLASH_ATTR emsuart_flush_fifos(); static void ICACHE_FLASH_ATTR tx_brk(); };