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.

159 lines
4.4 KiB
C

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/****************************************************************************
** 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.h"
#pragma pack (push ,1)
#ifdef _WIN32
#pragma comment(lib,"modbus.lib")
#endif
// 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分量告警
// 预留字节
struct RBS {
unsigned char rs1 : 1, // 1-通信异常
rs2 : 1, // self check exception
rs3 : 1, // signal exception
rs4 : 1, // power exception
rs5 : 1, // reserve
rs6 : 1, // reserve
rs7 : 1, // reserve
rs8 : 1; // reserve
};
// 监测状态位
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
};
typedef struct {
struct BST btl; // 监测单元状态
struct RBS brs; // reserve
struct BWL bwl; // 告警分量定义
struct BWM bwm; // 告警分量定义
struct BWH bwh; // 告警分量定义
unsigned char rsv; // reserve
}ST_BIT_MAP;
//负荷计算:
//发电状态下P1 = 电压(V)x电流(A)x发电持续时间(秒)
//抽水状态下P2 = 电压(V)x电流(A)x发电持续时间(秒)
//空闲状态下P3 = 电压(V)x电流(A)x发电持续时间(秒)
//P = ((P1+P2+P3)/(主变额定容量(VA)x1000*1000*24*3600))*100%
//主变额定容量(MVA)x1000 * 1000: 是单位转为VA.
//24*3600 : 一天的秒数。
#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 */