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

Modbus/TCP slave function definitions. More...

#include <stdbool.h>
#include <stdint.h>
#include <modbus_core/modbus.h>
#include <modbus_core/modbus_exceptions.h>
#include <modbus_core/modbus_types.h>
#include <modbus_core/modbus_rtos.h>
#include <modbus_tcp/modbus_tcp.h>

Data Structures

struct  mb_tcp_config_t
 This structure represents the configuration of a Modbus/TCP slave. More...

Macros

#define MB_MODBUS_PROTOCOL_ID   (0)
 Identification number of the modbus protocol.
#define MB_DEFAULT_TCP_PORT   (502)
 Registered TCP port of the modbus protocol.
#define MB_TCP_DEFAULT_KEEP_ALIVE   (120)
 Default keep-alive for TCP sockets.
#define MB_TCP_TRANS_IDLE   (0)
 Status of a transaction that is idle.
#define MB_TCP_TRANS_BUSY   (1)
 Status of a transaction that is not ready to be processed.
#define MB_TCP_TRANS_START   (2)
 Status of a transaction that is ready to be processed.
#define MB_TCP_TRANS_WAITING   (3)
 Status of a transaction waiting for response.
#define MB_TCP_TRANS_COMPLETED   (4)
 Status of a completed transaction.
#define MB_TCP_MAX_ADU_SIZE   (260)

Typedefs

typedef struct mb_tcp_transactions_queue mb_tcp_transactions_queue_t
 This structure represents a queue of transactions.

Functions

void mb_tcp_set_secure_addrs (const ip_addr_t *auth_addrs, uint8_t auth_addrs_count, mb_tcp_config_t *conf)
 Sets the secure addresses for a modbus node.
void mb_tcp_set_priority_conns (ip_addr_t *priority_conn_addrs, uint8_t priority_conn_addrs_count, mb_tcp_config_t *conf)
 Sets the addresses for the priority connection pool.
mb_tcp_config_tmb_tcp_init (uint8_t jbus, mb_data_handlers_t *handlers, uint16_t port, uint8_t socket_count, uint16_t keep_alive, uint8_t trans_count, uint8_t non_priority_conns_max)
 Initializes a modbus node.
void mb_tcp_close (mb_tcp_config_t *conf)
 Releases all the connections of the node.
uint8_t mb_tcp_slave_loop (mb_tcp_config_t *conf, uint32_t timeout)
 Function that processes modbus requests.

Detailed Description

Modbus/TCP slave function definitions.

Author
Tecnologix, 2021

Function Documentation

◆ mb_tcp_close()

void mb_tcp_close ( mb_tcp_config_t * conf)

Releases all the connections of the node.

The configuration structure is deallocated.

Parameters
confconfiguration structure of the modbus node to close.

◆ mb_tcp_init()

mb_tcp_config_t * mb_tcp_init ( uint8_t jbus,
mb_data_handlers_t * handlers,
uint16_t port,
uint8_t socket_count,
uint16_t keep_alive,
uint8_t trans_count,
uint8_t non_priority_conns_max )

Initializes a modbus node.

Parameters
jbus0 if the jbus mode is disabled.
handlerspointer to the data handlers structure containing the function pointers to use to process modbus requests.
portTCP port to listen on.
socket_countnumber of socket to use for listening for incoming connections.
keep_aliveTCP keep alive for the established connections.
trans_countmaximum number of transactions to process simultaneously.
non_priority_conns_maxmaximum number of connections of the non-priority pool.
Returns
the configuration of the modbus node.

◆ mb_tcp_set_priority_conns()

void mb_tcp_set_priority_conns ( ip_addr_t * priority_conn_addrs,
uint8_t priority_conn_addrs_count,
mb_tcp_config_t * conf )

Sets the addresses for the priority connection pool.

Connections from these addresses will not be rejected if they are authorized addresses.

Parameters
priority_conn_addrsarray of ip addresses.
priority_conn_addrs_countnumber of elements of the specified array.
confconfiguration of the modbus node.

◆ mb_tcp_set_secure_addrs()

void mb_tcp_set_secure_addrs ( const ip_addr_t * auth_addrs,
uint8_t auth_addrs_count,
mb_tcp_config_t * conf )

Sets the secure addresses for a modbus node.

Parameters
auth_addrsarray of IP addresses that are secure.
auth_addrs_countnumber of IP addresses that are secure.
confconfiguration of the modbus node.

◆ mb_tcp_slave_loop()

uint8_t mb_tcp_slave_loop ( mb_tcp_config_t * conf,
uint32_t timeout )

Function that processes modbus requests.

It has to be invoked in a loop.

Parameters
confconfiguration of the node.
timeouttime to wait for incoming requests to process.
Returns
MSG_RECEIVED if a request has been processed, MSG_TIMEOUT otherwise.