liblightmodbus 3.0
A lightweight, header-only, hardware-agnostic Modbus RTU/TCP library
Loading...
Searching...
No Matches
base.impl.h File Reference

Common types and functions (implementation) More...

#include "base.h"
#include <stdlib.h>
+ Include dependency graph for base.impl.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

ModbusError modbusDefaultAllocator (ModbusBuffer *buffer, uint16_t size, void *context)
 The default memory allocator based on realloc()
 
ModbusErrorInfo modbusBufferInit (ModbusBuffer *buffer, ModbusAllocator allocator)
 Initializes a buffer for use.
 
void modbusBufferFree (ModbusBuffer *buffer, void *context)
 Frees memory allocated inside the buffer.
 
void modbusBufferDestroy (ModbusBuffer *buffer, void *context)
 Equivalent of modbusBufferFree() \copydetail modbusBufferFree()
 
ModbusError modbusBufferAllocateADU (ModbusBuffer *buffer, uint16_t pduSize, void *context)
 Allocates memory to hold Modbus ADU.
 
uint16_t modbusCRC (const uint8_t *data, uint16_t length)
 Calculates 16-bit Modbus CRC of provided data.
 

Detailed Description

Common types and functions (implementation)

Function Documentation

◆ modbusBufferAllocateADU()

ModbusError modbusBufferAllocateADU ( ModbusBuffer buffer,
uint16_t  pduSize,
void *  context 
)

Allocates memory to hold Modbus ADU.

Parameters
pduSizesize of the PDU in bytes
contextcontext pointer passed on to the allocator
Returns
MODBUS_OK on success
MODBUS_ERROR_ALLOC on allocation failure

If called with pduSize == 0, the buffer is freed. Otherwise a buffer for (pduSize + buffer->padding) bytes is allocated. This guarantees that the buffer is big enough to hold the entire ADU.

This function is responsible for managing data, pdu and length fields in the buffer struct. The pdu pointer is set up to point pduOffset bytes after the data pointer unless data is a null pointer.

+ Here is the caller graph for this function:

◆ modbusBufferDestroy()

void modbusBufferDestroy ( ModbusBuffer buffer,
void *  context 
)

Equivalent of modbusBufferFree() \copydetail modbusBufferFree()

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ modbusBufferFree()

void modbusBufferFree ( ModbusBuffer buffer,
void *  context 
)

Frees memory allocated inside the buffer.

Parameters
contextcontext pointer passed on to the allocator
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ modbusBufferInit()

ModbusErrorInfo modbusBufferInit ( ModbusBuffer buffer,
ModbusAllocator  allocator 
)

Initializes a buffer for use.

Parameters
allocatorMemory allocator to be used by the buffer
Returns
MODBUS_NO_ERROR() on success
+ Here is the caller graph for this function:

◆ modbusCRC()

uint16_t modbusCRC ( const uint8_t *  data,
uint16_t  length 
)

Calculates 16-bit Modbus CRC of provided data.

Parameters
dataA pointer to the data to be processed
lengthNumber of bytes, starting at the data pointer, to process
Returns
16-bit Modbus CRC value
+ Here is the caller graph for this function:

◆ modbusDefaultAllocator()

ModbusError modbusDefaultAllocator ( ModbusBuffer buffer,
uint16_t  size,
void *  context 
)

The default memory allocator based on realloc()

Parameters
buffera pointer to the buffer to be reallocated
sizenew desired buffer size in bytes
contextuser's context pointer
Returns
MODBUS_ERROR_ALLOC on allocation failure
MODBUS_OK on success
See also
allocators