📄 iec104link.h
字号:
#ifndef _IEC104link_
#define _IEC104link_
//#include <afxsock.h>
/////////////////////////////////////////////////////////////////////////////
// CChanSock command target
//class CPingclientDlg;
#include "DBserver.h"
#include "typedef.h"
#define MAXLINKBUFF 249
#define MAXSOCKLBUFF 4096
#define MAXNUM_K 32
//#define MAX_W 8
#define SOCKDELAY 250
#define CMD_DISCONN 1
#define CMD_USTOP 2
#define CMD_USTART 3
#define SOUR_
#define APP2_
#define INFO3_
class AFX_EXT_CLASS CIEC104link:public CDBserver
{
public:
virtual void On_init_Link_process(){};
HANDLE rxmutex;
_int testtype;
_BYTE testtag;
_BYTE test_once;
_int test_once_len;
_int staNo;
_char curdir[128];
HANDLE dirmutex;
CIEC104link();
~CIEC104link();
char HostAddress[32];
_WORD port;
_int GetSizeofInput_buffer(_int *OneFrameLen,_int *FrameNum);
_int GetSizeofOutput_buffer(_int *OneFrameLen,_int *FrameNum);
//Copy ASDU msg to the Input_buffer
// When exit ,inputbuff_available=0;
// if urgent equ 1 then ACD=1;
bool InAvailable();
bool ApplayerToLink(_BYTE *asbuff,_int aslen);// put msg into input_buffer
bool ApplayerControltoLink(_BYTE cmd);
// _BYTE in_mutex; //0:available 1:unvailable
bool inputbuff_available;//0:unavailable 1:available
virtual void OnTxRemark()=0;
virtual void OnRxRemark()=0;
virtual void OnNoteRemark()=0;
_int GetLinkerTxRemark(_char * disp,_int Maxlen);
_int GetLinkerRxRemark(_char * disp,_int Maxlen);
_int GetLinkerNoteRemark(_char * disp,_int Maxlen);
_char notestr[256];
//The class inherited from this class,
virtual void OnApplayer(_int counts)=0; //
_int LinkToApplayer(_BYTE *asbuff,_int asmaxlen);// get msg from output_buffer , when exit outputbuff_available=0;
bool outputbuff_available;//0:unavailable 1:available
bool connected;
bool started;
bool proc_flag;
_int MAX_K;
_int MAX_W;
_int timer_conn,TIMER_CONN;//30s
_int TIMER_CLOSE;//15s
_int TIMER_SFORMAT;//10s
_int timer_Utest,TIMER_UTEST;//20protected:
// void OnRxOneFrame(_BYTE *rxbuf,_int *rxlen);
bool InitLink();
bool CloseLink();
private:
_int I_confirm_cnt;
bool I_nocontinue;
_int timer_Confirm;
bool timer_Confirmflag;
_WORD Rxcnt;
_WORD Txcnt;
_int timer_U_Start;
bool timer_U_Startflag;
_int timer_U_Stop;
bool timer_U_Stopflag;
_int timer_U_Test;
bool timer_U_Testflag;
static void Ontimer_thread(void *pp);
// void linkprocess();
HANDLE Ontimer_handle;
_int Ontimercnt;
_int Sendtimercnt;
typedef struct Inputstru
{
_int timer_close;
bool timer_flag;
_WORD Txcnt;
_BYTE Input_buffer[MAXLINKBUFF];
_int Inlength;
} Input_Stru;
Input_Stru In_area[MAXNUM_K];
_int In_area_frm_num;
typedef struct Outputstru
{
_BYTE Output_buffer[MAXLINKBUFF];
_int Outlength;
} Output_Stru;
Output_Stru Out_area[MAXNUM_K];
_int Out_area_frm_num;
_BYTE rxbuffer[MAXSOCKLBUFF];
_BYTE txbuffer[MAXSOCKLBUFF];
_int rxlength;
_int txlength;
virtual void OnReceive(int nErrorCode);
virtual void OnClose(int nErrorCode);
virtual void Accept_process();
void Start_process();
void OnTimer();
void SendProcess();
_BYTE rxraw_length;
_BYTE rxraw_buffer[MAXSOCKLBUFF];
_int RxOneBigFrame(_BYTE *rxbuf,_int maxbuflen);
void DecodeOneBigFrame(_BYTE *bigrxbuf,_int *biglength);
void DecodeFrame(_BYTE *rxbuf,_int rxlen);
_int TxOneBigFrame(_BYTE *txbuf,_int txlen);
_int EncodeFrame(_BYTE *txbuf);
//when enter, rxbuff_dealing_flag=1;
//when exit, rxbuff_dealing_flag=0 outputbuff_available=1;
//make output_buffer full of msg
// rxbuffer(msg: linker+ASDU)===>Output_buffer(msg: ASDU)
_int IND_decodeApplayer(_BYTE *rxbuf,_int rxlen);
//when enter
//when exit, inputbuff_available=1;
//make output_buffer full of msg
//Input_buffer(msg: ASDU)===>txbuffer(msg: linker+ ASDU)
_int REQ_encodeApplayer(_BYTE *inputbuf,_int inputlen);//when enter, rxbuff_dealing_flag=1;when exit, rxbuff_dealing_flag=0
bool rxbuff_dealing_flag;// 0:idle 1:busy
void TimerIncrease();
void scan_closeTimeout();
void scan_timer_Sformat();
void scan_timer_U_test();
void Send_I_frame();
void Recv_I_frame(_BYTE *rxbuf,bool * I_nocont);
void Recv_Utestcon_frame();
void Recv_Utest_frame();
void Recv_Ustart_frame();
void Recv_Ustop_frame();
void Recv_S_format(_BYTE *rxbuf);
void Send_U_Startcon();
void Send_Ustopcon_frame();
void Send_S_frame();
void Send_Utest_frame();
void Send_Utestcon_frame();
};
class AFX_EXT_CLASS CIEC104ASDU:public CIEC104link
{
public:
CIEC104ASDU();
~CIEC104ASDU();
virtual void OnApplayer(_int counts);
virtual void OnTxRemark();
virtual void OnRxRemark();
virtual void OnNoteRemark();
virtual void On_RecvMsg(_BYTE *msgbuf,_int len ){};//显示接收报文
virtual void On_SendMsg(_BYTE *msgbuf,_int len){};//显示发送报文
virtual void On_ErrorMsg(char *msgbuf){};
BYTE asdispRxbuf[MAXLINKBUFF*MAXNUM_K];
_BYTE asdispTxbuf[MAXLINKBUFF*MAXNUM_K];
_int asdispRxlen;
_int asdispTxlen;
BYTE asnoteRxbuf[MAXLINKBUFF*MAXNUM_K];
_int asnoteRxlen;
_BYTE asRxbuf[MAXLINKBUFF*MAXNUM_K];
_BYTE asTxbuf[MAXLINKBUFF];
_int asRxlen;
_int asTxlen;
bool I_need;
bool Cmd_need;
_BYTE Cmd_need_code;
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -