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

Client behavior to turn ON a specific relay channel. More...

#include <cb_relay_on.hpp>

Inheritance diagram for cl_modbus_tcp_relay::CbRelayOn:
Inheritance graph
Collaboration diagram for cl_modbus_tcp_relay::CbRelayOn:
Collaboration graph

Public Member Functions

 CbRelayOn (int channel)
 Construct behavior to turn on specified channel.
 
virtual ~CbRelayOn ()
 
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
virtual void onEntry () override
 
- 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 Attributes

int channel_
 
ClModbusTcpRelayclient_
 
CpModbusRelayrelayComponent_
 

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 turn ON a specific relay channel.

Posts EvCbSuccess on successful write, EvCbFailure on error.

Definition at line 34 of file cb_relay_on.hpp.

Constructor & Destructor Documentation

◆ CbRelayOn()

cl_modbus_tcp_relay::CbRelayOn::CbRelayOn ( int channel)
inlineexplicit

Construct behavior to turn on specified channel.

Parameters
channelRelay channel number (1-8)

Definition at line 41 of file cb_relay_on.hpp.

◆ ~CbRelayOn()

virtual cl_modbus_tcp_relay::CbRelayOn::~CbRelayOn ( )
inlinevirtual

Definition at line 43 of file cb_relay_on.hpp.

43{}

Member Function Documentation

◆ onEntry()

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

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 54 of file cb_relay_on.hpp.

55 {
56 RCLCPP_INFO(getLogger(), "[CbRelayOn] Turning ON channel %d", channel_);
57
58 if (!relayComponent_)
59 {
60 RCLCPP_ERROR(getLogger(), "[CbRelayOn] Relay component not available");
61 this->postFailureEvent();
62 return;
63 }
64
65 bool success = relayComponent_->writeCoil(channel_, true);
66
67 if (success)
68 {
69 RCLCPP_INFO(getLogger(), "[CbRelayOn] Channel %d turned ON successfully", channel_);
70 this->postSuccessEvent();
71 }
72 else
73 {
74 RCLCPP_ERROR(getLogger(), "[CbRelayOn] Failed to turn ON channel %d", channel_);
75 this->postFailureEvent();
76 }
77 }
bool writeCoil(int channel, bool state)
virtual rclcpp::Logger getLogger() const

References channel_, smacc2::ISmaccClientBehavior::getLogger(), smacc2::SmaccAsyncClientBehavior::postFailureEvent(), smacc2::SmaccAsyncClientBehavior::postSuccessEvent(), relayComponent_, and cl_modbus_tcp_relay::CpModbusRelay::writeCoil().

Here is the call graph for this function:

◆ onStateOrthogonalAllocation()

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

Member Data Documentation

◆ channel_

int cl_modbus_tcp_relay::CbRelayOn::channel_
private

Definition at line 80 of file cb_relay_on.hpp.

Referenced by onEntry().

◆ client_

ClModbusTcpRelay* cl_modbus_tcp_relay::CbRelayOn::client_
private

Definition at line 81 of file cb_relay_on.hpp.

Referenced by onStateOrthogonalAllocation().

◆ relayComponent_

CpModbusRelay* cl_modbus_tcp_relay::CbRelayOn::relayComponent_
private

Definition at line 82 of file cb_relay_on.hpp.

Referenced by onEntry(), and onStateOrthogonalAllocation().


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