SDCDoseDPC.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. // 下列 ifdef 块是创建使从 DLL 导出更简单的
  2. // 宏的标准方法。此 DLL 中的所有文件都是用命令行上定义的 SDCDOSEDPC_EXPORTS
  3. // 符号编译的。在使用此 DLL 的
  4. // 任何其他项目上不应定义此符号。这样,源文件中包含此文件的任何其他项目都会将
  5. // SDCDOSEDPC_API 函数视为是从 DLL 导入的,而此 DLL 则将用此宏定义的
  6. // 符号视为是被导出的。
  7. #pragma once
  8. #ifndef SDCDOSEDPC_EXPORTS
  9. #ifdef _WIN64
  10. #ifdef _DEBUG
  11. #pragma comment(lib, "SDCDoseDPCX64D.lib")
  12. #else
  13. #pragma comment(lib, "SDCDoseDPCX64.lib")
  14. #endif
  15. #else
  16. #ifdef _DEBUG
  17. #pragma comment(lib, "SDCDoseDPCD.lib")
  18. #else
  19. #pragma comment(lib, "SDCDoseDPC.lib")
  20. #endif
  21. #endif
  22. #endif
  23. #define PARAM_IN_TYPE
  24. #ifdef SDCDOSEDPC_EXPORTS
  25. #define GENDPC_API __declspec(dllexport)
  26. #else
  27. #define GENDPC_API __declspec(dllimport)
  28. #endif
  29. #include "LogicDriver.h"
  30. #include "SerialSCF.h"
  31. #include "DoseOemDevice.h"
  32. #include "common_api.h"
  33. #include "SyncGenOEM.h"
  34. #include "diosthread.h"
  35. //#include "afxmt.h"
  36. //extern "C" GENDPC_API DPC* GetDPC();
  37. //extern "C" GENDPC_API void ReleaseDPC(DPC *p);
  38. extern "C" GENDPC_API DriverDPC* GetDriverDPC();
  39. extern "C" GENDPC_API void ReleaseDriverDPC(DriverDPC *p);
  40. // 此类是从 SDCDoseDPC.dll 导出的
  41. class GENDPC_API SDCDoseDPC : public LogicDriver
  42. {
  43. std::string *m_pWorkpath;
  44. public:
  45. SDCDoseDPC(void);
  46. virtual ~SDCDoseDPC(void);
  47. //virtual bool DpcEntry(ResDataObject &Configuration);
  48. //virtual ResDataObject GetConnectionType();
  49. //virtual bool Connect(ResDataObject &Connection);
  50. //virtual bool Probe(ResDataObject &HardwareInfo);
  51. //virtual bool SetWorkPath(const char *pWorkPath);
  52. ////virtual LogicDevice* LoadLogicDevices();
  53. //virtual PVOID LoadLogicDevices();
  54. //virtual void UnloadLogicDevices(/*LogicDevice*/PVOID p);
  55. //virtual bool DisConnect();
  56. //virtual bool OnNotify(HANDLE ExitNotify);
  57. ///////////////////////////////////////////////////////
  58. virtual bool DriverEntry(ResDataObject &Configuration);
  59. virtual bool Driver_Probe(ResDataObject &HardwareInfo);
  60. virtual bool SYSTEM_CALL SetDriverWorkPath(const char * PARAM_IN pWorkPath);
  61. virtual PVOID SYSTEM_CALL LoadDriver();//无根节点
  62. virtual void SYSTEM_CALL UnloadDriver();
  63. //virtual bool OnNotify(HANDLE ExitNotify);
  64. virtual DWORD SYSTEM_CALL OnNotify(HANDLE evtList[], DWORD count);
  65. virtual bool Connect();
  66. virtual void DisConnect();
  67. //给硬件驱动设置Unique工作路径
  68. //如果是同一设备同一连接情况下,硬件多次接入,系统会保证工作路径是一样的.
  69. //连接后,单一硬件相关的数据要保存在此.
  70. virtual bool SYSTEM_CALL SetDeviceWorkPath(const char * PARAM_IN pWorkPath);
  71. //逻辑设备树的加载和卸载
  72. virtual PVOID SYSTEM_CALL LoadLogicDevices();
  73. virtual void SYSTEM_CALL UnloadLogicDevices();
  74. virtual bool SYSTEM_CALL OnHeartBeat();
  75. virtual bool Device_Probe(ResDataObject &HardwareInfo);
  76. /////////////////////////////////
  77. int SendCommand(char* strCommand, int nTimeOut = TIMEOUTVALUE); //对指令名称进行打包封装
  78. //Device Function
  79. bool ProcessCommand(char* strCommand, int nType = 0);
  80. //int SendCommand(string strcommand, bool bWaitACK, DWORD nWaitingTime);
  81. int SendCommand(string strcommand, bool bWaitACK = true, DWORD nWaitingTime = 350);
  82. bool WaitforAK(DWORD nWaitingTime = 500);
  83. bool WaitforRX1(DWORD nWaitingTime = 500);
  84. bool WaitforSA(DWORD nWaitingTime = 3000);
  85. bool WaitforRX0(DWORD nWaitingTime = 500);
  86. bool WaitforCP(DWORD nWaitingTime = 500);
  87. bool WaitforXR1(DWORD nWaitingTime = 40);
  88. bool ReProcessCommand(string strCommand);
  89. UINT SedecalSendingCommandsThread(HANDLE hExitFlag);
  90. void* m_pSendCommandThread;
  91. struct tagCommandStruct
  92. {
  93. string strCommand;
  94. //0, common commmand, not wait for ack command,
  95. //1 commmand, wait for vck command.,
  96. //2 APR command,
  97. //3, FO command
  98. int nCommmandType;
  99. };
  100. CRITICAL_SECTION g_cs;
  101. HANDLE m_hGenACKEvent;
  102. HANDLE m_hGenCPEvent;
  103. HANDLE m_hGenRX0Event;
  104. HANDLE m_hGenSAEvent;
  105. HANDLE m_hGenRX1Event;
  106. HANDLE m_hGenXR1Event;
  107. string m_strCurrentCommand;
  108. bool m_bReceiveRX1;
  109. bool m_bReceiveRX0;
  110. bool m_bReceiveXR1;
  111. bool m_bWaitforXR1;
  112. bool m_bWaitforRX1;
  113. bool m_bWaitforRX0;
  114. bool m_bSendXR1Failed;
  115. bool m_bInExposurePeriod;
  116. bool m_bIsNAK;
  117. bool m_bWaitAK;
  118. bool m_bStatusFlag;
  119. bool m_bResetting;
  120. bool m_bAPRProcessing;
  121. int m_nCurrentRsubmit;
  122. int m_nAKRsubmit;
  123. int m_nTotalRsubmit;
  124. int m_nTimeoutCounter;
  125. vector <tagCommandStruct> m_strCommondvector;
  126. tagCommandStruct m_SDCCommand;
  127. private:
  128. static PACKET_RET callbackPackageProcess(const char * RecData, DWORD nLength, DWORD& PacketLength);
  129. size_t OnCallback(const char * strPackage, size_t nLength);
  130. string LoadErrorContext(const char* strCode);
  131. ResDataObject m_DeviceConfig; //设备属性
  132. HMODULE m_SCFDllFileHandle;
  133. HMODULE m_LoggerDllFileHandle;
  134. Dose_OemDevice *m_pOEM; //Dose OEM
  135. SyncGen_OemDevice *m_pSyncGenOEM; //SynGen
  136. SyncSwitch_OemDevice *m_pSyncSwitchOEM; //SynSwitch
  137. SCF* m_pSCFServer;
  138. typedef SCF* (*GetSCF)();
  139. GetSCF getSCF;
  140. typedef void(*ReleaseSCF)(SCF *p);
  141. ReleaseSCF releaseSCF;
  142. SCFPacket *m_pSendPacket;
  143. SCFPacket *m_pReceivePacket;
  144. DWORD m_wReceiveTime;
  145. };
  146. class SendCommandThread :public Thread_Base
  147. {
  148. public:
  149. SendCommandThread(class SDCDoseDPC *pSDCDoseDPC);
  150. ~SendCommandThread();
  151. protected:
  152. bool Exec(void);
  153. SDCDoseDPC * m_pSDCDoseDPC;
  154. };