115 lines
4.4 KiB
C
115 lines
4.4 KiB
C
/******************************************************************************
|
|
|
|
版权所有 (C), 2013-2023, 科大智能电气有限公司
|
|
|
|
******************************************************************************
|
|
文 件 名 : gb101.h
|
|
版 本 号 : V1.0
|
|
生成日期 : 2022年03月23日
|
|
最近修改 :
|
|
功能描述 : gb101.c的头文件
|
|
函数列表 :
|
|
修改历史 :
|
|
1.日 期 : 2022年03月23日
|
|
修改内容 : 创建文件
|
|
|
|
******************************************************************************/
|
|
#ifndef __GB101_H
|
|
#define __GB101_H
|
|
/**************************************文件包含*******************************/
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include "lib60870_common.h"
|
|
#include "lib60870_public.h"
|
|
#include "lib60870_process.h"
|
|
#include "Asdu.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/**************************************宏定义*********************************/
|
|
#define START_CODE_101_LONG 0x68 //101规约长帧头
|
|
#define START_CODE_101_SHORT 0x10 //101规约短帧头
|
|
#define TAIL_CODE_101 0x16 //101规约报文尾
|
|
#define HEAD_LEN_101 7 //101规约ASDU前的字节长度 包含控制域及2字节地址
|
|
#define SHORT_LEN_S 5 //公共地址单字节时101短帧长度
|
|
#define SHORT_LEN 6 //公共地址双字节时101短帧长度
|
|
#define HEAD_TAIL_LEN 6 //101规约长帧头尾总长度
|
|
#define HEAD_LEN 4 //101规约长帧头长度
|
|
|
|
|
|
#define RESET_LINK 0 //复位链路
|
|
#define TEST_LINK 2 //测试帧
|
|
#define ACK_LINK 0 //确认帧
|
|
#define DATA_SEND 3 //长帧的功能码
|
|
#define NONE_DATA 4 //无回答数据
|
|
#define REQUEST_LINK 9 //请求链路状态
|
|
#define LINKSTATUS 11 //请求链路状态回复帧
|
|
#define FCVOFF 0 //FCB位无效
|
|
#define FCVON 1 //FCB位有效
|
|
#define PRM_MASTER 1 //启动站 这里与主站 终端有区别
|
|
#define PRM_SLAVE 0 //从动站 这里与主站 终端有区别
|
|
|
|
#define WAITTIME_101 10000 //短帧等待最大超时时间
|
|
#define TIMEOUT 3000 //101短帧超时重发时间
|
|
#define RESENDCNT_MAX 5 //重发次数
|
|
#define REINITTIME 300000 //5min重发初始化
|
|
/************************************数据结构定义*****************************/
|
|
/**
|
|
* @brief 平衡101规约控制域定义
|
|
*/
|
|
typedef union
|
|
{
|
|
struct //上行 低位在上
|
|
{
|
|
unsigned char FC : 4;
|
|
unsigned char DFC : 1;
|
|
unsigned char RES : 1;
|
|
unsigned char PRM : 1;
|
|
unsigned char DIR : 1;
|
|
} bits_up;
|
|
|
|
struct //下行
|
|
{
|
|
unsigned char FC : 4;
|
|
unsigned char FCV : 1;
|
|
unsigned char FCB : 1;
|
|
unsigned char PRM : 1;
|
|
unsigned char DIR : 1;
|
|
} bits_down;
|
|
|
|
unsigned char control;
|
|
} CONTROL101;
|
|
|
|
/**************************************数据声明******************************/
|
|
|
|
/**************************************内部函数声明***************************/
|
|
char GB101_DecodeProcess(CS10xHandle_t pstSelf, unsigned char *pucBuf, unsigned short usLen);
|
|
void GB101_LongFrame(CS10xHandle_t pstSelf, unsigned char *pucFrameStart);
|
|
void GB101_ShortFrame(CS10xHandle_t pstSelf, unsigned char *pucFrameStart);
|
|
char GB101_EncodeFrame(CS10xHandle_t pstSelf);
|
|
char GB101_EncodeOther(CS10xHandle_t pstSelf);
|
|
void GB101_TimerOut(CS10xHandle_t pstSelf, unsigned short usGap);
|
|
void GB101_Resend(CS10xHandle_t pstSelf, unsigned short usGap);
|
|
void GB101_Link_Init(CS10xHandle_t pstSelf, unsigned short usGap);
|
|
unsigned short GB101_EncodeFrameHead(CS10xHandle_t pstSelf, VIec101Frame * pstFrame);
|
|
void GB101_EncodeFrameTail(CS10xHandle_t pstSelf, VIec101Frame *pstFrame);
|
|
void GB101_Summon(CS10xHandle_t pstSelf);
|
|
void GB101_TimeSyn(CS10xHandle_t pstSelf);
|
|
void GB101_Heart(CS10xHandle_t pstSelf, unsigned short usGap);
|
|
void GB101_SendAck(CS10xHandle_t pstSelf);
|
|
void GB101_SendLinkStatus(CS10xHandle_t pstSelf);
|
|
void GB101_SendResetLink(CS10xHandle_t pstSelf);
|
|
void GB101_SendRequestLink(CS10xHandle_t pstSelf);
|
|
void GB101_SendTestLink(CS10xHandle_t pstSelf);
|
|
unsigned char GB101_Control(CS10xHandle_t pstSelf, unsigned char ucPRM, unsigned char ucFCV, unsigned char ucFC);
|
|
/************************************外部接口函数声明*************************/
|
|
|
|
extern void CS10x_101Init(CS10xHandle_t pstSelf, CS10x_SendCb cb, void *arg, CS10x_Type enType);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif |