247 lines
7.4 KiB
C
247 lines
7.4 KiB
C
/****************************************************************************/
|
||
/* Copyright (c) 2008,许继集团有限公司 */
|
||
/* All rights reserved. */
|
||
/* */
|
||
/* 模块描述: */
|
||
/** goose发送处理模块
|
||
* @file gse_demo.h */
|
||
/* */
|
||
/* 日期 作者 注释 */
|
||
/* 2010/01/20 DJF 创建文件 */
|
||
/****************************************************************************/
|
||
#ifndef IEC61850_GSE_DEMO_H
|
||
#define IEC61850_GSE_DEMO_H
|
||
|
||
#include "glbtypes.h"
|
||
#include "sysincs.h"
|
||
#include "stime.h"
|
||
#include "goose.h"
|
||
//#include "mvl_acse.h"
|
||
//#include "mms_mp.h"
|
||
//#include "mms_pvar.h"
|
||
//#include "mvl_defs.h"
|
||
//#include "mvl_uca.h"
|
||
#include <assert.h>
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif
|
||
|
||
#define MAX_SENDING_GOOSE 16 /*maximum number of sending GEESE Supported */
|
||
#define MAX_RXD_GOOSE 32 /*maximum number of receiving GEESE Supported */
|
||
#define MAX_IEC_REFERENCE_SIZE 65
|
||
#define MAC_ADDR_SIZE 6
|
||
|
||
//goose_state
|
||
#define SD_GOOSE_NOT_CONFIGURED 0
|
||
#define SD_GOOSE_CONFIGURED 1
|
||
#define SD_GOOSE_TRANSMITTING 2
|
||
#define SD_GOOSE_STOPPED 3
|
||
#define SD_GOOSE_IDLE 4
|
||
#define SD_GOOSE_RETRANSMIT 5
|
||
|
||
//reason
|
||
#define GOOSE_CALLBACK_REASON_STATECHANGE_DATA_UPDATED 0x01
|
||
#define GOOSE_CALLBACK_REASON_TIMEALLOWED_TO_LIVE_TIMEOUT 0x02
|
||
#define GOOSE_CALLBACK_REASON_OUT_OF_SEQUENCE_DETECTED 0x04
|
||
#define GOOSE_CALLBACK_REASON_CONFREV_MISMATCH 0x08
|
||
#define GOOSE_CALLBACK_REASON_NEED_COMMISSIONING 0x10
|
||
#define GOOSE_CALLBACK_REASON_TEST_MODE 0x20
|
||
#define GOOSE_CALLBACK_REASON_GCREF_MISMATCH 0x40
|
||
#define GOOSE_CALLBACK_REASON_APPID_MISMATCH 0x80
|
||
#define GOOSE_CALLBACK_REASON_DATSET_MISMATCH 0x100
|
||
|
||
//decode mode
|
||
#define GOOSE_DEC_MODE_NOT_SET 0
|
||
#define GOOSE_DEC_MODE_LAST_RX 1
|
||
#define GOOSE_DEC_MODE_IMMEDIATE 2
|
||
/*the following allows the definition of a retransmission curve */
|
||
/*individual retransmission curves can be associated with each */
|
||
/*GOOSE being sent */
|
||
#define MAX_NUM_RETRANS 16
|
||
|
||
#define MAX_IEC_GOOSE_ENCODE_BUF 1540 /*maximum size of IEC GOOSE encoding */
|
||
|
||
typedef struct retrans_curve
|
||
{
|
||
ST_UINT num_retrans;
|
||
ST_INT32 retrans[MAX_NUM_RETRANS]; /*storage of retrans time in msec.*/
|
||
} RETRANS_CURVE;
|
||
|
||
/*发送的goose控制块结构*/
|
||
typedef struct iec_goose_send_user_info
|
||
{
|
||
struct iec_goose_send_user_info * next;
|
||
struct iec_goose_send_user_info * prev;
|
||
|
||
ST_UINT goose_state; /*TRUE, ready to send GOOSE */
|
||
ST_DOUBLE next_time; /*下次发送时间 */
|
||
ST_UINT retrans_curve_offset; /*offset to current retrans curve */
|
||
RETRANS_CURVE * curve_pointer; /*pointer to retransmission curve*/
|
||
GSE_IEC_CTRL * gptr; /*pointer to GOOSE Control */
|
||
// MVL_NVLIST_CTRL * nvl; /*pointer to Data Set associated with GOOSE*/
|
||
// MVL_IND_PEND * scan_ind; /*pointer to structure that allows for polling*/
|
||
ST_UCHAR dstAddress[MAC_ADDR_SIZE]; /*destination MAC address to which GOOSE will be sent */
|
||
|
||
ST_UINT16 etype_tci; /* Ethertype TCI */
|
||
ST_UINT16 etype_id; /* Ethertype ID */
|
||
ST_UINT16 etype_appID; /* Ethertype AppID */
|
||
|
||
ST_BOOLEAN val_changed; /* 有数据变化,需要触发goose */
|
||
}IEC_GOOSE_SEND_USER_INFO;
|
||
|
||
typedef struct iec_goose_rx_time
|
||
{
|
||
ST_BOOLEAN connected;
|
||
ST_INT index;
|
||
ST_DOUBLE rx_time;
|
||
}IEC_GOOSE_RX_CON;
|
||
|
||
typedef struct network_device_cfg
|
||
{
|
||
ST_INT dev_num; /* number of network device */
|
||
ST_UINT16 devices[8]; /* network device array */
|
||
}NETWORK_DEVICE_CFG;
|
||
|
||
typedef struct rt_type_array
|
||
{
|
||
ST_INT num_rts; /*number of rts */
|
||
RUNTIME_TYPE * rt; /*pointer to type */
|
||
}RT_TYPE_ARRAY;
|
||
|
||
typedef struct
|
||
{
|
||
ST_MUTEX_SEM pub_mutex; /* controls access to pub_list */
|
||
IEC_GOOSE_SEND_USER_INFO * pub_list; /* linked list of publishers */
|
||
} PUBLISHER_CTRL;
|
||
|
||
//用于保存和nvl相关的报告控制块和用于发送的goosehandle,保存到nvl的user_info
|
||
typedef struct {
|
||
DBL_LNK l;
|
||
ST_BOOLEAN is_rcb;
|
||
union{
|
||
// MVLU_RPT_CTRL * rpt_ctrl;
|
||
IEC_GOOSE_SEND_USER_INFO * goosehandle;
|
||
}u;
|
||
}RELATED_CB_CTRL;//
|
||
|
||
/*function to create a control block and resources for publishing */
|
||
IEC_GOOSE_SEND_USER_INFO * iecGoosePubCreate( ST_UCHAR * DstAddress,
|
||
ST_CHAR * GoCBRef,
|
||
ST_CHAR * DataSetRef,
|
||
ST_CHAR * GoID,
|
||
ST_UINT32 ConfRev,
|
||
ST_BOOLEAN NeedsComm,
|
||
ST_UINT16 tci,
|
||
ST_UINT16 etypeID,
|
||
ST_UINT16 appID,
|
||
ST_INT max_time,
|
||
ST_INT min_time ) /* Ethertype APPID */;
|
||
/************************************************************************/
|
||
/* Global variables. */
|
||
/************************************************************************/
|
||
|
||
extern PUBLISHER_CTRL pub_ctrl; /* ctrl struct for all publishers. */
|
||
|
||
/**
|
||
* goose重发间隔初始化
|
||
*/
|
||
ST_VOID init_retrans_curve( RETRANS_CURVE * retrans_curve );
|
||
|
||
/**
|
||
* pub_ctrl中添加IEC_GOOSE_SEND_USER_INFO信息
|
||
* @param gptr GSE_IEC_CTRL*
|
||
* @return IEC_GOOSE_SEND_USER_INFO
|
||
*/
|
||
IEC_GOOSE_SEND_USER_INFO * add_sending_goose( GSE_IEC_CTRL * gptr );
|
||
/**
|
||
* 删除IEC_GOOSE_SEND_USER_INFO信息,释放内存
|
||
* @param user_info IEC_GOOSE_SEND_USER_INFO*
|
||
* @return void
|
||
*/
|
||
ST_VOID delete_sending_goose ( IEC_GOOSE_SEND_USER_INFO * user_info );
|
||
|
||
/**
|
||
* 61850参引转换为OBJECT_NAME
|
||
*/
|
||
//OBJECT_NAME * convert_reference_to_mms_obj( ST_CHAR * reference, OBJECT_NAME * obj );
|
||
|
||
/**
|
||
* 首次发送goose调用此函数
|
||
*/
|
||
ST_RET start_trans_goose ( IEC_GOOSE_SEND_USER_INFO * user_info, RETRANS_CURVE * retrans_curve ) ;
|
||
|
||
/**
|
||
* goose重发
|
||
*/
|
||
ST_VOID retrans_goose ( void );
|
||
|
||
/**
|
||
* 从网络上接收goose信息
|
||
*/
|
||
ST_VOID execute_as_subscriber ( ST_VOID );
|
||
|
||
/**
|
||
* 检查每一个goose信息发送链表,处理每一个需要发送的goose
|
||
*/
|
||
ST_VOID execute_as_publisher ( ST_VOID );
|
||
|
||
/**
|
||
* 释放goosehandle
|
||
*/
|
||
ST_VOID iecGoosePubDestroy ( IEC_GOOSE_SEND_USER_INFO * goosehandle );
|
||
|
||
/**
|
||
* 处理goose信息控制块goosehandle,发送goose
|
||
*/
|
||
ST_VOID iecGoosePublish ( IEC_GOOSE_SEND_USER_INFO * goosehandle );
|
||
|
||
/**
|
||
* 打开网卡,创建goose信息,初始化时调用
|
||
*/
|
||
ST_RET gse_start( ST_CHAR * scl_info );
|
||
|
||
/**
|
||
* 终止化网络,关闭所有网卡,释放goose信息块
|
||
*/
|
||
ST_VOID gse_end( ST_VOID );
|
||
|
||
/**
|
||
* 发送、接收goose
|
||
*/
|
||
ST_VOID gse_handle( ST_VOID );
|
||
|
||
/**
|
||
* goose数据变化时调用此接口,此接口不发送数据,只是更新数据,并作发送标志
|
||
*/
|
||
ST_VOID as_gse_value_changed( AS_DA_MAP * map_entry, ST_VOID * data );
|
||
|
||
/**
|
||
* 触发goose,用户应在as_gse_value_changed()设置好所有变化数据后立即调用此函数,
|
||
* 以加快goose发送速度
|
||
*/
|
||
ST_VOID as_check_and_send_goose( void );
|
||
|
||
/**
|
||
* 设置所有发送的goose的test标识,检修压板投退时调用
|
||
*/
|
||
ST_VOID gs_tx_set_test_all( ST_BOOLEAN test );
|
||
|
||
/**
|
||
* 根据传入appid查找gseSend_ctrl
|
||
*/
|
||
IEC_GOOSE_SEND_USER_INFO * as_find_gseSend_ctrl( ST_UINT16 etypeAppid );
|
||
|
||
/**
|
||
*VxWorks下,发送GOOSE的处理,由保护定时调用
|
||
*/
|
||
ST_VOID gse_send_goose( ST_VOID );
|
||
|
||
/****获取结构体 add 2012-12-19******/
|
||
const NETWORK_DEVICE_CFG * gse_get_network_device( ST_VOID );
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
#endif
|