/**************************************************************************** ** File name : HTModbus.h ** Description : ISO Modbus protoclo api ** Create date : 2019.09.01 ** Auther by : Liuyx ** Version info : V1.0.01 ** Copyright (C) 2002-2019 xi'an huatek, Inc Co., Ltd ** Update record: ** DATE AUTHER DESC ** ------------------------------------------------------------------------- ** 2019.09.01 Liuyx first build ****************************************************************************/ #ifndef __HT_MODBUS_PROTOCOL_H #define __HT_MODBUS_PROTOCOL_H #include "HTGlobal.h" //#include "modbus/modbus.h" #pragma pack (push ,1) #ifdef _WIN32 //#pragma comment(lib,"modbus.lib") #endif // 设备地址 #define MODBUS_DEVICE_ADDR 0x01 // 控制参数地址定义 #define MODBUS_CONTROL_START_ADDR 0x00CF //控制参数寄存器起始地址-噪声启动信号 #define MODBUS_CONTROL_ADDR_COUNT 32 //控制参数寄存器个数 // 监测单元地址定义 #define MODBUS_MONITOR_START_ADDR 0x0000 // 监测单元寄存器起始地址 #define MODBUS_MONITOR_UNIT_COUNT 3 // 监测单元寄存器个数 // Modbus function code #define MODBUS_FUNC_CODE3 0x03 // 3 #define MODBUS_FUNC_CODE6 0x06 // 6 #define MODBUS_FUNC_CODE16 0x10 // 16 // Modbus respone code #define MODBUS_FUNC_CODE3_ERR 0x83 // 3异常代码 // Modbus通信方式 typedef enum{ HT_MODBUS_MODE_TCP = 1, /* modbus communication mode by tcp */ HT_MODBUS_MODE_RTU = 2, /* modbus communication mode by rtu */ HT_MODBUS_MODE_ASC = 3 /* modbus communication mode by ascii */ }HT_MODBUS_TYPE; #define HT_MODBUS_RTU // 监测单元定义 #define HT_UNIT_VOLTAGE 0x0001 // 母线电压单元 #define HT_UNIT_CAPACITY 0x0002 // 容性监测单元 #define HT_UNIT_ARRESTER 0x0003 // 避雷器监测单元 #define HT_UNIT_ICGE 0x0004 // 变压器铁芯监测单元 #define HT_UNIT_TEMP_HUMI 0x000A // 环境温湿度监测单元 #define HT_UNIT_SLV 0x000F // 声级振动监测单元 // 监测状态定义 #define HT_STAT_NORNAL 0x0000 // 正常 #define HT_STAT_NET_EXCEPTION 0x0001 // 通信异常 #define HT_STAT_SELF_CHECK 0x0002 // 自检异常 #define HT_STAT_SIGNAL 0x0004 // 信号异常 #define HT_STAT_POWER 0x0008 // 供电异常 // 告警分量定义 #define WARN_HIGT_BIT0_100HZ ((1<<16) & 0xff) // Bit0 = 1 原边加速度100HZ分量告警 //Bit1 = 1 原边加速度200HZ分量告警 //Bit2 = 1 原边加速度300HZ分量告警 //Bit3 = 1 原边加速度400HZ分量告警 //Bit4 = 1 原边加速度500HZ分量告警 //Bit5 = 1 原边加速度600HZ分量告警 //Bit6 = 1 原边加速度700HZ分量告警 //Bit7 = 1 原边加速度800HZ分量告警 //Bit8 = 1 原边加速度900HZ分量告警 //Bit9 = 1 原边加速度1000HZ分量告警 //Bit10 = 1 副边加速度100HZ分量告警 //Bit11 = 1 副边加速度200HZ分量告警 //Bit12 = 1 副边加速度300HZ分量告警 //Bit13 = 1 副边加速度400HZ分量告警 //Bit14 = 1 副边加速度500HZ分量告警 //Bit15 = 1 副边加速度600HZ分量告警 typedef struct { char errcode; char errmsg[64]; }ST_MODBUS_ERRMSG; // 监测单元状态 typedef struct { unsigned char rs0 : 1,// 预留位 rs1 : 1, // 预留位 rs2 : 1, // 预留位 rs3 : 1, // 预留位 rs4 : 1, // 预留位 st5 : 1, // Bit2=1 采样板3通讯异常 st6 : 1, // Bit1=1 采样板2通讯异常 st7 : 1; // Bit0=1 采样板1通讯异常 }UCTYPE; // 监测状态位 struct BST { unsigned char cex : 1, // 1-通信异常 cce : 1, // self check exception sig : 1, // signal exception pex : 1, // power exception bt4 : 1, // reserve bt5 : 1, // reserve bt6 : 1, // reserve bt7 : 1; // reserve }; //监测告警位 struct BWL { unsigned char p100 : 1, // 1-通信异常 p200 : 1, // self check exception p300 : 1, // signal exception p400 : 1, // power exception p500 : 1, // reserve p600 : 1, // reserve p700 : 1, // reserve p800 : 1; // reserve }; //监测告警位 struct BWM { unsigned char p900 : 1, // 1-通信异常 p1000 : 1, // self check exception s100 : 1, // signal exception s200 : 1, // power exception s300 : 1, // reserve s400 : 1, // reserve s500 : 1, // reserve s600 : 1; // reserve }; //监测告警位 struct BWH { unsigned char s700 : 1, // 1-通信异常 s800 : 1, // self check exception s900 : 1, // signal exception s1000 : 1, // power exception s300 : 1, // reserve s400 : 1, // reserve s500 : 1, // reserve s600 : 1; // reserve }; // 按位定义unsigned short struct stUSHORT{ char Low; UCTYPE Hig; }; typedef struct { unsigned short usUtilType; // 监测单元类型 unsigned char ucL1; // 预留 UCTYPE ucH1; // 监测单元状态 unsigned char ucL2; // 预留 UCTYPE ucH2; // 监测单元故障 }ST_BIT_MAP; // 控制参数 typedef struct { // 控制参数-下设IED参数 unsigned short usEnvEnable; //13噪声启动信号 unsigned short usNeuEnable; //14中心点启动信号 unsigned short usAUpEnable; //1原边A相上侧启动信号 unsigned short usADnEnable; //2原边A相下侧启动信号 unsigned short usBUpEnable; //3原边B相上侧启动信号 unsigned short usBDnEnable; //4原边B相下侧启动信号 unsigned short usCUpEnable; //5原边C相上侧启动信号 unsigned short usCDnEnable; //6原边C相下侧启动信号 unsigned short usaupEnable; //7副边A相上侧启动信号 unsigned short usadnEnable; //8副边A相下侧启动信号 unsigned short usbupEnable; //9副边B相上侧启动信号 unsigned short usbdnEnable; //10副边B相下侧启动信号 unsigned short uscupEnable; //11副边C相上侧启动信号 unsigned short uscdnEnable; //12副边C相下侧启动信号 unsigned short usSmpProd; //15采集频率(KHz) unsigned short usSmpInt; //16采样间隔(小时) unsigned short usStartTime; //17起始时间 unsigned short usEnable; //18使能信号, true:yes false: no unsigned short usEnvChannel; //19噪声传感器通道号 unsigned short usNeuChannel; //20电流传感器通道号 unsigned short usAUChannel; //21原边A相上侧传感器通道号 unsigned short usADChannel; //22原边A相下侧传感器通道号 unsigned short usBUChannel; //23原边B相上侧传感器通道号 unsigned short usBDChannel; //24原边B相下侧传感器通道号 unsigned short usCUChannel; //25原边C相上侧传感器通道号 unsigned short usCDChannel; //26原边C相下侧传感器通道号 unsigned short usauChannel; //27副边A相上侧传感器通道号 unsigned short usadChannel; //28副边A相下侧传感器通道号 unsigned short usbuChannel; //29副边B相上侧传感器通道号 unsigned short usbdChannel; //30副边B相下侧传感器通道号 unsigned short uscuChannel; //31副边C相上侧传感器通道号 unsigned short uscdChannel; //32副边C相下侧传感器通道号 }ST_MODBUS_CONTROL; typedef struct { unsigned short useqid; // 为此次通信事务处理标识符,一般每次通信之后将被要求加1以区别不同的通信数据报文 unsigned short usprotol; // 协议标识符,00 00为modbus协议 unsigned short uslength; // 数据长度,用来指示接下来数据的长度,单位字节; unsigned char bdevid; // 设备地址,应答报文要求与先前对应的请求保持一致,用以标识连接在串行线或者网络上的远程服务端的地址。以上七个字节也被称为modbus报文头 unsigned char bfunc; // 功能码,此时代码03为读取保持寄存器数据 }ST_MODBUS_HEADER; typedef struct { ST_MODBUS_HEADER stHeader; // 包头 unsigned short usbeginaddr; // 首个寄存器地址/索引 unsigned short uscount; // 寄存器的个数 RTU格式 (无需CRC) }ST_REQ_READ_REGEDIT_FUNC3; // 功能代码3应答报文格式 typedef struct { ST_MODBUS_HEADER stHeader; // 包头 unsigned char blength; // 读取的字节数(功能代码3,返回的每个寄存器的数值为2字节) unsigned short *pusVal; // 寄存器数据 (无需CRC) }ST_RSP_READ_REGEDIT_FUNC3; typedef struct { ST_MODBUS_HEADER stHeader; // 包头 unsigned short usbeginaddr; // 首个寄存器地址/索引 unsigned short uscount; // 寄存器的个数 RTU格式 (无需CRC) unsigned char blen; // 发送字节个数 }ST_REQ_WRITE_REGEDIT_FUNC16; #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ void *thread_modbus_service_proc(void *arg); #ifdef __cplusplus } #endif #pragma pack (pop) #endif /* end __HT_MODBUS_PROTOCOL_H */