BusBricks: ServiceInterface_modbusRTU Class Reference
BusBricks  0.1
Customize bus-communication
Loading...
Searching...
No Matches
ServiceInterface_modbusRTU Class Reference

Service-Interface-class for Modbus-RTU: Impart incoming frames from the CommInterface to the designated service of the service-cluster. Build outgoing modbus-RTU-frames from the payload provided by the services and impart them to the Communication-Interface. The service-IDs of the associated services are mapped to the modbus-rtu-function-code. If a Frame is sent by a modbus-slave device, the frame's slave-id is the same as the sender-id (and the local device-id). If a Frame is sent by a modbus-device in mastermode, the frame's slave-id is the receiver-id provided by the service, that provided the payload for the frame. More...

#include <ServiceInterface_modbusRTU.h>

Inheritance diagram for ServiceInterface_modbusRTU:
[legend]
Collaboration diagram for ServiceInterface_modbusRTU:
[legend]

Public Member Functions

 ServiceInterface_modbusRTU (ServiceClusterBase *services, CommInterface_modbusRTU *comm_interface)
 Construct a new ServiceInterface_modbusRTU object.
 
 ~ServiceInterface_modbusRTU ()
 Destroy the ServiceInterface_modbusRTU object.
 
void communicate () override
 Manages data transfer between the CommInterface and services.
 
- Public Member Functions inherited from ServiceInterface< CommInterface_modbusRTU, Frame_modbusRTU >
 ServiceInterface (CommInterface_modbusRTU *comm_interface, ServiceClusterBase *services)
 Construct a new Service Interface object.
 
- Public Member Functions inherited from ErrorState
 ErrorState ()
 Default constructor for ErrorState.
 
 ~ErrorState ()
 Destroy the ErrorState object.
 
void raiseError (errorCodes code)
 raises a new error by setting the given error-code as errorState
 
errorCodes getErrorState ()
 Get the currently active error-code.
 
void clearErrorState ()
 sets the current error-state to "no Error"
 

Additional Inherited Members

- Protected Member Functions inherited from ServiceInterface< CommInterface_modbusRTU, Frame_modbusRTU >
virtual void addPDU_to_services ()=0
 Impart all received PDUs from the receivestack to the associated services, depending on how frametype stores the information, which service the payload is designated for (Implemented in derived Class)
 
virtual void addPDU_to_services ()
 Add PDUs from all received frames to the corresponding services.
 
virtual void processServices ()
 start the stackProcessing of the registered services
 
void raiseError (errorCodes code)
 Check if an ErrorService is registered in the service cluster under the defined ERRORSERVICE_ID of the Service Interface and call raiseError for that Service. If no ErrorService is registered, the errorState is stored regularly in the ErrorState class.
 
virtual void processSendStack ()
 Send all Frames, stored in the sendStack. As long as the sendStack is not empty, the function is getting pointers to the representation of the Frame on the bottom of the stack. The pointer to the string-formatted representation is imparted to the CommInterface as teh next frame to be sent by calling sendNewFrame. Then the CommInterface's sendCycle get's executed. Exit, after the sendStack is empty.
 
virtual void processRecStack ()
 Add items received by the CommInterface to the recStack and execute the CommInterface's receiveCycle to wait for new incoming frames. Exit, if the recStack is full or the CommInterface did not received new Frames within the in receiveCycle specified timeout.
 
- Protected Attributes inherited from ServiceInterface< CommInterface_modbusRTU, Frame_modbusRTU >
CommInterface_modbusRTUcomm_interface
 pointer to Communication-Interface (instance of CommInterface-derived class)
 
ServiceClusterBaseservices
 pointer to ServiceCluster, containing the Services associated with the Interface (instance of ServiceCluster-derived class)

 
Content_stack< Frame_modbusRTU, STACKSIZErecStack
 stack for received frames (instance of Content_stack-derived class, specified for type of frames, the bus is using)

 
Content_stack< Frame_modbusRTU, STACKSIZEsendStack
 stack for frames to send next (instance of Content_stack-derived class, specified for type of frames, the bus is using)

 
CharArray sendItem
 Item to be sent next

 
CharArray recItem
 Item received last

 

Detailed Description

Service-Interface-class for Modbus-RTU: Impart incoming frames from the CommInterface to the designated service of the service-cluster. Build outgoing modbus-RTU-frames from the payload provided by the services and impart them to the Communication-Interface. The service-IDs of the associated services are mapped to the modbus-rtu-function-code. If a Frame is sent by a modbus-slave device, the frame's slave-id is the same as the sender-id (and the local device-id). If a Frame is sent by a modbus-device in mastermode, the frame's slave-id is the receiver-id provided by the service, that provided the payload for the frame.

Constructor & Destructor Documentation

◆ ServiceInterface_modbusRTU()

ServiceInterface_modbusRTU::ServiceInterface_modbusRTU ( ServiceClusterBase * services,
CommInterface_modbusRTU * comm_interface )

Construct a new ServiceInterface_modbusRTU object.

Parameters
servicespointer to Service-cluster containing all services associated with the ServiceInterface
comm_interfacepointer to the CommInterface_modbusRTU-instance to use for communication

Member Function Documentation

◆ communicate()

void ServiceInterface_modbusRTU::communicate ( )
overridevirtual

Manages data transfer between the CommInterface and services.

This function coordinates the entire communication process by:

  • Retrieving incoming frames from the communication interface.
  • Processing and adding received PDUs to the appropriate services.
  • Updating communication stacks as needed.
  • Executing the communication cycle for the interface.
  • Calls processRecStack to handle incoming frames and manage the receive stack.
  • Uses addPDU_to_services to distribute PDUs to services based on the Modbus RTU function code.
  • Executes processServices to perform any necessary actions or updates within the services.
  • Retrieves PDUs from services and prepares them for sending using getPDU_from_services.
  • Finally, calls processSendStack to manage and send the new frames to the communication interface.
Note
  • The function orchestrates the communication between the CommInterface and services, ensuring data is properly transferred in both directions.

Implements ServiceInterface< CommInterface_modbusRTU, Frame_modbusRTU >.

Here is the call graph for this function:

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