123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- #pragma once
- #include <mutex>
- #include <string>
- #include <deque>
- #include <vector>
- 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 <tagCommandStruct> m_SdcCommondvector;
- std::vector <tagCommandTye> 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;
- };
|