ESPHome
2022.6.2
|
Modbus controller class. More...
#include <modbus_controller.h>
Public Member Functions | |
ModbusController (uint16_t throttle=0) | |
void | dump_config () override |
void | loop () override |
void | setup () override |
void | update () override |
void | queue_command (const ModbusCommandItem &command) |
queues a modbus command in the send queue More... | |
void | add_sensor_item (SensorItem *item) |
Registers a sensor with the controller. Called by esphomes code generator. More... | |
void | on_modbus_data (const std::vector< uint8_t > &data) override |
called when a modbus response was parsed without errors More... | |
void | on_modbus_error (uint8_t function_code, uint8_t exception_code) override |
called when a modbus error response was received More... | |
void | on_register_data (ModbusRegisterType register_type, uint16_t start_address, const std::vector< uint8_t > &data) |
default delegate called by process_modbus_data when a response has retrieved from the incoming queue More... | |
void | on_write_register_response (ModbusRegisterType register_type, uint16_t start_address, const std::vector< uint8_t > &data) |
default delegate called by process_modbus_data when a response for a write response has retrieved from the incoming queue More... | |
void | set_command_throttle (uint16_t command_throttle) |
called by esphome generated code to set the command_throttle period More... | |
![]() | |
PollingComponent () | |
PollingComponent (uint32_t update_interval) | |
Initialize this polling component with the given update interval in ms. More... | |
virtual void | set_update_interval (uint32_t update_interval) |
Manually set the update interval in ms for this polling object. More... | |
void | call_setup () override |
virtual uint32_t | get_update_interval () const |
Get the update interval in ms of this sensor. More... | |
![]() | |
virtual float | get_setup_priority () const |
priority of setup(). More... | |
float | get_actual_setup_priority () const |
void | set_setup_priority (float priority) |
virtual float | get_loop_priority () const |
priority of loop(). More... | |
void | call () |
virtual void | on_shutdown () |
virtual void | on_safe_shutdown () |
uint32_t | get_component_state () const |
virtual void | mark_failed () |
Mark this component as failed. More... | |
bool | is_failed () |
virtual bool | can_proceed () |
bool | status_has_warning () |
bool | status_has_error () |
void | status_set_warning () |
void | status_set_error () |
void | status_clear_warning () |
void | status_clear_error () |
void | status_momentary_warning (const std::string &name, uint32_t length=5000) |
void | status_momentary_error (const std::string &name, uint32_t length=5000) |
bool | has_overridden_loop () const |
void | set_component_source (const char *source) |
Set where this component was loaded from for some debug messages. More... | |
const char * | get_component_source () const |
Get the integration where this component was declared as a string. More... | |
![]() | |
void | set_parent (Modbus *parent) |
void | set_address (uint8_t address) |
void | send (uint8_t function, uint16_t start_address, uint16_t number_of_entities, uint8_t payload_len=0, const uint8_t *payload=nullptr) |
void | send_raw (const std::vector< uint8_t > &payload) |
bool | waiting_for_response () |
Protected Member Functions | |
size_t | create_register_ranges_ () |
parse sensormap_ and create range of sequential addresses More... | |
SensorSet | find_sensors_ (ModbusRegisterType register_type, uint16_t start_address) const |
void | update_range_ (RegisterRange &r) |
submit the read command for the address range to the send queue More... | |
void | process_modbus_data_ (const ModbusCommandItem *response) |
parse incoming modbus data More... | |
bool | send_next_command_ () |
send the next modbus command from the send queue More... | |
size_t | get_command_queue_length_ () |
get the number of queued modbus commands (should be mostly empty) More... | |
void | dump_sensors_ () |
dump the parsed sensormap for diagnostics More... | |
![]() | |
virtual void | call_loop () |
virtual void | call_dump_config () |
void | set_interval (const std::string &name, uint32_t interval, std::function< void()> &&f) |
Set an interval function with a unique name. More... | |
void | set_interval (uint32_t interval, std::function< void()> &&f) |
bool | cancel_interval (const std::string &name) |
Cancel an interval function. More... | |
void | set_retry (const std::string &name, uint32_t initial_wait_time, uint8_t max_attempts, std::function< RetryResult()> &&f, float backoff_increase_factor=1.0f) |
Set an retry function with a unique name. More... | |
void | set_retry (uint32_t initial_wait_time, uint8_t max_attempts, std::function< RetryResult()> &&f, float backoff_increase_factor=1.0f) |
bool | cancel_retry (const std::string &name) |
Cancel a retry function. More... | |
void | set_timeout (const std::string &name, uint32_t timeout, std::function< void()> &&f) |
Set a timeout function with a unique name. More... | |
void | set_timeout (uint32_t timeout, std::function< void()> &&f) |
bool | cancel_timeout (const std::string &name) |
Cancel a timeout function. More... | |
void | defer (const std::string &name, std::function< void()> &&f) |
Defer a callback to the next loop() call. More... | |
void | defer (std::function< void()> &&f) |
Defer a callback to the next loop() call. More... | |
bool | cancel_defer (const std::string &name) |
Cancel a defer callback using the specified name, name must not be empty. More... | |
Protected Attributes | |
SensorSet | sensorset_ |
Collection of all sensors for this component. More... | |
std::vector< RegisterRange > | register_ranges_ |
Continous range of modbus registers. More... | |
std::list< std::unique_ptr< ModbusCommandItem > > | command_queue_ |
Hold the pending requests to be sent. More... | |
std::queue< std::unique_ptr< ModbusCommandItem > > | incoming_queue_ |
modbus response data waiting to get processed More... | |
uint32_t | last_command_timestamp_ |
when was the last send operation More... | |
uint16_t | command_throttle_ |
min time in ms between sending modbus commands More... | |
![]() | |
uint32_t | update_interval_ |
![]() | |
uint32_t | component_state_ {0x0000} |
State of this component. More... | |
float | setup_priority_override_ {NAN} |
const char * | component_source_ = nullptr |
![]() | |
friend | Modbus |
Modbus * | parent_ |
uint8_t | address_ |
Modbus controller class.
Each instance handles the modbus commuinication for all sensors with the same modbus address
all sensor items (sensors, switches, binarysensor ...) are parsed in modbus address ranges. when esphome calls ModbusController::Update the commands for each range are created and sent Responses for the commands are dispatched to the modbus sensor items.
Definition at line 408 of file modbus_controller.h.
|
inline |
Definition at line 410 of file modbus_controller.h.
|
inline |
Registers a sensor with the controller. Called by esphomes code generator.
Definition at line 419 of file modbus_controller.h.
|
protected |
parse sensormap_ and create range of sequential addresses
Definition at line 169 of file modbus_controller.cpp.
|
overridevirtual |
Reimplemented from esphome::Component.
Definition at line 275 of file modbus_controller.cpp.
|
protected |
dump the parsed sensormap for diagnostics
Definition at line 312 of file modbus_controller.cpp.
|
protected |
Definition at line 82 of file modbus_controller.cpp.
|
inlineprotected |
get the number of queued modbus commands (should be mostly empty)
Definition at line 445 of file modbus_controller.h.
|
overridevirtual |
Reimplemented from esphome::Component.
Definition at line 293 of file modbus_controller.cpp.
|
overridevirtual |
called when a modbus response was parsed without errors
Implements esphome::modbus::ModbusDevice.
Definition at line 49 of file modbus_controller.cpp.
|
overridevirtual |
called when a modbus error response was received
Reimplemented from esphome::modbus::ModbusDevice.
Definition at line 67 of file modbus_controller.cpp.
void esphome::modbus_controller::ModbusController::on_register_data | ( | ModbusRegisterType | register_type, |
uint16_t | start_address, | ||
const std::vector< uint8_t > & | data | ||
) |
default delegate called by process_modbus_data when a response has retrieved from the incoming queue
Definition at line 96 of file modbus_controller.cpp.
void esphome::modbus_controller::ModbusController::on_write_register_response | ( | ModbusRegisterType | register_type, |
uint16_t | start_address, | ||
const std::vector< uint8_t > & | data | ||
) |
default delegate called by process_modbus_data when a response for a write response has retrieved from the incoming queue
Definition at line 307 of file modbus_controller.cpp.
|
protected |
parse incoming modbus data
Definition at line 61 of file modbus_controller.cpp.
void esphome::modbus_controller::ModbusController::queue_command | ( | const ModbusCommandItem & | command | ) |
queues a modbus command in the send queue
Definition at line 107 of file modbus_controller.cpp.
|
protected |
send the next modbus command from the send queue
Definition at line 21 of file modbus_controller.cpp.
|
inline |
called by esphome generated code to set the command_throttle period
Definition at line 431 of file modbus_controller.h.
|
overridevirtual |
Reimplemented from esphome::Component.
Definition at line 10 of file modbus_controller.cpp.
|
overridevirtual |
Implements esphome::PollingComponent.
Definition at line 155 of file modbus_controller.cpp.
|
protected |
submit the read command for the address range to the send queue
Definition at line 124 of file modbus_controller.cpp.
|
protected |
Hold the pending requests to be sent.
Definition at line 453 of file modbus_controller.h.
|
protected |
min time in ms between sending modbus commands
Definition at line 459 of file modbus_controller.h.
|
protected |
modbus response data waiting to get processed
Definition at line 455 of file modbus_controller.h.
|
protected |
when was the last send operation
Definition at line 457 of file modbus_controller.h.
|
protected |
Continous range of modbus registers.
Definition at line 451 of file modbus_controller.h.
|
protected |
Collection of all sensors for this component.
Definition at line 449 of file modbus_controller.h.