/**
* @file:    $RCSfile: interface.h,v $
* @brief:   $IEC 61850 Protocol  
*
* @version: $Revision: 1.4 $
* @date:    $Date: 2019/01/08 08:15:34 $
* @author:  $Author: lizhongming $
* @state:   $State: Exp $
*
* @latest:  $Id: interface.h,v 1.4 2019/01/08 08:15:34 lizhongming Exp $
*
*/

//$Header: /JoyProject/jspqfe/src/pt61850netd_pqfe/source/mms/interface.h,v 1.4 2019/01/08 08:15:34 lizhongming Exp $
/************************************************************************/
/* SAC HEADER ************************************************************/
/************************************************************************/
/*									*/
/* MODULE NAME : interface.h						*/
/* PRODUCT(S)  : wg_sac_61850						*/
/*									*/
/* MODULE DESCRIPTION :							*/
/*	Defines functions that should be use between mmsease and scadacom */
/*									*/
/* MODIFICATION LOG :							*/
/*  Date     Who   Rev			Comments			*/
/* --------  ---  ------   -------------------------------------------	*/

/* 2006-6-23 lzm    01    		New						*/
/************************************************************************/

#ifndef SAC_INTERFACE_H
#define SAC_INTERFACE_H


///////////////////////////////////////////////////////
#if defined (_WIN32)
#include <winsock2.h>
#endif

#include "sasstd.h"

#include "glbtypes.h"
#include "sysincs.h"
#include "signal.h"
#include "mmsdefs.h"
#include "mms_pvmd.h"
#include "mms_pvar.h"
#include "mms_vvar.h"
#include "mms_err.h"
#include "mms_pcon.h"
#include "asn1defs.h"
#include "mmsop_en.h"
#include "mvl_log.h"
#include "slog.h"
#include "tp4api.h"
#include "clntobj.h"
#include "mmsclient.h"


///////////////////////////////////////////////////


#define MAX_DATA_STR_SIZE 256

#define DATA_INT_TYPE 		0
#define DATA_UINT_TYPE 		1
#define DATA_INT64_TYPE 	2
#define DATA_UINT64_TYPE 	3
#define DATA_DOUBLE_TYPE 	4
#define DATA_STR_TYPE 		5
#define DATA_TIME_TYPE 		6

typedef struct mms_decode_data_item
  {
  	ST_CHAR			comp_name[MAX_DATA_STR_SIZE];
  	ST_UCHAR		type; 	//数据类型
  	ST_UCHAR		size; 	//数据的有效字节数
  union
    {
    	ST_INT32	data_int;
		ST_UINT32	data_uint;
#ifdef INT64_SUPPORT
		ST_INT64 	data_int64;
		ST_UINT64	data_uint64;
#endif  
		ST_DOUBLE	data_double;
		ST_CHAR	data_str[MAX_DATA_STR_SIZE];
		MMS_BTIME6 	data_bTime6;
    } u;   	
  	
  } MMS_DECODE_DATA_ITEM;
  
#define MAX_DATA_ITEMS_IN_ONE_DATA 	1024   // change for  PQS882 2016-5-10   //10-10-26-8-53 bei jing
typedef struct mms_decode_data
  {
  	ST_UINT					item_num; 	//数据的有效个数
	MMS_DECODE_DATA_ITEM	data_item[MAX_DATA_ITEMS_IN_ONE_DATA];  	
  	
  } MMS_DECODE_DATA;


void init_MMS();
void exit_MMS();
ST_VOID doCommService ();

ST_VOID init_log_cfg (ST_VOID);
ST_VOID set_rem_dib_table_size (ST_INT size);

//lnk20250207
#ifdef __cplusplus
extern "C" {
#endif
ST_VOID add_rem_dib_table (ST_INT pos,ST_CHAR *remAr,unsigned short port);
#ifdef __cplusplus
}
#endif

ST_RET mms_connectToServer (ST_CHAR * dev_key,ST_CHAR *dev_series, ST_CHAR *serverARName,
	MVL_NET_INFO **clientNetInfo, MVL_REQ_PEND **reqCtrl);

ST_RET mms_mvla_identify (MVL_NET_INFO  *net_info,char** ident,int iTimeout);
ST_RET mms_mvla_fdir (MVL_NET_INFO  *net_info,ST_CHAR *filespec,int iTimeout,
	char*** filenames ,int* filenum,apr_pool_t *pool);
ST_RET mms_getFile (MVL_NET_INFO *clientNetInfo, ST_CHAR *loc_file, 
	ST_CHAR *rem_file, ST_INT iTimeout);
	
ST_RET mms_mvla_status (MVL_NET_INFO  *net_info,int iTimeout);
	
ST_RET mms_mvla_getnam (MVL_NET_INFO  *net_info,ST_INT scope, 
	ST_CHAR *domName,ST_INT16 mms_class, int iTimeout,
	char*** varnames ,int* varnum,apr_pool_t *pool);

ST_INT mms_var_type_id_create (MVL_NET_INFO *clientNetInfo, ST_INT scope,
	ST_CHAR *dom_name, ST_CHAR *var_name, int iTimeOut);
	
ST_RET mms_named_var_read (MVL_NET_INFO *net_info, ST_CHAR *varName,
		ST_INT scope, ST_CHAR *domName,
		ST_INT type_id, ST_VOID *dataDest, ST_INT timeOut);
	
ST_VOID Callback_channel_disconnect_ind(MVL_NET_INFO * NetInfo, ST_INT discType);		
ST_RET mms_disconnectFromServer (MVL_NET_INFO *clientNetInfo,MVL_REQ_PEND **reqCtrl);

RCB_INFO *mms_register_iec_rpt (MVL_NET_INFO *clientNetInfo, RPT_TYPEIDS *rpt_typeids,
		ST_CHAR *dom_name,	/* domain which contains the RCB*/
		ST_CHAR *rcb_name,	/* RCB (e.g. "LLN0$BR$PosReport")*/
		ST_INT timeOut, ST_INT scanRate,ST_UCHAR trgops,ST_UINT8* pEntryID,ST_UINT8* OptFlds);

ST_RET mms_unregister_iec_rpt (MVL_NET_INFO *clientNetInfo, RPT_TYPEIDS *rpt_typeids,
		ST_CHAR *dom_name,	/* domain which contains the RCB*/
		ST_CHAR *rcb_name,	/* RCB (e.g. "LLN0$BR$PosReport")*/
		ST_INT timeOut );
//WW 2023-08-29 增加设备类型处理
RCB_INFO *mms_register_iec_rpt_by_devtype(MVL_NET_INFO *clientNetInfo, RPT_TYPEIDS *rpt_typeids,
	ST_CHAR *dom_name,	/* domain which contains the RCB*/
	ST_CHAR *rcb_name,	/* RCB (e.g. "LLN0$BR$PosReport")*/
	ST_INT timeOut, ST_CHAR *dev_type, ST_CHAR *ip, int port, ST_INT scanRate, ST_UCHAR trgops, ST_UINT8* pEntryID, ST_UINT8* OptFlds);

ST_RET mms_unregister_iec_rpt_by_devtype(MVL_NET_INFO *clientNetInfo, RPT_TYPEIDS *rpt_typeids, ST_CHAR *dev_type, ST_CHAR *ip, int port,
	ST_CHAR *dom_name,	/* domain which contains the RCB*/
	ST_CHAR *rcb_name,	/* RCB (e.g. "LLN0$BR$PosReport")*/
	ST_INT timeOut);
//WW end

void my_local_to_data (ST_CHAR *datptr, SD_CONST RUNTIME_TYPE *rt_head, 
			ST_INT rt_num,MMS_DECODE_DATA *data);
	

RCB_INFO* FindRcbInfo(MVL_NET_INFO *net_info,ST_CHAR *dom_name,	ST_CHAR *rcb_name);

int mms_iec_setPoint(ST_UCHAR  ctlModel, MVL_NET_INFO *clientNetInfo,
					 ST_CHAR *dom_name,	ST_CHAR *ctrl_name,	float32_t fctlVal, ST_BOOLEAN Check, int iTimeOut);	

int mms_iec_control (ST_UCHAR  ctlModel,MVL_NET_INFO *clientNetInfo, 
					ST_CHAR *dom_name,	ST_CHAR *ctrl_name,	int ictlVal, ST_BOOLEAN Check, int iTimeOut);

int mms_iec_control_yt (ST_UCHAR  ctlModel,MVL_NET_INFO *clientNetInfo, 
					ST_CHAR *dom_name,	ST_CHAR *ctrl_name,	int ictlVal, ST_BOOLEAN Check, int iTimeOut);
	
ST_INT mms_get_datatype_from_type_id (ST_INT type_id, ST_UCHAR* datatype,ST_INT *len);

void convert_apr_time_to_utc_time(apr_time_t tm,MMS_UTC_TIME *utc_time);

ST_RET my_asn1_convert_utc_to_btod (MMS_UTC_TIME *utc, MMS_BTOD *btod);

apr_time_t convert_btod_to_apr_time (MMS_BTOD *btod );
apr_time_t convert_btime6_to_apr_time (MMS_BTIME6 *bTime6 );

#endif //SAC_INTERFACE_H

