LogicDriver.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. #pragma once
  2. // 下列 ifdef 块是创建使从 DLL 导出更简单的
  3. // 宏的标准方法。此 DLL 中的所有文件都是用命令行上定义的 LOGICDRIVER_EXPORTS
  4. // 符号编译的。在使用此 DLL 的
  5. // 任何其他项目上不应定义此符号。这样,源文件中包含此文件的任何其他项目都会将
  6. // LOGICDRIVER_API 函数视为是从 DLL 导入的,而此 DLL 则将用此宏定义的
  7. // 符号视为是被导出的。
  8. #ifndef LOGICDRIVER_EXPORTS
  9. #ifdef _WIN64
  10. #ifdef _DEBUG
  11. #pragma comment(lib, "LogicDriverX64D.lib")
  12. #else
  13. #pragma comment(lib, "LogicDriverX64.lib")
  14. #endif
  15. #else
  16. #ifdef _DEBUG
  17. #pragma comment(lib, "LogicDriverD.lib")
  18. #else
  19. #pragma comment(lib, "LogicDriver.lib")
  20. #endif
  21. #endif
  22. #endif
  23. #include "DPC.h"
  24. #include "LogicDevice.h"
  25. #ifdef LOGICDRIVER_EXPORTS
  26. #define LOGICDRIVER_API __declspec(dllexport)
  27. #define LOGICDRIVER_C_API extern "C" __declspec(dllexport)
  28. #else
  29. #define LOGICDRIVER_API __declspec(dllimport)
  30. #define LOGICDRIVER_C_API extern "C" __declspec(dllimport)
  31. #endif
  32. class SubDeviceDescriptList : public BaseJsonDataObject<bool>
  33. {
  34. public:
  35. vector<string> m_DeviceList;
  36. SubDeviceDescriptList()
  37. {
  38. SetKey("DeviceList");
  39. };
  40. ~SubDeviceDescriptList()
  41. {
  42. };
  43. ResDataObject GetResVal()
  44. {
  45. ResDataObject Sub;
  46. try {
  47. m_ValString = "";
  48. for (size_t i = 0; i < m_DeviceList.size(); i++)
  49. {
  50. Sub.add(m_DeviceList[i].c_str(), "");
  51. }
  52. }
  53. catch (...)
  54. {
  55. Sub.clear();
  56. }
  57. return Sub;
  58. };
  59. void GetResDataObject(ResDataObject &obj)
  60. {
  61. try {
  62. ResDataObject Sub;
  63. for (size_t i = 0; i < m_DeviceList.size(); i++)
  64. {
  65. Sub.add(m_DeviceList[i].c_str(), "");
  66. }
  67. obj.add(GetKey(), Sub);
  68. }
  69. catch (...)
  70. {
  71. }
  72. };
  73. bool SetResDataObject(ResDataObject &obj)
  74. {
  75. bool ret = true;
  76. try {
  77. // mainkey
  78. // subkey1 ""
  79. // subkey2 ""
  80. // subkey3 ""
  81. assert(0);//suppose not using this method
  82. }
  83. catch (...)
  84. {
  85. ret = false;
  86. }
  87. return ret;
  88. };
  89. bool AddDevice(const char *pPath)
  90. {
  91. bool ret = true;
  92. try {
  93. string path = pPath;
  94. for (size_t i = 0; i < m_DeviceList.size(); i++)
  95. {
  96. if (m_DeviceList[i] == path)
  97. {
  98. return false;
  99. }
  100. }
  101. m_DeviceList.push_back(path);
  102. }
  103. catch (...)
  104. {
  105. ret = false;
  106. }
  107. return ret;
  108. };
  109. bool DelDevice(const char *pPath)
  110. {
  111. bool ret = false;
  112. //key is the path
  113. string path = pPath;
  114. vector<string>::iterator iter = m_DeviceList.begin();
  115. while (iter != m_DeviceList.end())
  116. {
  117. if (*iter == path)
  118. {
  119. iter = m_DeviceList.erase(iter);
  120. ret = true;
  121. continue;
  122. }
  123. ++iter;
  124. }
  125. return ret;
  126. };
  127. };
  128. //单个CONNECTION相关的属性
  129. //Title
  130. //type : TCPIP
  131. //port : 1234
  132. //ipaddress : 192.168.2.1
  133. //comment : ......
  134. //Title
  135. //type : COM
  136. //port : COM4
  137. //baudrate : 115200
  138. //bytesize : 8
  139. //parity : 0
  140. //stopbits : 8
  141. //comment : ......
  142. // 此类是从 LogicDriver.dll 导出的
  143. class LOGICDRIVER_API LogicDriver : public DriverDPC,public LogicDevice
  144. {
  145. protected:
  146. ResDataObject m_SerialNo;
  147. //设备属性
  148. //XML文件参数
  149. ResDataObject *m_pConfigFile;//不对外公开,内部对象之间共享
  150. //连接状态
  151. BaseJsonDataObject<bool> *m_pConnectionStatus;
  152. //断线重连Flag,断线重连TimePeriod
  153. BaseJsonDataObject<bool> *m_pReConnectFlag;
  154. BaseJsonDataObject<DWORD> *m_pReConnectTimePeriod;
  155. BaseJsonDataObject<DWORD> *m_pHeartBeatTimePeriod;
  156. DWORD m_ReConnectLastTryTime;
  157. BaseJsonDataObject<DWORD> *m_pSelfTestResult;
  158. //connections
  159. //Example
  160. //Connections
  161. //Seq
  162. //type : TCPIP
  163. //port : 1234
  164. //ipaddress : 192.168.2.1
  165. //comment : Sequance con
  166. //Acq
  167. //type : TCPIP
  168. //port : 1236
  169. //ipaddress : 192.168.2.1
  170. //comment : Used to Acquire Images
  171. ResDataObject *m_pConnections;
  172. //子【逻辑设备】列表
  173. SubDeviceDescriptList *m_pSubDeviceList;
  174. public:
  175. HANDLE m_DisConnectionStatusEvt;
  176. LogicDriver(void);
  177. ~LogicDriver(void);
  178. //内部接口
  179. HANDLE SYSTEM_CALL GetPassiveDisConnectEvtHandle();
  180. void SYSTEM_CALL ReSetPassiveDisConnect(bool DisConnect);
  181. void SYSTEM_CALL GetConfiguration(ResDataObject *pConfig);
  182. bool SYSTEM_CALL AddDevice(const char *pPath);
  183. bool SYSTEM_CALL DelDevice(const char *pPath);
  184. void SYSTEM_CALL GetDeviceList(ResDataObject &Object);
  185. DWORD SYSTEM_CALL GetLastDisconnectTime();
  186. void SYSTEM_CALL SetLastDisconnectTime(DWORD LastTick);
  187. //逻辑设备接口
  188. //get device type
  189. virtual bool SYSTEM_CALL GetDeviceType(GUID &DevType);
  190. //get device resource
  191. virtual RET_STATUS SYSTEM_CALL GetDeviceResource(ResDataObject PARAM_OUT *pDeviceResource);
  192. virtual RET_STATUS DATA_ACTION GetDeviceConfig(ResDataObject PARAM_OUT *pDeviceConfig);
  193. virtual RET_STATUS DATA_ACTION SetDeviceConfig(ResDataObject PARAM_IN *DeviceConfig);
  194. virtual RET_STATUS SYSTEM_CALL GetSEQResource(ResDataObject PARAM_OUT *pDeviceResource);
  195. //ResourceCommand Request In and Response Out
  196. virtual RET_STATUS SYSTEM_CALL Request(ResDataObject PARAM_IN *pRequest, ResDataObject PARAM_OUT *pResponse);
  197. //notify to lower layer
  198. virtual RET_STATUS SYSTEM_CALL CmdToLogicDev(ResDataObject PARAM_IN *pCmd);
  199. //设备行为
  200. //Connect(OEM必须实现)
  201. //DisConnect(OEM必须实现)
  202. RET_STATUS DATA_ACTION SetHeartBeatTimePeriod(DWORD TimePeriod);
  203. RET_STATUS DATA_ACTION SetReConnectOption(bool Flag, DWORD TimePeriod);
  204. RET_STATUS DATA_ACTION GetReConnectOption(bool &Flag, DWORD &TimePeriod);
  205. bool SYSTEM_CALL GetConnectionStatus();
  206. ResDataObject& SYSTEM_CALL GetConnectionParam();
  207. RET_STATUS DATA_ACTION GetHeartBeatTimePeriod(DWORD &TimePeriod);
  208. RET_STATUS DATA_ACTION SetConnectionParam(const char *pTitle, ResDataObject &ConnectionContext);
  209. virtual bool DATA_ACTION Connect();
  210. virtual void DATA_ACTION DisConnect();
  211. virtual RET_STATUS DATA_ACTION SelfTest();
  212. //对象接口
  213. virtual bool SYSTEM_CALL DriverEntry(ResDataObject& PARAM_IN Configuration);
  214. //Driver_Probe(OEM实现)
  215. //SetDriverWorkPath(OEM实现)
  216. //LoadDriver(OEM必须实现)
  217. //UnloadDriver(OEM必须实现)
  218. //Device_Probe(OEM必须实现)
  219. //SetDeviceWorkPath(OEM必须实现)
  220. //LoadLogicDevices(OEM必须实现)
  221. //UnloadLogicDevices(OEM必须实现)
  222. //OnNotify(OEM必须实现)
  223. //CALLIN 时机--------------------
  224. //由驱动线程进行CALL IN.
  225. //Timeperiod 是 ReConnect用的时间
  226. //函数实现内容-------------------
  227. // 计算当前->最后交互时间(R/W) timeperiod
  228. // 获取配置文件中的HeartBeat timeperiod
  229. // 一旦超时,进行一次 Req -> Res 的交互.
  230. // Ex:特定状态下,不允许进行交互,这个由DPC自行判断.
  231. // 一旦确认掉线,设置掉线事件,并返回即可.
  232. virtual bool SYSTEM_CALL OnHeartBeat();
  233. const char* SYSTEM_CALL GetDpcsSerialNo();
  234. void SYSTEM_CALL SetDpcsIdentifyKey(const char *pszSerialkey);
  235. };