commCPU_SUPV/code/protect/demo/protect_61850.c
2025-04-30 16:24:29 +08:00

286 lines
7.1 KiB
C
Raw 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.

/****************************************************************************
文件名: .c
----------------------------------------------------------------------------
描述 : 保护与61850的接口函数
----------------------------------------------------------------------------
修改日志 :
日期 姓名 操作
----------------------------------------------------------------------------
2014-01-27 hsj create
****************************************************************************/
#include <stdio.h>
#include "protect_61850.h"
#include "shmbuff.h"
#include <string.h>
//#include "gse_clnp.h"
//---------------------------------------------------------------------------------
//下面是goose相关回调函数
//---------------------------------------------------------------------------------
#if 0
#ifdef _WIN32
#include <windows.h>
#pragma comment(lib,"ws2_32.lib")
#endif
#define printf inf_shm_printf_write
/**
* 收到goose信息后的回调用户从gserCtrl中取goose数据
*/
void protect_callback_receive_goose(GSE_RX_CTRL *gserCtrl, unsigned long err)
{
int i, j;
AS_DA_MAP *da_map;
GOOSE_MAP_CTRL *goose_map = 0;
printf("recved goose appid=%04x, stNum=%d, sqNum=%d\n", gserCtrl
->ini_info.etypeAppid, gserCtrl->stNum, gserCtrl->sqNum);
if (gserCtrl->goose_maps == 0)
{
return ;
}
for (i = 0; i < gserCtrl->numUnits; i++)
{
goose_map = &gserCtrl->goose_maps[i];
for (j = 0; j < goose_map->da_map_num; j++)
{
da_map = goose_map->da_maps[j];
if (da_map)
{
printf(" da_ref=%s, usr_data_info(%s)\n", da_map->da_ref, da_map
->usr_data_info);
}
}
}
}
/**
* goose通道恢复正常时的回调
*/
void protect_callback_goose_connected(int eth_index, GSE_RX_CTRL *gserCtrl,
unsigned char con)
{
if (con)
{
printf("goose connected, appid=%04x, eth=%d\n", gserCtrl
->ini_info.etypeAppid, eth_index);
}
else
{
printf("goose disconnected, appid=%04x, eth=%d\n", gserCtrl
->ini_info.etypeAppid, eth_index);
}
}
/**
* goose通道出现异常后的回调。双网时意味着两个通道都异常了。
*/
void protect_callback_goose_allchnl_disconnected(GSE_RX_CTRL *gserCtrl)
{
printf("goose all chnl disconnected, appid=%04x\n", gserCtrl
->ini_info.etypeAppid);
}
/**
* 采样值回调函数的定义
*/
void protect_smv2_callback_recv(GSV_SV2RECV_CTRL *pSmv92Data, int svIndex, int
svNum, unsigned int recvTime)
{
printf("smv recv index=%d, num=%d, time=%d.\n", svIndex, svNum, recvTime);
}
/**
* 初始化GOOSE变量的值在61850系统启动的时候会调用本函数
* 需要保护完成本函数内容初始化GOOSE值
*/
void protect_init_goose_data(const IEC_GOOSE_SEND_USER_INFO *gseSend_user_list)
{
//调用函数gw61850gse_data_value_change
printf(">>Recv protect_init_goose_data().\n");
}
/**************************************************************************/
/* */
/**************************************************************************/
void protect_smv2_callback_initilized(const GSV_SV2RECV_CTRL *pSmv92Data_array,
int number, int accessMode)
{
//完成SMV初始化后调用函数通知保护获取自己想要的参数
int iLoop;
for (iLoop = 0; iLoop < number; iLoop++)
{
printf(">>SMV recv %s initilized, appid=%X, index=%d.\n",
pSmv92Data_array[iLoop].svId, pSmv92Data_array[iLoop].appid,
pSmv92Data_array[iLoop].ctrlIndex);
}
}
/**************************************************************************/
/* */
/**************************************************************************/
void protect_goose_recv_callback_initilized(const GSE_RX_CTRL *gserCtrl_list)
{
printf(">>protect_goose_recv_callback_initilized().\n");
}
/**************************************************************************/
/* */
/**************************************************************************/
void protect_callback_init_fail(unsigned int err)
{
//初始化GOOSE SMV 错误
printf(">>protect_callback_init_fail()=%d.\n", err);
}
/*****************************************************************/
/*****************************************************************/
#ifndef CCES_ADI
int main(void)
#else
int main_prog(void)
#endif
{
int ret;
ret = goosesmv_init();
if (0 == ret)
{
printf(">>goosesmv_init() success.\n");
}
while (1)
{
const unsigned char *nRecv = NULL;
#if 0
int len;
unsigned char *buff;
len = 0;
buff = gsv_clnp_recv(1, &len);
if (len > 0)
{
printf("%d: %02X-%02X.\n", len, buff[0], buff[1]);
}
{
//测试发送GOOSE
unsigned char buff[128] =
{
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE1, 0x2E, 0x4F, 0xFF, 0x55, 0xAB,
0x08, 0x06, 0x00, 0x01, 0x08, 0x00, 0x06, 0x04, 0x00, 0x01, 0xe8,
0x9a, 0x8f, 0x9b, 0xc7, 0x52, 0xc0, 0xa8, 0x01, 0x64, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xc0, 0xa8, 0x02, 0x09, 0xAA, 0X55, 0XAA, 0X55
};
gsv_clnp_send(1, buff, 46); //
//gsv_clnp_send( 0, buff, 46 );
}
#elif 0
//测试LP的发送和接收
int len;
static unsigned char coun = 0;
unsigned char buff[128];
coun++;
if (0 == coun)
{
coun++;
}
memset(buff, coun, 128);
//gsv_clnp_send( 1, buff, 128 );
len = 0;
nRecv = gsv_clnp_recv(1, &len);
if (0 < len)
{
int iLoop, size0 = 0;
char buff[256] =
{
0
};
printf(">>Recv %d from 1:\n", len);
len /= 4;
for (iLoop = 0; iLoop < len; iLoop++)
{
if (iLoop % 16 == 0)
{
size0 += sprintf(buff + size0, "\n");
printf(buff);
size0 = 0;
}
size0 += sprintf(buff + size0, "%02X ", nRecv[iLoop]);
}
size0 += sprintf(buff + size0, "\n");
printf(buff);
size0 = 0;
//printf("%d: %02X-%02X, %02X-%02X.\n", len, buff[0], buff[1],
// buff[16], buff[16+1] );
}
len = 0;
nRecv = gsv_clnp_recv(2, &len);
if (0 < len)
{
int iLoop, size0 = 0;
char buff[256] =
{
0
};
printf(">>Recv %d from 2:\n", len);
len /= 4;
for (iLoop = 0; iLoop < len; iLoop++)
{
if (iLoop % 16 == 0)
{
size0 += sprintf(buff + size0, "\n");
printf(buff);
size0 = 0;
}
size0 += sprintf(buff + size0, "%02X ", nRecv[iLoop]);
}
size0 += sprintf(buff + size0, "\n");
printf(buff);
size0 = 0;
//printf("%d: %02X-%02X, %02X-%02X.\n", len, buff[0], buff[1],
// buff[16], buff[16+1] );
}
#else
gse_handle(); //GOOSE、SMV相关处理(主要是发送)(接收在中断函数里面处理)
#endif
protect_simul_handle(0);
#ifdef CCES_ADI
#endif
sMsSleep(10);
}
return 0;
}
/**************************************************************************/
/* */
/**************************************************************************/
#endif