File syn_modbus_tcp.c¶
FileList > proto > syn_modbus_tcp.c
Go to the source code of this file
Modbus TCP ADU (MBAP) framing implementation.
#include "../util/syn_assert.h"#include "../util/syn_pack.h"#include "syn_modbus_tcp.h"#include <string.h>
Public Functions¶
| Type | Name |
|---|---|
| bool | syn_mbap_decode_header (const uint8_t * buf, SYN_MBAP_Header * hdr) Decode an MBAP header from a byte buffer. |
| void | syn_mbap_encode_header (const SYN_MBAP_Header * hdr, uint8_t * buf) Encode an MBAP header into a byte buffer. |
| SYN_Status | syn_modbus_tcp_build_client_adu (uint16_t transaction_id, uint8_t unit_id, const uint8_t * pdu, uint16_t pdu_len, uint8_t * req_adu, uint16_t req_max, uint16_t * req_len) Build a Modbus TCP Master request ADU. |
| bool | syn_modbus_tcp_process_slave (SYN_Modbus * mb, const uint8_t * req_adu, uint16_t req_len, uint8_t * resp_adu, uint16_t resp_max, uint16_t * resp_len) Process an incoming Modbus TCP ADU frame on a Modbus Slave instance. |
Public Static Functions¶
| Type | Name |
|---|---|
| uint16_t | get_response_pdu_len (const uint8_t * buf) |
Public Functions Documentation¶
function syn_mbap_decode_header¶
Decode an MBAP header from a byte buffer.
Parameters:
bufInput byte buffer (must be at least 7 bytes).hdrPointer to destination MBAP header structure.
Returns:
true if valid Modbus protocol ID (0x0000).
function syn_mbap_encode_header¶
Encode an MBAP header into a byte buffer.
Parameters:
hdrPointer to MBAP header structure.bufOutput byte buffer (must be at least 7 bytes).
function syn_modbus_tcp_build_client_adu¶
Build a Modbus TCP Master request ADU.
SYN_Status syn_modbus_tcp_build_client_adu (
uint16_t transaction_id,
uint8_t unit_id,
const uint8_t * pdu,
uint16_t pdu_len,
uint8_t * req_adu,
uint16_t req_max,
uint16_t * req_len
)
Parameters:
transaction_idTransaction sequence number.unit_idTarget Unit ID (slave address).pduRaw PDU bytes (Function Code + Data).pdu_lenPDU length in bytes.req_aduOutput buffer for complete Modbus TCP ADU.req_maxOutput buffer capacity.req_lenOut: Total ADU length (7 + pdu_len).
Returns:
SYN_OK on success, SYN_NO_MEMORY if buffer too small.
function syn_modbus_tcp_process_slave¶
Process an incoming Modbus TCP ADU frame on a Modbus Slave instance.
bool syn_modbus_tcp_process_slave (
SYN_Modbus * mb,
const uint8_t * req_adu,
uint16_t req_len,
uint8_t * resp_adu,
uint16_t resp_max,
uint16_t * resp_len
)
Takes a full Modbus TCP ADU (MBAP header + PDU), processes the PDU using the Modbus slave engine, and builds the corresponding Modbus TCP response ADU.
Parameters:
mbModbus RTU/PDU slave instance.req_aduInput Modbus TCP request ADU buffer.req_lenLength of request ADU in bytes.resp_aduOutput Modbus TCP response ADU buffer.resp_maxCapacity of response ADU buffer.resp_lenOut: Length of generated response ADU in bytes.
Returns:
true if response ADU generated, false if no response (or invalid ADU).
Public Static Functions Documentation¶
function get_response_pdu_len¶
The documentation for this class was generated from the following file src/syntropic/proto/syn_modbus_tcp.c