#pragma once #include #include #include #include class tagCommandTye { public: int nCommandType; bool IsWaitforACK; int WaitingTime; bool IsResend; bool IsClearSendVector; bool IsFirstSend; bool IsWaitforCP; int WatingCPtime; int NAKTimes; int NCPTimes; bool isClearSamePriority; tagCommandTye() { nCommandType=-1; IsWaitforACK=false; WaitingTime=300; IsResend=true; IsClearSendVector=false; IsFirstSend=false; IsWaitforCP=false; WatingCPtime=1000; NAKTimes=3; NCPTimes=1; isClearSamePriority=false; }; tagCommandTye(bool newIsWaitforACK,int newWaitingTime, bool newIsResend,bool newIsClearSendVector,bool newIsFirstSend, bool newIsWaitforCP,int newWatingCPtime,int newNAKTimes,int newNCPTimes,bool newisClearSamePriority) { nCommandType=-1; IsWaitforACK=newIsWaitforACK; WaitingTime=newWaitingTime; IsResend=newIsResend; IsClearSendVector=newIsClearSendVector; IsFirstSend=newIsFirstSend; IsWaitforCP=newIsWaitforCP; WatingCPtime=newWatingCPtime; NAKTimes=newNAKTimes; NCPTimes=newNCPTimes; isClearSamePriority=newisClearSamePriority; }; }; //通过回调函数调用上层处理函数 typedef void __stdcall SendCommands(const char * pData,unsigned long DataLength,void* lparam); //通过回调函数写日志 enum LOG_V2_LEVEL { LOG_V2_FATAL = 0, // Fatal Error. LOG_V2_ERROR = 1, // Error. LOG_V2_WARNING = 2, // Warning. LOG_V2_INFO = 3 // Information. }; typedef void __stdcall WriteLog(const char* pData, LOG_V2_LEVEL level); class CDeliverModule { struct tagCommandStruct { std::string strCommand; //0 等回复,250ms超时重发3次 //1 不等回复,也不重发 int nCommmandType; }; public: CDeliverModule(WriteLog* logFun = NULL); ~CDeliverModule(void); public://发送线程相关的函数 bool SetLogFun(WriteLog* logFun); bool InitSendModle(SendCommands* pSendData,void* lparam = NULL); void EixtSendModle(); static DWORD SendingCommandsThread(LPVOID pParam); bool StartSendingCommandsThread(CDeliverModule* pCurrentGen); void StopSendingCommandsThread(); bool ProcessCommand(std::string strCommand,int nType = 0); bool ReProcessCommand(tagCommandStruct strCommand); void SendCommand(std::string strcommand, int commandtype); bool WaitforACK(DWORD nWaitingTime); bool ReceiveACK (bool IsACK=true); bool WaitforCP(DWORD nWaitingTime); bool ReceiveCP (bool IsCP=true); void SetPriority(int nCommandType,bool IsWaitforACK=true,int WaitingTime=350,bool IsResend=true, bool IsClearSendVector=false,bool IsFirstSend=false,bool IsWaitforCP=false,int WatingCPtime=3000,bool isClearSamePriority=false); void SetGenErrStatus(bool isGenErr); std::string GetCurrentCommand(); int GetCurrentCommandPriority(); bool GetCurrentErrorState(); void SetAKResendNum(int ResendNum); void SetCPResendNum(int ResendNum); private: int m_nAKResendTotalNum; int m_nCPResendTotalNum; public: tagCommandStruct m_strcurrentcmd; HANDLE m_hSendingThreadToggleEvent; HANDLE m_SendingCommandsThread; int m_nSendingCommandsThreadId; bool m_bSendingCommandsThreadExit; SendCommands* m_pSendData; WriteLog* m_pLogFun; tagCommandStruct m_SDCCommand; std::mutex m_iCriticalSection; std::deque m_SdcCommondvector; std::vector m_CommondType; HANDLE m_hACKEvent; int m_nAKRsubmit; bool m_bisNAK; HANDLE m_hCPEvent; int m_nCPRsubmit; bool m_bisNCP; void *m_ClientControl; bool m_bIsGenErr; };