/****************************************************************************/
/* Copyright (c) 2007,许继集团有限公司                                      */
/* All rights reserved.                                                     */
/*                                                                          */
/*  模块描述：                                                              */
/** iec61850基本数据类型和宏定义   
 *  @file  ai_def.h                                                         */
/*                                                                          */
/* 日期         作者    注释                                                */
/* 2007/07/12   DJF     创建文件                                            */
/****************************************************************************/

#ifndef IEC61850_AI_DEF_H
#define IEC61850_AI_DEF_H

#include "sysincs.h"
#include "glbtypes.h"
#include "mms_def2.h"
#include "mmsobj.h"

#ifdef __cplusplus
extern "C" {
#endif

/**61850服务代码*/
typedef enum{  
	IEC61850_OP_UNKNOWN = 0,
	IEC61850_OP_ASSOC,
	IEC61850_OP_RELEASE	,
	IEC61850_OP_ABORT,

	IEC61850_OP_GETSRVDIR,
	IEC61850_OP_GETLDDIR,
	IEC61850_OP_GETLNDIR,
	IEC61850_OP_GETDODEF,

	IEC61850_OP_READ,
	IEC61850_OP_WRITE,

	IEC61850_OP_GETSGV,
	IEC61850_OP_SETSGV,

	IEC61850_OP_SELVAL,
	IEC61850_OP_SELECT,
	IEC61850_OP_CANCEL,
	IEC61850_OP_OPER,

	IEC61850_OP_CRTDS,
	IEC61850_OP_DELDS,
	IEC61850_OP_GETDSDIR,
	IEC61850_OP_GETDSVAL,
	IEC61850_OP_SETDSVAL,

	IEC61850_OP_GETFAV,
	IEC61850_OP_GETFILE,
	IEC61850_OP_SETFILE,
	IEC61850_OP_DELFILE	,

	IEC61850_OP_QUERYLOGBT,
	IEC61850_OP_QUERYLOGA,
	IEC61850_OP_RPTENA  // 报告使能
}IEC61850_OP;

/**
 * 通道号枚举值     
 */
typedef enum 
{
    AC_CHANNEL_A,
    AC_CHANNEL_B,
    AC_CHANNEL_UNKNOWN
}AC_CHANNEL;

#define MAX_REFERENCE_LENGTH 129
/**
 * 61850对象参引数据类型     
 */
typedef ST_CHAR AI_OBJ_REF[MAX_REFERENCE_LENGTH + 1];

/**
 * 61850对象id数据类型，在服务器内唯一标识一个对象     
 */
typedef ST_INT   AI_OBJ_ID;


/**
 * 61850简单数据类型     
 */
typedef enum{
	VAL_TYPE_UNKNOWN = 0,
	VAL_TYPE_BOOLEAN,                         
	VAL_TYPE_INT8,
	VAL_TYPE_INT16,
	VAL_TYPE_INT32,
	VAL_TYPE_INT128,
	VAL_TYPE_INT8U,
	VAL_TYPE_INT16U,
	VAL_TYPE_INT32U,
	VAL_TYPE_FLOAT32,
	VAL_TYPE_FLOAT64, 
	VAL_TYPE_CODEDENUM,     //固定长度的bitstring, 2bit
	VAL_TYPE_TCMD,			//固定长度的bitstring, 2bit
	VAL_TYPE_OSTRING8,      //变长octet string,最大长度8个字节
	VAL_TYPE_OSTRING64,     //变长octet string,最大长度64个字节
	VAL_TYPE_VSTRING64,     //可视变长字符串，最大长度64
	VAL_TYPE_VSTRING65,     //可视变长字符串，最大长度65
	VAL_TYPE_VSTRING129,     //可视变长字符串，最大长度129
	VAL_TYPE_VSTRING255	,	//可视变长字符串，最大长度255
	VAL_TYPE_UNISTRING255,  //utf-8字符串，最大255个字符

	VAL_TYPE_QUALITY,		//变长bitstring 13bit
	VAL_TYPE_TIMESTAMP,		//utctime
	VAL_TYPE_ENTRYTIME,		//binary time，btime6格式
	VAL_TYPE_OPTFLDS,		//变长bitstring 10bit
	VAL_TYPE_TRGC,			//变长bitstring 6bit
	VAL_TYPE_CHECK,			//变长bitstring 2bit
	VAL_TYPE_ENTRYID,		//固定长度的octet string, 8个字节
	VAL_TYPE_STRUCT			//复杂类型的数据
}AI_VAL_TYPE;

/*da 类型定义,每个宏定义的值和AI_OBJ_VAL中的枚举值一致 */
#define		AI_DATYPE_UNKNOWN		    VAL_TYPE_UNKNOWN
#define		AI_DATYPE_BOOLEAN		    VAL_TYPE_BOOLEAN        
#define		AI_DATYPE_INT8			    VAL_TYPE_INT8          
#define		AI_DATYPE_INT16			    VAL_TYPE_INT16          
#define		AI_DATYPE_INT32			    VAL_TYPE_INT32         
#define		AI_DATYPE_INT128		    VAL_TYPE_INT128       
#define		AI_DATYPE_INT8U			    VAL_TYPE_INT8U        
#define		AI_DATYPE_INT16U		    VAL_TYPE_INT16U         
#define		AI_DATYPE_INT32U		    VAL_TYPE_INT32U        
#define		AI_DATYPE_FLOAT32		    VAL_TYPE_FLOAT32      
#define		AI_DATYPE_FLOAT64		    VAL_TYPE_FLOAT64        
#define		AI_DATYPE_CODEDENUM		    VAL_TYPE_CODEDENUM
#define		AI_DATYPE_TCMD              VAL_TYPE_CODEDENUM
#define		AI_DATYPE_OSTRING8          VAL_TYPE_OSTRING8      
#define		AI_DATYPE_OSTRING64		    VAL_TYPE_OSTRING64      
#define		AI_DATYPE_VSTRING64		    VAL_TYPE_VSTRING64       
#define		AI_DATYPE_VSTRING65		    VAL_TYPE_VSTRING65      
#define		AI_DATYPE_VSTRING129		VAL_TYPE_VSTRING129      
#define		AI_DATYPE_VSTRING255	    VAL_TYPE_VSTRING255    
#define		AI_DATYPE_UNISTRING255	    VAL_TYPE_UNISTRING255     												  	   
#define		AI_DATYPE_QUALITY		    VAL_TYPE_QUALITY   	          
#define		AI_DATYPE_TIMESTAMP		    VAL_TYPE_TIMESTAMP                           
#define		AI_DATYPE_ENTRYTIME		    VAL_TYPE_ENTRYTIME     
#define		AI_DATYPE_OPTFLDS		    VAL_TYPE_OPTFLDS
#define     AI_DATYPE_TRGC              VAL_TYPE_TRGC
#define		AI_DATYPE_CHECK			    VAL_TYPE_CHECK
#define     AI_DATYPE_ENTRYID           VAL_TYPE_ENTRYID
#define		AI_DATYPE_STRUCT		    VAL_TYPE_STRUCT  
       
/**                                            
 * 61850对象类型                                
 */                                       
typedef enum                              
{  
	OBJECT_TYPE_UNKNOWN = 0,
	OBJECT_TYPE_IED,
	OBJECT_TYPE_LD,
	OBJECT_TYPE_LN,
	OBJECT_TYPE_DS,
	OBJECT_TYPE_FCN, //带fc的ln
	OBJECT_TYPE_FCD, 
	OBJECT_TYPE_FCDA,
	OBJECT_TYPE_CB  //控制块
}AI_OBJ_TYPE;

typedef		ST_INT		AI_FCO_SUBTYPE; //值为AI_CBTYPE_XXX AI_LNTYPE_XXX AI_DOTYPE_XXX AI_DATYPE_XXX等
#define		AI_FCO_SUBTYPE_UNKNOWN	0     

/** cb控制块类型定义 */
#define		AI_CBTYPE_UNKNOWN		0  
#define		AI_CBTYPE_SGCB			1	//SP
#define		AI_CBTYPE_URCB			2	//RP
#define		AI_CBTYPE_BRCB			3   //BR
#define		AI_CBTYPE_LCB			4   //LG
#define		AI_CBTYPE_GOCB			5   //GO
#define		AI_CBTYPE_GSCB			6   //GS
#define		AI_CBTYPE_MSVCB			7   //MS
#define		AI_CBTYPE_USVCB			8   //US

/** ln 类型定义*/                         
#define		AI_LNTYPE_UNKNOWN	    0     		 /*   NOT IN STANDARD LN TYPE */
#define		AI_LNTYPE_LLN0          1             
#define		AI_LNTYPE_LPHD          2             
#define		AI_LNTYPE_PDIF          3             
#define		AI_LNTYPE_PDIR          4             
#define		AI_LNTYPE_PDIS          5             
#define		AI_LNTYPE_PDOP          6             
#define		AI_LNTYPE_PDUP          7             
#define		AI_LNTYPE_PFRC          8             
#define		AI_LNTYPE_PHAR          9             
#define		AI_LNTYPE_PHIZ          10            
#define		AI_LNTYPE_PIOC          11            
#define		AI_LNTYPE_PMRI          12            
#define		AI_LNTYPE_PMSS          13            
#define		AI_LNTYPE_POPF          14            
#define		AI_LNTYPE_PPAM          15            
#define		AI_LNTYPE_PSCH          16            
#define		AI_LNTYPE_PSDE          17            
#define		AI_LNTYPE_PTEF          18            
#define		AI_LNTYPE_PTOC          19            
#define		AI_LNTYPE_PTOF          20            
#define		AI_LNTYPE_PTOV          21            
#define		AI_LNTYPE_PTRC          22            
#define		AI_LNTYPE_PTTR          23            
#define		AI_LNTYPE_PTUC          24            
#define		AI_LNTYPE_PTUF          25            
#define		AI_LNTYPE_PTUV          26            
#define		AI_LNTYPE_PUPF          27            
#define		AI_LNTYPE_PVOC          28            
#define		AI_LNTYPE_PVPH          29            
#define		AI_LNTYPE_PZSU          30            
#define		AI_LNTYPE_RADR          31            
#define		AI_LNTYPE_RBDR          32            
#define		AI_LNTYPE_RBRF          33            
#define		AI_LNTYPE_RDIR          34            
#define		AI_LNTYPE_RDRE          35            
#define		AI_LNTYPE_RDRS          36            
#define		AI_LNTYPE_RFLO          37            
#define		AI_LNTYPE_RPSB          38            
#define		AI_LNTYPE_RREC          39            
#define		AI_LNTYPE_RSYN          40            
#define		AI_LNTYPE_CALH          41            
#define		AI_LNTYPE_CCGR          42            
#define		AI_LNTYPE_CILO          43            
#define		AI_LNTYPE_CPOW          44            
#define		AI_LNTYPE_CSWI          45            
#define		AI_LNTYPE_GAPC          46            
#define		AI_LNTYPE_GGIO          47            
#define		AI_LNTYPE_GSAL          48            
#define		AI_LNTYPE_IARC          49            
#define		AI_LNTYPE_IHMI          50            
#define		AI_LNTYPE_ITCI          51            
#define		AI_LNTYPE_ITMI          52            
#define		AI_LNTYPE_ANCR          53            
#define		AI_LNTYPE_ARCO          54            
#define		AI_LNTYPE_ATCC          55            
#define		AI_LNTYPE_AVCO          56            
#define		AI_LNTYPE_MDIF          57            
#define		AI_LNTYPE_MHAI          58            
#define		AI_LNTYPE_MHAN          59            
#define		AI_LNTYPE_MMTR          60            
#define		AI_LNTYPE_MMXN          61            
#define		AI_LNTYPE_MMXU          62            
#define		AI_LNTYPE_MSQI          63            
#define		AI_LNTYPE_MSTA          64            
#define		AI_LNTYPE_SARC          65            
#define		AI_LNTYPE_SIMG          66            
#define		AI_LNTYPE_SIML          67            
#define		AI_LNTYPE_SPDC          68            
#define		AI_LNTYPE_XCBR          69            
#define		AI_LNTYPE_XSWI          70            
#define		AI_LNTYPE_TCTR          71            
#define		AI_LNTYPE_TVTR          72            
#define		AI_LNTYPE_YEFN          73            
#define		AI_LNTYPE_YLTC          74            
#define		AI_LNTYPE_YPSH          75            
#define		AI_LNTYPE_YPTR          76            
#define		AI_LNTYPE_ZAXN          77            
#define		AI_LNTYPE_ZBAT          78            
#define		AI_LNTYPE_ZBSH          79            
#define		AI_LNTYPE_ZCAB          80            
#define		AI_LNTYPE_ZCAP          81            
#define		AI_LNTYPE_ZCON          82            
#define		AI_LNTYPE_ZGEN          83            
#define		AI_LNTYPE_ZGIL          84            
#define		AI_LNTYPE_ZLIN          85            
#define		AI_LNTYPE_ZMOT          86            
#define		AI_LNTYPE_ZREA          87            
#define		AI_LNTYPE_ZRRC          88            
#define		AI_LNTYPE_ZSAR          89            
#define		AI_LNTYPE_ZTCF          90            
#define		AI_LNTYPE_ZTCR          91        

/** do类型定义 */                    
#define		AI_DOTYPE_UNKNOWN	    0    /*   NOT IN STANDARD  TYPE */
#define		AI_DOTYPE_SPS           1  
#define		AI_DOTYPE_DPS           2  
#define		AI_DOTYPE_INS           3  
#define		AI_DOTYPE_ACT           4  
#define		AI_DOTYPE_ACD           5  
#define		AI_DOTYPE_SEC           6  
#define		AI_DOTYPE_BCR           7  
#define		AI_DOTYPE_MV            8  
#define		AI_DOTYPE_CMV           9  
#define		AI_DOTYPE_SAV           10 
#define		AI_DOTYPE_SPC           11 
#define		AI_DOTYPE_DPC           12 
#define		AI_DOTYPE_INC           13 
#define		AI_DOTYPE_BSC           14 
#define		AI_DOTYPE_ISC           15 
#define		AI_DOTYPE_APC           16 
#define		AI_DOTYPE_SPG           17 
#define		AI_DOTYPE_ING           18 
#define		AI_DOTYPE_ASG           19 
#define		AI_DOTYPE_CURVE         20 
#define		AI_DOTYPE_DPL           21 
#define		AI_DOTYPE_LPL           22 
#define		AI_DOTYPE_CSD           23
#define		AI_DOTYPE_WYE           24 
#define		AI_DOTYPE_DEL           25 
#define		AI_DOTYPE_SEQ           26 
#define		AI_DOTYPE_HMV           27 
#define		AI_DOTYPE_HWYE          28
#define		AI_DOTYPE_HDEL          29 
//下面是在iec61850v2.0中新增的cdc类型
#define		AI_DOTYPE_ENC          30 
#define		AI_DOTYPE_ENS          31 
#define		AI_DOTYPE_ENG          32 
#define		AI_DOTYPE_HST          33 
#define		AI_DOTYPE_ORG          34 
#define		AI_DOTYPE_TSG          35 
#define		AI_DOTYPE_CSG          36
#define     AI_DOTYPE_ERS          37  



                       
                        
											 
											 
/**                                         
 * 61850常用基本数据类型定义    
 */
#define	 ST_OSTRING8	OCTET_STRING8_TDEF  		/* octet string */
#define  ST_OSTRING64	OCTET_STRING64_TDEF 		/* octet string */
#define  ST_VSTRING255	VISIBLE_STRING255_TDEF		/* Visible String */
#define  ST_VSTRING64	VISIBLE_STRING64_TDEF		/* Visible String */
#define  ST_VSTRING65	VISIBLE_STRING65_TDEF		/* Visible String */
#define  ST_VSTRING129	VISIBLE_STRING129_TDEF		/* Visible String */
#define  ST_USTRING255	UNICODE_STRING255_TDEF		/* utf8String */
#define  ST_TIMESTAMP	TimeStamp_TDEF				/* utc time */
#define  ST_ENTRYTIME	EntryTime_TDEF				/* btime6 */
#define  ST_QUALITY		Quality_TDEF				/* BVstring13 */
#define  ST_ENTRYID		EntryID_TDEF				/* 8个字节的8位位组 */
#define  ST_OPTFLDS		OPTFLDS_TDEF				/* BVstring10 */
#define  ST_TRGOP		TRG_CONDITION_TDEF			/* BVstring6 */
#define  ST_CHECK		Check_TDEF					/* BVstring2 */


/**
 * 61850简单数据类型对象的值的数据结构定义     
 */
typedef struct
{
	AI_VAL_TYPE   type;		/**< 基本数据类型 */
	ST_INT        size;		/**< 数据元素占用的字节数，即data的长度 */
	ST_VOID       *data;	/**< 数据缓冲区 */
}AI_PRIM_VAL;

/**
 * 61850对象值的数据结构定义     
 */
typedef struct
{
	AI_OBJ_ID	obj_id;		/**< 对象ID */
	AI_OBJ_ID	*prim_ids;	/**< 此对象包含的简单类型对象的id，数组 */  
	AI_PRIM_VAL *prim_vals;	/**< 本对象的所有简单类型的子成员的值，数组 */
	ST_INT		prim_num;	/**< 数组大小 */
}AI_OBJ_VAL;

/**
 * acsi服务错误代码     
 */
typedef  ST_INT8  AC_REQ_RESULT;
#define  AC_RESULT_SUCCESS  0;	/**< 服务成功 */
#define  AC_RESULT_FAILURE  1;	/**< 服务失败 */
#define  AC_RESULT_TIMEOUT  2;	/**< 服务超时失败 */


#ifdef __cplusplus
}
#endif


#endif /* ACSI_DEFINED_INCLUDE */


