ECSDKToolKit.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. #ifndef ECSDKTOOLKIT_H
  2. #define ECSDKTOOLKIT_H
  3. #include "ECSDKTypes.h"
  4. namespace ECSDKFrameWork {
  5. /**
  6. * @brief The ExtrasManageListener class
  7. */
  8. class EC_DLL_EXPORT IECToolKitListener
  9. {
  10. public:
  11. /**
  12. * @brief ~ExtrasManageListener
  13. */
  14. virtual ~IECToolKitListener();
  15. /**
  16. * @brief onQueryTime
  17. *
  18. * @param gmtTime GMT(UTC) time in milliseconds.
  19. *
  20. * @param localTime Local time in milliseconds.
  21. *
  22. * @param timeZone Time zone, etc. "Asia/Shanghai".
  23. *
  24. * @param dateTime: "27.07.2022 9:45:06.120", ÊÖ»úµ±Ç°ÈÕÆÚʱ¼ä¡£format£ºdd.MM.yyy hh:mm:ss.zzz
  25. *
  26. */
  27. virtual void onQueryTime(uint64_t gmtTime, uint64_t localTime, const string& timeZone, const string& dateTime) {};
  28. /**
  29. * @brief onQueryGPS
  30. *
  31. * @param status Whether GPS information is valid, true means valid.
  32. *
  33. * @param longitude GPS longitude.
  34. *
  35. * @param latitude GPS latitude.
  36. */
  37. virtual void onQueryGPS(bool status, const ECGPSInfo& info) {};
  38. /**
  39. * @brief Called when bulk data is received(RESERVED).
  40. *
  41. * @param data Buffer of bulk data.
  42. *
  43. * @param length Buffer length.
  44. *
  45. * @note THIS IS A RESERVED METHOD. PLEASE IGNORE IT NOW.
  46. */
  47. virtual void onBulkDataReceived(const void *data, uint32_t length) {};
  48. /**
  49. * @brief Called when forwardToPhone result.
  50. *
  51. * @param forwardInfo the forward result.
  52. *
  53. */
  54. virtual void onForwardToPhone(const ECForwardInfo& forwardInfo) {};
  55. /**
  56. * @brief Called when GenerateQRCodeUrl result.
  57. *
  58. * @param url The url string.
  59. *
  60. */
  61. virtual void onGenerateQRCodeUrl(const string& url, const uint8_t* data, const uint32_t dataLen) {};
  62. };
  63. /**
  64. * @class ECCustomProtocol
  65. *
  66. * @brief An abstract class to send and receive custom data between HU and phone.
  67. *
  68. * @note An instantiated object of this abstract class can be gained by ECSDKToolKit::getInstance()->getCustomProtocol().
  69. */
  70. class EC_DLL_EXPORT ECCustomProtocol
  71. {
  72. public:
  73. struct ECCustomData
  74. {
  75. uint32_t cmdType; ///< the cmd type of custom data
  76. uint32_t reqSeq; ///< the request sequence of current send or reply.
  77. uint32_t rspSeq; ///< the response sequence of current send or reply.
  78. void* data; ///< the data buffer.
  79. uint32_t length; ///< the length of data buffer.
  80. ECCustomData()
  81. {
  82. cmdType = 0;
  83. reqSeq = 0;
  84. rspSeq = 0;
  85. data = nullptr;
  86. length = 0;
  87. }
  88. };
  89. /**
  90. * @class ICustomDataResponse
  91. *
  92. * @brief An interface class to implement response for a send with reply.
  93. */
  94. class ICustomDataResponse
  95. {
  96. public:
  97. /**
  98. * @brief Called when a reply from phone was received.
  99. *
  100. * @param data The custom data of reply from phone.
  101. *
  102. * @note the rspSeq of data will be non-zero, which was equal to the reqSeq of one send.
  103. */
  104. virtual void onReceive(const ECCustomData& data) {};
  105. /**
  106. * @brief Called When an error occurs for current send.
  107. *
  108. * @param reqSeq The real reqSeq of current send.
  109. *
  110. * @param errNo The error num.
  111. * -1 failed to allocate memory.
  112. * -2 failed to send to phone.
  113. * -3 the version of phone app does not support the function of custom protocol.
  114. * @param error The error description.
  115. */
  116. virtual void onError(uint32_t reqSeq, int32_t errorNo, const string& error) {};
  117. /**
  118. * @brief Called When the specified timeout time is reached.
  119. *
  120. * @param reqSeq The real reqSeq of current send.
  121. */
  122. virtual void onTimeout(uint32_t reqSeq) {};
  123. };
  124. /**
  125. * @class ICustomDataReceiver
  126. *
  127. * @brief An interface class to implement receive of custom data from phone.
  128. */
  129. class ICustomDataReceiver
  130. {
  131. public:
  132. /**
  133. * @brief Called When custom data from phone was received.
  134. *
  135. * @param data The custom data of phone.
  136. *
  137. * @note the rspSeq of data will be zero.
  138. */
  139. virtual void onReceive(const ECCustomData& data) {};
  140. };
  141. /**
  142. * @brief set a receiver to handle receive of custom data from phone.
  143. *
  144. * @param receiver The ICustomDataReceiver object.
  145. */
  146. virtual int32_t registerCustomDataReceiver(ICustomDataReceiver* receiver) = 0;
  147. /**
  148. * @brief send custom data to phone.
  149. *
  150. * @param data The custom data.
  151. *
  152. * @param timeout Timeout for corresponding reply to current send in seconds. An value of -1 indicates no timeout.
  153. *
  154. * @param responseCallback The ICustomDataResponse object.
  155. *
  156. * @note If the send has reply, then responseCallback cann't be null.
  157. *
  158. * If the send has no reply, then responseCallback should be null. ECCustomProtocol::sendCustomData(data) can be used.
  159. *
  160. * User has no need to set reqSeq and rspSeq of data. After the method is invoked, the reqSeq and rspSeq of data is set to the actual value used.
  161. */
  162. virtual int32_t sendCustomData(ECCustomData& data, int32_t timeout = -1, ICustomDataResponse* responseCallback = nullptr) = 0;
  163. /**
  164. * @brief reply custom data to phone.
  165. *
  166. * @param data The custom data.
  167. *
  168. * @param reqSeq The reqSeq of the custom data received. It will be as rspSeq of current send to phone.
  169. *
  170. * @note User has no need to set reqSeq and rspSeq of data. After the method is invoked, the reqSeq and rspSeq of data is set to the actual value used.
  171. */
  172. virtual int32_t replyCustomData(ECCustomData& data, uint32_t reqSeq) = 0;
  173. };
  174. /*
  175. * @brief The ECSDKExtrasManage class
  176. */
  177. class EC_DLL_EXPORT ECSDKToolKit
  178. {
  179. public:
  180. /**
  181. * @brief getInstance
  182. * @return
  183. */
  184. static ECSDKToolKit *getInstance();
  185. /**
  186. * @brief initialize
  187. * @param pListener
  188. * @return
  189. */
  190. virtual bool initialize(IECToolKitListener* listener = nullptr) = 0;
  191. /**
  192. * @brief release
  193. * @return
  194. */
  195. virtual void release() = 0;
  196. /**
  197. * @brief Open ftp server which forwards the local ports on HUD to the ports on the connected phone.
  198. *
  199. * @param userName Specifying the username of ftp.
  200. *
  201. * @param pwd Specifying the password of ftp.
  202. *
  203. * @return ECSDK_OK on success, others on fail.
  204. *
  205. * @note This interface shall be called only after
  206. * IECSDKListener::onSdkConnectStatus::EC_CONNECT_PHONE_SUCCEED
  207. *
  208. */
  209. virtual int32_t openFtpServer(const string& userName, const string& pwd) = 0;
  210. /**
  211. * @brief Send an request to phone for time information.
  212. *
  213. * @return ECSDK_OK on success, others on fail.
  214. */
  215. virtual int32_t queryTime() = 0;
  216. /**
  217. * @brief Send an request to phone for GPS information.
  218. *
  219. * @return ECSDK_OK on success, others on fail.
  220. *
  221. * @note The query result to see ExtrasManageListener::onQueryGPS.
  222. */
  223. virtual int32_t queryGPS() = 0;
  224. /**
  225. * @brief Send bulk data to phone(RESERVED).
  226. *
  227. * @param data Buffer of bulk data.
  228. *
  229. * @param length Buffer length.
  230. *
  231. * @return ECSDK_OK on success, others on fail.
  232. *
  233. * @note THIS IS A RESERVED METHOD. PLEASE IGNORE IT NOW.
  234. */
  235. virtual int32_t sendBulkDataToPhone(const void *data, uint32_t length) = 0;
  236. /**
  237. * @brief This method can set up forwarding of HU's port to connected phone's port when connection is via usb.
  238. *
  239. * @param in Which tell the local port and remote port which will be mapped.
  240. *
  241. * @return ECSDK_OK on success, others on fail.
  242. *
  243. * @note If the connection is via wifi, ip in forwardInfo is the connected phone's ip,
  244. * the localPort in forwardInfo is equal to the phonePort.
  245. *
  246. * If the connection is via usb, ip in forwardInfo will be 127.0.0.1,
  247. * the localPort is the real port of HU forwarded to connected phone.
  248. *
  249. * IECToolKitListener::onForwardToPhone will tell the result of forwardTophone.
  250. */
  251. virtual int32_t forwardToPhone(const ECForwardInfo& in) = 0;
  252. virtual ECCustomProtocol* getCustomProtocol() = 0;
  253. /**
  254. * @brief This method will get a url string for qr code.
  255. *
  256. * @param info The ssid and pwd of info will be encoded to url.
  257. * @param type Specify the type of build. reference ECQrCodeType.
  258. * @param fileName Specify the generated file name
  259. * @param qrParam Parameters required to generate QRcode
  260. * @param bmpParam Parameters required for generating BMP pictures
  261. *
  262. * @return ECSDK_OK on success, others on fail.
  263. */
  264. virtual int32_t generateQRCodeUrl(const ECQRInfo& info, const int32_t type=0, const char* fileName=NULL, const ECQrCodeParam* qrParam=NULL,const ECQrCodeBmpParam* bmpParam=NULL) = 0;
  265. protected:
  266. ECSDKToolKit();
  267. virtual ~ECSDKToolKit();
  268. };
  269. }
  270. #endif // ECSDKTOOLKIT_H