[modbus] Frame accessors, PDU-relative lengths, and span-based send_pdu (#17846)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Bonne Eggleston
2026-07-25 03:09:05 +00:00
committed by GitHub
co-authored by Claude Fable 5
parent 58385bebff
commit eaa79b3696
10 changed files with 366 additions and 81 deletions
@@ -298,6 +298,17 @@ class ModbusController final : public PollingComponent, public modbus::ModbusCli
/// queues a modbus command in the send queue
void queue_command(const ModbusCommandItem &command);
/// Sends a raw payload (address byte + PDU, no CRC) with responses routed back to this controller.
/// The payload carries its own address byte, which may differ from this controller's address.
/// Deliberately shadows the deprecated ModbusClientDevice::send_raw() with identical semantics:
/// controller-level raw sends stay supported until the command machinery is replaced.
void send_raw(const std::vector<uint8_t> &payload) {
if (payload.empty()) {
this->on_not_sent(); // match the hub-level send_raw(): a refused send is always signalled
return;
}
this->parent_->send_pdu(payload[0], std::span<const uint8_t>(payload).subspan(1), this);
}
/// Registers a sensor with the controller. Called by esphomes code generator
void add_sensor_item(SensorItem *item) { sensorset_.insert(item); }
/// called when a modbus response was parsed without errors