mirror of
https://github.com/esphome/esphome.git
synced 2026-10-10 05:23:07 +00:00
[modbus] Use a numeric scheduler id for the deferred server reply (#20368)
This commit is contained in:
@@ -11,6 +11,8 @@ namespace esphome::modbus {
|
||||
|
||||
ESPHOME_LOG_TAG(TAG, "modbus");
|
||||
|
||||
static constexpr uint32_t DEFERRED_SEND_TIMEOUT_ID = 0;
|
||||
|
||||
static constexpr size_t MODBUS_MAX_LOG_BYTES = 64;
|
||||
|
||||
static constexpr uint32_t US_PER_SEC = 1000000;
|
||||
@@ -205,7 +207,7 @@ void ModbusServerHub::parse_modbus_frames() {
|
||||
while (!this->rx_buffer_.empty()) {
|
||||
if (this->deferred_payload_len_ != 0) {
|
||||
// Another frame arrived before the deferred reply went out, so the client has moved on.
|
||||
this->cancel_timeout("deferred_send");
|
||||
this->cancel_timeout(DEFERRED_SEND_TIMEOUT_ID);
|
||||
ESP_LOGD(TAG, "Dropped deferred reply to %" PRIu8 ": a new frame arrived first", this->deferred_payload_[0]);
|
||||
this->deferred_payload_len_ = 0;
|
||||
}
|
||||
@@ -1216,7 +1218,7 @@ void ModbusServerHub::send_raw_(const uint8_t *payload, uint16_t len) {
|
||||
std::memcpy(this->deferred_payload_.data(), payload, len);
|
||||
this->deferred_payload_len_ = len;
|
||||
// set_timeout() takes milliseconds; round the microsecond delay up so we never fire early.
|
||||
this->set_timeout("deferred_send", (this->tx_delay_remaining() + US_PER_MS - 1) / US_PER_MS, [this]() {
|
||||
this->set_timeout(DEFERRED_SEND_TIMEOUT_ID, (this->tx_delay_remaining() + US_PER_MS - 1) / US_PER_MS, [this]() {
|
||||
ModbusFrame frame(this->deferred_payload_[0], this->deferred_payload_.data() + 1,
|
||||
this->deferred_payload_len_ - 1);
|
||||
this->deferred_payload_len_ = 0;
|
||||
|
||||
Reference in New Issue
Block a user