📄 iec104link.h
字号:
#ifndef _IEC104link_
#define _IEC104link_
#include <winsock2.h>
/////////////////////////////////////////////////////////////////////////////
// CChanSock command target
//class CPingclientDlg;
class AFX_EXT_CLASS CBasechSocket
{
public:
void Close();
int Receive(char *buff,int bufflen);
int Send(char *buff,int len);
bool Create(UINT Serport);
bool Accept();
void thread_process();
CBasechSocket();
~CBasechSocket();
BOOL Connect( LPCTSTR lpszHostAddress, UINT nHostPort );
BOOL ShutDown( int nHow = 1 );
virtual void OnAccept(int nErrorCode);
virtual void OnReceive(int nErrorCode);
virtual void OnClose(int nErrorCode);
HANDLE thread_handle;
DWORD ThreadID;
static void thread(void *pp);
SOCKET sock,newsock;
int length;
struct sockaddr_in SockAddr;
struct sockaddr tcpaddr;
char buf[1024];
int rval,len;
char cli_name[64];
char cli_ip[32];
bool bConn;
};
#include "typedef.h"
#define MAXLINKBUFF 249
#define MAXSOCKLBUFF 4096
#define MAXNUM_K 32
//#define MAX_W 8
#define SOCKDELAY 250
#define CMD_CONN 0
#define CMD_DISCONN 1
#define CMD_USTOP 2
#define CMD_USTART 3
#define SOUR_
#define APP2_
#define INFO3_
class AFX_EXT_CLASS CIEC104link:public CBasechSocket
{
public:
_int MAX_K;
_int MAX_W;
HANDLE rxmutex;
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 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 On_init_Link_process(){};
virtual void On_init_Sock_process(){};
virtual void OnTxRemark()=0;
virtual void OnRxRemark()=0;
virtual void OnNoteRemark()=0;
_int rxraw_length;
_int rxraw_buffer[MAXSOCKLBUFF];
_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 timer_conn,TIMER_CONN;//30s
_int TIMER_CLOSE;//15s
_int TIMER_SFORMAT;//10s
_int timer_Utest,TIMER_UTEST;//20
HANDLE Ontimer_handle;
_int Ontimercnt;
protected:
// 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();
_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*2];
_BYTE txbuffer[MAXSOCKLBUFF];
_int rxlength;
_int txlength;
virtual void OnReceive(int nErrorCode);
virtual void OnClose(int nErrorCode);
void Start_process();
void OnTimer();
void SendProcess();
_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_Ustartcon_frame();
void Recv_Ustopcon_frame();
void Recv_S_format(_BYTE *rxbuf);
void Send_U_Start();
void Send_Ustop_frame();
void Send_S_frame();
void Send_Utest_frame();
void Send_Utestcon_frame();
};
class AFX_EXT_CLASS CIEC104ASDU:public CIEC104link
{
public:
void InitInstance();
bool has_been_registered;
WORD limit_rtunum;
WORD limit_days;
char m_hardno[128];
bool ReadRegisterKey();
CIEC104ASDU();
~CIEC104ASDU();
virtual void On_Recv_ASDU_Msg(BYTE *recvbuf,int len ){};//显示接收报文
virtual void On_SendMsg(BYTE *msgbuf,int len){};
virtual void On_RecvMsg(BYTE *msgbuf,int len){};
virtual void On_ErrorMsg(char *msgbuf){};
virtual void OnApplayer(_int counts);
virtual void OnTxRemark();
virtual void OnRxRemark();
virtual void OnNoteRemark();
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 + -