mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-08 08:49:52 +03:00
@@ -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);
|
LOG_DEBUG(F("Registering new Boiler with device ID 0x%02X"), device_id);
|
||||||
|
|
||||||
// the telegram handlers...
|
// 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(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(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));
|
register_telegram_type(0x34, F("UBAMonitorWW"), false, std::bind(&Boiler::process_UBAMonitorWW, this, _1));
|
||||||
|
|||||||
@@ -584,9 +584,11 @@ void EMSESP::incoming_telegram(uint8_t * data, const uint8_t length) {
|
|||||||
txservice_.send_poll(); // close the bus
|
txservice_.send_poll(); // close the bus
|
||||||
txservice_.post_send_query(); // follow up with any post-read
|
txservice_.post_send_query(); // follow up with any post-read
|
||||||
tx_successful = true;
|
tx_successful = true;
|
||||||
|
txservice_.reset_retry_count();
|
||||||
} else if (first_value == TxService::TX_WRITE_FAIL) {
|
} else if (first_value == TxService::TX_WRITE_FAIL) {
|
||||||
LOG_ERROR(F("Last Tx write rejected by host"));
|
LOG_ERROR(F("Last Tx write rejected by host"));
|
||||||
txservice_.send_poll(); // close the bus
|
txservice_.send_poll(); // close the bus
|
||||||
|
txservice_.reset_retry_count();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// got a telegram with data in it. See if the src/dest matches that from the last one we sent
|
// 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"));
|
LOG_DEBUG(F("Last Tx read successful"));
|
||||||
txservice_.increment_telegram_read_count();
|
txservice_.increment_telegram_read_count();
|
||||||
txservice_.send_poll(); // close the bus
|
txservice_.send_poll(); // close the bus
|
||||||
|
txservice_.reset_retry_count();
|
||||||
tx_successful = true;
|
tx_successful = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -605,6 +608,9 @@ void EMSESP::incoming_telegram(uint8_t * data, const uint8_t length) {
|
|||||||
if (!tx_successful) {
|
if (!tx_successful) {
|
||||||
// the telegram we got wasn't what we had requested
|
// the telegram we got wasn't what we had requested
|
||||||
// So re-send the last Tx and increment retry count
|
// 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
|
uint8_t retries = txservice_.retry_tx(); // returns 0 if exceeded count
|
||||||
if (retries) {
|
if (retries) {
|
||||||
LOG_ERROR(F("Last Tx operation failed. Retrying #%d..."), retries);
|
LOG_ERROR(F("Last Tx operation failed. Retrying #%d..."), retries);
|
||||||
@@ -810,8 +816,8 @@ void EMSESP::start() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
system_.start();
|
system_.start();
|
||||||
console_.start();
|
|
||||||
network_.start();
|
network_.start();
|
||||||
|
console_.start();
|
||||||
sensors_.start();
|
sensors_.start();
|
||||||
rxservice_.start();
|
rxservice_.start();
|
||||||
txservice_.start();
|
txservice_.start();
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ void Sensors::loop() {
|
|||||||
if (time_now - last_activity_ >= READ_INTERVAL_MS) {
|
if (time_now - last_activity_ >= READ_INTERVAL_MS) {
|
||||||
// LOG_DEBUG(F("Read sensor temperature")); // uncomment for debug
|
// LOG_DEBUG(F("Read sensor temperature")); // uncomment for debug
|
||||||
if (bus_.reset()) {
|
if (bus_.reset()) {
|
||||||
|
yield();
|
||||||
bus_.skip();
|
bus_.skip();
|
||||||
bus_.write(CMD_CONVERT_TEMP);
|
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());
|
LOG_ERROR(F("Bus reset failed before reading scratchpad from %s"), Device(addr).to_string().c_str());
|
||||||
return NAN;
|
return NAN;
|
||||||
}
|
}
|
||||||
|
yield();
|
||||||
uint8_t scratchpad[SCRATCHPAD_LEN] = {0};
|
uint8_t scratchpad[SCRATCHPAD_LEN] = {0};
|
||||||
|
|
||||||
bus_.select(addr);
|
bus_.select(addr);
|
||||||
bus_.write(CMD_READ_SCRATCHPAD);
|
bus_.write(CMD_READ_SCRATCHPAD);
|
||||||
bus_.read_bytes(scratchpad, SCRATCHPAD_LEN);
|
bus_.read_bytes(scratchpad, SCRATCHPAD_LEN);
|
||||||
|
yield();
|
||||||
if (!bus_.reset()) {
|
if (!bus_.reset()) {
|
||||||
LOG_ERROR(F("Bus reset failed after reading scratchpad from %s"), Device(addr).to_string().c_str());
|
LOG_ERROR(F("Bus reset failed after reading scratchpad from %s"), Device(addr).to_string().c_str());
|
||||||
return NAN;
|
return NAN;
|
||||||
}
|
}
|
||||||
|
yield();
|
||||||
if (bus_.crc8(scratchpad, SCRATCHPAD_LEN - 1) != scratchpad[SCRATCHPAD_LEN - 1]) {
|
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"),
|
LOG_WARNING(F("Invalid scratchpad CRC: %02X%02X%02X%02X%02X%02X%02X%02X%02X from device %s"),
|
||||||
scratchpad[0],
|
scratchpad[0],
|
||||||
|
|||||||
@@ -489,6 +489,8 @@ void TxService::send_telegram(const QueuedTxTelegram & tx_telegram) {
|
|||||||
|
|
||||||
if (status != EMS_TX_STATUS_OK) {
|
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"));
|
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
|
tx_waiting(true); // tx now in a wait state
|
||||||
|
|||||||
@@ -32,9 +32,6 @@ static intr_handle_t uart_handle;
|
|||||||
static RingbufHandle_t buf_handle = NULL;
|
static RingbufHandle_t buf_handle = NULL;
|
||||||
static bool drop_next_rx = true;
|
static bool drop_next_rx = true;
|
||||||
static uint8_t tx_mode_ = 0xFF;
|
static uint8_t tx_mode_ = 0xFF;
|
||||||
static uint32_t emsRxTime;
|
|
||||||
|
|
||||||
#define EMS_RX_TO_TX_TIMEOUT 20
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Task to handle the incoming data
|
* 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))) {
|
if ((!drop_next_rx) && ((length == 2) || (length > 4))) {
|
||||||
int baseType = 0;
|
int baseType = 0;
|
||||||
xRingbufferSendFromISR(buf_handle, rxbuf, length - 1, &baseType);
|
xRingbufferSendFromISR(buf_handle, rxbuf, length - 1, &baseType);
|
||||||
emsRxTime = millis();
|
|
||||||
}
|
}
|
||||||
drop_next_rx = false;
|
drop_next_rx = false;
|
||||||
}
|
}
|
||||||
@@ -103,7 +99,7 @@ void EMSuart::start(uint8_t tx_mode) {
|
|||||||
drop_next_rx = true;
|
drop_next_rx = true;
|
||||||
buf_handle = xRingbufferCreate(128, RINGBUF_TYPE_NOSPLIT);
|
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));
|
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
|
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
|
* returns code, 1=success
|
||||||
*/
|
*/
|
||||||
EMSUART_STATUS EMSuart::transmit(uint8_t * buf, uint8_t len) {
|
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) {
|
if (len > 0) {
|
||||||
for (uint8_t i = 0; i < len; i++) {
|
for (uint8_t i = 0; i < len; i++) {
|
||||||
EMS_UART.fifo.rw_byte = buf[i];
|
EMS_UART.fifo.rw_byte = buf[i];
|
||||||
|
|||||||
@@ -24,8 +24,10 @@
|
|||||||
|
|
||||||
namespace emsesp {
|
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 * pEMSRxBuf;
|
||||||
EMSuart::EMSRxBuf_t * paEMSRxBuf[EMS_MAXBUFFERS];
|
EMSuart::EMSRxBuf_t * paEMSRxBuf[EMS_MAXBUFFERS];
|
||||||
uint8_t emsRxBufIdx = 0;
|
uint8_t emsRxBufIdx = 0;
|
||||||
@@ -34,8 +36,6 @@ uint8_t tx_mode_ = 0xFF;
|
|||||||
bool drop_next_rx = true;
|
bool drop_next_rx = true;
|
||||||
uint32_t emsRxTime;
|
uint32_t emsRxTime;
|
||||||
|
|
||||||
#define EMS_RX_TO_TX_TIMEOUT 20
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Main interrupt handler
|
// Main interrupt handler
|
||||||
// Important: must not use ICACHE_FLASH_ATTR
|
// 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
|
if (USIS(EMSUART_UART) & ((1 << UIBD))) { // BREAK detection = End of EMS data block
|
||||||
length = 0;
|
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);
|
uint8_t rx = USF(EMSUART_UART);
|
||||||
if (length < EMS_MAXBUFFERSIZE) {
|
if (length < EMS_MAXBUFFERSIZE) {
|
||||||
uart_buffer[length++] = rx;
|
uart_buffer[length++] = rx;
|
||||||
@@ -59,7 +59,7 @@ void ICACHE_RAM_ATTR EMSuart::emsuart_rx_intr_handler(void * para) {
|
|||||||
if (!drop_next_rx) {
|
if (!drop_next_rx) {
|
||||||
pEMSRxBuf->length = 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
|
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;
|
drop_next_rx = false;
|
||||||
system_os_post(EMSUART_recvTaskPrio, 0, 0); // call emsuart_recvTask() at next opportunity
|
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) {
|
if (len == 0) {
|
||||||
return EMS_TX_STATUS_OK; // nothing to send
|
return EMS_TX_STATUS_OK; // nothing to send
|
||||||
}
|
}
|
||||||
if (millis() > (emsRxTime + EMS_RX_TO_TX_TIMEOUT)) { // send allowed within 20 ms
|
#ifdef EMSESP_DEBUG
|
||||||
return EMS_TX_WTD_TIMEOUT;
|
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
|
// new code from Michael. See https://github.com/proddy/EMS-ESP/issues/380
|
||||||
if (tx_mode_ == EMS_TXMODE_NEW) {
|
if (tx_mode_ == EMS_TXMODE_NEW) {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#include <user_interface.h>
|
#include <user_interface.h>
|
||||||
|
#include <uuid/log.h>
|
||||||
|
|
||||||
#define EMSUART_UART 0 // UART 0
|
#define EMSUART_UART 0 // UART 0
|
||||||
#define EMSUART_CONFIG 0x1C // 8N1 (8 bits, no stop bits, 1 parity)
|
#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_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 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 EMSUART_recvTaskQueueLen 10 // number of queued Rx triggers
|
||||||
|
|
||||||
#define EMS_TXMODE_DEFAULT 1
|
#define EMS_TXMODE_DEFAULT 1
|
||||||
@@ -47,7 +48,7 @@
|
|||||||
#define EMSUART_TX_LAG 8
|
#define EMSUART_TX_LAG 8
|
||||||
#define EMSUART_BUSY_WAIT (EMSUART_BIT_TIME / 8)
|
#define EMSUART_BUSY_WAIT (EMSUART_BIT_TIME / 8)
|
||||||
#define EMS_TX_TO_CHARS (2 + 20)
|
#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 {
|
namespace emsesp {
|
||||||
|
|
||||||
@@ -74,9 +75,10 @@ class EMSuart {
|
|||||||
} EMSRxBuf_t;
|
} EMSRxBuf_t;
|
||||||
|
|
||||||
private:
|
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_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_recvTask(os_event_t * events);
|
||||||
|
|
||||||
static void ICACHE_FLASH_ATTR emsuart_flush_fifos();
|
static void ICACHE_FLASH_ATTR emsuart_flush_fifos();
|
||||||
static void ICACHE_FLASH_ATTR tx_brk();
|
static void ICACHE_FLASH_ATTR tx_brk();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user