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.

77 lines
1.6 KiB
C

#ifndef __PD_MODBUS_H__
#define __PD_MODBUS_H__
#ifdef CFG_DEV_TYPE_LAND_PD
#include "pd_main.h"
#define WRITE 1
#define READ 0
#define MODBUS_DEVICE_TYPE_ADDR 0x0
#define MODBUS_DEVICE_TYPE_LEN 2
#define MODBUS_IR_CURRENT_ADDR 0x10 // 铁芯电流
#define MODBUS_IR_CURRENT_LEN 2
#define MODBUS_IR_ALARM_ADDR 0x20 // 铁芯报警
#define MODBUS_IR_ALARM_LEN 1
#define MODBUS_DC_CURRENT_ADDR 0x34 // 直流偏磁
#define MODBUS_DC_CURRENT_LEN 2
#define MODBUS_UNIT_IR 0x01
#define DEVICE_M_TYPE 0x03
#define DEVICE_IR_TYPE 0x04
#define DEVICE_DC_TYPE 0x05
#define POS_DATA_LEN 4
#define POS_UINT_ID 6
#define POS_FUNCTION 7
typedef struct
{
uint8_t unit_id;
uint8_t status;
uint8_t is_insert;
uint8_t is_connect;
uint8_t type_m;
uint8_t type_s;
uint32_t current;
uint16_t alarm;
} card_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];
card_t card[PD_SLOTS_MAX];
}modbus_t;
extern modbus_t modbus;
extern int32_t modbus_handle_init(void);
extern int32_t modbus_handle_init_after(void);
#endif
#endif