GaIA BIOS Library
Loading...
Searching...
No Matches
modbus_tcp_slave_utils.h File Reference

Modbus/TCP slave common utility functions. More...

#include <stdint.h>
#include <modbus_tcp/modbus_tcp_slave.h>

Functions

bool mb_is_secure_addr (mb_tcp_config_t *conf, const ip_addr_t *ip_addr)
 Checks if an address is marked as secure.
mb_tcp_connection_tmb_get_connection_by_socket (mb_tcp_config_t *conf, uintptr_t socket)
 Returns the connection corresponding to the given socket.
mb_tcp_connection_tmb_get_new_connection (mb_tcp_config_t *conf, ip_addr_t *ip_addr)
 Returns a new connection with the given IP address.
void mb_release_connection_slot (mb_tcp_config_t *conf, uintptr_t socket)
 Releases a connection slot.
int mb_prepare_transaction (mb_tcp_config_t *config, mb_tcp_transaction_t *trans, uintptr_t socket, const uint8_t *buf, uint32_t len)
 Validates the received Modus/TCP ADU and starts a transaction.

Detailed Description

Modbus/TCP slave common utility functions.

Author
Tecnologix, 2021

Function Documentation

◆ mb_get_connection_by_socket()

mb_tcp_connection_t * mb_get_connection_by_socket ( mb_tcp_config_t * conf,
uintptr_t socket )

Returns the connection corresponding to the given socket.

Parameters
confthe slave configuration.
socketsocket to search for.
Returns
the connection corresponding to the given socket or NULL if none is found.

◆ mb_get_new_connection()

mb_tcp_connection_t * mb_get_new_connection ( mb_tcp_config_t * conf,
ip_addr_t * ip_addr )

Returns a new connection with the given IP address.

Parameters
confthe slave configuration.
ip_addrremote IP address.
Returns
the connection corresponding to the given IP address or NULL if none is found.

◆ mb_is_secure_addr()

bool mb_is_secure_addr ( mb_tcp_config_t * conf,
const ip_addr_t * ip_addr )

Checks if an address is marked as secure.

If no secure address was specified, every address is secure.

Parameters
confModbus/TCP slave configuration.
ip_addrIP address to be checked.
Returns
true if the address id secure, false otherwise.

◆ mb_prepare_transaction()

int mb_prepare_transaction ( mb_tcp_config_t * config,
mb_tcp_transaction_t * trans,
uintptr_t socket,
const uint8_t * buf,
uint32_t len )

Validates the received Modus/TCP ADU and starts a transaction.

Parameters
configthe slave configuration.
transthe transaction to be used.
socketthe socket on which the data has been received.
bufthe data received.
lennumber of bytes received.
Returns
MB_TCP_NO_ERROR if the transaction was correctly started, MB_TCP_NOT_FOUND if no connection was found for the given socket, MB_TCP_INVALID if the received data is not a valid Modbus/TCP ADU.

◆ mb_release_connection_slot()

void mb_release_connection_slot ( mb_tcp_config_t * conf,
uintptr_t socket )

Releases a connection slot.

Parameters
confthe slave configuration.
socketthe socket corresponding to the connection to be released.