You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

292 lines
11 KiB
C

2 years ago
/************************************************************************************
*
* Copyright (C) 2004-2005 SCADA Control Technology Co., Ltd.
* All rights reserved.
*
* buban104.h
* 104
* 104
2 years ago
*
* 1.0
* aaawen
* 2005/09/14
2 years ago
*
* 1.0
*
*
2 years ago
*
*
2 years ago
* u8 --- BYTE(usigned char)
* ch --- char
* w --- WORD(u_short, usigned short)
* sh --- short
* b --- BOOL(bool)
* i --- int
* l --- long
* u32 --- u_32
* ui --- unsigned int(u_int)
* ul --- unsigned long(u_long)
* f --- float
* db --- double
* c --- class
* s --- struct
* sta --- static
* g ---
* Array ---
* a ---
* m_ ---
* p ---
* str ---
* ---
* ---
2 years ago
**************************************************************************************/
// buban104.h: interface for the buban104 class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(_BUBAN104_H_200509141152__INCLUDED_)
#define _BUBAN104_H_200509141152__INCLUDED_
#ifdef OS_LINUX
#include "baohulib/common.h"
#else
#include "common.h"
#endif
//////////////////////////////////////////////////////////////////////////
// 宏定义 //
2 years ago
// WEN 2005.09.08 //
//////////////////////////////////////////////////////////////////////////
#define MAX_104_PINUM 30
#define FORMAT_I 14 // I-格式
#define FORMAT_S 15 // S-格式
#define FORMAT_U_START_ACT 16 // U-格式启动
#define FORMAT_U_START_CON 17 // U-格式启动应答
#define FORMAT_U_STOP_ACT 18 // U-格式停止
#define FORMAT_U_STOP_CON 19 // U-格式停止应答
#define FORMAT_U_TEST_ACT 20 // U-格式测试
#define FORMAT_U_TEST_CON 21 // U-格式测试应答
2 years ago
// 定时召唤命令及命令名称
#define BUBAN104_TIMER_CMD_NUM 3 // 最大命令数目
#define MAX_SEQUENCE 0x7fff // 最大帧计数
2 years ago
#define MAX_FRAMEMATCHING_SIZE 2 // 帧序匹配最大尺寸
2 years ago
// 规约版本号
#define VER_BUBAN_104 0 // 部颁104
2 years ago
#define VER_IEC870_5_104 1 // IEC104
/////////////////////////////结构定义/////////////////////////////////
2 years ago
typedef struct
{
long CmdTimerCnt;
long CmdTimerConst;
} BUBAN104CMDDEF;
typedef struct tagBUBAN104PORTPARAM
{
BOOL LinkOk; // 主站初始化标志 1:ok; 0:no 初始化时FALSE
BOOL Initdata; // 初始化总召唤标志 TRUE收到总召唤结束帧
// FALSE未收到总召唤结束帧
// 召唤电度标志 TRUE收到召唤结束帧
// FALSE未收到召唤结束帧
WORD wLinkAddr; // 地址域
2 years ago
WORD wSendSequence; // 发送帧计数
WORD wRecvSequence; // 接收帧计数
WORD wAckSequence; // 应答帧计数
BOOL bAckRight; // 应答帧是否同步 (子站端有效)
BOOL bStopComm; // 通讯停止
2 years ago
BOOL bSendFormatI;
BYTE ProvAckOrNot; // 转发是否要求应答
2 years ago
long lTimeOutSendTest;// 超时发送测试帧
long lTimeOutConst; // 超时时间间隔
long lTimeOutCnt; // 超时时间计数
long lYkYtAckTimeConst;// 返校超时时间间隔
long lYkYtAckTime; // 返校超时时间计数
BOOL bCloseSocket; // 关闭socket端口
char YkCmdBuf[32]; // 遥控延迟发送返校缓冲区
long lYkCmdBuflen; // 遥控延迟发送返校缓冲区数据长
2 years ago
long m_lNoDataCnt; // 无数据时间,超过超时时间发送测试帧
2 years ago
short RtuVersion; // 版本号
int m_iPublishYear; // 发布时间(缺省为2000版)
2 years ago
short CurCmdIdx;
short YkMode; // 遥控方式(=0双点遥控=1单点遥控=2直控方式)
2 years ago
// wen 2005.01.15 修改数据信息体起始地址
int iAiBaseAddr; // 遥测起始地址
int iDiBaseAddr; // 遥信起始地址
int iPiBaseAddr; // 遥脉起始地址
int iYkBaseAddr; // 遥控起始地址
2 years ago
BYTE m_au8RecvBuf[300];
int m_iRecvLen;
int m_iFrameSize; // 帧序应答尺寸
2 years ago
BYTE m_bProvAiType; // 转发遥测类型标识
2 years ago
BUBAN104CMDDEF CmdTime[BUBAN104_TIMER_CMD_NUM];
SIO_PARAM_BAOHU_DEF *m_psBaoHu; // 该规约的端口数据指针
2 years ago
} BUBAN104PORTPARAM, *pBUBAN104PORTPARAM;
/////////////////////////以下为通用函数接口///////////////////////////
2 years ago
/*!
\brief
\param commid --
2 years ago
\note
0 -- MaxSerialPortNum + MaxNetPortNum -1\n
2 years ago
*/
void Buban104ReadConfig(int commid); // 初始化处理
2 years ago
/*!
\brief
\param commid --
2 years ago
\note
0 -- MaxSerialPortNum + MaxNetPortNum -1\n
\param buf --
\param len --
2 years ago
*/
void Buban104RecvData(int commid, u_char *buf, int len);// 规约读数据处理
2 years ago
/*!
\brief
\param commid --
2 years ago
\note
0 -- MaxSerialPortNum + MaxNetPortNum -1\n
2 years ago
*/
void Buban104Timer(int commid); // 定时器处理
2 years ago
/*!
\brief
\param commid --
2 years ago
\note
0 -- MaxSerialPortNum + MaxNetPortNum -1\n
\param buf --
\param len --
2 years ago
*/
void Buban104YkYtProcess(int commid, u_char *buf, int len); // 遥控遥调处理
2 years ago
/*!
\brief
\param commid --
2 years ago
\note
0 -- MaxSerialPortNum + MaxNetPortNum -1\n
2 years ago
*/
void Buban104SendSystemTime(int commid); // 系统对时
2 years ago
/*!
\brief 退
\param commid --
2 years ago
\note
0 -- MaxSerialPortNum + MaxNetPortNum -1\n
2 years ago
*/
void Buban104Exit(int commid); // 规约退出
2 years ago
/*!
\brief
\param commid --
\param rtumsg --
2 years ago
\note
0 -- MaxSerialPortNum + MaxNetPortNum -1\n
2 years ago
*/
void Buban104BaoHuCmdProcess(int commid, RTUMSG *rtumsg, BOOL bUpData);
/*!
\brief
\param commid --
\param iProvAddr --
\param ppBaoHuDB --
\retval --
2 years ago
*/
int Buban104GetBaohuDataBase(int commid, int iProvAddr, GROUPDEF **ppBaoHuDB);
/////////////////////////通用函数接口结束///////////////////////////////
2 years ago
/////////////////////////buban104公共函数接口///////////////////////////
//指令缓冲区初始化
2 years ago
void InitBuban104CommandBuffer(int commid);
//关闭socket通讯
2 years ago
void Buban104CloseSocket(u_32 commid);
/////////////////////////buban104公共函数接口结束///////////////////////
2 years ago
/////////////////////////以下为通用函数支持接口/////////////////////////
2 years ago
void Buban104ProvMakeYkYtCommand(int commid, u_char *buf, int len);
/////////////////////////通用函数支持接口结束///////////////////////////
2 years ago
///////////////////////////以下为指令生成函数///////////////////////////
//生成 Buban104 命令?
2 years ago
void MakeBuban104Command(u_32 commid, u_char cmdidx);
//生成遥控遥调指令
2 years ago
void MakeBuBan104YkYtCommand(u_32 commid, u_char *buf, int len);
///////////////////////////指令生成函数结束/////////////////////////////
2 years ago
/////////////////////以下为POLLING规约常规函数接口//////////////////////
2 years ago
void Buban104FindNextCmd(int commid);
void Buban104FindNextProvCmd(int commid);
void Buban104SendCmdFormPollCmdBuf(int commid);
//////////////////////POLLING规约常规函数接口结束///////////////////////
2 years ago
///////////////////////以下为规约处理函数接口///////////////////////////
//======================以下为主站数据处理============================
2 years ago
void Buban104ProcessData(u_32 commid, BUBAN104PORTPARAM *psPortParam, BOOL bProcess);
//处理数据格式I
2 years ago
void Buban104FormatI(RTUMSG *rtumsg);
//处理数据格式U
2 years ago
void Buban104FormatU(RTUMSG *rtumsg);
//Buban104 初始化数据处理
2 years ago
void Buban104InitdataProecss(RTUMSG * rtumsg);
//电度结束帧
2 years ago
void Buban104PidataEnd(RTUMSG * rtumsg);
//设定确认
2 years ago
void Buban104SetAck(RTUMSG *rtumsg);
//Buban104 遥控遥调返校程序
2 years ago
void Buban104YkYtAck(RTUMSG * rtumsg);
//Buban104 对时程序
2 years ago
void Buban104SynTime(RTUMSG * rtumsg);
// 子站主动传送遥信变位帧
2 years ago
void Buban104AutoSendDiProcess(RTUMSG *rtumsg);
void Buban104AiWithPzDataProcess(RTUMSG *, int);
void Buban104AllAiDataProcess(RTUMSG *rtumsg);
void Buban104AllFloatAiDataProcess(RTUMSG *rtumsg);
void Buban104DiDataProcess(RTUMSG *rtumsg, int);
void Buban104SoeDataProcess(RTUMSG *rtumsg, int);
void Buban104PiDataProcess(RTUMSG * rtumsg);
void Buban104PiWithTimeDataProcess(RTUMSG *rtumsg);
//保护数据处理
2 years ago
void Buban104BaoHuDataProcess(RTUMSG *rtumsg);
void Buban104DefaultBaoHuDataProcess(RTUMSG *rtumsg);
// 新增函数,含有 7 BYTE 的时标
2 years ago
void Buban104SoeDataProcessWithCP56Time2a(RTUMSG *rtumsg, int flag);
void Buban104AiWithDataProcessWithM_ME_TD_1(RTUMSG * rtumsg);
void Buban104AiWithDataProcessWithM_ME_TE_1(RTUMSG * rtumsg);
void Buban104AiWithDataProcessWithM_ME_TF_1(RTUMSG * rtumsg);
void Buban104PiWithTimeDataProcessWithM_IT_TB_1(RTUMSG *rtumsg);
//======================以下为子站数据处理============================
2 years ago
void ProvBuban104dataProcess(int commid, RTUMSG *rtumsg);
void ProvBuban104FormatI(int commid, RTUMSG *rtumsg);
void ProvBuban104FormatU(int commid, RTUMSG *rtumsg);
void ProvBuban104FormatS(int commid, RTUMSG *rtumsg);
void ProvBuban104SendAllData(int commid, RTUMSG *rtumsg);
void ProvBuban104SendPIData(int commid, RTUMSG *rtumsg);
void ProvBuban104ProcessTime(int commid, RTUMSG *rtumsg);
//iGroupNo=0为响应总召唤
2 years ago
void ProvBuban104SendPI(int commid, RTUMSG *rtumsg, int iGroupNo);
void ProvBuban104SendAI(int commid, RTUMSG *rtumsg, int iGroupNo);
void ProvBuban104SendDI(int commid, RTUMSG *rtumsg, int iGroupNo);
void ProvBuban104SendSoe(int commid);
void ProvBuban104YkYtData(int commid, RTUMSG *rtumsg);
void MakeProvBuban104YkYtAckMsg(int commid, int pnt, int op, int step);
void ProvBuban104SendClass1(int commid);
void ProvBuban104SendClass2(int commid);
void ProvMakeBuban104Command(int commid, u_char cmdidx);
void ProvBuban104SendAIwithFloat(int commid, RTUMSG *rtumsg, int iGroupNo);
void ProvBuban104SendClass2withFloat(int commid);
/////////////////////////规约处理函数接口结束///////////////////////////
2 years ago
#endif // !defined(_BUBAN104_H_200509141152__INCLUDED_)