/**
 * @file:    $RCSfile: IEC60870DEF.h,v $
 * @brief:   $60870相关定义
 *
 * @version: $Revision: 1.1 $
 * @date:    $Date: 2018/11/24 06:54:49 $
 * @author:  $Author: lizhongming $
 * @state:   $State: Exp $
 *
 * @latest:  $Id: IEC60870DEF.h,v 1.1 2018/11/24 06:54:49 lizhongming Exp $
 */

/******************************************************************************
*
* Module:      $ IEC60870-5-101 Library.
* Filename:    $ IEC60870DEF.h
* Copyright:   $ Copyright(C) 2004 SNAC Ltd. All rights reserved.
* Author:      $ DGY,YXF
* Release:     $ 
* Create:      $ 2004/08/07
* Modify:      $ ver 0.1  - 2004/09/07
*              $ 
*              $ 
* Language:	   $ C
* Environment: $ VC6/VC7 - WIN32 - I386 (support)
*              $ GCC     - LINUX - I386 (support)
* Description: $ Base data type of the IEC60870-5-101 protocol.
*
******************************************************************************/

#ifndef _INC_IEC60870_5_101_TYPE_H
#define _INC_IEC60870_5_101_TYPE_H

/**
 * @defgroup S_IEC60870_5_PROTOCOL  IEC60870-5 serial protocols type identification 
 * @{
 */

#define  INVALID_0  0	/**<   Invalid data type                                                       */
/* Process information in monitor direction (station-specific parameter)                               */
#define  M_SP_NA_1  1	/**<   Single-point information                                                */
#define  M_SP_TA_1  2	/**<   Single-point information with time tag                                  */
#define  M_DP_NA_1  3	/**<   Double-point information                                                */
#define  M_DP_TA_1  4	/**<   Double-point information with time tag                                  */
#define  M_ST_NA_1  5	/**<   Step position information                                               */
#define  M_ST_TA_1  6	/**<   Step position information with time tag                                 */
#define  M_BO_NA_1  7	/**<   Bitstring of 32 bit                                                     */
#define  M_BO_TA_1  8	/**<   Bitstring of 32 bit with time tag                                       */
#define  M_ME_NA_1  9	/**<   Measured value, normalised value                                        */
#define  M_ME_TA_1  10	/**<   Measured value, normalised value with time tag                          */
#define  M_ME_NB_1  11	/**<   Measured value, scaled value                                            */
#define  M_ME_TB_1  12	/**<   Measured value, scaled value with time tag                              */
#define  M_ME_NC_1  13	/**<   Measured value, short floating point value                              */
#define  M_ME_TC_1  14	/**<   Measured value, short floating point value with time tag                */
#define  M_IT_NA_1  15	/**<   Integrated totals                                                       */
#define  M_IT_TA_1  16	/**<   Integrated totals with time tag                                         */
#define  M_EP_TA_1  17	/**<   Event of protection equipment with time tag                             */
#define  M_EP_TB_1  18	/**<   Packed start events of protection equipment with time tag               */
#define  M_EP_TC_1  19	/**<   Packed output circuit information of protection equipment with time tag */
#define  M_PS_NA_1  20	/**<   Packed single point information with time tag                           */
#define  M_ME_ND_1  21	/**<   Measured value, normalised value without quality descriptor             */
#define  M_SP_TB_1  30	/**<   Single point information with time tag CP56Time2a                       */
#define  M_DP_TB_1  31	/**<   Double point information with time tag CP56Time2a                       */
#define  M_ST_TB_1  32	/**<   Step position information with time tag CP56Time2a                      */
#define  M_BO_TB_1  33	/**<   Bitstring of 32 bit with time tag CP56Time2a                            */
#define  M_ME_TD_1  34	/**<   Measured value, normalised value with time tag CP56Time2a               */
#define  M_ME_TE_1  35	/**<   Measured value, scaled value with time tag CP56Time2a                   */
#define  M_ME_TF_1  36	/**<   Measured value, short floating point value with time tag CP56Time2a     */ 
#define  M_IT_TB_1  37	/**<   Integrated totals with time tag CP56Time2a                              */
#define  M_EP_TD_1  38	/**<   Event of protection equipment with time tag CP56Time2a                  */
#define  M_EP_TE_1  39	/**<   Packed start events of protection equipment with time tag CP56Time2a    */
#define  M_EP_TF_1  40	/**<   Packed tripping events of protection equipment with time tag CP56Time2a */
/* Process information in control direction (station-specific parameter)                               */
#define  C_SC_NA_1  45	/**<   Single command                                                          */
#define  C_DC_NA_1  46	/**<   Double command                                                          */
#define  C_RC_NA_1  47	/**<   Regulating step command                                                 */
#define  C_SE_NA_1  48	/**<   Set point command, normalised value                                     */
#define  C_SE_NB_1  49	/**<   Set point command, scaled value                                         */
#define  C_SE_NC_1  50	/**<   Set point command, short floating point value                           */
#define  C_BO_NA_1  51	/**<   Bitstring of 32 bit                                                     */
#define  C_SC_TA_1  58	/**<   Single command with time tag CP56Time2a                                 */
#define  C_DC_TA_1  59	/**<   Double command with time tag CP56Time2a                                 */
#define  C_RC_TA_1  60	/**<   Regulating step command with time tag CP56Time2a                        */
#define  C_SE_TA_1  61	/**<   Set point command, normalised value with time tag CP56Time2a            */
#define  C_SE_TB_1  62	/**<   Set point command, scaled value with time tag CP56Time2a                */
#define  C_SE_TC_1  63	/**<   Set point command, short floating point value with time tag CP56Time2a  */
#define  C_BO_TA_1  64	/**<   Bitstring of 32 bit with time tag CP56Time2a                            */
/* System information in monitor direction (station-specific parameter)                                */
#define  M_EI_NA_1  70	/**<   End of initialisation                                                   */
/*   System information in control direction (station-specific parameter)                              */
#define  C_IC_NA_1  100	/**<   Interrogation command    定值召唤                                       */
#define  C_CI_NA_1  101	/**<   Counter interrogation command                                           */
#define  C_RD_NA_1  102	/**<   Read command                                                            */
#define  C_CS_NA_1  103	/**<   Clock synchronisation command                                           */
#define  C_TS_NA_1  104	/**<   Test command                                                            */
#define  C_RP_NA_1  105	/**<   Reset process command                                                   */
#define  C_CD_NA_1  106	/**<   Delay acquisition command                                               */
#define  C_TS_TA_1  107	/**<   Test command with time tag CP56Time2a                                   */
/* Parameter in control direction (station-specific parameter)                                         */
#define  P_ME_NA_1  110	/**<   Parameter of measured value, normalised value                           */
#define  P_ME_NB_1  111	/**<   Parameter of measured value, scaled value                               */
#define  P_ME_NC_1  112	/**<   Parameter of measured value, short floating point value                 */
#define  P_AC_NA_1  113	/**<   Active parameter                                                        */
/* File Transfer (station-specific parameter)                                                          */
#define  F_FR_NA_1  120	/**<   File ready                                                              */
#define  F_SR_NA_1  121	/**<   Section ready                                                           */
#define  F_SC_NA_1  122	/**<   Call directory, select file, call file, call section                    */
#define  F_LS_NA_1  123	/**<   Last section, last segment                                              */
#define  F_AF_NA_1  124	/**<   Ack file, ack section                                                   */
#define  F_SG_NA_1  125	/**<   Segment                                                                 */
#define  F_DR_TA_1  126	/**<   Directory                                                               */

/* Special type for AGC                                                                                */
#define  C_SE_ND_1  136	/**<   Set multi-point command, normalised value                               */

/* EYE-LINUX系统顺控特殊定义                                                                           */
#define  M_ES_NA_1  41	/**<   顺控执行信息上送的数据类型					                           */
#define  C_GS_NA_1  114	/**<                             */
#define  C_SS_NA_1  115	/**<                             */

/* EYE-LINUX系统特殊定义                                                                               */
#define  C_MT_ND_1  152	/**<   Multi-point transmit command, normalised value (用于下定值)             */
#define  M_EX_TA_1  153 /**<   带SOE参数的扩展提出报文												   */
#define  C_SE_EX_1  154 /**<   Set Point Command,设点命令，无选择过程，直接执行                        */


#define  M_GD_NA_1  160	/**<   IEC60870-5-103 GDD type monitor direction data [字符串]                         */
#define  C_GD_NA_1  168	/**<   IEC60870-5-103 GDD type control direction data                          */

/* EYE-LINUX系统特殊定义                                                                                */
#define D_RE_DT_1   180 /**<   招录波列表命令                                                           */
#define D_FA_SE_1   181 /**<   招录波命令                                                               */
#define D_ACC_ACK_1	182 /**<   录波规约响应			*/

#define  M_IT_S1_1  185 /** Signed   int 1			*/
#define  M_IT_U1_1  186 /** Unsigned int 1          */
#define  M_IT_S2_1  187 /** Signed   int 2          */
#define  M_IT_U2_1  188 /** Unsigned int 2          */
#define  M_IT_S4_1  189 /** Signed   int 4          */
#define  M_IT_U4_1  190 /** Unsigned int 4          */
#define  M_IT_F4_1  191 /** float 4 				*/
#define  M_IT_F8_1  192 /** float 8 				*/

/* ------------------------------------------------------------------------------------
* IEC60870-5-101 cause of transmission possibilities for each ASDU 
* Cause := UI6[1..6] <0..63>                              
* <14..19> := reserved for further compatible definitions 
* <42..47> := reserved for further compatible definitions 
*/
#define COT0_NOTUSED_1    0 /**<   not used                                      */
#define COT1_PERCYC_1     1 /**<   periodic, cyclic                              */
#define COT2_BACK_1       2 /**<   background scan                               */
#define COT3_SPONT_1      3 /**<   spontaneous                                   */
#define COT4_INIT_1       4 /**<   initialised                                   */
#define COT5_REQ_1        5 /**<   request or requested                          */
#define COT6_ACT_1        6 /**<   activation                                    */
#define COT7_ACTCON_1     7 /**<   activation confirmation                       */
#define COT8_DEACT_1      8 /**<   deactivation                                  */
#define COT9_DEACTCON_1   9 /**<   deactivation confirmation                     */
#define COT10_ACTTERM_1  10 /**<   activation termination                        */
#define COT11_RETREM_1   11 /**<   return information caused by a remote command */
#define COT12_RETLOC_1   12 /**<   return information caused by a local command  */
#define COT13_FILE_1     13 /**<   file transfer                                 */
#define COT20_INROGEN_1  20 /**<   interrogated by general interrogation         */
#define COT21_INRO1_1    21 /**<   interrogated by group 1 interrogation         */
#define COT22_INRO2_1    22 /**<   interrogated by group 2 interrogation         */
#define COT23_INRO3_1    23 /**<   interrogated by group 3 interrogation         */
#define COT24_INRO4_1    24 /**<   interrogated by group 4 interrogation         */
#define COT25_INRO5_1    25 /**<   interrogated by group 5 interrogation         */
#define COT26_INRO6_1    26 /**<   interrogated by group 6 interrogation         */
#define COT27_INRO7_1    27 /**<   interrogated by group 7 interrogation         */
#define COT28_INRO8_1    28 /**<   interrogated by group 8 interrogation         */
#define COT29_INRO9_1    29 /**<   interrogated by group 9 interrogation         */
#define COT30_INRO10_1   30 /**<   interrogated by group 10 interrogation        */
#define COT31_INRO11_1   31 /**<   interrogated by group 11 interrogation        */
#define COT32_INRO12_1   32 /**<   interrogated by group 12 interrogation        */
#define COT33_INRO13_1   33 /**<   interrogated by group 13 interrogation        */
#define COT34_INRO14_1   34 /**<   interrogated by group 14 interrogation        */
#define COT35_INRO15_1   35 /**<   interrogated by group 15 interrogation        */
#define COT36_INRO16_1   36 /**<   interrogated by group 16 interrogation        */
#define COT37_REQCOGEN_1 37 /**<   reques ted by general counter request         */
#define COT38_REQCO1_1   38 /**<   reques ted by group 1 counter request         */
#define COT39_REQCO1_1   39 /**<   reques ted by group 2 counter request         */
#define COT40_REQCO1_1   40 /**<   reques ted by group 3 counter request         */
#define COT41_REQCO1_1   41 /**<   reques ted by group 4 counter request         */

/**< 动作参数					*/

 

#ifdef _OS_WIN32_
#pragma pack(push,1)   
#endif

typedef struct I_STRUCT I_STRUCT;
/** I_STRUCT */
struct I_STRUCT {
    uint32_t flag:1;    /**< I format flag = 0  */
    uint32_t SNO:15;    /**< Send number        */
    uint32_t RES:1;     /**< Reserved = 0       */
    uint32_t RNO:15;    /**< Recieve number     */
}ALIGNPACKED;           /**< I format           */

typedef struct S_STRUCT S_STRUCT;
/** S_STRUCT */
struct S_STRUCT {
    uint32_t flag:2;    /**< S format flag = 01 */
    uint32_t RES:15;    /**< Reserved = 0       */
    uint32_t RNO:15;    /**< Recieve number     */
}ALIGNPACKED;              /**< S format           */


typedef struct U_STRUCT U_STRUCT;
/** U_STRUCT */
struct U_STRUCT {
    uint32_t flag:2;    /**< U format flag = 11 */
    uint32_t STARTDT:2; /**< STARTDT            */
    uint32_t STOPDT:2;  /**< STOPDT             */
    uint32_t TESTFR:2;  /**< TESTFR             */
    uint32_t RES:24;    /**< Reserved = 0       */ 
}ALIGNPACKED;           /**< U format           */

typedef union ctrlarea_t ctrlarea_t;
 /** Control field      */
union ctrlarea_t {         
    byte_t   byte[4];
    I_STRUCT I;
    S_STRUCT S;
    U_STRUCT U;
}ALIGNPACKED; 

typedef struct apci_t apci_t;
/** apci_t */
struct apci_t {              /* IEC60870-5-104 special */
	byte_t     startC1;      /* Start character = 68H  */
	byte_t     length1;      /* length                 */
	ctrlarea_t ctrl_field;   /* Control field          */
}ALIGNPACKED;
/* FRAME_TYPE()/IS_I_FRAME()/IS_S_FRAME()/IS_U_FRAME()*/

typedef struct asdustd_t asdustd_t;
struct asdustd_t {
	byte_t    typid;        /* Type identification          */
	byte_t    vsq;          /* Variable structure qualifier */
	uint16_t  cot;          /* Cause of transmission        */
	uint16_t  addr;         /* Common address of ASDUs      */
	byte_t    data[256];    /* Variable structure qualifier */
}ALIGNPACKED;

// =============================================================================== 
/** 品质描述字的含义
 *  BL=封锁/未被封锁
 *    信息体的值被闭锁后，为了传输需要，传输被封锁前的值，封锁和解锁可以由当地联锁
 *    机构或当地其他原因来启动。
 *  SB=取代/未被取代
 *    信息体的值被值班员的输入值或由一个自动装置的输入所取代。
 *  NT=当前值/非当前值
 *    若最近的刷新成功则值就称为当前值。若在一个指定的时间间隔内刷新不成功或者值不
 *    可用就称为非当前值。
 *  IV=有效/无效
 *    若值被正确采集就是有效，在采集功能确认信息源的反常状态(丧失或非工作刷新)则值
 *    就是无效，信息体值在这些条件下没有被定义。标上无效用以提醒使用者，此值不正确
 *    而不能被使用。
 *  OV=溢出/未溢出
 *  EI=事件状态
 *    若动作时间值被正确采集就为有效，在采集功能确认它为反常状态时，则动作时间值为
 *    无效，信息体动作时间值在这些条件下未被定义。标上无效用以提醒使用者，此值不正
 *    确而不能被使用。
 */

typedef struct siq_t siq_t;
/** 带品质描述的单点信息 
 *  SPI∶=BS1［１］＜0～1＞
 *  ＜0＞∶=OFF 开
 *  ＜1＞∶=ON 合
 */
#ifdef PPC_LINUX
struct siq_t {  
	byte_t  IV:1;
	byte_t  NT:1;
	byte_t  SB:1;
	byte_t  BL:1;
	byte_t  RES:3;
	byte_t  SPI:1;
}ALIGNPACKED;
#else
struct siq_t {      
	byte_t  SPI:1;
	byte_t  RES:3;
	byte_t  BL:1;
	byte_t  SB:1;
	byte_t  NT:1;
	byte_t  IV:1;
}ALIGNPACKED;
#endif

typedef union SIQ SIQ;      
union SIQ {      
	byte_t  bits;
	siq_t   parts;
}ALIGNPACKED;

typedef struct diq_t diq_t; 
/** 带品质描述的双点信息
 *  DPI∶=UI2［1～2］＜0～3＞
 *  ＜0＞∶=中间状态或不确定
 *  ＜1＞∶=确定状态开(OFF)
 *  ＜2＞∶=确定状态合(ON)
 *  ＜3＞∶=中间状态或不确定
 */    
#ifdef PPC_LINUX
struct diq_t { 
	byte_t  IV:1;
	byte_t  NT:1;
	byte_t  SB:1;
	byte_t  BL:1;
	byte_t  RES:2;
	byte_t  DPI:2;
}ALIGNPACKED;
#else
struct diq_t {      
	byte_t  DPI:2;
	byte_t  RES:2;
	byte_t  BL:1;
	byte_t  SB:1;
	byte_t  NT:1;
	byte_t  IV:1;
}ALIGNPACKED;
#endif

typedef union DIQ DIQ;      
union DIQ {      
	byte_t  bits;
	diq_t   parts;
}ALIGNPACKED;

typedef struct qdp_t qdp_t;      
/** 继电保护装置事件的品质描述词 */
#ifdef PPC_LINUX
struct qdp_t { 
	byte_t  IV:1;
	byte_t  NT:1;
	byte_t  SB:1;
	byte_t  BL:1;
	byte_t  EI:1;
	byte_t  RES:3;		
}ALIGNPACKED;
#else
struct qdp_t {      
	byte_t  RES:3;
	byte_t  EI:1;
	byte_t  BL:1;
	byte_t  SB:1;
	byte_t  NT:1;
	byte_t  IV:1;
}ALIGNPACKED;
#endif

typedef union QDP QDP;      
union QDP {      
	byte_t  bits;
	qdp_t   parts;
}ALIGNPACKED;

typedef struct qds_t qds_t;
/** 品质描述词 */
#ifdef PPC_LINUX
struct qds_t {   
	byte_t  IV:1;
	byte_t  NT:1;
	byte_t  SB:1;
	byte_t  BL:1;
	byte_t  RES:3;
	byte_t  OV:1;	
}ALIGNPACKED;
#else
struct qds_t {      
	byte_t  OV:1;
	byte_t  RES:3;
	byte_t  BL:1;
	byte_t  SB:1;
	byte_t  NT:1;
	byte_t  IV:1;
}ALIGNPACKED;
#endif

typedef union QDS QDS;      
union QDS {      
	byte_t  bits;
	qds_t   parts;
}ALIGNPACKED;

typedef struct vti_t vti_t;
/** 带瞬变状态指示的值 */
#ifdef PPC_LINUX
struct vti_t {  
	byte_t  transient:1;
	byte_t  value:7;
}ALIGNPACKED;
#else
struct vti_t {      
	byte_t  value:7;
	byte_t  transient:1;
}ALIGNPACKED;
#endif

typedef union VTI VTI;      
union VTI {      
	byte_t  bits;
	vti_t   parts;
}ALIGNPACKED;

typedef struct NVA NVA;
/** 测量量，归一化值 */
struct NVA {      
	int16_t value;
}ALIGNPACKED;
typedef union VA VA;      
union VA {      
	uint16_t ui;
	int16_t  i;
}ALIGNPACKED;

typedef struct sva_t sva_t;
/** 测量量，标度化值 */
#ifdef PPC_LINUX
struct sva_t {  
	uint16_t sign:1;
	uint16_t value:15;
}ALIGNPACKED;
#else
struct sva_t {      
	uint16_t value:15;
	uint16_t sign:1;
}ALIGNPACKED;
#endif

typedef union SVA SVA;      
union SVA {      
	int16_t bits;
	sva_t   parts;
}ALIGNPACKED;

typedef struct ieee754dp_t ieee754dp_t;
/** 测量量，IEEE STD754 R64.52浮点数 */
#ifdef PPC_LINUX
struct ieee754dp_t {
	uint64_t sign:1;
	uint64_t bexp:11;
	uint64_t mant:52;	
}ALIGNPACKED;
#else
struct ieee754dp_t {
	uint64_t mant:52;
	uint64_t bexp:11;
	uint64_t sign:1;
}ALIGNPACKED;
#endif

typedef union IEEE754DP IEEE754DP;
union IEEE754DP {
	uint64_t     bits;
	ieee754dp_t  parts;
	double       d;
}ALIGNPACKED;

typedef struct ieee754sp_t ieee754sp_t;
/** 测量量，IEEE STD754 R32.23短浮点数 */
#ifdef PPC_LINUX
struct ieee754sp_t {
	uint32_t sign:1;
	uint32_t bexp:8;
	uint32_t mant:23;
}ALIGNPACKED;
#else
struct ieee754sp_t {
	uint32_t mant:23;
	uint32_t bexp:8;
	uint32_t sign:1;
}ALIGNPACKED;
#endif

typedef union IEEE754SP IEEE754SP;
union IEEE754SP {
	uint32_t    bits;
	ieee754sp_t parts;
	float       f;
}ALIGNPACKED;

typedef struct scd_t scd_t;
/** 状态和状态变化检出 */
struct scd_t {      
	uint16_t ST;
	uint16_t CD;
}ALIGNPACKED;
typedef union SCD SCD;      
union SCD {      
	uint32_t bits;
	scd_t    parts;
}ALIGNPACKED;

typedef struct bcr_t bcr_t;
/** 二进制计数器读数 */
#ifdef PPC_LINUX
struct bcr_t {      
	uint32_t counter;	
	byte_t   IV:1;
	byte_t   CA:1;
	byte_t   CY:1;
	byte_t   SQ:5;	
}ALIGNPACKED;
#else
struct bcr_t {      
	uint32_t counter;
	byte_t   SQ:5;
	byte_t   CY:1;
	byte_t   CA:1;
	byte_t   IV:1;
}ALIGNPACKED;
#endif

typedef union BCR BCR;      
union BCR {      
	byte_t  bits[5];
	bcr_t   parts;
}ALIGNPACKED;

typedef struct sep_t sep_t;
/** 继电保护装置的单个事件 */
#ifdef PPC_LINUX
struct sep_t {  
	byte_t IV:1;
	byte_t NT:1;
	byte_t SB:1;
	byte_t BL:1;
	byte_t EI:1;
	byte_t RES:1;
	byte_t ES:2;		
}ALIGNPACKED;
#else
struct sep_t {      
	byte_t ES:2;
	byte_t RES:1;
	byte_t EI:1;
	byte_t BL:1;
	byte_t SB:1;
	byte_t NT:1;
	byte_t IV:1;
}ALIGNPACKED;
#endif

typedef union SEP SEP;      
union SEP {      
	byte_t  bits;
	sep_t   parts;
}ALIGNPACKED;

typedef struct spe_t spe_t;
/** 继电保护装置启动事件 */
#ifdef PPC_LINUX
struct spe_t {  
	byte_t RES:2;
	byte_t SRD:1;
	byte_t SIE:1;
	byte_t SL3:1;
	byte_t SL2:1;
	byte_t SL1:1;
	byte_t GS:1;	
}ALIGNPACKED;
#else
struct spe_t {      
	byte_t GS:1;
	byte_t SL1:1;
	byte_t SL2:1;
	byte_t SL3:1;
	byte_t SIE:1;
	byte_t SRD:1;
	byte_t RES:2;
}ALIGNPACKED;
#endif

typedef union SPE SPE;      
union SPE {      
	byte_t  bits;
	spe_t   parts;
}ALIGNPACKED;

typedef struct oci_t oci_t;
/** 保护装置输出电路信息 */
#ifdef PPC_LINUX
struct oci_t {   
	byte_t RES:4;
	byte_t CL3:1;
	byte_t CL2:1;
	byte_t CL1:1;
	byte_t GC:1;	
}ALIGNPACKED;
#else
struct oci_t {      
	byte_t GC:1;
	byte_t CL1:1;
	byte_t CL2:1;
	byte_t CL3:1;
	byte_t RES:4;
}ALIGNPACKED;
#endif

typedef union OCI OCI;      
union OCI {      
	byte_t  bits;
	oci_t   parts;
}ALIGNPACKED;

typedef union BSI BSI;      
/** 二进状态信息 */
union BSI {      
	uint32_t  bits;
	byte_t    parts[4];
}ALIGNPACKED;

typedef struct sco_t sco_t;
/** 单命令 */
#ifdef PPC_LINUX
struct sco_t {   
	byte_t   SE:1;
	byte_t   QU:5;
	byte_t   RES:1;
	byte_t   SCS:1;	
}ALIGNPACKED;
#else
struct sco_t {      
	byte_t   SCS:1;
	byte_t   RES:1;
	byte_t   QU:5;
	byte_t   SE:1;
}ALIGNPACKED;
#endif

typedef union SCO SCO;      
union SCO {      
	byte_t  bits;
	sco_t   parts;
}ALIGNPACKED;

typedef struct dco_t dco_t;
/** 双命令 */
#ifdef PPC_LINUX
struct dco_t {   
	byte_t   SE:1;
	byte_t   QU:5;
	byte_t   DCS:2;
}ALIGNPACKED;
#else
struct dco_t {      
	byte_t   DCS:2;
	byte_t   QU:5;
	byte_t   SE:1;
}ALIGNPACKED;
#endif

typedef union DCO DCO;      
union DCO {      
	byte_t  bits;
	dco_t   parts;
}ALIGNPACKED;

typedef struct rco_t rco_t;
/** 步调节命令 */
#ifdef PPC_LINUX
struct rco_t {   
	byte_t   SE:1;
	byte_t   QU:5;
	byte_t   RCS:2;
}ALIGNPACKED;
#else
struct rco_t {      
	byte_t   RCS:2;
	byte_t   QU:5;
	byte_t   SE:1;
}ALIGNPACKED;
#endif

typedef union RCO RCO;      
union RCO {      
	byte_t  bits;
	rco_t   parts;
}ALIGNPACKED;

typedef struct qos_t qos_t;
/** 设点命令限定词 */
#ifdef PPC_LINUX
struct qos_t {    
	byte_t   SE:1;
	byte_t   QL:7;
}ALIGNPACKED;
#else
struct qos_t {      
	byte_t   QL:7;
	byte_t   SE:1;
}ALIGNPACKED;
#endif

typedef union QOSP QOSP;      
union QOSP {      
	byte_t  bits;
	qos_t   parts;
}ALIGNPACKED;

typedef struct coi_t coi_t;
/** 初始化原因 */
#ifdef PPC_LINUX
struct coi_t {   
	byte_t   state:1;
	byte_t   cause:7;
}ALIGNPACKED;
#else
struct coi_t {      
	byte_t   cause:7;
	byte_t   state:1;
}ALIGNPACKED;
#endif

typedef union COI COI;      
union COI {      
	byte_t  bits;
	coi_t   parts;
}ALIGNPACKED;

typedef struct QOI QOI;
/** 召唤命令的限定词 */
struct QOI {      
	byte_t   qoi;
}ALIGNPACKED;

typedef struct qcc_t qcc_t;
/** 电能计数量召唤命令的限定词 */
#ifdef PPC_LINUX
struct qcc_t {
	byte_t   FRZ:2;
	byte_t   RQT:6;
}ALIGNPACKED;
#else
struct qcc_t {
	byte_t   RQT:6;
	byte_t   FRZ:2;
}ALIGNPACKED;
#endif

typedef union QCC QCC;      
union QCC {      
	byte_t  bits;
	qcc_t   parts;
}ALIGNPACKED;

typedef struct FBP FBP;
/** 固定测试字 */
struct FBP {
	uint16_t  HEX;
}ALIGNPACKED;
//#define FBP (uint16_t)(0x55aa)

typedef struct QRP QRP;
/** 复位进程命令的限定词 */
struct QRP {
	byte_t  qrp;
}ALIGNPACKED;

typedef struct qpm_t qpm_t;
/** 测量值参数限定词 */
#ifdef PPC_LINUX
struct qpm_t {
	byte_t  POP:1;
	byte_t  LPC:1;
	byte_t  KPA:6;
}ALIGNPACKED;
#else
struct qpm_t {
	byte_t  KPA:6;
	byte_t  LPC:1;
	byte_t  POP:1;
}ALIGNPACKED;
#endif

typedef union QPM QPM;  
union QPM {      
	byte_t  bits;
	qpm_t   parts;
}ALIGNPACKED;

#define QPM_NOTUSED     0   /** not used                                */
#define QPM_THRESHOLD   1   /** threshold value                         */    
#define QPM_SMOOTHING   2   /** smoothing factor (filter time constant) */    
#define QPM_LOWLIMIT    3   /** high limits                             */    
#define QPM_HIGHLIMIT   4   /** low limits                              */    

typedef struct QPA QPA;
/** 参数激活限定词 */
struct QPA {
	byte_t  qpa;
}ALIGNPACKED;

/* File Transfer (station-specific parameter) */

/* 文件名定义，其中文件名第2个8位组为将来应用保留 */
#define FILE_TRANSPARENT    (1)  /**<   透明文件                   */
#define FILE_EQUIP          (2)  /**<   继电保护设备的扰动数据     */
#define FILE_EVENT_SEQ      (3)  /**<   事件序列                   */
#define FILE_ANALOG_SEQ     (4)  /**<   被记录的模拟量系列         */
/* 传输原因 */
#define FILE_TRAN_DEFAULT   (0)  /**<   缺省                       */
#define FILE_TRAN_SEL       (1)  /**<   选择文件                   */
#define FILE_TRAN_REQ		(2)  /**<   请求文件                   */
#define FILE_TRAN_INACTIVE  (3)  /**<   停止激活文件               */
#define FILE_TRAN_DELETE    (4)  /**<   删除文件                   */
//....
#define FILE_ERR_MEM        (0)  /**<   无所请求的空间             */
#define FILE_ERR_CHKSUM     (1)  /**<   校验和错                   */
//....
#define FILE_ERR_FILENAME   (4)  /**<   非所期望文件名称           */

/** Name Of File */
typedef uint16_t NOF;

/** Name Of Session */
typedef byte_t NOS;

typedef struct LOF LOF;
/** Length Of File */
struct LOF {
	byte_t lof[3];
}ALIGNPACKED;

/** Length Of Session */
typedef byte_t LOS;

/** CHeckSum  */
typedef byte_t CHS; 

typedef struct sof_t sof_t;
/** State Of File */
#ifdef PPC_LINUX
struct sof_t {
	byte_t FA:1;
	byte_t FOR:1;
	byte_t LFD:1;
	byte_t STATUS:5;
}ALIGNPACKED;
#else
struct sof_t {
	byte_t STATUS:5;
	byte_t LFD:1;
	byte_t FOR:1;
	byte_t FA:1;
}ALIGNPACKED;
#endif

typedef union SOF SOF;      
/** State Of File */
union SOF {      
	byte_t  bits;
	sof_t   parts;
}ALIGNPACKED;

typedef struct frq_t frq_t;
/** File Ready Qualifier */
#ifdef PPC_LINUX
struct frq_t {
	byte_t ACK:1;      /**< =0 ack; =1 deny */
	byte_t FILES:7;
}ALIGNPACKED;
#else
struct frq_t {
	byte_t FILES:7;
	byte_t ACK:1;      /**< =0 ack; =1 deny */
}ALIGNPACKED;
#endif

typedef union FRQ FRQ;      
/** File Ready Qualifier */
union FRQ {      
	byte_t  bits;
	frq_t   parts;
}ALIGNPACKED;

typedef struct srq_t srq_t;
/** Session Ready Qualifier */
#ifdef PPC_LINUX
struct srq_t {
	byte_t  READY:1;
	byte_t  SESSION:7;
}ALIGNPACKED;
#else
struct srq_t {
	byte_t  SESSION:7;
	byte_t  READY:1;
}ALIGNPACKED;
#endif

typedef union SRQ SRQ;      
/** Session Ready Qualifier */
union SRQ {      
	byte_t  bits;
	srq_t   parts;
}ALIGNPACKED;

typedef struct scq_t scq_t;
/** Select/Call Qualifier */
#ifdef PPC_LINUX
struct scq_t {
	byte_t  RESPONSE:4;
	byte_t  REQUEST:4;
}ALIGNPACKED;
#else
struct scq_t {
	byte_t  REQUEST:4;
	byte_t  RESPONSE:4;
}ALIGNPACKED;
#endif

typedef union SCQ SCQ;      
/** Select/Call Qualifier */
union SCQ {      
	byte_t  bits;
	scq_t   parts;
}ALIGNPACKED;

/** Lasted Session Qualifier */
typedef byte_t LSQ;

typedef struct afq_t afq_t;
/** Ack File/Session Qualifier */
#ifdef PPC_LINUX
struct afq_t {
	byte_t  STATUS:4;
	byte_t  ACK:4;
}ALIGNPACKED;
#else
struct afq_t {
	byte_t  ACK:4;
	byte_t  STATUS:4;
}ALIGNPACKED;
#endif

typedef union AFQ AFQ;      
/** Ack File/Session Qualifier */
union AFQ {      
	byte_t  bits;
	afq_t   parts;
}ALIGNPACKED;

/** ===========================信息对象结构定义区================================= */

/** Process information in monitor direction (station-specific parameter)          */
typedef struct M_SP_NA_1_t M_SP_NA_1_t;
/** Single-point information */
struct M_SP_NA_1_t {
	SIQ      siq;
}ALIGNPACKED;	

typedef struct M_SP_TA_1_t M_SP_TA_1_t;
/** Single-point information with time tag */
struct M_SP_TA_1_t {
	SIQ        siq;
	CP24Time2a tm;
}ALIGNPACKED;	

typedef struct M_DP_NA_1_t M_DP_NA_1_t;
/** Double-point information */
struct M_DP_NA_1_t {
	DIQ      diq;
}ALIGNPACKED;	

typedef struct M_DP_TA_1_t M_DP_TA_1_t;
/** Double-point information with time tag */
struct M_DP_TA_1_t {
	DIQ        diq;
	CP24Time2a tm;
}ALIGNPACKED;	

typedef struct M_ST_NA_1_t M_ST_NA_1_t;
/** Step position information */
struct M_ST_NA_1_t {
	VTI      vti;
	QDS      qds;
}ALIGNPACKED;	

typedef struct M_ST_TA_1_t M_ST_TA_1_t;
/** Step position information with time tag */
struct M_ST_TA_1_t {
	VTI        vti;
	QDS        qds;
	CP24Time2a tm;
}ALIGNPACKED;	

typedef struct M_BO_NA_1_t M_BO_NA_1_t;
/** Bitstring of 32 bit */
struct M_BO_NA_1_t {	
	BSI        bsi;
	QDS        qds;
}ALIGNPACKED;	

typedef struct M_SA_NA_1_t M_SA_NA_1_t;
/** String of ASCII */
struct M_SA_NA_1_t {
    byte_t    length;
	char      str[1];
}ALIGNPACKED;	

typedef struct M_BO_TA_1_t M_BO_TA_1_t;
/** Bitstring of 32 bit with time tag */
struct M_BO_TA_1_t {
	BSI        bsi;
	QDS        qds;
	CP24Time2a tm;
}ALIGNPACKED;	

typedef struct M_ME_NA_1_t M_ME_NA_1_t;
/** Measured value, normalised value */
struct M_ME_NA_1_t {
	NVA      nva;
	QDS      qds;
}ALIGNPACKED;	

typedef struct M_ME_TA_1_t M_ME_TA_1_t;
/** Measured value, normalised value with time tag */
struct M_ME_TA_1_t {
	NVA        nva;
	QDS        qds;
	CP24Time2a tm;
}ALIGNPACKED;	

typedef struct M_ME_NB_1_t M_ME_NB_1_t;
/** Measured value, scaled value */
struct M_ME_NB_1_t {
	SVA        sva;
	QDS        qds;
}ALIGNPACKED;	

typedef struct M_ME_TB_1_t M_ME_TB_1_t;
/** Measured value, scaled value with time tag */
struct M_ME_TB_1_t {
	SVA        sva;
	QDS        qds;
	CP24Time2a tm;
}ALIGNPACKED;	

typedef struct M_ME_NC_1_t M_ME_NC_1_t;
/** Measured value, short floating point value */
struct M_ME_NC_1_t {
	IEEE754SP std;
	QDS       qds;
}ALIGNPACKED;	

typedef struct M_ME_TC_1_t M_ME_TC_1_t;
/** Measured value, short floating point value with time tag */
struct M_ME_TC_1_t {
	IEEE754SP   std;
	QDS         qds;
	CP24Time2a  tm;
}ALIGNPACKED;	

typedef struct M_IT_NA_1_t M_IT_NA_1_t;
/** Integrated totals */
struct M_IT_NA_1_t {
	BCR        bcr;
}ALIGNPACKED;

typedef struct M_IT_TA_1_t M_IT_TA_1_t;
/** Integrated totals with time tag */
struct M_IT_TA_1_t {
	BCR         bcr;
	CP24Time2a  tm;
}ALIGNPACKED;	

typedef struct M_EP_TA_1_t M_EP_TA_1_t;
/** Event of protection equipment with time tag */
struct M_EP_TA_1_t {
	SEP         sep;
	CP16Time2a  tm16;
	CP24Time2a  tm24;
}ALIGNPACKED;	

typedef struct M_EP_TB_1_t M_EP_TB_1_t;
/** Packed start events of protection equipment with time tag */
struct M_EP_TB_1_t {
	SPE         spe;
	QDP         qdp;
	CP16Time2a  tm16;
	CP24Time2a  tm24;
}ALIGNPACKED;	

typedef struct M_EP_TC_1_t M_EP_TC_1_t;
/** Packed output circuit information of protection equipment with time tag */
struct M_EP_TC_1_t {
	OCI         oci;
	QDP         qdp;
	CP16Time2a  tm16;
	CP24Time2a  tm24;
}ALIGNPACKED;	

typedef struct M_PS_NA_1_t M_PS_NA_1_t;
/** Packed single point information with time tag */
struct M_PS_NA_1_t {
	SCD      scd;
	QDS      qds;
}ALIGNPACKED;	

typedef struct M_ME_ND_1_t M_ME_ND_1_t;
/** Measured value, normalised value without quality descriptor */
struct M_ME_ND_1_t {
	NVA      nva;
}ALIGNPACKED;

typedef struct M_SP_TB_1_t M_SP_TB_1_t;
/** Single point information with time tag CP56Time2a */
struct M_SP_TB_1_t {
	SIQ        siq;
	CP56Time2a tm;
}ALIGNPACKED;	

typedef struct M_DP_TB_1_t M_DP_TB_1_t;
/** Double point information with time tag CP56Time2a */
struct M_DP_TB_1_t {
	DIQ        diq;
	CP56Time2a tm;
}ALIGNPACKED;	

typedef struct M_ST_TB_1_t M_ST_TB_1_t;
/** Step position information with time tag CP56Time2a */
struct M_ST_TB_1_t {
	VTI        vti;
	QDS        qds;
	CP56Time2a tm;
}ALIGNPACKED;	

typedef struct M_BO_TB_1_t M_BO_TB_1_t;
/** Bitstring of 32 bit with time tag CP56Time2a */
struct M_BO_TB_1_t {
	BSI        bsi;
	CP56Time2a tm;
}ALIGNPACKED;

typedef struct M_ME_TD_1_t M_ME_TD_1_t;
/** Measured value, normalised value with time tag CP56Time2a */
struct M_ME_TD_1_t {
	NVA        nva;
	QDS        qds;
	CP56Time2a tm;
}ALIGNPACKED;	

typedef struct M_ME_TE_1_t M_ME_TE_1_t;
/** Measured value, scaled value with time tag CP56Time2a */
struct M_ME_TE_1_t {
	SVA        sva;
	QDS        qds;
	CP56Time2a tm;
}ALIGNPACKED;	

typedef struct M_ME_TF_1_t M_ME_TF_1_t;
/** Measured value, short floating point value with time tag CP56Time2a */ 
struct M_ME_TF_1_t {
	IEEE754SP   std;
	QDS         qds;
	CP56Time2a  tm;
}ALIGNPACKED;	

typedef struct M_IT_TB_1_t M_IT_TB_1_t;
/** Integrated totals with time tag CP56Time2a */
struct M_IT_TB_1_t {
	BCR        bcr;
	CP56Time2a tm;
}ALIGNPACKED;	

typedef struct M_EP_TD_1_t M_EP_TD_1_t;
/** Event of protection equipment with time tag CP56Time2a */
struct M_EP_TD_1_t {
	SEP         sep;
	CP16Time2a  tm16;
	CP56Time2a  tm56;
}ALIGNPACKED;	

typedef struct M_EP_TE_1_t M_EP_TE_1_t;
/** Packed start events of protection equipment with time tag CP56Time2a */
struct M_EP_TE_1_t {
	SPE         spe;
	QDP         qdp;
	CP16Time2a  tm16;
	CP56Time2a  tm56;
}ALIGNPACKED;	

typedef struct M_EP_TF_1_t M_EP_TF_1_t;
/** Packed tripping events of protection equipment with time tag CP56Time2a */
struct M_EP_TF_1_t {
	OCI         oci;
	QDP         qdp;
	CP16Time2a  tm16;
	CP56Time2a  tm56;
}ALIGNPACKED;	

/** 顺控执行信息上送的数据类型结构 */
typedef struct es_nva_t es_nva_t;
struct es_nva_t {
	byte_t		step;
	byte_t		flag;
	byte_t		no;
	byte_t		pause_time;
	byte_t		rsv2;
	byte_t		rsv3;
	byte_t		rsv4;
	byte_t		rsv5;
	byte_t		rsv6;
	byte_t		rsv7;
	byte_t		rsv8;
}ALIGNPACKED;
typedef struct es_str_t es_str_t;
struct es_str_t {
	byte_t		strlen;
	byte_t		string[255];
}ALIGNPACKED;
typedef struct M_ES_NA_1_t M_ES_NA_1_t;
struct M_ES_NA_1_t {
	es_nva_t	esn;
	es_str_t	ess;
}ALIGNPACKED;

/** Process information in control direction (station-specific parameter) */
typedef struct C_SC_NA_1_t C_SC_NA_1_t;
/** Single command */
struct C_SC_NA_1_t {
	SCO      sco;
}ALIGNPACKED;	

typedef struct C_DC_NA_1_t C_DC_NA_1_t;
/** Double command */
struct C_DC_NA_1_t {
	DCO      dco;
}ALIGNPACKED;	

typedef struct C_RC_NA_1_t C_RC_NA_1_t;
/** Regulating step command */
struct C_RC_NA_1_t {
	RCO      rco;
}ALIGNPACKED;	

typedef struct C_SE_NA_1_t C_SE_NA_1_t;
/** Set point command, normalised value */
struct C_SE_NA_1_t {
	NVA      nva;
	QOSP     qos;
}ALIGNPACKED;	

typedef struct C_SE_EX_1_t C_SE_EX_1_t;
/** Set point command, normalised value ,直接执行，无需反校
S/E 位无效，置为 0 
*/
struct C_SE_EX_1_t {
	NVA      nva;
	QOSP     qos;
}ALIGNPACKED;	

typedef struct C_SE_NB_1_t C_SE_NB_1_t;
/** Set point command, scaled value */
struct C_SE_NB_1_t {
	SVA      sva;
	QOSP     qos;
}ALIGNPACKED;	

typedef struct C_SE_NC_1_t C_SE_NC_1_t;
/** Set point command, short floating point value */
struct C_SE_NC_1_t {
	IEEE754SP std;
	QOSP      qos;
}ALIGNPACKED;	

typedef struct C_BO_NA_1_t C_BO_NA_1_t;
/** Bitstring of 32 bit */
struct C_BO_NA_1_t {
	BSI       bsi;
}ALIGNPACKED;

typedef struct C_SC_TA_1_t C_SC_TA_1_t;
/** Single command with time tag CP56Time2a */
struct C_SC_TA_1_t {
	SCO         sco;
	CP56Time2a  tm;
}ALIGNPACKED;	

typedef struct C_DC_TA_1_t C_DC_TA_1_t;
/** Double command with time tag CP56Time2a */
struct C_DC_TA_1_t {
	DCO         dco;
	CP56Time2a  tm;
}ALIGNPACKED;	

typedef struct C_RC_TA_1_t C_RC_TA_1_t;
/** Regulating step command with time tag CP56Time2a */
struct C_RC_TA_1_t {
	RCO         rco;
	CP56Time2a  tm;
}ALIGNPACKED;	

typedef struct C_SE_TA_1_t C_SE_TA_1_t;
/** Set point command, normalised value with time tag CP56Time2a */
struct C_SE_TA_1_t {
	NVA         nva;
	QOSP        qos;
	CP56Time2a  tm;
}ALIGNPACKED;	

typedef struct C_SE_TB_1_t C_SE_TB_1_t;
/** Set point command, scaled value with time tag CP56Time2a */
struct C_SE_TB_1_t {
	SVA         sva;
	QOSP        qos;
	CP56Time2a  tm;
}ALIGNPACKED;	

typedef struct C_SE_TC_1_t C_SE_TC_1_t;
/** Set point command, short floating point value with time tag CP56Time2a */
struct C_SE_TC_1_t {
	IEEE754SP std;
	QOSP        qos;
	CP56Time2a  tm;
}ALIGNPACKED;	

typedef struct C_BO_TA_1_t C_BO_TA_1_t;
/** Bitstring of 32 bit with time tag CP56Time2a */
struct C_BO_TA_1_t {
	BSI         bsi;
	CP56Time2a  tm;
}ALIGNPACKED;	

/** System information in monitor direction (station-specific parameter) */
typedef struct M_EI_NA_1_t M_EI_NA_1_t;
/** End of initialisation */
struct M_EI_NA_1_t {
	COI      coi;
}ALIGNPACKED;	

/** System information in control direction (station-specific parameter) */
typedef struct C_IC_NA_1_t C_IC_NA_1_t;
/** Interrogation command */
struct C_IC_NA_1_t {
	QOI      qoi;
}ALIGNPACKED;	

typedef struct C_CI_NA_1_t C_CI_NA_1_t;
/** Counter interrogation command */
struct C_CI_NA_1_t {
	QCC      qcc;
}ALIGNPACKED;	

/* Read command = C_RD_NA_1 no structure body */

typedef struct C_CS_NA_1_t C_CS_NA_1_t;
/** Clock synchronisation command */
struct C_CS_NA_1_t {
	CP56Time2a tm;
}ALIGNPACKED;	

typedef struct C_TS_NA_1_t C_TS_NA_1_t;
/** Test command */
struct C_TS_NA_1_t {
	FBP      fbp;
}ALIGNPACKED;	

typedef struct C_RP_NA_1_t C_RP_NA_1_t;
/** Reset process command */
struct C_RP_NA_1_t {
	QRP      qrp;
}ALIGNPACKED;	

typedef struct C_CD_NA_1_t C_CD_NA_1_t;
/** Delay acquisition command */
struct C_CD_NA_1_t {
	CP16Time2a  tm;
}ALIGNPACKED;	

typedef struct C_TS_TA_1_t C_TS_TA_1_t;
/** Test command with time tag CP56Time2a       */
struct C_TS_TA_1_t {
	FBP      fbp;
	CP56Time2a tm;
}ALIGNPACKED;	

/** Parameter in control direction (station-specific parameter) */
typedef struct P_ME_NA_1_t P_ME_NA_1_t;
/** Parameter of measured value, normalised value */
struct P_ME_NA_1_t {
	NVA      nva;
	QPM      qpm;
}ALIGNPACKED;	

typedef struct P_ME_NB_1_t P_ME_NB_1_t;
/** Parameter of measured value, scaled value */
struct P_ME_NB_1_t {
	SVA      sva;
	QPM      qpm;
}ALIGNPACKED;	

typedef struct P_ME_NC_1_t P_ME_NC_1_t;
/** Parameter of measured value, short floating point value */
struct P_ME_NC_1_t {
	IEEE754SP std;
	QPM         qpm;
}ALIGNPACKED;	

typedef struct P_AC_NA_1_t P_AC_NA_1_t;
/** Active parameter */
struct P_AC_NA_1_t {
	QPA      qpa;
}ALIGNPACKED;

typedef struct F_FR_NA_1_t F_FR_NA_1_t;
/** File Transfer (station-specific parameter) */
struct F_FR_NA_1_t {
	NOF		nof;
	LOF		lof;
	FRQ		frq;
}ALIGNPACKED;

typedef struct F_SR_NA_1_t F_SR_NA_1_t;
/** Section ready */
struct F_SR_NA_1_t {
	NOF     nof;
	NOS     nos;
	LOF		lof;
}ALIGNPACKED;	

typedef struct F_SC_NA_1_t F_SC_NA_1_t;
/** Call directory, select file, call file, call section */
struct F_SC_NA_1_t {
	NOF     nof;
	NOS     nos;
	SCQ     scq;
}ALIGNPACKED;	

typedef struct F_LS_NA_1_t F_LS_NA_1_t;
/** Last section, last segment */
struct F_LS_NA_1_t {
	NOF     nof;
	NOS     nos;
    LSQ     lsq;
    CHS     chs;
}ALIGNPACKED;	

typedef struct F_AF_NA_1_t F_AF_NA_1_t;
/** Ack file, ack section */
struct F_AF_NA_1_t {
	NOF     nof;
	NOS     nos;
    AFQ     afq;
}ALIGNPACKED;	

typedef struct F_SG_NA_1_t F_SG_NA_1_t;
/** Segment */
struct F_SG_NA_1_t {
	NOF     nof;
	NOS     nos;
    LOS     los;
    byte_t  seg[1];
}ALIGNPACKED;	

typedef struct F_DR_TA_1_t F_DR_TA_1_t;
/** Directory */
struct F_DR_TA_1_t {
	NOF        nof;
    LOF        lof;
	SOF        nos;
    CP56Time2a tm;
}ALIGNPACKED;	

/** Special type for AGC  */
typedef struct C_SE_ND_1_t C_SE_ND_1_t;
/** Set multi-point command, normalised value */
struct C_SE_ND_1_t {
	uint16_t  num; /** 设定值数目 */
}ALIGNPACKED;

/** ===========================故障信息结构定义================================= */
typedef struct ACC_PARAM_RELTIME_t ACC_PARAM_RELTIME_t;
struct ACC_PARAM_RELTIME_t{
    uint16_t    relativetime;
}ALIGNPACKED;

typedef struct ACC_PARAM_FAN_t ACC_PARAM_FAN_t;
struct ACC_PARAM_FAN_t{
    uint16_t    fan;
}ALIGNPACKED;

typedef struct ACC_PARAM_NOF_t ACC_PARAM_NOF_t;
struct ACC_PARAM_NOF_t{
    uint16_t    nof;
}ALIGNPACKED;

#ifdef PPC_LINUX
struct PHASE_t{
	byte_t  phaseA  :1;		//A相故障
	byte_t  phaseB  :1;		//B相故障
	byte_t  phaseC  :1;		//C相故障
	byte_t  phaseI  :1;		//接地故障
	byte_t  phaseO  :1;		//区外故障
	byte_t  res     :2;		//备用
    byte_t  valid   :1;		//有效位 
}ALIGNPACKED;
#else
struct PHASE_t{
    byte_t  phaseA  :1;		//A相故障
    byte_t  phaseB  :1;		//B相故障
    byte_t  phaseC  :1;		//C相故障
    byte_t  phaseI  :1;		//接地故障
	byte_t  phaseO  :1;		//区外故障
    byte_t  res     :2;		//备用
    byte_t  valid   :1;		//有效位
}ALIGNPACKED;
#endif

typedef union ACC_PARAM_PHASE_t ACC_PARAM_PHASE_t;
union ACC_PARAM_PHASE_t{
    byte_t          bit;
    struct PHASE_t  phase;
}ALIGNPACKED;

typedef struct ACC_PARAM_DISTANCE_t ACC_PARAM_DISTANCE_t;
struct ACC_PARAM_DISTANCE_t{
    float        distance;
}ALIGNPACKED;

typedef struct ACC_PARAM_MAXI_t ACC_PARAM_MAXI_t;
struct ACC_PARAM_MAXI_t{
    float        max_i;
}ALIGNPACKED;

typedef struct ACC_PARAM_MINI_t ACC_PARAM_MINI_t;
struct ACC_PARAM_MINI_t{
    float        min_i;
}ALIGNPACKED;

/** ===========================EYE-LINUX系统特殊结构================================= */
typedef struct C_MT_ND_1_t C_MT_ND_1_t;
/** Multi-point transmit command, normalised value */
struct C_MT_ND_1_t {
	uint16_t  num;    /** 设定值数目   */
	dco_t     dco;    /** 选择/执行    */
    byte_t    desc;   /** 定值描述     */
	uint16_t  start;  /** 定值起始点号 */
	uint16_t  end;    /** 定值结束点号 */
}ALIGNPACKED;	

typedef struct gd_t gd_t;
struct gd_t {
	byte_t  size;      //首字节表示后续字符串的长度 ，c字符串的需包含  结尾 \0所占的长度
    byte_t  gid[255];
}ALIGNPACKED;
/** 字符串类型定义  */
/*  字符串类型使用示例
	byte_t       value[256];
	value_t      val;

	val.data  = &value;
	val.typid = M_GD_NA_1;	
	value[0]  = strlen(str)+1 ;		//val.data部分，首字节表示后续字符串的长度 ，加上1 是c字符串的结尾 \0所占的长度 
	val.size  = value[0] +1;		  //value_t的size 应该是： 字符本身长度 + 长度域一字节
	strcpy(value+1,str);
*/
/** Special type for eye-linux  */
typedef union M_GD_NA_1_t M_GD_NA_1_t;
/** IEC60870-5-103 GDD structure, eye-linux special */
union M_GD_NA_1_t {
	byte_t    bits[256];
    gd_t      parts;
};

typedef union C_GD_NA_1_t C_GD_NA_1_t;
/** IEC60870-5-103 GDD structure, eye-linux special */
union C_GD_NA_1_t {
	byte_t    bits[256];
    gd_t      parts;
}ALIGNPACKED;

typedef struct value_t value_t;
/** 描述存储特定类型数据的缓冲区结构 */
struct value_t { 
    byte_t   typid;   /**< 数据类型，使用IEC60870-5-101的ASDU TYP定义      */
    uint16_t size;    /**< = sizeof(typid类型的数据)                       */
    void*    data;    /**< 指向size大小的内存缓冲区(存储着typid类型的数据) */
}ALIGNPACKED;

#define REQ_TD_2    2   //选择录波
#define STA_TD_4    4   //启动录波

#define ACC_ACK_OK          1       //招录波(列表)命令下发成功
#define ACC_ACK_FALUT       2       //招录波(列表)命令下发失败
#define ACC_ACK_BUZY        3       //装置忙，命令未下发
#define ACC_ACK_NOSUPPORT   4       //装置不支持招录波(手动录波）

typedef struct dist_record_t dist_record_t;
/** Disurbance record  */
struct dist_record_t {
    uint16_t   fan;
    byte_t     sof;
    CP56Time2a glb_tm;
}ALIGNPACKED;

typedef struct dist_table_t dist_table_t;
/** Recorded disturbance table */
struct dist_table_t {
    uint32_t      ied;
    uint16_t      cpu;
    byte_t        nor;      /**< Number of disturbance recorded */
    dist_record_t *rec;
};

typedef struct sfa_t sfa_t;
/** Status of Fault */
#ifdef PPC_LINUX
struct sfa_t {
	byte_t  RES:4;
	byte_t  OTEV:1; /**< Other event (disturbance data recording initiated by) */
	byte_t  TEST:1; /**< Type of disturbance values                            */
	byte_t  TM:1;   /**< Transmit (disturbance data)                           */
    byte_t  TP:1;   /**< Trip (Recorded fault)                                 */   
}ALIGNPACKED;
#else
struct sfa_t {
    byte_t  TP:1;   /**< Trip (Recorded fault)                                 */
    byte_t  TM:1;   /**< Transmit (disturbance data)                           */
    byte_t  TEST:1; /**< Type of disturbance values                            */
    byte_t  OTEV:1; /**< Other event (disturbance data recording initiated by) */
    byte_t  RES:4;
}ALIGNPACKED;
#endif

typedef union SFA SFA;
/** Status of Fault */
union SFA {
    byte_t  bits;
    sfa_t   parts;
}ALIGNPACKED;

typedef struct accs_t accs_t;
/** Actual channel data */
struct accs_t {
    byte_t     tov;        /**< Type of disturbance values          */
    byte_t     acc;        /**< Actual channel                      */
    char       name[32];   /**< channel name                        */
    char       szPhase[8]; /**< channel Phase                       */
    char       szUnit[8];  /**< Unit                                */
    IEEE754SP  rpv;        /**< Rated primary value                 */
    IEEE754SP  rsv;        /**< Rated secondary value               */
    IEEE754SP  rfa;        /**< Reference factor                    */
    byte_t     maxframe;   /**< max frame number                     */
    uint16_t   *ndv;       /**< Number of disturbance value         */
    uint16_t   *nfe;       /**< The order of firsr disturbance value*/
    int16_t    **sdv;      /**< Single disturbance value buffer     */
}ALIGNPACKED;

typedef struct tap_t tap_t;
/** Tag postion */
struct tap_t {
    uint16_t   tap;        /**< Tag postion                         */	
    DIQ        dpi;        /**< Double point information            */
}ALIGNPACKED;

typedef struct tags_t tags_t;
/** Tag postion data */
struct tags_t {
	byte_t     fun;        /**< Function type                       */
	byte_t     inf;        /**< Information number                  */
	byte_t     noe;        /**< number of tag                       */
	char       name[32];   /**< tag Name                            */
	tap_t      *tag;/**< Tag postion buffer                  */
}ALIGNPACKED;



typedef struct timespan_t timespan_t;
struct timespan_t {
	int			flag;		// (0=召非故障录波和故障录波) （1=只召故障录波）
    CP56Time2a  lowbound;   //low bound of acc time
    CP56Time2a  highbound;  //high bound of acc time
}ALIGNPACKED;

typedef struct M_EX_TA_1_t M_EX_TA_1_t;
#define EXT_SOE_PARAMETER		(100) /**< SOE参数扩展 */
struct M_EX_TA_1_t {
	byte_t		typid;			/**< 普通SOE报文类型												*/
	byte_t		res_flag1;		/**< 备用标志，目前填0												*/
	byte_t		data_1[16];	    /**< 填写入普通SOE报文 (Cp56+FLOAT+QOS=7+4+1=13 16 should enough)	*/
    byte_t		ext_typid;		/**< 扩展报文类型													*/
	uint16_t	len;			/**< 扩展部分报文长度												*/
	byte_t		res_flag2;		/**< 备用															*/
	char		data_2[256];    /**< 扩展部分内容													*/
}ALIGNPACKED;

typedef struct EXT_SOE_PARAMETER_HEADER_t	EXT_SOE_PARAMETER_HEADER_t;
struct EXT_SOE_PARAMETER_HEADER_t {
	byte_t	param_id;		/**< 参数ID号 */
	byte_t  param_type;		/**< 参数TYPE */
	byte_t  param_len;		/**< 参数长度 */
	/*...参数内容 */
}ALIGNPACKED;

//招指定装置录波列表
typedef struct D_RE_DT_1_t D_RE_DT_1_t;
struct D_RE_DT_1_t {
	timespan_t timespan;
}ALIGNPACKED;
//根据列表招录波
typedef struct D_FA_SE_1_t D_FA_SE_1_t;
struct D_FA_SE_1_t {
	dist_record_t dist_record;
}ALIGNPACKED;

typedef struct D_ACC_ACK_1_t D_ACC_ACK_1_t;
struct D_ACC_ACK_1_t{
	byte_t	response; //规约响应(ACC_ACK_OK等)
}ALIGNPACKED;


typedef struct M_IT_S1_1_t   M_IT_S1_1_t;

struct M_IT_S1_1_t {
	int8_t	s_int1;	
	QDS        qds;	
}ALIGNPACKED;	

typedef struct M_IT_U1_1_t   M_IT_U1_1_t;

struct M_IT_U1_1_t {
	byte_t	u_int1;	
	QDS        qds;	
}ALIGNPACKED;	


typedef struct M_IT_S2_1_t   M_IT_S2_1_t;

struct M_IT_S2_1_t {
	int16_t s_int2;	
	QDS        qds;	
}ALIGNPACKED;	

typedef struct M_IT_U2_1_t   M_IT_U2_1_t;

struct M_IT_U2_1_t {
	uint16_t u_int2;	
	QDS        qds;	
}ALIGNPACKED;	

typedef struct M_IT_S4_1_t   M_IT_S4_1_t;
struct M_IT_S4_1_t {
	int32_t s_int4;	
	QDS        qds;	
}ALIGNPACKED;	

typedef struct M_IT_U4_1_t   M_IT_U4_1_t;
struct M_IT_U4_1_t {
	uint32_t u_int4;	
	QDS        qds;	
}ALIGNPACKED;	

typedef struct M_IT_F4_1_t   M_IT_F4_1_t;
struct M_IT_F4_1_t {
	float32_t  f_4;
	QDS        qds;	
}ALIGNPACKED;

typedef struct M_IT_F8_1_t   M_IT_F8_1_t;
struct M_IT_F8_1_t {
	float64_t  f_8;
	QDS        qds;	
}ALIGNPACKED;





#ifdef _OS_WIN32_
#pragma pack(pop)    
#endif 

/** @} */

#ifdef __cplusplus
extern "C" {
#endif

/** 复制基于IEC60870标准定义的vlaue_t结构的值，含格式转换  */
APR_DECLARE(int) copy_iec_data(value_t *dstval,value_t *srcval,uint32_t flags);

/** 求出某一具体IEC60870-5-101标准信息对象结构的字节长度   */
APR_DECLARE(size_t) sizeof_typid_data(byte_t typid);

/** 求出某一具体IEC60870-5-101标准信息对象缓冲区的字节长度 */
APR_DECLARE(size_t) sizeof_typid_buf(byte_t typid, byte_t *buf);

/** 将value_t表示的值转换成表示该值实际意义的字符串        */
APR_DECLARE(int) data_value2string(value_t *val,char *szvalue);

APR_DECLARE(int) data_actual_val(value_t *val,void *actval);
/** 得到EX_TA_1 的实际扩展部分长度字节的偏移量   */
APR_DECLARE(size_t) RDB_Get_EX_TA_Len_offset(byte_t *buf);

/** 大小端转换基于IEC60870标准定义的vlaue_t结构的值 */
APR_DECLARE(int) htolval_iec_data(value_t *dstval,value_t *srcval);

#ifdef __cplusplus
}
#endif

#endif /*_INC_IEC60870_5_101_TYPE_H */
