16 #if AGILE_MODBUS_USING_TCP
56 if (ctx_tcp->
t_id < UINT16_MAX)
60 req[0] = ctx_tcp->
t_id >> 8;
61 req[1] = ctx_tcp->
t_id & 0x00ff;
73 req[9] = addr & 0x00ff;
75 req[11] = nb & 0x00ff;
92 rsp[0] = sft->
t_id >> 8;
93 rsp[1] = sft->
t_id & 0x00ff;
117 return (req[0] << 8) + req[1];
129 int mbap_length = req_length - 6;
131 req[4] = mbap_length >> 8;
132 req[5] = mbap_length & 0x00FF;
160 const uint8_t *rsp,
int rsp_length)
165 if (req[0] != rsp[0] || req[1] != rsp[1])
169 if (rsp[2] != 0x0 && rsp[3] != 0x0)
Agile Modbus software package common header file.
Agile Modbus package TCP header file.
void agile_modbus_common_init(agile_modbus_t *ctx, uint8_t *send_buf, int send_bufsz, uint8_t *read_buf, int read_bufsz)
initialize modbus handle
@ AGILE_MODBUS_BACKEND_TYPE_TCP
TCP.
#define AGILE_MODBUS_TCP_CHECKSUM_LENGTH
#define AGILE_MODBUS_TCP_PRESET_RSP_LENGTH
#define AGILE_MODBUS_TCP_MAX_ADU_LENGTH
#define AGILE_MODBUS_TCP_PRESET_REQ_LENGTH
#define AGILE_MODBUS_TCP_HEADER_LENGTH
int agile_modbus_tcp_init(agile_modbus_tcp_t *ctx, uint8_t *send_buf, int send_bufsz, uint8_t *read_buf, int read_bufsz)
TCP initialization.
static const agile_modbus_backend_t agile_modbus_tcp_backend
TCP backend interface.
static int agile_modbus_tcp_pre_check_confirmation(agile_modbus_t *ctx, const uint8_t *req, const uint8_t *rsp, int rsp_length)
TCP pre-check confirmation interface (compare transaction identifier and protocol identifier)
static int agile_modbus_tcp_set_slave(agile_modbus_t *ctx, int slave)
TCP set address interface.
static int agile_modbus_tcp_check_integrity(agile_modbus_t *ctx, uint8_t *msg, const int msg_length)
TCP check receiving data integrity interface.
static int agile_modbus_tcp_send_msg_pre(uint8_t *req, int req_length)
TCP pre-send data interface (calculate the value of the length field and store it)
static int agile_modbus_tcp_build_request_basis(agile_modbus_t *ctx, int function, int addr, int nb, uint8_t *req)
TCP builds the basic request message interface (header message)
static int agile_modbus_tcp_build_response_basis(agile_modbus_sft_t *sft, uint8_t *rsp)
TCP builds a basic response message interface (header message)
static int agile_modbus_tcp_prepare_response_tid(const uint8_t *req, int *req_length)
TCP ready response interface.
Agile Modbus backend interface structure.
contains the modbus header parameter structure
int t_id
Transaction identifier.
int function
function code
agile_modbus_t _ctx
modbus handle
uint16_t t_id
Extract from MODBUS Messaging on TCP/IP Implementation Guide V1.0b (page 23/46): The transaction iden...
const agile_modbus_backend_t * backend
Backend interface.
void * backend_data
Backend data, pointing to RTU or TCP structure.