map/das-dn/inc/iec_101_104_lib.h
2024-07-08 10:27:17 +08:00

424 lines
19 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef _ZJD_IEC_101_104_LIB_H_
#define _ZJD_IEC_101_104_LIB_H_
//define for iec101 and iec104
#define M_SP_NA_1 1 //单点遥信
#define M_SP_TA_1 2 //带时标的单点遥信
#define M_DP_NA_1 3 //双点遥信
#define M_DP_TA_1 4 //带时标的双点遥信
#define M_ST_NA_1 5 //步位信息
#define M_ST_TA_1 6 //带时标的步位信息
#define M_BO_NA_1 7 //32比特串
#define M_BO_TA_1 8 //带时标的32比特串
#define M_ME_NA_1 9 //测量值,归一化值
#define M_ME_TA_1 10 //带时标的遥测量,归一化值
#define M_ME_NB_1 11 //测量值,标度化值
#define M_ME_TB_1 12 //带时标的遥测量,标度化值
#define M_ME_NC_1 13 //测量值,短浮点数
#define M_ME_TC_1 14 //带时标的遥测量值,短浮点数
#define M_IT_NA_1 15 //累积量
#define M_IT_TA_1 16 //带时标的累计量
#define M_EP_TA_1 17 //带时标的继电保护设备事件
#define M_EP_TB_1 18 //带时标的继电保护设备成组启动事件
#define M_EP_TC_1 19 //带时标的继电保护设备成组输出电路信息
#define M_PS_NA_1 20 //带变为检出的成组单点信息
#define M_ME_ND_1 21 //测量值,不带品质描述的归一化测量值
#define M_SP_TB_1 30 //带CP56Time2a时标的单点信息
#define M_DP_TB_1 31 //带CP56Time2a时标的双点信息
#define M_ST_TB_1 32 //带CP56Time2a时标的步位置信息
#define M_BO_TB_1 33 //带CP56Time2a时标的32比特串
#define M_ME_TD_1 34 //带CP56Time2a时标的遥测量值归一化值
#define M_ME_TE_1 35 //带CP56Time2a时标的遥测量值标度化值
#define M_ME_TF_1 36 //带CP56Time2a时标的遥测量值短浮点数
#define M_IT_TB_1 37 //带CP56Time2a时标的累计量
#define M_EP_TD_1 38 //带CP56Time2a时标的继电保护设备事件
#define M_EP_TE_1 39 //带CP56Time2a时标的继电保护设备成组启动事件
#define M_EP_TF_1 40 //带CP56Time2a时标的继电保护设备成组输出电路信息
#define M_EI_NA_1 70 //初始化结束
#define C_SC_NA_1 45 //单点令
#define C_DC_NA_1 46 //双点令
#define C_RC_NA_1 47 //步调节命令
#define C_SE_NA_1 48 //设定值命令,归一化值
#define C_SE_NB_1 49 //设定值命令,标度化值
#define C_SE_NC_1 50 //设定值命令,短浮点数
#define C_BO_NA_1 51 //32比特串
#define C_SC_TA_1 58
#define C_DC_TA_1 59
#define C_RC_TA_1 60
#define C_SE_TA_1 61
#define C_SE_TB_1 62
#define C_SE_TC_1 63
#define C_BO_TA_1 64
#define C_IC_NA_1 100 //总召唤命令
#define C_CI_NA_1 101 //累计量召唤命令
#define C_RD_NA_1 102 //读命令
#define C_CS_NA_1 103 //时钟同步
#define C_TS_NA_1 104 //测试命令
#define C_RP_NA_1 105 //复位进程命令
#define C_CD_NA_1 106 //延时获得命令
#define C_TS_TA_1 107 //带CP56Time2a时标的测试命令
#define P_ME_NA_1 110 //测量值参数,归一化值
#define P_ME_NB_1 111 //测量值参数,标度化值
#define P_ME_NC_1 112 //测量值参数,短浮点数
#define P_AC_NA_1 113 //参数激活
#define F_FR_NA_1 120 //文件准备就绪
#define F_SR_NA_1 121 //节准备就绪
#define F_SC_NA_1 122 //召唤目录,选择文件,召唤文件召唤节
#define F_LS_NA_1 123 //最后的节,最后的段
#define F_AF_NA_1 124 //认可文件,认可节
#define F_SG_NA_1 125 //段
#define F_DR_TA_1 126 //目录
#define F_SC_NB_1 127
#define C_TD_NA_1 145
#define M_TD_NA_1 146
#define C_SB_NA_1 133
#define M_SB_NA_1 130
#define C_NC_NA_1 147
#define M_NC_NA_1 148
#define C_HD_NB_1 180 //综合能源服务平台终端扩展
#define C_HD_NC_1 182 //综合能源服务平台终端扩展补采遥测(遥信数据也包含)标识
#define C_HD_ND_1 183 //综合能源服务平台终端扩展补采电度标识
#define IEC_101_104_COT_PER_CYC 1 //周期、循环
#define IEC_101_104_COT_BACK 2 //背景扫描
#define IEC_101_104_COT_SPONT 3 //突发(自发)
#define IEC_101_104_COT_INIT 4 //初始化完成
#define IEC_101_104_COT_REQ 5 //请求或者被请求
#define IEC_101_104_COT_ACT 6 //激活
#define IEC_101_104_COT_ACTCON 7 //激活确认
#define IEC_101_104_COT_DEACT 8 //停止激活
#define IEC_101_104_COT_DEACTCON 9 //停止激活确认
#define IEC_101_104_COT_ACTTREM 10 //激活终止
#define IEC_101_104_COT_RETREM 11 //远方命令引起的返送信息
#define IEC_101_104_COT_RETLOC 12 //当地命令引起的返送信息
#define IEC_101_104_COT_FILE 13 //文件传送
#define IEC_101_104_COT_INTERROGATION 20 //响应总召唤
#define IEC_101_104_COT_INRO1 21 //响应第一组召唤
#define IEC_101_104_COT_INRO2 22 //响应第二组召唤
#define IEC_101_104_COT_INRO3 23 //响应第三组召唤
#define IEC_101_104_COT_INRO4 24 //响应第四组召唤
#define IEC_101_104_COT_INRO5 25 //响应第五组召唤
#define IEC_101_104_COT_INRO6 26 //响应第六组召唤
#define IEC_101_104_COT_INRO7 27 //响应第七组召唤
#define IEC_101_104_COT_INRO8 28 //响应第八组召唤
#define IEC_101_104_COT_INRO9 29 //响应第九组召唤
#define IEC_101_104_COT_INRO10 30 //响应第十组召唤
#define IEC_101_104_COT_INRO11 31 //响应第十一组召唤
#define IEC_101_104_COT_INRO12 32 //响应第十二组召唤
#define IEC_101_104_COT_INRO13 33 //响应第十三组召唤
#define IEC_101_104_COT_INRO14 34 //响应第十四组召唤
#define IEC_101_104_COT_INRO15 35 //响应第十五组召唤
#define IEC_101_104_COT_INRO16 36 //响应第十六组召唤
#define IEC_101_104_COT_REQCOGEN 37 //响应计数量站召唤
#define IEC_101_104_COT_REQCO1 38 //响应笫一组计数量召唤
#define IEC_101_104_COT_REQCO2 39 //响应笫二组计数量召唤
#define IEC_101_104_COT_REQCO3 40 //响应笫三组计数量召唤
#define IEC_101_104_COT_REQCO4 41 //响应笫四组计数量召唤
#define IEC_101_104_COT_UNKNOWN_TI 44 //未知类型标识
#define IEC_101_104_COT_UNKNOWN_COT 45 //未知传送原因
#define IEC_101_104_COT_UNKNOWN_ASDU 46 //未知的应用服务数据单元公共地址
#define IEC_101_104_COT_UNKNOWN_INFO 47 //未知的信息对象地址
#define IEC_101_104_COT_HDREQ 180 //综合能源服务平台终端扩展
#define IEC_101_104_COT_TEST 0x80
#define IEC_101_104_COT_PN 0x40
typedef BYTE TypeID;
typedef BYTE QualifierOfInterrogation;
#define IEC60870_QOI_STATION 20
#define IEC60870_QOI_GROUP_1 21
#define IEC60870_QOI_GROUP_2 22
#define IEC60870_QOI_GROUP_3 23
#define IEC60870_QOI_GROUP_4 24
#define IEC60870_QOI_GROUP_5 25
#define IEC60870_QOI_GROUP_6 26
#define IEC60870_QOI_GROUP_7 27
#define IEC60870_QOI_GROUP_8 28
#define IEC60870_QOI_GROUP_9 29
#define IEC60870_QOI_GROUP_10 30
#define IEC60870_QOI_GROUP_11 31
#define IEC60870_QOI_GROUP_12 32
#define IEC60870_QOI_GROUP_13 33
#define IEC60870_QOI_GROUP_14 34
#define IEC60870_QOI_GROUP_15 35
#define IEC60870_QOI_GROUP_16 36
typedef BYTE QualifierOfCIC;
#define IEC60870_QCC_RQT_GROUP_1 1
#define IEC60870_QCC_RQT_GROUP_2 2
#define IEC60870_QCC_RQT_GROUP_3 3
#define IEC60870_QCC_RQT_GROUP_4 4
#define IEC60870_QCC_RQT_GENERAL 5
#define IEC_101_104_YX_START_ADDR 0x0001
#define IEC_101_104_YX_END_ADDR 0x1000
#define IEC_101_104_RELAY_EVENT_START_ADDR 0x1001
#define IEC_101_104_RELAY_EVENT_END_ADDR 0x2000
#define IEC_101_104_RELAY_CURRENT_START_ADDR 0x2001
#define IEC_101_104_RELAY_CURRENT_END_ADDR 0x3000
#define IEC_101_104_RELAY_SETTINGS_START_ADDR 0x3001
#define IEC_101_104_RELAY_SETTINGS_END_ADDR 0x4000
#define IEC_101_104_YC_START_ADDR 0x4001
#define IEC_101_104_YC_END_ADDR 0x5000
#define IEC_101_104_PARAM_START_ADDR 0x5001
#define IEC_101_104_PARAM_END_ADDR 0x6000
#define IEC_101_104_YK_YT_START_ADDR 0x6001
#define IEC_101_104_YK_YT_END_ADDR 0x6200
#define IEC_101_104_SETADDR_START_ADDR 0x6201
#define IEC_101_104_SETADDR_END_ADDR 0x6400
#define IEC_101_104_YM_START_ADDR 0x6401
#define IEC_101_104_YM_END_ADDR 0x6600
#define LL_FC_00_RESET_REMOTE_LINK 0
#define LL_FC_01_RESET_USER_PROCESS 1
#define LL_FC_02_TEST_FUNCTION_FOR_LINK 2
#define LL_FC_03_USER_DATA_CONFIRMED 3
#define LL_FC_04_USER_DATA_NO_REPLY 4
#define LL_FC_07_RESET_FCB 7
#define LL_FC_08_REQUEST_FOR_ACCESS_DEMAND 8
#define LL_FC_09_REQUEST_LINK_STATUS 9
#define LL_FC_10_REQUEST_USER_DATA_CLASS_1 10
#define LL_FC_11_REQUEST_USER_DATA_CLASS_2 11
#define LL_FC_00_ACK 0
#define LL_FC_01_NACK 1
#define LL_FC_08_RESP_USER_DATA 8
#define LL_FC_09_RESP_NACK_NO_DATA 9
#define LL_FC_11_STATUS_OF_LINK_OR_ACCESS_DEMAND 11
#define LL_FC_14_SERVICE_NOT_FUNCTIONING 14
#define LL_FC_15_SERVICE_NOT_IMPLEMENTED 15
#define USE_YX_SP 0
#define USE_YX_DP 1
#define USE_YC_NA 0
#define USE_YC_NB 1
#define USE_YC_NC 2
#define USE_YC_ND 3
#define USE_YK_DEF 0
#define USE_YK_DC 1
#define USE_YK_SC 2
#define USE_YT_NA 0
#define USE_YT_NB 1
#define USE_YT_NC 2
#define DCO_ON 0x02
#define DCO_OFF 0x01
#define SCO_ON 0x01
#define SCO_OFF 0x00
#define IEC_101_104_SE 0x80
#define IEC_LEVEL_NUM 20 //每个优先级的数量
#define MAX_LEVEL_BUFFER_SIZE 512
#define GET_COT(X) ((X & 0x3f))
#define GET_NUM(X) ((X & 0x7f))
#define GET_SPI(X) ((X & 0x01) == 0x01 ? TRUE : FALSE)
#define GET_DPI(X) ((X & 0x03) == 0x02 ? TRUE : FALSE)
#define GET_SCO(X) ((X & 0x01) == 0x01 ? TRUE : FALSE)
#define GET_DCO(X) ((X & 0x03) == 0x02 ? TRUE : FALSE)
#define GET_SE(X) ((X & 0x80) == 0x80 ? TRUE : FALSE)
#define GET_SQ(X) ((X & 0x80) == 0x80 ? TRUE : FALSE)
#define GET_PN(X) ((X & 0x80) == 0x80 ? TRUE : FALSE)
#define GET_TEST(X) ((X & 0x40) == 0x40 ? TRUE : FALSE)
typedef struct
{
WORD NS;
WORD length;
BYTE data[4096];
time_t timer;
} APDUBuffer;
#if !defined(NO_ERROR)
#define NO_ERROR 0L
#endif
#define ERROR_CAUSE_OF_TRANSMISSION -1L
#define ERROR_PN -2L
#define ERROR_TEST -3L
#define ERROR_ASDU -4L
#define ERROR_VSQ -5L
#define ERROR_INFORMATION_ADDRESS -6L
#define ERROR_PARAM -7L
#define ERROR_UNKNOWN -8L
//IEC101_IEC104
static const value_string iec_101_104_asdu_types [] = {
{ M_SP_NA_1, "M_SP_NA_1" },
{ M_DP_NA_1, "M_DP_NA_1" },
{ M_ST_NA_1, "M_ST_NA_1" },
{ M_BO_NA_1, "M_BO_NA_1" },
{ M_ME_NA_1, "M_ME_NA_1" },
{ M_ME_NB_1, "M_ME_NB_1" },
{ M_ME_NC_1, "M_ME_NC_1" },
{ M_IT_NA_1, "M_IT_NA_1" },
{ M_PS_NA_1, "M_PS_NA_1" },
{ M_ME_ND_1, "M_ME_ND_1" },
{ M_SP_TB_1, "M_SP_TB_1" },
{ M_DP_TB_1, "M_DP_TB_1" },
{ M_ST_TB_1, "M_ST_TB_1" },
{ M_BO_TB_1, "M_BO_TB_1" },
{ M_ME_TD_1, "M_ME_TD_1" },
{ M_ME_TE_1, "M_ME_TE_1" },
{ M_ME_TF_1, "M_ME_TF_1" },
{ M_IT_TB_1, "M_IT_TB_1" },
{ M_EP_TD_1, "M_EP_TD_1" },
{ M_EP_TE_1, "M_EP_TE_1" },
{ M_EP_TF_1, "M_EP_TF_1" },
{ C_SC_NA_1, "C_SC_NA_1" },
{ C_DC_NA_1, "C_DC_NA_1" },
{ C_RC_NA_1, "C_RC_NA_1" },
{ C_SE_NA_1, "C_SE_NA_1" },
{ C_SE_NB_1, "C_SE_NB_1" },
{ C_SE_NC_1, "C_SE_NC_1" },
{ C_BO_NA_1, "C_BO_NA_1" },
{ C_SC_TA_1, "C_SC_TA_1" },
{ C_DC_TA_1, "C_DC_TA_1" },
{ C_RC_TA_1, "C_RC_TA_1" },
{ C_SE_TA_1, "C_SE_TA_1" },
{ C_SE_TB_1, "C_SE_TB_1" },
{ C_SE_TC_1, "C_SE_TC_1" },
{ C_BO_TA_1, "C_BO_TA_1" },
{ M_EI_NA_1, "M_EI_NA_1" },
{ C_IC_NA_1, "C_IC_NA_1" },
{ C_CI_NA_1, "C_CI_NA_1" },
{ C_RD_NA_1, "C_RD_NA_1" },
{ C_CS_NA_1, "C_CS_NA_1" },
{ C_TS_NA_1, "C_TS_NA_1" },
{ C_RP_NA_1, "C_RP_NA_1" },
{ C_CD_NA_1, "C_CD_NA_1" },
{ C_TS_TA_1, "C_TS_TA_1" },
{ P_ME_NA_1, "P_ME_NA_1" },
{ P_ME_NB_1, "P_ME_NB_1" },
{ P_ME_NC_1, "P_ME_NC_1" },
{ P_AC_NA_1, "P_AC_NA_1" },
{ F_FR_NA_1, "F_FR_NA_1" },
{ F_SR_NA_1, "F_SR_NA_1" },
{ F_SC_NA_1, "F_SC_NA_1" },
{ F_LS_NA_1, "F_LS_NA_1" },
{ F_AF_NA_1, "F_AF_NA_1" },
{ F_SG_NA_1, "F_SG_NA_1" },
{ F_DR_TA_1, "F_DR_TA_1" },
{ F_SC_NB_1, "F_SC_NB_1" },
{ 0, NULL }
};
static const value_string iec_101_104_asdu_lngtypes [] = {
{ M_SP_NA_1, "single-point information" },
{ M_DP_NA_1, "double-point information" },
{ M_ST_NA_1, "step position information" },
{ M_BO_NA_1, "bitstring of 32 bits" },
{ M_ME_NA_1, "measured value, normalized value" },
{ M_ME_NB_1, "measured value, scaled value" },
{ M_ME_NC_1, "measured value, short floating point number" },
{ M_IT_NA_1, "integrated totals" },
{ M_PS_NA_1, "packed single-point information with status change detection" },
{ M_ME_ND_1, "measured value, normalized value without quality descriptor" },
{ M_SP_TB_1, "single-point information with time tag CP56Time2a" },
{ M_DP_TB_1, "double-point information with time tag CP56Time2a" },
{ M_ST_TB_1, "step position information with time tag CP56Time2a" },
{ M_BO_TB_1, "bitstring of 32 bit with time tag CP56Time2a" },
{ M_ME_TD_1, "measured value, normalized value with time tag CP56Time2a" },
{ M_ME_TE_1, "measured value, scaled value with time tag CP56Time2a" },
{ M_ME_TF_1, "measured value, short floating point number with time tag CP56Time2a" },
{ M_IT_TB_1, "integrated totals with time tag CP56Time2a" },
{ M_EP_TD_1, "event of protection equipment with time tag CP56Time2a" },
{ M_EP_TE_1, "packed start events of protection equipment with time tag CP56Time2a" },
{ M_EP_TF_1, "packed output circuit information of protection equipment with time tag CP56Time2a" },
{ C_SC_NA_1, "single command" },
{ C_DC_NA_1, "double command" },
{ C_RC_NA_1, "regulating step command" },
{ C_SE_NA_1, "set point command, normalized value" },
{ C_SE_NB_1, "set point command, scaled value" },
{ C_SE_NC_1, "set point command, short floating point number" },
{ C_BO_NA_1, "bitstring of 32 bits" },
{ C_SC_TA_1, "single command with time tag CP56Time2a" },
{ C_DC_TA_1, "double command with time tag CP56Time2a" },
{ C_RC_TA_1, "regulating step command with time tag CP56Time2a" },
{ C_SE_TA_1, "set point command, normalized value with time tag CP56Time2a" },
{ C_SE_TB_1, "set point command, scaled value with time tag CP56Time2a" },
{ C_SE_TC_1, "set point command, short floating-point number with time tag CP56Time2a" },
{ C_BO_TA_1, "bitstring of 32 bits with time tag CP56Time2a" },
{ M_EI_NA_1, "end of initialization" },
{ C_IC_NA_1, "interrogation command" },
{ C_CI_NA_1, "counter interrogation command" },
{ C_RD_NA_1, "read command" },
{ C_CS_NA_1, "clock synchronization command" },
{ C_TS_NA_1, "test command" },
{ C_RP_NA_1, "reset process command" },
{ C_CD_NA_1, "get timedelay" },
{ C_TS_TA_1, "test command with time tag CP56Time2a" },
{ P_ME_NA_1, "parameter of measured value, normalized value" },
{ P_ME_NB_1, "parameter of measured value, scaled value" },
{ P_ME_NC_1, "parameter of measured value, short floating-point number" },
{ P_AC_NA_1, "parameter activation" },
{ F_FR_NA_1, "file ready" },
{ F_SR_NA_1, "section ready" },
{ F_SC_NA_1, "call directory, select file, call file, call section" },
{ F_LS_NA_1, "last section, last segment" },
{ F_AF_NA_1, "ack file, ack section" },
{ F_SG_NA_1, "segment" },
{ F_DR_TA_1, "directory" },
{ F_SC_NB_1, "Query Log - Request archive file" },
{ 0, NULL }
};
static const value_string iec_101_104_causetx_types [] = {
{ IEC_101_104_COT_PER_CYC, "Per/Cyc" },
{ IEC_101_104_COT_BACK, "Back" }, //背景扫描
{ IEC_101_104_COT_SPONT, "Spont" }, //突发(自发)
{ IEC_101_104_COT_INIT, "Init" }, //初始化完成
{ IEC_101_104_COT_REQ, "Req" }, //请求或者被请求
{ IEC_101_104_COT_ACT, "Act" }, //激活
{ IEC_101_104_COT_ACTCON, "Actcon" }, //激活确认
{ IEC_101_104_COT_DEACT, "Deact" }, //停止激活
{ IEC_101_104_COT_DEACTCON, "Deactcon" }, //停止激活确认
{ IEC_101_104_COT_ACTTREM, "Actterm" }, //激活终止
{ IEC_101_104_COT_RETREM, "Reterm" }, //远方命令引起的返送信息
{ IEC_101_104_COT_RETLOC, "Retloc" }, //当地命令引起的返送信息
{ IEC_101_104_COT_FILE, "File" }, //文件传送
{ IEC_101_104_COT_INTERROGATION, "Interrogation" }, //响应总召唤
{ IEC_101_104_COT_INRO1, "Inro1" }, //响应第一组召唤
{ IEC_101_104_COT_INRO2, "Inro2" }, //响应第二组召唤
{ IEC_101_104_COT_INRO3, "Inro3" }, //响应第三组召唤
{ IEC_101_104_COT_INRO4, "Inro4" }, //响应第四组召唤
{ IEC_101_104_COT_INRO5, "Inro5" }, //响应第五组召唤
{ IEC_101_104_COT_INRO6, "Inro6" }, //响应第六组召唤
{ IEC_101_104_COT_INRO7, "Inro7" }, //响应第七组召唤
{ IEC_101_104_COT_INRO8, "Inro8" }, //响应第八组召唤
{ IEC_101_104_COT_INRO9, "Inro9" }, //响应第九组召唤
{ IEC_101_104_COT_INRO10, "Inro10" }, //响应第十组召唤
{ IEC_101_104_COT_INRO11, "Inro11" }, //响应第十一组召唤
{ IEC_101_104_COT_INRO12, "Inro12" }, //响应第十二组召唤
{ IEC_101_104_COT_INRO13, "Inro13" }, //响应第十三组召唤
{ IEC_101_104_COT_INRO14, "Inro14" }, //响应第十四组召唤
{ IEC_101_104_COT_INRO15, "Inro15" }, //响应第十五组召唤
{ IEC_101_104_COT_INRO16, "Inro16" }, //响应第十六组召唤
{ IEC_101_104_COT_REQCOGEN, "Reqcongen" }, //响应计数量站召唤
{ IEC_101_104_COT_REQCO1, "Reqco1" }, //响应笫一组计数量召唤
{ IEC_101_104_COT_REQCO2, "Reqco2" }, //响应笫二组计数量召唤
{ IEC_101_104_COT_REQCO3, "Reqco3" }, //响应笫三组计数量召唤
{ IEC_101_104_COT_REQCO4, "Reqco4" }, //响应笫四组计数量召唤
{ IEC_101_104_COT_UNKNOWN_TI, "Unknown type id" }, //未知类型标识
{ IEC_101_104_COT_UNKNOWN_COT, "Unknown cot" }, //未知传送原因
{ IEC_101_104_COT_UNKNOWN_ASDU, "Unknown asdu address" }, //未知的应用服务数据单元公共地址
{ IEC_101_104_COT_UNKNOWN_INFO, "Unknown infomation address" }, //未知的信息对象地址
{ 0, NULL }
};
#endif //_ZJD_IEC_101_104_LIB_H_