You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.4 KiB
C

#ifndef __PD_MODBUS_H__
#define __PD_MODBUS_H__
#ifdef CFG_DEV_TYPE_LAND_PD
#define WRITE 1
#define READ 0
#define MODBUS_DEVICE_TYPE_ADDR 0x0
#define MODBUS_IR_CURRENT_ADDR 0x10 // 铁芯
#define MODBUS_IR_CURRENT_LEN 2
#define MODBUS_DC_CURRENT_ADDR 0x34 // 直流偏磁
#define MODBUS_DC_CURRENT_LEN 2
#define MODBUS_UNIT_IR 0x01
#define MODBUS_CURRENT_LEN 4
#define MODBUS_ADDR_ALARM 0x32
#define MODBUS_ALARM_LEN 2
#define DEVICE_IR_TYPE 0x0304
#define DEVICE_DC_TYPE 0x0305
#define POS_UINT_ID 6
#define POS_FUNCTION 7
#define MAX_SLOT 6
typedef struct
{
uint8_t unit_id;
uint8_t status;
uint16_t type;
uint32_t current;
uint16_t alarm;
} stat_t;
// 定义Modbus TCP MBAP头
//#pragma pack(push, 1)
typedef struct
{
uint16_t transaction_id; // 事务处理标识
uint16_t protocol_id; // 协议标识
uint16_t length; // 数据长度
uint8_t unit_id; // 设备地址
uint8_t function_code; // 功能码
} modbus_tcp_t;
//#pragma pack(pop)
typedef struct
{
uint8_t function;
uint16_t address;
uint16_t length;
} pdu_t;
typedef struct
{
int fd;
uint8_t txbuf[512];
uint8_t rxbuf[512];
stat_t stat[MAX_SLOT];
}modbus_t;
extern int32_t modbus_handle_init(void);
extern int32_t modbus_handle_init_after(void);
#endif
#endif