1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-12 00:02:21 +01:00

Improve DSMR read timeout handling (#2699)

This commit is contained in:
Maurice Makaay
2021-11-29 16:40:53 +01:00
committed by GitHub
parent cae283dc86
commit adf48246a9
6 changed files with 136 additions and 100 deletions

View File

@@ -52,6 +52,7 @@ class UARTComponent {
void set_tx_pin(InternalGPIOPin *tx_pin) { this->tx_pin_ = tx_pin; }
void set_rx_pin(InternalGPIOPin *rx_pin) { this->rx_pin_ = rx_pin; }
void set_rx_buffer_size(size_t rx_buffer_size) { this->rx_buffer_size_ = rx_buffer_size; }
size_t get_rx_buffer_size() { return this->rx_buffer_size_; }
void set_stop_bits(uint8_t stop_bits) { this->stop_bits_ = stop_bits; }
uint8_t get_stop_bits() const { return this->stop_bits_; }

View File

@@ -90,6 +90,11 @@ void UARTDummyReceiver::loop() {
}
}
// In the upcoming log functions, a delay was added after all log calls.
// This is done to allow the system to ship the log lines via the API
// TCP connection(s). Without these delays, debug log lines could go
// missing when UART devices block the main loop for too long.
void UARTDebug::log_hex(UARTDirection direction, std::vector<uint8_t> bytes, uint8_t separator) {
std::string res;
if (direction == UART_DIRECTION_RX) {
@@ -107,6 +112,7 @@ void UARTDebug::log_hex(UARTDirection direction, std::vector<uint8_t> bytes, uin
res += buf;
}
ESP_LOGD(TAG, "%s", res.c_str());
delay(10);
}
void UARTDebug::log_string(UARTDirection direction, std::vector<uint8_t> bytes) {
@@ -150,6 +156,7 @@ void UARTDebug::log_string(UARTDirection direction, std::vector<uint8_t> bytes)
}
res += '"';
ESP_LOGD(TAG, "%s", res.c_str());
delay(10);
}
void UARTDebug::log_int(UARTDirection direction, std::vector<uint8_t> bytes, uint8_t separator) {
@@ -167,6 +174,7 @@ void UARTDebug::log_int(UARTDirection direction, std::vector<uint8_t> bytes, uin
res += to_string(bytes[i]);
}
ESP_LOGD(TAG, "%s", res.c_str());
delay(10);
}
void UARTDebug::log_binary(UARTDirection direction, std::vector<uint8_t> bytes, uint8_t separator) {
@@ -186,6 +194,7 @@ void UARTDebug::log_binary(UARTDirection direction, std::vector<uint8_t> bytes,
res += buf;
}
ESP_LOGD(TAG, "%s", res.c_str());
delay(10);
}
} // namespace uart