📄 nsclass.h
字号:
// LnkLayer DLL implementation module
// NSClass.h :
//
// This is a part of the Nice Information's source code.
// Copyright (C) 1994 Nice Information Corporation
// All rights reserved.
//
// Complier: Microsoft Visual C++ 5.00, MFC 4.2
//
// create : Doo, 1998.12.28
//
#ifndef NSCLASS_INC
#define NSCLASS_INC
#include <afxtempl.h>
#include <winsock.h>
#include "datafile.h"
#include "sockapi.h"
// ASDU size
#define ASDU_5_SIZE 19
#define ASDU_6_SIZE 13
#define ASDU_7_SIZE 7
#define ASDU_10_SIZE 15
#define ASDU_20_SIZE 8
#define ASDU_21_SIZE 11
#define ASDU_24_SIZE 11
#define ASDU_25_SIZE 11
#define ASDU_26_SIZE 21
#define ASDU_27_SIZE 23
#define ASDU_28_SIZE 10
#define ASDU_31_SIZE 11
#define ASDU_64_SIZE 8
// ASDU struct
#define ASDUHEAD_TYP 0
#define ASDUHEAD_VSQ 1
#define ASDUHEAD_COT 2
#define ASDUHEAD_ADR 3
#define ASDUHEAD_FUN 4
#define ASDUHEAD_INF 5
#define ASDUHEAD_DAT 6
// ASDU type
#define ASDU_1 1
#define ASDU_2 2
#define ASDU_3 3
#define ASDU_4 4
#define ASDU_5 5
#define ASDU_6 6
#define ASDU_7 7
#define ASDU_8 8
#define ASDU_9 9
#define ASDU_10 10
#define ASDU_20 20
#define ASDU_21 21
#define ASDU_23 23
#define ASDU_24 24
#define ASDU_25 25
#define ASDU_26 26
#define ASDU_27 27
#define ASDU_28 28
#define ASDU_29 29
#define ASDU_30 30
#define ASDU_31 31
#define ASDU_40 40
#define ASDU_41 41
#define ASDU_42 42
#define ASDU_43 43
#define ASDU_44 44
#define ASDU_45 45
#define ASDU_46 46
#define ASDU_47 47
#define ASDU_64 64
// COT
#define COT_AUTO 1
#define COT_LOOP 2
#define COT_FCB 3
#define COT_CU 4
#define COT_START 5
#define COT_POWER 6
#define COT_TEST 7
#define COT_TIME 8
#define COT_GI 9
#define COT_GIEND 10
#define COT_LOCAL 11
#define COT_REMOT 12
#define COT_COMMAND 20
#define COT_ACK 20
#define COT_NAK 21
#define COT_EVTDAT 31
#define COT_GW 40
#define COT_ACKYGW 40
#define COT_ACKNGW 41
#define COT_GR 42
#define COT_ACKYGR 42
#define COT_ACKNGR 43
#define COT_ACKGW 44
// ASDU inf
#define ASDUINF_RSTFCB 2
#define ASDUINF_RSTCU 3
#define ASDUINF_START 4
#define ASDUINF_POWERON 5
#define ASDUINF_RELAY 180
#define ASDUINF_STEP 190
#define ASDUINF_SYS_B 0
#define ASDUINF_SYS_E 15
#define ASDUINF_STA_B 16
#define ASDUINF_STA_E 31
#define ASDUINF_MON_B 32
#define ASDUINF_MON_E 47
#define ASDUINF_ACC_B 48
#define ASDUINF_ACC_E 143
#define ASDUINF_ANA_B 144
#define ASDUINF_ANA_E 159
#define ASDUINF_ACKW 249
#define ASDUINF_EXCW 250
#define ASDUINF_CANW 251
// length const
#define GIN_LEN 2
#define KOD_LEN 1
#define GDD_LEN 3
// group type
#define GRP_SYS1 0x00 //系统类(所有保护及自动装置的系统参数及功能、定值区切换)
#define GRP_SYS2 0x01 //系统类
#define GRP_VAL1 0x02 //定值类
#define GRP_VAL2 0x03 //定值类
#define GRP_EVT1 0x04 //事件类(动作及状态事件)
#define GRP_EVT2 0x05 //事件类(如告警事件)
#define GRP_ANA1 0x06 //遥测类(保护测量值)
#define GRP_ANA2 0x07 //遥测类(如电流、电压、功率、频率、水位、温度等)
#define GRP_DGT1 0x08 //遥信类(如刀闸、开关、信号、状态等)
#define GRP_DGT2 0x09 //遥信类
#define GRP_PUL 0x0A //电量类
#define GRP_RLY 0x0B //遥控开关类(跳/合)
#define GRP_FJT 0x0C //遥控分头类(升/降)
#define GRP_SPT 0x0D //遥调类(DA输出)
#define GRP_RYB 0x0E //遥控压板类(保护功能投/退)
#define GRP_DBG 0x0F //调试及操作信息类(用于装置的调试及操作记录)
#define GRP_CHL 0x10 //录波通道
#define GRP_STA 0x11 //录波状态量
#define GRP_SEL 0x12 //小电流选线
#define GRP_SOE 0x18 //SOE
#define SYS_INF_CURAREA 0x02
#define SYS_INF_RUNAREA 0x03
#define SYS_INF_PULSEFZ 0x05
#define SYS_INF_SIGRST 0x06
// KOD type
#define KOD_NONE 0
#define KOD_VALUE 1
#define KOD_DEFAULT 2
#define KOD_RANGE 3
#define KOD_RES4 4
#define KOD_PRECISION 5
#define KOD_FACTOR 6
#define KOD_REFRENCE 7
#define KOD_ENUMERATION 8
#define KOD_DIMENSION 9
#define KOD_DESCRIPTION 10
#define KOD_RES11 11
#define KOD_PASSWORD 12
#define KOD_READONLY 13
#define KOD_WRITEONLY 14
// GDD type
#define GDD_NONE 0
#define GDD_ASCII 1
#define GDD_BYTE 2
#define GDD_UINT 3
#define GDD_INT 4
#define GDD_UFLOAT 5
#define GDD_FLOAT 6
#define GDD_REAL 7
#define GDD_DOUBLE 8
#define GDD_2BITS 9
#define GDD_1BIT 10
#define GDD_VAL_Q 12
#define GDD_TIMELABEL 18
#define GDD_RELTIMELABEL 19
// DPI value
#define DPI_OFF 0x01
#define DPI_ON 0x02
#define MAX_PROTEVENT 32
// state value
typedef enum
{
STATE_NONE,
STATE_VERSION,
STATE_TIMESYNC,
STATE_GI,
STATE_ACCIDENTINF,
STATE_EVENTINF,
STATE_CHANNELINF,
STATE_STATEINF,
STATE_RESET,
STATE_FREEZEPULSE,
STATE_CALLPULSE,
STATE_FREEPULSE,
STATE_WRITEPULSE,
STATE_REQUESTPROTANA,
STATE_RELAY,
STATE_REQUESTYB,
STATE_CHANGEYB,
STATE_ACKCHANGEYB,
STATE_CANCELCHANGEYB,
STATE_REQUESTAREA,
STATE_CHANGEAREA,
STATE_ACKCHANGEAREA,
STATE_CANCELCHANGEAREA,
STATE_REQUESTVAL,
STATE_CHANGEVAL,
STATE_ACKCHANGEVAL,
STATE_CANCELCHANGEVAL,
STATE_REQUESTACC,
} APPSTATE;
// info-struct for multi common addr. in same IP
//
typedef struct _tagLogicAddr
{
BYTE m_btAddrLgc; // comman address of the equipment
char m_szName[STNAMELEN]; // name in database
BYTE m_btType; // device type : type number in template
WORD m_wRtu; // order of the equipment in rdb : RTUNO
WORD m_wNo; // order of the equipment in rdb : STNO
} LOGICADDR;
/////////////////////////////////////////////////////////////////////////////
// CProtectValue
#define VALUETYPE_STRING 1
#define VALUETYPE_FLOAT 2
class CProtectValue : public CObject
{
// Construction
public:
CProtectValue();
~CProtectValue();
public:
BYTE m_btCode;
BYTE m_btDataType;
int m_nValueType;
float m_fValue;
CString m_szValue;
};
class CChannel;
/////////////////////////////////////////////////////////////////////////////
// CEquipment
class CEquipment : public CObject
{
public:
CEquipment();
~CEquipment();
public:
CString m_szDeviceName;
// socket channel
CChannel* m_pChannel;
LOGICADDR m_LogicAddr;
BYTE m_btScn;
// asdu inf.
BYTE m_btInf;
BYTE m_btCot;
// relay command
WORD m_wRelayRtu;
WORD m_wRelayIndex;
BYTE m_btRelayValue;
// protect command
WORD m_wProtectRtu;
BYTE m_btProtectKOD;
HWND m_hProtectWnd;
BYTE m_btStep, m_btChannel;
WORD m_wOrder;
// time counter for task
UINT m_uTaskTimeCounter;
// time counter for pulse
UINT m_uPulseTimeout, m_uPulseTimeCounter;
// version info.
char m_szInfo[9];
BYTE m_btInfo[4];
CList<CProtectValue*, CProtectValue*> m_ListAccidentInf;
CList<CProtectValue*, CProtectValue*> m_ListEventInf;
CList<CProtectValue*, CProtectValue*> m_ListChannelInf;
CList<CProtectValue*, CProtectValue*> m_ListStateInf;
CPtrList m_ListUnprocess;
CList<CProtectValue*, CProtectValue*> m_ListValue;
BYTE* m_pValue;
int m_nLength;
BYTE m_btValue;
public:
APPSTATE m_nState;
BOOL m_bComm;
BOOL m_bAnswer;
UINT m_uNoAnswer;
// 2000.12.19 doo, for comm-state digital
WORD m_wCommRtu, m_wCommIndex;
protected:
BOOL IsCommFree();
void OnNoAnswer( BOOL bNoAnswer );
void OnCommError();
void OnCommOK();
void ClearList();
CString GetEvtExplain( BYTE btType, BYTE btCode );
void ProcessProtEvt( PROTEVENT* pProtEvent );
void CheckUnprocess();
void ProcessTime( PROTEVENT& ProtEvent, BYTE* pData );
void ProcessRelativeTime( PROTEVENT& ProtEvent, BYTE* pData );
short ProcessMEA( BYTE* pData );
int ProcessSend();
// process asdu10 sets
void EndProcess();
void ProcessSysSet( BYTE* pData );
void ProcessValSet( BYTE* pData, BYTE btLen );
void ProcessAnaSet( BYTE* pData );
void ProcessDgtSet( BYTE* pData );
void ProcessPulSet( BYTE* pData );
void ProcessEvtSet( BYTE btType, BYTE* pData, int nLength );
void ProcessRlySet( BYTE btInf, BYTE* pData );
void ProcessSOESet( BYTE* pData );
void ProcessInfSet( BYTE btType, BYTE* pData, int nLength );
void OnAsdu10( BYTE* pData );
void OnAsdu5( BYTE* pData );
void OnAsdu23( BYTE* pData );
void OnAsdu26( BYTE* pData );
void OnAsdu27( BYTE* pData );
void OnAsdu28( BYTE* pData );
void OnAsdu29( BYTE* pData );
void OnAsdu30( BYTE* pData );
void OnAsdu31( BYTE* pData );
int GetAsdu10Length( BYTE* pData, int nLength );
public:
static void GetSyncTime( BYTE* pData );
BOOL IsLogicDevice( WORD wRtu ) { return m_LogicAddr.m_wRtu == wRtu; };
BYTE GetLogicAddr() { return m_LogicAddr.m_btAddrLgc; };
void Startup();
void ProcessClose();
void ProcessReceive( BYTE* pData, int nLength );
// accident & event inf
int LoadAccidentInf();
int LoadEventInf();
// channel & state inf. in trend data
int LoadChannelInf();
int LoadStateInf();
// pulse
int FreezePulse();
int CallPulse();
int FreePulse();
int WritePulse( WORD wIndex, BYTE* pValue, BYTE btType );
// relay
int RelaySelect( WORD wRtu, BYTE btType, WORD wIndex, BYTE btValue );
int RelayRun( WORD wRtu, BYTE btType, WORD wIndex, BYTE btValue );
int RelayCancel( WORD wRtu, BYTE btType, WORD wIndex, BYTE btValue );
int RequestVal( WORD wRtu, HWND hWnd, BYTE btKOD );
int ChangeVal( WORD wRtu, HWND hWnd, BYTE* pValue, APPSTATE appState );
int RequestYb( WORD wRtu, HWND hWnd, BYTE btKOD );
int ChangeYb( WORD wRtu, HWND hWnd, BYTE* pValue, APPSTATE appState );
int RequestArea( WORD wRtu, HWND hWnd, BYTE btType );
int ChangeArea( WORD wRtu, HWND hWnd, BYTE btType, BYTE btArea, APPSTATE appState );
int RequestProtAna( WORD wRtu, HWND hWnd, BYTE btKOD );
int RequestRst( WORD wRtu, HWND hWnd );
int RequestAcc( WORD wRtu, HWND hWnd, BYTE btStep, WORD wOrder, BYTE btChannel );
int Version();
int TimeSync();
int GI();
void OnTimer();
};
/////////////////////////////////////////////////////////////////////////////
// CChannel
class CChannel : public CObject
{
public:
CChannel();
~CChannel();
public:
// ip addr.
CString m_szIP;
// socket to device
SOCKET m_socket;
CList<CEquipment*, CEquipment*> m_ListEquipment;
protected:
CEquipment* GetEquipment( BYTE btLogicAddr );
int GetAsdu10Length( BYTE* pData, int nLength );
int GetAsdu23Length( BYTE* pData, int nLength );
int GetAsdu29Length( BYTE* pData, int nLength );
int GetAsdu30Length( BYTE* pData, int nLength );
public:
CString GetIP() { return m_szIP; };
void SetIP( CString szIP ) { m_szIP = szIP; };
SOCKET GetSocket() { return m_socket; };
void SetSocket( SOCKET Socket ) { m_socket = Socket; };
CEquipment* AddEquipment( BYTE btLogicAddr );
void AddEquipment( CEquipment* pEquipment );
public:
BOOL IsCommOK() { return INVALID_SOCKET != m_socket; };
void Startup();
void ProcessClose();
BOOL ProcessSend( char* pData, int nLength );
BOOL ProcessReceive();
};
#endif //NSCLASS_INC
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -