BusBricks: ServiceInterface< CommInterfaceBase, frameType > Class Template Reference
BusBricks  0.1
Customize bus-communication
Loading...
Searching...
No Matches
ServiceInterface< CommInterfaceBase, frameType > Class Template Referenceabstract

Template for generic Service-Interface Defines the handling of incoming frames from CommInterface to services stored in the associated ServiceCluster and the conversion from PDU provided by Services in the ServiceCluster to frames, getting sent by the communication-interface. The ServiceInterface dedicates memory to the CommInterface by iterating through it's stacks. More...

#include <ServiceInterface.h>

Inheritance diagram for ServiceInterface< CommInterfaceBase, frameType >:
[legend]
Collaboration diagram for ServiceInterface< CommInterfaceBase, frameType >:
[legend]

Public Member Functions

 ServiceInterface (CommInterfaceBase *comm_interface, ServiceClusterBase *services)
 Construct a new Service Interface object.
 
virtual void communicate ()=0
 Execute all relevant tasks for transferring data between CommInterface and Services: Getting payloads to sent from the Services, adding received payloads to the right Services, Updating communication-stacks, Executing the CommInterfaces send- and receive-cycle (Has to be implemented in the derived class)
 
- 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"
 

Protected Member Functions

virtual void getPDU_from_services ()=0
 Add all PDUs provided by the services to the sendstack, depending on how frametype stores the information, which service the payload is designated for (Implemented in derived Class)
 
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 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 addPDU_to_services ()
 Add PDUs from all received frames to the corresponding services.
 
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

CommInterfaceBasecomm_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< frameType, STACKSIZE > recStack
 stack for received frames (instance of Content_stack-derived class, specified for type of frames, the bus is using)

 
Content_stack< frameType, STACKSIZE > sendStack
 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

template<typename CommInterfaceBase, typename frameType>
class ServiceInterface< CommInterfaceBase, frameType >

Template for generic Service-Interface Defines the handling of incoming frames from CommInterface to services stored in the associated ServiceCluster and the conversion from PDU provided by Services in the ServiceCluster to frames, getting sent by the communication-interface. The ServiceInterface dedicates memory to the CommInterface by iterating through it's stacks.

Template Parameters
CommInterfaceBasetype of CommInterface to use, derived Class of the abstract CommInterface-Class (e.g. CommInterface_modbusRTU)
frameTypetype of the frames to be send, derived Class of the abstract Frame-Class (e.g. Frame_modbusRTU)

Constructor & Destructor Documentation

◆ ServiceInterface()

template<typename CommInterfaceBase , typename frameType >
ServiceInterface< CommInterfaceBase, frameType >::ServiceInterface ( CommInterfaceBase * comm_interface,
ServiceClusterBase * services )
inline

Construct a new Service Interface object.

Parameters
comm_interfacepointer to an instance of a CommInterface-derived class-object
servicespointer to an instance of a ServiceCluster-derived class-object containing the associated services

Member Function Documentation

◆ addPDU_to_services()

template<typename CommInterfaceBase , typename frameType >
virtual void ServiceInterface< CommInterfaceBase, frameType >::addPDU_to_services ( )
inlineprotectedvirtual

Add PDUs from all received frames to the corresponding services.

This function processes all frames available in the receive stack (recStack). For each frame, it checks the CRC-16 checksum and, if valid, adds the PDU to the appropriate service's receive stack. If the frame's CRC check fails, it raises a CRC error. If no matching service is found for the frame's function code, it raises a service-not-found error and discards the frame.

  • If the receive stack is empty, the function returns immediately.
  • Frames with no matching service are discarded, and a service-not-found error is raised.
  • Valid frames are added to the corresponding service's receive stack.
Note
The function continues processing until the receive stack is empty.
Here is the call graph for this function:

◆ communicate()

template<typename CommInterfaceBase , typename frameType >
virtual void ServiceInterface< CommInterfaceBase, frameType >::communicate ( )
pure virtual

Execute all relevant tasks for transferring data between CommInterface and Services: Getting payloads to sent from the Services, adding received payloads to the right Services, Updating communication-stacks, Executing the CommInterfaces send- and receive-cycle (Has to be implemented in the derived class)

Implemented in ServiceInterface_modbusRTU.

◆ processRecStack()

template<typename CommInterfaceBase , typename frameType >
virtual void ServiceInterface< CommInterfaceBase, frameType >::processRecStack ( )
inlineprotectedvirtual

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.

If the CommInterface received a new frame (that means, it's recBuffer is set to nullptr), the function creates the Frame-instance (specified by frameType) from it's recItem and adds it to the recStack. (If the creation of the Frame-instance fails (isValid returned false), the Framing-Error is raised) Then it initializes the recItem and imparts it's reference to the comm_interface by calling getReceivedFrame. The CommInterface is now storing the next Frame received at this address. After specifying the destination for received frames for ComInterface, the receiveCycle is executed again, to wait for incoming Frames.

The ErrorStates of the CommInterface are transferred to the ServiceInterface ErrorState.

Here is the call graph for this function:

◆ processSendStack()

template<typename CommInterfaceBase , typename frameType >
virtual void ServiceInterface< CommInterfaceBase, frameType >::processSendStack ( )
inlineprotectedvirtual

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.

The ErrorStates of the CommInterface are transferred to the ServiceInterface ErrorState.

Here is the call graph for this function:

◆ raiseError()

template<typename CommInterfaceBase , typename frameType >
void ServiceInterface< CommInterfaceBase, frameType >::raiseError ( errorCodes code)
inlineprotected

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.

Parameters
codeThe error code of the error to be raised.
Here is the call graph for this function:
Here is the caller graph for this function:

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