|
SMACC2
|
Component that manages Modbus TCP connection lifecycle and heartbeat monitoring. More...
#include <cp_modbus_connection.hpp>


Public Member Functions | |
| CpModbusConnection () | |
| virtual | ~CpModbusConnection () |
| void | onInitialize () override |
| template<typename TOrthogonal , typename TClient > | |
| void | onStateOrthogonalAllocation () |
| Configure component for event posting during orthogonal allocation. | |
| bool | connect () |
| void | disconnect () |
| bool | reconnect () |
| bool | isConnected () const |
| modbus_t * | getContext () |
| std::mutex & | getMutex () |
| std::string | getIpAddress () const |
| int | getPort () const |
| int | getSlaveId () const |
| template<typename T > | |
| smacc2::SmaccSignalConnection | onConnectionLost (void(T::*callback)(), T *object) |
| template<typename T > | |
| smacc2::SmaccSignalConnection | onConnectionRestored (void(T::*callback)(), T *object) |
| template<typename T > | |
| smacc2::SmaccSignalConnection | onConnectionError (void(T::*callback)(const std::string &), T *object) |
Public Member Functions inherited from smacc2::ISmaccComponent | |
| ISmaccComponent () | |
| virtual | ~ISmaccComponent () |
| virtual std::string | getName () const |
Public Member Functions inherited from smacc2::ISmaccUpdatable | |
| ISmaccUpdatable () | |
| ISmaccUpdatable (rclcpp::Duration duration) | |
| void | executeUpdate (rclcpp::Node::SharedPtr node) |
| void | setUpdatePeriod (rclcpp::Duration duration) |
Public Attributes | |
| smacc2::SmaccSignal< void()> | onConnectionLost_ |
| smacc2::SmaccSignal< void()> | onConnectionRestored_ |
| smacc2::SmaccSignal< void(const std::string &)> | onConnectionError_ |
Protected Member Functions | |
| void | update () override |
Protected Member Functions inherited from smacc2::ISmaccComponent | |
| template<typename TOrthogonal , typename TClient > | |
| void | onComponentInitialization () |
| template<typename EventType > | |
| void | postEvent (const EventType &ev) |
| template<typename EventType > | |
| void | postEvent () |
| template<typename TOrthogonal , typename TSourceObject > | |
| void | onStateOrthogonalAllocation () |
| template<typename TComponent > | |
| void | requiresComponent (TComponent *&requiredComponentStorage, ComponentRequirement requirementType=ComponentRequirement::SOFT) |
| template<typename TComponent > | |
| void | requiresComponent (std::string name, TComponent *&requiredComponentStorage, ComponentRequirement requirementType=ComponentRequirement::SOFT) |
| template<typename TClient > | |
| void | requiresClient (TClient *&requiredClientStorage) |
| template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs> | |
| SmaccComponentType * | createSiblingComponent (TArgs... targs) |
| template<typename SmaccComponentType , typename TOrthogonal , typename TClient , typename... TArgs> | |
| SmaccComponentType * | createSiblingNamedComponent (std::string name, TArgs... targs) |
| rclcpp::Node::SharedPtr | getNode () |
| rclcpp::Logger | getLogger () const |
| ISmaccStateMachine * | getStateMachine () |
Protected Member Functions inherited from smacc2::ISmaccUpdatable | |
Private Member Functions | |
| template<typename T > | |
| void | declareAndLoadParam (const std::string &name, T &value, const T &default_val) |
Private Attributes | |
| std::string | ip_address_ |
| int | port_ |
| int | slave_id_ |
| int | heartbeat_interval_ms_ |
| bool | connect_on_init_ |
| modbus_t * | ctx_ |
| bool | connected_ |
| std::mutex | mutex_ |
| std::function< void()> | postConnectionLostEvent_ |
| std::function< void()> | postConnectionRestoredEvent_ |
Additional Inherited Members | |
Protected Attributes inherited from smacc2::ISmaccComponent | |
| ISmaccStateMachine * | stateMachine_ |
| ISmaccClient * | owner_ |
Component that manages Modbus TCP connection lifecycle and heartbeat monitoring.
Responsibilities:
Configuration is loaded from YAML parameters: modbus_relay.ip_address: IP address of the relay (default: "192.168.1.254") modbus_relay.port: Modbus TCP port (default: 502) modbus_relay.slave_id: Modbus slave ID (default: 1) modbus_relay.heartbeat_interval_ms: Heartbeat check interval (default: 1000) modbus_relay.connect_on_init: Connect automatically on init (default: true)
Definition at line 56 of file cp_modbus_connection.hpp.
| cl_modbus_tcp_relay::CpModbusConnection::CpModbusConnection | ( | ) |
Definition at line 26 of file cp_modbus_connection.cpp.
|
virtual |
Definition at line 38 of file cp_modbus_connection.cpp.
References ctx_, and disconnect().

| bool cl_modbus_tcp_relay::CpModbusConnection::connect | ( | ) |
Definition at line 114 of file cp_modbus_connection.cpp.
References connected_, ctx_, smacc2::ISmaccComponent::getLogger(), ip_address_, mutex_, onConnectionError_, and port_.
Referenced by onInitialize(), and reconnect().


|
private |
Definition at line 49 of file cp_modbus_connection.cpp.
References smacc2::ISmaccComponent::getNode().
Referenced by onInitialize().


| void cl_modbus_tcp_relay::CpModbusConnection::disconnect | ( | ) |
Definition at line 147 of file cp_modbus_connection.cpp.
References connected_, ctx_, smacc2::ISmaccComponent::getLogger(), and mutex_.
Referenced by reconnect(), and ~CpModbusConnection().


| modbus_t * cl_modbus_tcp_relay::CpModbusConnection::getContext | ( | ) |
Definition at line 172 of file cp_modbus_connection.cpp.
References ctx_.
Referenced by cl_modbus_tcp_relay::CpModbusRelay::readAllCoils(), cl_modbus_tcp_relay::CpModbusRelay::readCoil(), cl_modbus_tcp_relay::CpModbusRelay::writeAllCoils(), and cl_modbus_tcp_relay::CpModbusRelay::writeCoil().

|
inline |
| std::mutex & cl_modbus_tcp_relay::CpModbusConnection::getMutex | ( | ) |
Definition at line 174 of file cp_modbus_connection.cpp.
References mutex_.
Referenced by cl_modbus_tcp_relay::CpModbusRelay::readAllCoils(), cl_modbus_tcp_relay::CpModbusRelay::readCoil(), cl_modbus_tcp_relay::CpModbusRelay::writeAllCoils(), and cl_modbus_tcp_relay::CpModbusRelay::writeCoil().

|
inline |
|
inline |
| bool cl_modbus_tcp_relay::CpModbusConnection::isConnected | ( | ) | const |
Definition at line 166 of file cp_modbus_connection.cpp.
References connected_, and mutex_.
Referenced by cl_modbus_tcp_relay::CpModbusRelay::readAllCoils(), cl_modbus_tcp_relay::CpModbusRelay::readCoil(), cl_modbus_tcp_relay::CpModbusRelay::writeAllCoils(), and cl_modbus_tcp_relay::CpModbusRelay::writeCoil().

|
inline |
Definition at line 111 of file cp_modbus_connection.hpp.
References smacc2::ISmaccStateMachine::createSignalConnection(), and smacc2::ISmaccComponent::getStateMachine().

|
inline |
Definition at line 99 of file cp_modbus_connection.hpp.
References smacc2::ISmaccStateMachine::createSignalConnection(), and smacc2::ISmaccComponent::getStateMachine().

|
inline |
Definition at line 105 of file cp_modbus_connection.hpp.
References smacc2::ISmaccStateMachine::createSignalConnection(), and smacc2::ISmaccComponent::getStateMachine().

|
overridevirtual |
Reimplemented from smacc2::ISmaccComponent.
Definition at line 74 of file cp_modbus_connection.cpp.
References connect(), connect_on_init_, ctx_, declareAndLoadParam(), smacc2::ISmaccComponent::getLogger(), heartbeat_interval_ms_, ip_address_, onConnectionError_, port_, smacc2::ISmaccUpdatable::setUpdatePeriod(), and slave_id_.

|
inline |
Configure component for event posting during orthogonal allocation.
Definition at line 68 of file cp_modbus_connection.hpp.
References postConnectionLostEvent_, postConnectionRestoredEvent_, and smacc2::ISmaccComponent::postEvent().

| bool cl_modbus_tcp_relay::CpModbusConnection::reconnect | ( | ) |
Definition at line 159 of file cp_modbus_connection.cpp.
References connect(), disconnect(), and smacc2::ISmaccComponent::getLogger().

|
overrideprotectedvirtual |
Implements smacc2::ISmaccUpdatable.
Definition at line 176 of file cp_modbus_connection.cpp.
References connected_, ctx_, smacc2::ISmaccComponent::getLogger(), mutex_, onConnectionLost_, onConnectionRestored_, postConnectionLostEvent_, and postConnectionRestoredEvent_.

|
private |
Definition at line 126 of file cp_modbus_connection.hpp.
Referenced by onInitialize().
|
private |
Definition at line 130 of file cp_modbus_connection.hpp.
Referenced by connect(), disconnect(), isConnected(), and update().
|
private |
Definition at line 129 of file cp_modbus_connection.hpp.
Referenced by connect(), disconnect(), getContext(), onInitialize(), update(), and ~CpModbusConnection().
|
private |
Definition at line 125 of file cp_modbus_connection.hpp.
Referenced by onInitialize().
|
private |
Definition at line 122 of file cp_modbus_connection.hpp.
Referenced by connect(), getIpAddress(), and onInitialize().
|
mutableprivate |
Definition at line 131 of file cp_modbus_connection.hpp.
Referenced by connect(), disconnect(), getMutex(), isConnected(), and update().
| smacc2::SmaccSignal<void(const std::string &)> cl_modbus_tcp_relay::CpModbusConnection::onConnectionError_ |
Definition at line 95 of file cp_modbus_connection.hpp.
Referenced by connect(), and onInitialize().
| smacc2::SmaccSignal<void()> cl_modbus_tcp_relay::CpModbusConnection::onConnectionLost_ |
Definition at line 93 of file cp_modbus_connection.hpp.
Referenced by update().
| smacc2::SmaccSignal<void()> cl_modbus_tcp_relay::CpModbusConnection::onConnectionRestored_ |
Definition at line 94 of file cp_modbus_connection.hpp.
Referenced by update().
|
private |
Definition at line 123 of file cp_modbus_connection.hpp.
Referenced by connect(), getPort(), and onInitialize().
|
private |
Definition at line 134 of file cp_modbus_connection.hpp.
Referenced by onStateOrthogonalAllocation(), and update().
|
private |
Definition at line 135 of file cp_modbus_connection.hpp.
Referenced by onStateOrthogonalAllocation(), and update().
|
private |
Definition at line 124 of file cp_modbus_connection.hpp.
Referenced by getSlaveId(), and onInitialize().