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.
300 lines
11 KiB
C
300 lines
11 KiB
C
/************************************************************************************
|
|
*
|
|
* Copyright (C) 2002-2003 SCADA Control Technology Co., Ltd. All rights reserved.
|
|
*
|
|
* $Source: /opt/CVS_ROOT_PGC_EX2000/commserver/windows/widgets/tcphost.h,v $
|
|
*
|
|
* $Author: jehu $
|
|
*
|
|
* $Date: 2006/07/05 07:31:44 $
|
|
*
|
|
* $Revision: 1.1.1.1 $
|
|
*
|
|
* $State: Exp $
|
|
*
|
|
* $Name: $
|
|
*
|
|
* $Locker: $
|
|
*
|
|
* $Log: tcphost.h,v $
|
|
* Revision 1.1.1.1 2006/07/05 07:31:44 jehu
|
|
* no message
|
|
*
|
|
* Revision 1.5 2006/05/26 10:38:03 administrator
|
|
* 增加32位模拟量传送
|
|
*
|
|
* Revision 1.4 2006/04/22 07:49:26 administrator
|
|
* 可以屏蔽网络连接的错误信息,支持端口通讯时不切换主备机及网络连接成功的算法
|
|
*
|
|
* Revision 1.2 2006/01/17 06:14:53 Administrator
|
|
* 增加对时、装置并列运行以及端口号偏移
|
|
*
|
|
* Revision 1.1 2005/10/20 06:20:34 Administrator
|
|
* 新增前置机功能
|
|
*
|
|
* Revision 1.1 2005/10/12 06:03:46 Administrator
|
|
* 增加前置机功能
|
|
*
|
|
*
|
|
**************************************************************************************/
|
|
//***************************************************************
|
|
//* TcpHost.h *
|
|
//* Liangchu Lee 1999.12.20 *
|
|
//***************************************************************
|
|
|
|
#ifndef __TCPHOST_H_ICL__
|
|
#define __TCPHOST_H_ICL__
|
|
|
|
#include "common.h"
|
|
|
|
// 另外一个前置机装置是pc还是ds-3116
|
|
#define FEND_OTHERDEV_DS3116 1
|
|
|
|
#define HOST_CLOSE_NET 1
|
|
#define OVER_TIME_CLOSE_NET 2
|
|
#define FEND_CLOSE_NET 3
|
|
#define ERROR_CLOSE_NET 4
|
|
|
|
#define CHECK_VERSION_FLAG 1
|
|
|
|
// 运行方式是主备方式
|
|
#define RUN_MODE_STANDBY 0
|
|
// 并列方式,同时运行
|
|
#define RUN_MODE_ALLHOT 1
|
|
|
|
//**************** 端口数据类型 ************************
|
|
#define iCOMM_DATA 0x10 // RTU数据包类型
|
|
|
|
//************ 前置机 --> 主机 数据类型 ****************
|
|
#define iREQUESTHOSTSTATUS 0x14 // 请求主机状态
|
|
#define iTIMEINFORM 0x2c // 前置机对时
|
|
#define iAIDATA 0x31 // 变化遥测
|
|
#define iDIDATA 0x32 // 变化遥信
|
|
#define iPIDATA 0x33 // 变化电度
|
|
#define iSOEDATA 0x34 // SOE 数据
|
|
#define iACKDATA 0x35 // 遥控遥调返校
|
|
|
|
#define WUXI_ZHUANFA_AI_TO_HOST 0x36
|
|
#define WUXI_ZHUANFA_DI_TO_HOST iDIALLDATA
|
|
#define WUXI_ZHUANFA_PI_TO_HOST 0x37
|
|
|
|
#define iODDATA 0x38 // 离线遥信数据
|
|
#define iODALLDATA 0x39 // 离线遥信全数据
|
|
#define iWUFANGYKYTREQ 0x3d // 五防遥控遥调请求
|
|
|
|
#define iAIALLDATA 0x40 // 遥测全数据
|
|
#define iDIALLDATA 0x41 // 遥信全数据
|
|
#define iPIALLDATA 0x42 // 电度全数据
|
|
// wen 2006.05.20 32bit传送模拟量数据
|
|
#define PGC3_AI32DATA 0x45 // 变化32位遥测数据
|
|
#define PGC3_AI32ALLDATA 0x46 // 遥测32位全数据
|
|
|
|
#define iBYPASSDATA 0x50 // 直通数据
|
|
|
|
#define iODPOINT 0x81 // 读离线量点数据
|
|
#define iANPOINT 0x82 // 读模拟量点数据
|
|
#define iDIPOINT 0x83 // 读数字量点数据
|
|
#define iLINESTATUS 0x84 // 端口线路状态
|
|
#define iNETTESTMSG 0xf0 // 网络状态包
|
|
#define iNETNAMEPLATE 0xef // 网络标示包
|
|
|
|
//************ 主机 --> 前置机 数据类型 ****************
|
|
#define hHOSTSTATUS 0x15 // 主机状态
|
|
#define NET_PROFILE_UPDATE 0x1B // 主机下发更改数据库指令
|
|
#define hTIMEINFORM 0x2c // 主机对时
|
|
#define hYKYTCMD 0x35 // 遥控遥调命令
|
|
#define hBYPASSCMD 0x50 // 直通数据
|
|
#define hMAPANDATA 0x82 // 模拟量点数据
|
|
#define hMAPDIDATA 0x83 // 数字量点数据
|
|
#define hDATA_OUTPUT_CTRL 0x85 // 数据输出控制
|
|
#define hRELOADDATABASE 0x86 // 重新装入数据库
|
|
#define hNETTESTMSG 0xf0 // 网络状态包
|
|
#define hMAPALLOP 0xf4 // 模拟盘全盘操作
|
|
|
|
|
|
//*********************数据缓冲区************************
|
|
#define AIMSGNO 0
|
|
#define DIMSGNO 1
|
|
#define SOEMSGNO 2
|
|
#define YKYTACKNO 3
|
|
#define ODMSGNO 4
|
|
#define PIMSGNO 5
|
|
#define RTUCHANGMSGNUM 6
|
|
|
|
//******************************************************
|
|
|
|
typedef struct tagTCP_SEND_DATA_BUF
|
|
{
|
|
int MsgLen __attribute__ ((packed));
|
|
BYTE MsgData[MAX_NET_BUF] __attribute__ ((packed));
|
|
} TCP_SEND_DATA_BUF;
|
|
|
|
typedef struct tagTCP_RCV_DATA_BUF
|
|
{
|
|
int MsgCnt __attribute__ ((packed));// 信息内容计数
|
|
int Front __attribute__ ((packed));// 信息取数指针
|
|
int Rear __attribute__ ((packed));// 信息存入指针
|
|
BYTE MsgData[MAX_NET_BUF] __attribute__ ((packed));// 信息数据
|
|
} TCP_RCV_DATA_BUF;
|
|
|
|
typedef struct tagFEND_DEF
|
|
{
|
|
char Name[MAX_MACHINE_NAME_LEN] __attribute__ ((packed));
|
|
int FendIdx __attribute__ ((packed));
|
|
int LinkFlag __attribute__ ((packed));
|
|
int EnableLink __attribute__ ((packed));
|
|
char SetTcpIpAddr[MAX_FEND*MAX_ADDR][TCPIP_ADDR_LEN] __attribute__ ((packed));
|
|
char TcpIpAddr[MAX_ADDR][TCPIP_ADDR_LEN] __attribute__ ((packed));
|
|
u_long HostIpAddr[MAX_ADDR] __attribute__ ((packed));
|
|
u_long AllIpAddr[MAX_ADDR] __attribute__ ((packed));
|
|
u_long BroadCastAddr[MAX_ADDR] __attribute__ ((packed));
|
|
int LinkStatus[MAX_FEND] __attribute__ ((packed));
|
|
int LinkCnt[MAX_FEND] __attribute__ ((packed));
|
|
|
|
int FendExistFlag[MAX_FEND] __attribute__ ((packed));
|
|
int FendExistCnt[MAX_FEND] __attribute__ ((packed));
|
|
|
|
int SendTxdDataFlag[MAX_FEND] __attribute__ ((packed));
|
|
|
|
// wen 2006.01.14 增加装置的起始厂站号的偏移
|
|
int iPortOffset __attribute__ ((packed));
|
|
int iRunMode __attribute__ ((packed));
|
|
|
|
// wen 2006.04.22 主备切换时,判断的端口通讯状态屏蔽字(按位屏蔽)
|
|
int iPortMask __attribute__ ((packed));
|
|
|
|
// wen 2006.05.20 32bit传送模拟量数据
|
|
int iSendAiof32Bit __attribute__ ((packed));
|
|
} FEND_DEF;
|
|
|
|
typedef struct tagTCP_LINK_DEF
|
|
{
|
|
u_char InitFlag __attribute__ ((packed));// 初始化标志
|
|
u_char InitOk __attribute__ ((packed));// 初始化成功标志
|
|
long InitLinkCnt __attribute__ ((packed));// 初始化计数
|
|
|
|
char ExistFlag __attribute__ ((packed));// 存在标志
|
|
u_char CommFlag __attribute__ ((packed));// 通讯标志
|
|
u_char Status __attribute__ ((packed));// 工作状态
|
|
long StatusCnt __attribute__ ((packed));// 状态计数
|
|
SOCKET SocketId __attribute__ ((packed));// 连接号
|
|
|
|
u_char LinkType __attribute__ ((packed));// 连接类型
|
|
|
|
char CurLinkIdx __attribute__ ((packed));
|
|
u_char TcpIpAddr[MAX_ADDR][TCPIP_ADDR_LEN] __attribute__ ((packed));// Tcp/Ip 地址
|
|
|
|
u_char VersionFalgByte __attribute__ ((packed));// 服务器版本号标志
|
|
int RevHostStatusMsg __attribute__ ((packed));// 接收主机广播信息
|
|
|
|
char NetNameplateFalg __attribute__ ((packed));
|
|
|
|
int iNoWriteNum __attribute__ ((packed));
|
|
} TCP_LINK_DEF;
|
|
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
// 兼容老系统的RTUMSG结构
|
|
typedef struct tagORTUMSGHEAD
|
|
{
|
|
u_char MsgType __attribute__ ((packed));// 信息类型
|
|
u_char PortNumber __attribute__ ((packed));// 信息端口号
|
|
short MsgLen __attribute__ ((packed));// 信息长度
|
|
} ORTUMSGHEAD;
|
|
|
|
typedef struct tagORTUMSG
|
|
{
|
|
u_char MsgType __attribute__ ((packed));// 信息类型
|
|
u_char PortNumber __attribute__ ((packed));// 信息端口号
|
|
short MsgLen __attribute__ ((packed));// 信息长度
|
|
u_char MsgData[MAX_RTU_MSG_SIZE] __attribute__ ((packed));// 信息数据
|
|
} ORTUMSG;
|
|
|
|
typedef struct tagHOSTMSGHEAD
|
|
{
|
|
WORD MsgType __attribute__ ((packed));// 信息类型
|
|
WORD PortNumber __attribute__ ((packed));// 信息端口号
|
|
WORD MsgLen __attribute__ ((packed));// 信息长度
|
|
WORD EMsgLen __attribute__ ((packed));// 扩展信息长度
|
|
} HOSTMSGHEAD;
|
|
|
|
typedef struct tagHOSTMSG
|
|
{
|
|
WORD MsgType __attribute__ ((packed));// 信息类型
|
|
WORD PortNumber __attribute__ ((packed));// 信息端口号
|
|
WORD MsgLen __attribute__ ((packed));// 信息长度
|
|
WORD EMsgLen __attribute__ ((packed));// 扩展信息长度
|
|
u_char MsgData[MAX_RTU_MSG_SIZE] __attribute__ ((packed));// 信息数据
|
|
} HOSTMSG;
|
|
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
BOOL GetConfigName(char *szFileName, int iFileNameLen, int IsPortConfig);
|
|
BOOL IsWouldBlock();
|
|
BOOL IsWouldBlockEx(int neterrno);
|
|
int GetNetErrorNo();
|
|
void CloseNetSocket(SOCKET sock);
|
|
void ULongToIPString(char *ipstr, u_long ipulong);
|
|
|
|
void InitSetTcpIpAddr(void);
|
|
|
|
void SendNetNameplateMsgToHost(int flag);
|
|
BOOL InitFendMsg(void);
|
|
BOOL InitHostWSAStartup(void);
|
|
void FindCurrentFend(void);
|
|
void LinkOneHost(int hostid);
|
|
void HostConnect(SOCKET socket, WORD error);
|
|
void LinkToHost(void);
|
|
void CloseHostSocket(SOCKET socket, int flag);
|
|
void CloseHost(void);
|
|
BOOL ReadHost(int hostid);
|
|
int GetHostMsgFormHostRevBuf(HOSTMSG *hostmsg, int hostid);
|
|
BOOL ReadDataFormHost(SOCKET socket);
|
|
int SendDataToHostSendBuf(int hostid, u_char *buf, int len, BOOL bInsert);
|
|
void SendDataToAllHostSendBuf(u_char *buf, int len);
|
|
void SendHostSendBufToHost(void);
|
|
void ClearSendBuffer(int hostid);
|
|
void ClearRecvBuffer(int hostid);
|
|
|
|
// 服务器数据处理及发送
|
|
void HostDataProceWithSignalYkYt(HOSTMSG *hmsg);
|
|
void HostDataProce(HOSTMSG *hostmsg);
|
|
void SendRtuChangeDataToHost(void);
|
|
void SendPortStatisticsToHost(void);
|
|
void SendPortStatusToHost(int flag);
|
|
void SendPortAllDataToHost(void);
|
|
void SetSoeData(int commidex, SOE_DEF *pSoeData);
|
|
void SetYkYtAckData(int portno, char *buf);
|
|
|
|
void SelectHostSocketEvent(void);
|
|
void SelectHostSocketEventEx(void);
|
|
void TcpHostTimer(void);
|
|
|
|
// 服务器模拟盘数据处理
|
|
void MapAnPointToHost(int iMapOutPort, int iMapSavePort);
|
|
void MapDiPointToHost(int iMapOutPort, int iMapSavePort);
|
|
void FormHostMapDataProce(int iMapOutPort, int iMapSavePort, HOSTMSG *msg);
|
|
|
|
// 获取前置机的下发标识
|
|
int GetFendTxdFlag(void);
|
|
|
|
// 判断网络地址是否是前置机地址
|
|
int CheckIsFendIpAddr(u_long addr);
|
|
|
|
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
// 前置机功能函数
|
|
void WriteChangeData(int commidex, int point, void *pntmsg, BYTE type);
|
|
BOOL IsSendDatatoPort(int port);
|
|
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
// 获取全局变量
|
|
TCP_LINK_DEF *GetHostLinkPtr();
|
|
FEND_DEF *GetFendMsgPtr();
|
|
HOSTMSG *GetRtuChangeMsgPtr();
|
|
|
|
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
// 增加字节顺序转换函数
|
|
BOOL AllDataHostToRtuByteSequence(HOSTMSG *hmsg, ORTUMSG *pSendMsg);
|
|
BOOL AllDataRtuToHostByteSequence(HOSTMSG *hmsg);
|
|
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
void SendSystemTimeToHost(void);
|
|
#endif
|