40 lines
834 B
C
40 lines
834 B
C
#ifndef MODBUSTCPSLAVE_H
|
|
#define MODBUSTCPSLAVE_H
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
|
|
#ifndef DATA_BUF_SIZE
|
|
#define DATA_BUF_SIZE 2048
|
|
#endif
|
|
|
|
// RTU接收状态结构体
|
|
typedef struct {
|
|
uint8_t buf[512];
|
|
_Bool done;
|
|
uint16_t size;
|
|
} RtuRxST;
|
|
|
|
extern uint8_t loopback_tcps_modbus_rxbuf[1024];
|
|
extern uint8_t loopback_tcps_modbus_txbuf[1024];
|
|
|
|
// Modbus TCP服务主函数
|
|
int32_t loopback_tcps_modbus(uint8_t sn, uint16_t port);
|
|
|
|
// Modbus TCP转RTU转发主函数
|
|
int32_t loopback_tcps_modbus_to485(uint8_t sn, uint8_t *buf, uint16_t port, uint16_t *timeout, RtuRxST *rtu_rx);
|
|
|
|
// 工具函数
|
|
uint16_t tcp_to_rtu(uint8_t *tcp_buf, uint8_t *rtu_buf);
|
|
uint16_t rtu_to_tcp(uint8_t *rtu_buf, uint8_t *tcp_buf, uint16_t rtu_len, uint8_t *rx_buf);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|