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

Class for defining the structure of the Modbus-RTU-Frame. Can be constructed by a given modbus-frame and extracts payload, device-id and function-code (additionally checking CRC) or by providing payload, device-id and function-code (additionally calculating CRC). More...

#include <Frame_modbusRTU.h>

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

Public Member Functions

 Frame_modbusRTU (String *pdu, char *slaveId, char *functionCode)
 Construct a new Frame_modbusRTU object by PDU, modbus-slave-ID and modus-function-code. Object calculates and adds the CRC16, the Modbus-Slave-ID and the Modbus-Function-Code and concatenates them to the modbus-frame (representation) by calling content_to_rep during construction. Allocate heap-memory (buffer) to the frame-representation and let the Content's representation (parent-class-template) point to that buffer on heap.
 
 Frame_modbusRTU (CharArray *frame)
 Construct Modbus-RTU-Frame from given Byte-Frame (Representation). Copy the representation, the argument is pointing to, to heap-memory and let by calling copy_to_heap and let Content's representation (parent-class-template) point to that buffer on heap. Extract Payload, device-ID and function-Code. Check the CRC16 for plausibility by checking rest = 0.
 
 Frame_modbusRTU ()
 Construct empty Modbus-RTU-Frame.
 
 ~Frame_modbusRTU ()
 Destroy the Frame_modbusRTU object.
 
bool checkCRC16 ()
 Verifies the CRC16 checksum of the current Modbus RTU frame.
 
uint8_t getServiceId () override
 Get the Service-ID (Modbus-RTU-function-code) of the frame-instance.
 
- Public Member Functions inherited from Frame
 Frame ()
 Construct a new empty Frame object.
 
 ~Frame ()
 Destroy the Frame object.
 
 Frame (String *pdu)
 Constructor for creating Frame-instance from pdu (Content)
 
 Frame (CharArray *frame)
 Constructor for creating Frame-Object from byte-frame (Representation)
 
- Public Member Functions inherited from Content< String, CharArray >
 Content (String content)
 Construct a new Content object from an instance from type content_type (content itself)
 
 Content (CharArray representation)
 Construct a new Content object from it's representation from type representation_type.
 
CharArrayget_representation ()
 Get the address of the informations representation of type representation-type.
 
Stringget_content ()
 Get the address of the informations content of type content_type.
 
bool isValid ()
 Representation and Content of the object are existent (not default)
 

Additional Inherited Members

- Protected Member Functions inherited from Content< String, CharArray >
- Protected Attributes inherited from Content< String, CharArray >
String content
 Content of an information (view on information (content) closer to Service-Layer)

 
CharArray representation
 Representation of an information (view on information (content) closer to physical layer)

 

Detailed Description

Class for defining the structure of the Modbus-RTU-Frame. Can be constructed by a given modbus-frame and extracts payload, device-id and function-code (additionally checking CRC) or by providing payload, device-id and function-code (additionally calculating CRC).

Because the frame-representation is stored as a reference, the representation has to be allocated on the heap-memory (buffer) The allocation is done during the conversion from "Content" (construction by PDU) within the content_to_rep-function or it has to be initiated by calling the function "copy_to_heap" (e.g. in copy-constructor or during construction by frame-representation)

Constructor & Destructor Documentation

◆ Frame_modbusRTU() [1/2]

Frame_modbusRTU::Frame_modbusRTU ( String * pdu,
char * slaveId,
char * functionCode )

Construct a new Frame_modbusRTU object by PDU, modbus-slave-ID and modus-function-code. Object calculates and adds the CRC16, the Modbus-Slave-ID and the Modbus-Function-Code and concatenates them to the modbus-frame (representation) by calling content_to_rep during construction. Allocate heap-memory (buffer) to the frame-representation and let the Content's representation (parent-class-template) point to that buffer on heap.

Parameters
pdu
slaveId
functionCode

◆ Frame_modbusRTU() [2/2]

Frame_modbusRTU::Frame_modbusRTU ( CharArray * frame)

Construct Modbus-RTU-Frame from given Byte-Frame (Representation). Copy the representation, the argument is pointing to, to heap-memory and let by calling copy_to_heap and let Content's representation (parent-class-template) point to that buffer on heap. Extract Payload, device-ID and function-Code. Check the CRC16 for plausibility by checking rest = 0.

Parameters
frameconst char** to a modbus-rtu-frame to construct the Frame-object from

Member Function Documentation

◆ checkCRC16()

bool Frame_modbusRTU::checkCRC16 ( )

Verifies the CRC16 checksum of the current Modbus RTU frame.

This function calculates the CRC16 checksum of the frame's representation and checks whether it is correct.

Returns
true if the CRC16 checksum is correct, false otherwise.

The function creates a temporary buffer, copies the frame's representation to it, and then compares the calculated CRC16 checksum with the expected value. The temporary buffer is deleted after use.

Here is the call graph for this function:

◆ getServiceId()

uint8_t Frame_modbusRTU::getServiceId ( )
overridevirtual

Get the Service-ID (Modbus-RTU-function-code) of the frame-instance.

Returns
uint8_t Service-ID (Modbus-RTU-function-code) of the frame-instance

Implements Frame.


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