ESPHome
2023.9.1
|
Modbus controller class. More...
#include <modbus_controller.h>
Public Member Functions | |
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... | |
void | set_offline_skip_updates (uint16_t offline_skip_updates) |
called by esphome generated code to set the offline_skip_updates More... | |
size_t | get_command_queue_length () |
get the number of queued modbus commands (should be mostly empty) More... | |
bool | get_module_offline () |
get if the module is offline, didn't respond the last command 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 () |
bool | is_ready () |
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... | |
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(uint8_t)> &&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(uint8_t)> &&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_ |
Continuous 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... | |
bool | module_offline_ |
if module didn't respond the last command More... | |
uint16_t | offline_skip_updates_ |
how many updates to skip if module is offline 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 410 of file modbus_controller.h.
|
inline |
Registers a sensor with the controller. Called by esphomes code generator.
Definition at line 420 of file modbus_controller.h.
|
protected |
parse sensormap_ and create range of sequential addresses
Definition at line 191 of file modbus_controller.cpp.
|
overridevirtual |
Reimplemented from esphome::Component.
Definition at line 297 of file modbus_controller.cpp.
|
protected |
dump the parsed sensormap for diagnostics
Definition at line 334 of file modbus_controller.cpp.
|
protected |
Definition at line 105 of file modbus_controller.cpp.
|
inline |
get the number of queued modbus commands (should be mostly empty)
Definition at line 436 of file modbus_controller.h.
|
inline |
get if the module is offline, didn't respond the last command
Definition at line 438 of file modbus_controller.h.
|
overridevirtual |
Reimplemented from esphome::Component.
Definition at line 315 of file modbus_controller.cpp.
|
overridevirtual |
called when a modbus response was parsed without errors
Implements esphome::modbus::ModbusDevice.
Definition at line 60 of file modbus_controller.cpp.
|
overridevirtual |
called when a modbus error response was received
Reimplemented from esphome::modbus::ModbusDevice.
Definition at line 90 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 119 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 329 of file modbus_controller.cpp.
|
protected |
parse incoming modbus data
Definition at line 84 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 130 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 432 of file modbus_controller.h.
|
inline |
called by esphome generated code to set the offline_skip_updates
Definition at line 434 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 177 of file modbus_controller.cpp.
|
protected |
submit the read command for the address range to the send queue
Definition at line 146 of file modbus_controller.cpp.
|
protected |
Hold the pending requests to be sent.
Definition at line 458 of file modbus_controller.h.
|
protected |
min time in ms between sending modbus commands
Definition at line 464 of file modbus_controller.h.
|
protected |
modbus response data waiting to get processed
Definition at line 460 of file modbus_controller.h.
|
protected |
when was the last send operation
Definition at line 462 of file modbus_controller.h.
|
protected |
if module didn't respond the last command
Definition at line 466 of file modbus_controller.h.
|
protected |
how many updates to skip if module is offline
Definition at line 468 of file modbus_controller.h.
|
protected |
Continuous range of modbus registers.
Definition at line 456 of file modbus_controller.h.
|
protected |
Collection of all sensors for this component.
Definition at line 454 of file modbus_controller.h.