![]() |
GaIA BIOS Library
|
Modbus/TCP common 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>Data Structures | |
| union | ip_addr_t |
| This structure represents an IP address. More... | |
| struct | mb_tcp_adu_t |
| This structure represents a Modbus/TCP Application Data Unit. More... | |
| struct | mb_tcp_connection_t |
| This structure represents a Modbus/TCP connection. More... | |
| struct | mb_tcp_transaction_t |
| This structure represents a Modbus/TCP transaction. 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) |
| Maxiumum size of the Modbus/TCP ADU in bytes. | |
| #define | MB_TCP_NO_ERROR (0) |
| No error. | |
| #define | MB_TCP_QUEUE_EMPTY (-1) |
| Queue is empty. | |
| #define | MB_TCP_NOT_FOUND (-2) |
| The specified object was not found. | |
| #define | MB_TCP_INVALID (-3) |
| The provided date is invalid (e.g. | |
| #define | MB_TCP_ALLOC_ERROR (-4) |
| Error while allocating an object. | |
| #define | MB_TCP_NOT_AUTH (-5) |
| Not authorized. | |
| #define | MB_TCP_NETWORK_ERROR (-6) |
| A network error occurred (e.g. | |
Functions | |
| void | mb_tcp_fill_adu (mb_tcp_adu_t *adu, const uint8_t *buf, uint32_t len) |
| Fills the provided Modbus/TCP ADU with data. | |
| void | mb_tcp_fill_hdr_buf (uint8_t *buf, mb_tcp_adu_t *adu) |
| Fills the provided buffer with the header data from the provided Modbus/TCP ADU. | |
| void | mb_tcp_fill_buf (uint8_t *buf, mb_tcp_adu_t *adu) |
| Fills the provided buffer with header and payload data from the provided Modbus/TCP ADU. | |
| void | mb_tcp_init_tx_adu (mb_tcp_adu_t *adu, uint16_t trans_id, uint8_t unit_id, uint8_t func_code) |
| Initializes a Modbus/TCP ADU to be transmitted. | |
Modbus/TCP common function definitions.
| #define MB_TCP_INVALID (-3) |
The provided date is invalid (e.g.
ADU length not correct).
| #define MB_TCP_NETWORK_ERROR (-6) |
A network error occurred (e.g.
socket is disconnected).
| void mb_tcp_fill_adu | ( | mb_tcp_adu_t * | adu, |
| const uint8_t * | buf, | ||
| uint32_t | len ) |
Fills the provided Modbus/TCP ADU with data.
This function is generally used to copy raw data from a TCP packet to a Modbus/TCP ADU structure and takes care of byte reordering.
| adu | Modbus/TCP ADU to be filled. |
| buf | buffer containing raw data. |
| len | size of buf. |
| void mb_tcp_fill_buf | ( | uint8_t * | buf, |
| mb_tcp_adu_t * | adu ) |
Fills the provided buffer with header and payload data from the provided Modbus/TCP ADU.
This function takes care of byte reordering is generally used to copy data from a Modbus/TCP ADU to a raw buffer before sending it.
| buf | buffer to store the header data into. |
| adu | Modbus/TCP ADU to read the header data from. |
| void mb_tcp_fill_hdr_buf | ( | uint8_t * | buf, |
| mb_tcp_adu_t * | adu ) |
Fills the provided buffer with the header data from the provided Modbus/TCP ADU.
This function takes care of byte reordering and is generally used to copy data from a Modbus/TCP ADU to a raw buffer before sending it.
| buf | buffer to store the header data into. |
| adu | Modbus/TCP ADU to read the header data from. |
| void mb_tcp_init_tx_adu | ( | mb_tcp_adu_t * | adu, |
| uint16_t | trans_id, | ||
| uint8_t | unit_id, | ||
| uint8_t | func_code ) |
Initializes a Modbus/TCP ADU to be transmitted.
| adu | Modbus/TCP ADU to be initialized. |
| trans_id | transaction id. |
| unit_id | unit id. |
| func_code | Modbus function code. |