LogicDriver.h 5.8 KB

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