Modbus Vault v1.0
Loading...
Searching...
No Matches
modbus_slicer.h File Reference

Slicer for Modbus. More...

#include "slab_pool.h"
#include <stdint.h>
Include dependency graph for modbus_slicer.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  modbus_slicer_frame_t
 Modbus slicer frame structure. More...
 
struct  modbus_slicer_config_t
 Modbus slicer configuration structure. More...
 
struct  modbus_slicer_t
 Modbus slicer type structure. More...
 

Enumerations

enum  modbus_slicer_error_t { MODBUS_SLICER_OK = 0 , MODBUS_SLICER_ERROR_CRC , MODBUS_SLICER_ERROR_OVERFLOW , MODBUS_SLICER_ERROR_NO_MEM }
 Modbus slicer error enum. More...
 
enum  modbus_slicer_state_t { MODBUS_SLICER_STATE_IDLE , MODBUS_SLICER_STATE_RECEIVING }
 Modbus slicer state enum. More...
 

Functions

void modbus_slicer_init (modbus_slicer_t *slicer_ptr, modbus_slicer_config_t *config_ptr)
 Initialize slicer.
 
void modbus_slicer_feed (modbus_slicer_t *slicer_ptr, const uint8_t *data_ptr, size_t length, int64_t timestamp_us)
 Feed data to slicer state-machine.
 
void modbus_slicer_timeout (modbus_slicer_t *slicer_ptr)
 Signal frame timeout.
 
void modbus_slicer_check_timeout (modbus_slicer_t *slicer_ptr)
 Check for frame timeout.
 

Detailed Description

Slicer for Modbus.

Author
Abanoub Salah

Provides bytes slicing according to Modbus framing rule of 3.5 characters interframe silent duration

Enumeration Type Documentation

◆ modbus_slicer_error_t

Modbus slicer error enum.

Enumerator
MODBUS_SLICER_OK 

Frame OK and ready

MODBUS_SLICER_ERROR_CRC 

Frame CRC error

MODBUS_SLICER_ERROR_OVERFLOW 

Local buffer would overflowed

MODBUS_SLICER_ERROR_NO_MEM 

No buffers available

◆ modbus_slicer_state_t

Modbus slicer state enum.

Enumerator
MODBUS_SLICER_STATE_IDLE 

Slicer is idle

MODBUS_SLICER_STATE_RECEIVING 

Slicer in the middle of receiving a frame

Function Documentation

◆ modbus_slicer_check_timeout()

void modbus_slicer_check_timeout ( modbus_slicer_t slicer_ptr)

Check for frame timeout.

Check for frame timeout by comparing last received byte to current time and timeout if it exceeds 3.5 characters time

Parameters
slicer_ptrPointer to slicer structure
Note
Frame boundary primary determined using timing from rs485 driver layer as it's timeout threshold is set approximately 3.5 characters time
Here is the call graph for this function:
Here is the caller graph for this function:

◆ modbus_slicer_feed()

void modbus_slicer_feed ( modbus_slicer_t slicer_ptr,
const uint8_t *  data_ptr,
size_t  length,
int64_t  timestamp_us 
)

Feed data to slicer state-machine.

Parameters
slicer_ptrPointer to slicer structure
data_ptrPointer to data buffer
lengthData buffer length
timestamp_usData timestamp
Note
A slab gets allocated here and if passed to callback function successfully it's the consumer responsibility to free it otherwise it gets freed later in the same component
Emits overflow when data is coming but buffer is exhausted
Emits no memory when there is no available buffers
Here is the call graph for this function:
Here is the caller graph for this function:

◆ modbus_slicer_init()

void modbus_slicer_init ( modbus_slicer_t slicer_ptr,
modbus_slicer_config_t config_ptr 
)

Initialize slicer.

Initialize slicer by calculating 3.5 characters time using standard frame length 11-bits and baud rate used by rs485 driver

Parameters
slicer_ptrPointer to slicer structure
config_ptrPointer to slicer configuration structure
Note
Assumes standard frame length of 11-bits
Added 20% to 3.5 characters duration for timing practicality
Here is the caller graph for this function:

◆ modbus_slicer_timeout()

void modbus_slicer_timeout ( modbus_slicer_t slicer_ptr)

Signal frame timeout.

Slice the frame since 3.5 characters time has passed and call registered callback function

Parameters
slicer_ptrPointer to slicer structure
Note
Intercharacter timing is not implemented here since current setup doesn't allow for 1.5 characters timeout
Frames are dropped if there is no callback registered
Callback is triggered if there is data present otherwise it is called when errors happen and slab is reused if present
Here is the caller graph for this function: