SMACC2
Loading...
Searching...
No Matches
cl_modbus_tcp_relay::CbRelayStatus Class Reference

Client behavior to read relay channel status. More...

#include <cb_relay_status.hpp>

Inheritance diagram for cl_modbus_tcp_relay::CbRelayStatus:
Inheritance graph
Collaboration diagram for cl_modbus_tcp_relay::CbRelayStatus:
Collaboration graph

Public Member Functions

 CbRelayStatus ()
 Construct behavior to read all channel statuses.
 
 CbRelayStatus (int channel)
 Construct behavior to read a specific channel status.
 
virtual ~CbRelayStatus ()
 
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
virtual void onEntry () override
 
uint8_t getChannelStates () const
 Get the last read channel states (bitmask)
 
virtual void onStatusRead (uint8_t channelStates)
 Virtual callback for status read completion Override in derived classes for custom handling.
 
- Public Member Functions inherited from smacc2::SmaccAsyncClientBehavior
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
virtual ~SmaccAsyncClientBehavior ()
 
template<typename TCallback , typename T >
smacc2::SmaccSignalConnection onSuccess (TCallback callback, T *object)
 
template<typename TCallback , typename T >
smacc2::SmaccSignalConnection onFinished (TCallback callback, T *object)
 
template<typename TCallback , typename T >
smacc2::SmaccSignalConnection onFailure (TCallback callback, T *object)
 
void requestForceFinish ()
 
void executeOnEntry () override
 
void executeOnExit () override
 
void waitOnEntryThread (bool requestFinish)
 
template<typename TCallbackMethod , typename T >
smacc2::SmaccSignalConnection onSuccess (TCallbackMethod callback, T *object)
 
template<typename TCallbackMethod , typename T >
smacc2::SmaccSignalConnection onFinished (TCallbackMethod callback, T *object)
 
template<typename TCallbackMethod , typename T >
smacc2::SmaccSignalConnection onFailure (TCallbackMethod callback, T *object)
 
- Public Member Functions inherited from smacc2::ISmaccClientBehavior
 ISmaccClientBehavior ()
 
virtual ~ISmaccClientBehavior ()
 
ISmaccStateMachinegetStateMachine ()
 
std::string getName () const
 
template<typename SmaccClientType >
void requiresClient (SmaccClientType *&storage)
 
template<typename SmaccComponentType >
void requiresComponent (SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
virtual void onExit ()
 

Private Member Functions

void readSingleChannel (int channel)
 
void readAllChannels ()
 

Private Attributes

std::optional< int > channel_
 
ClModbusTcpRelayclient_
 
CpModbusRelayrelayComponent_
 
uint8_t channelStates_ = 0
 

Additional Inherited Members

- Protected Member Functions inherited from smacc2::SmaccAsyncClientBehavior
void postSuccessEvent ()
 
void postFailureEvent ()
 
virtual void dispose () override
 
bool isShutdownRequested ()
 onEntry is executed in a new thread. However the current state cannot be left until the onEntry thread finishes. This flag can be checked from the onEntry thread to force finishing the thread.
 
- Protected Member Functions inherited from smacc2::ISmaccClientBehavior
virtual void runtimeConfigure ()
 
template<typename EventType >
void postEvent (const EventType &ev)
 
template<typename EventType >
void postEvent ()
 
ISmaccStategetCurrentState ()
 
virtual rclcpp::Node::SharedPtr getNode () const
 
virtual rclcpp::Logger getLogger () const
 

Detailed Description

Client behavior to read relay channel status.

Can read single channel or all channels. Posts EvCbSuccess on successful read, EvCbFailure on error.

Definition at line 37 of file cb_relay_status.hpp.

Constructor & Destructor Documentation

◆ CbRelayStatus() [1/2]

cl_modbus_tcp_relay::CbRelayStatus::CbRelayStatus ( )
inline

Construct behavior to read all channel statuses.

Definition at line 43 of file cb_relay_status.hpp.

43: channel_(std::nullopt) {}

◆ CbRelayStatus() [2/2]

cl_modbus_tcp_relay::CbRelayStatus::CbRelayStatus ( int channel)
inlineexplicit

Construct behavior to read a specific channel status.

Parameters
channelRelay channel number (1-8)

Definition at line 49 of file cb_relay_status.hpp.

49: channel_(channel) {}

◆ ~CbRelayStatus()

virtual cl_modbus_tcp_relay::CbRelayStatus::~CbRelayStatus ( )
inlinevirtual

Definition at line 51 of file cb_relay_status.hpp.

51{}

Member Function Documentation

◆ getChannelStates()

uint8_t cl_modbus_tcp_relay::CbRelayStatus::getChannelStates ( ) const
inline

Get the last read channel states (bitmask)

Returns
Bitmask of channel states (bit 0 = channel 1, etc.)

Definition at line 78 of file cb_relay_status.hpp.

References channelStates_.

◆ onEntry()

virtual void cl_modbus_tcp_relay::CbRelayStatus::onEntry ( )
inlineoverridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 62 of file cb_relay_status.hpp.

63 {
64 if (channel_.has_value())
65 {
67 }
68 else
69 {
71 }
72 }

References channel_, readAllChannels(), and readSingleChannel().

Here is the call graph for this function:

◆ onStateOrthogonalAllocation()

template<typename TOrthogonal , typename TSourceObject >
void cl_modbus_tcp_relay::CbRelayStatus::onStateOrthogonalAllocation ( )
inline

◆ onStatusRead()

virtual void cl_modbus_tcp_relay::CbRelayStatus::onStatusRead ( uint8_t channelStates)
inlinevirtual

Virtual callback for status read completion Override in derived classes for custom handling.

Parameters
channelStatesBitmask of channel states

Definition at line 85 of file cb_relay_status.hpp.

86 {
87 RCLCPP_INFO(getLogger(), "[CbRelayStatus] Status read callback: 0x%02X", channelStates);
88 }
virtual rclcpp::Logger getLogger() const

References smacc2::ISmaccClientBehavior::getLogger().

Referenced by readAllChannels(), and readSingleChannel().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readAllChannels()

void cl_modbus_tcp_relay::CbRelayStatus::readAllChannels ( )
inlineprivate

Definition at line 124 of file cb_relay_status.hpp.

125 {
126 RCLCPP_INFO(getLogger(), "[CbRelayStatus] Reading all channel statuses");
127
128 if (!relayComponent_)
129 {
130 RCLCPP_ERROR(getLogger(), "[CbRelayStatus] Relay component not available");
131 this->postFailureEvent();
132 return;
133 }
134
136
137 if (success)
138 {
139 RCLCPP_INFO(getLogger(), "[CbRelayStatus] All channel statuses: 0x%02X", channelStates_);
140
141 // Log individual channel states
142 for (int i = 0; i < 8; i++)
143 {
144 bool state = (channelStates_ & (1 << i)) != 0;
145 RCLCPP_INFO(getLogger(), "[CbRelayStatus] Channel %d: %s", i + 1, state ? "ON" : "OFF");
146 }
147
149 this->postSuccessEvent();
150 }
151 else
152 {
153 RCLCPP_ERROR(getLogger(), "[CbRelayStatus] Failed to read channel statuses");
154 this->postFailureEvent();
155 }
156 }
virtual void onStatusRead(uint8_t channelStates)
Virtual callback for status read completion Override in derived classes for custom handling.

References channelStates_, smacc2::ISmaccClientBehavior::getLogger(), onStatusRead(), smacc2::SmaccAsyncClientBehavior::postFailureEvent(), smacc2::SmaccAsyncClientBehavior::postSuccessEvent(), cl_modbus_tcp_relay::CpModbusRelay::readAllCoils(), and relayComponent_.

Referenced by onEntry().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readSingleChannel()

void cl_modbus_tcp_relay::CbRelayStatus::readSingleChannel ( int channel)
inlineprivate

Definition at line 96 of file cb_relay_status.hpp.

97 {
98 RCLCPP_INFO(getLogger(), "[CbRelayStatus] Reading channel %d status", channel);
99
100 if (!relayComponent_)
101 {
102 RCLCPP_ERROR(getLogger(), "[CbRelayStatus] Relay component not available");
103 this->postFailureEvent();
104 return;
105 }
106
107 bool state;
108 bool success = relayComponent_->readCoil(channel, state);
109
110 if (success)
111 {
112 channelStates_ = state ? (1 << (channel - 1)) : 0;
113 RCLCPP_INFO(getLogger(), "[CbRelayStatus] Channel %d is %s", channel, state ? "ON" : "OFF");
115 this->postSuccessEvent();
116 }
117 else
118 {
119 RCLCPP_ERROR(getLogger(), "[CbRelayStatus] Failed to read channel %d", channel);
120 this->postFailureEvent();
121 }
122 }
bool readCoil(int channel, bool &state)

References channelStates_, smacc2::ISmaccClientBehavior::getLogger(), onStatusRead(), smacc2::SmaccAsyncClientBehavior::postFailureEvent(), smacc2::SmaccAsyncClientBehavior::postSuccessEvent(), cl_modbus_tcp_relay::CpModbusRelay::readCoil(), and relayComponent_.

Referenced by onEntry().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ channel_

std::optional<int> cl_modbus_tcp_relay::CbRelayStatus::channel_
private

Definition at line 91 of file cb_relay_status.hpp.

Referenced by onEntry().

◆ channelStates_

uint8_t cl_modbus_tcp_relay::CbRelayStatus::channelStates_ = 0
private

Definition at line 94 of file cb_relay_status.hpp.

Referenced by getChannelStates(), readAllChannels(), and readSingleChannel().

◆ client_

ClModbusTcpRelay* cl_modbus_tcp_relay::CbRelayStatus::client_
private

Definition at line 92 of file cb_relay_status.hpp.

Referenced by onStateOrthogonalAllocation().

◆ relayComponent_

CpModbusRelay* cl_modbus_tcp_relay::CbRelayStatus::relayComponent_
private

The documentation for this class was generated from the following file: