ql_api_qthsdk.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. 
  2. /** @file
  3. ql_api_qthsdk.h
  4. @brief
  5. TODO
  6. */
  7. /*================================================================
  8. Copyright (c) 2021 Quectel Wireless Solution, Co., Ltd. All Rights Reserved.
  9. Quectel Wireless Solution Proprietary and Confidential.
  10. =================================================================*/
  11. /*=================================================================
  12. EDIT HISTORY FOR MODULE
  13. This section contains comments describing changes made to the module.
  14. Notice that changes are listed in reverse chronological order.
  15. WHEN WHO WHAT, WHERE, WHY
  16. ------------ ------- -------------------------------------------------------------------------------
  17. =================================================================*/
  18. #ifndef __QL_API_QTHSDK_H__
  19. #define __QL_API_QTHSDK_H__
  20. typedef unsigned char quint8_t;
  21. typedef char qint8_t;
  22. typedef unsigned short quint16_t;
  23. typedef short qint16_t;
  24. typedef unsigned int quint32_t;
  25. typedef int qint32_t;
  26. typedef unsigned long long quint64_t;
  27. typedef long long qint64_t;
  28. typedef bool qbool;
  29. typedef unsigned long int pointer_t;
  30. enum
  31. {
  32. QIOT_ATEVENT_TYPE_AUTH = 1,
  33. QIOT_ATEVENT_TYPE_CONN = 2,
  34. QIOT_ATEVENT_TYPE_SUBCRIBE = 3,
  35. QIOT_ATEVENT_TYPE_SEND = 4,
  36. QIOT_ATEVENT_TYPE_RECV = 5,
  37. QIOT_ATEVENT_TYPE_LOGOUT = 6,
  38. QIOT_ATEVENT_TYPE_OTA = 7,
  39. QIOT_ATEVENT_TYPE_SERVER = 8,
  40. QIOT_ATEVENT_TYPE_UNAUTH = 10,
  41. };
  42. enum
  43. {
  44. QIOT_AUTH_SUCC = 10200, /* 设备认证成功 */
  45. QIOT_AUTH_ERR_DMP_INSIDE = 10404, /* DMP内部接口调用失败 */
  46. //QIOT_AUTH_ERR_REQDATA = 10420, /* 请求数据错误(连接失败)*/
  47. QIOT_AUTH_ERR_DONE = 10422, /* 设备已认证(连接失败)*/
  48. QIOT_AUTH_ERR_PKPS_INVALID = 10423, /* 没有找到产品信息(连接失败)*/
  49. QIOT_AUTH_ERR_PAYLOAD_INVALID = 10424, /* PAYLOAD解析失败(连接失败)*/
  50. QIOT_AUTH_ERR_SIGN_INVALID = 10425, /* 签名验证未通过(连接失败)*/
  51. QIOT_AUTH_ERR_VERSION_INVALID = 10426, /* 认证版本错误(连接失败)*/
  52. QIOT_AUTH_ERR_HASH_INVALID = 10427, /* 散列信息不合法(连接失败)*/
  53. //QIOT_AUTH_ERR_PK_CHANGE = 10430, /* PK发生改变 */
  54. QIOT_AUTH_ERR_DK_ILLEGAL = 10431, /* DK不合法 */
  55. //QIOT_AUTH_ERR_PK_VER_NOCOR = 10432, /* PK与认证版本不匹配 */
  56. QIOT_AUTH_ERR_FLAG = 10433, /* Flag不符合规则;仅0000与0001其他非法 */
  57. QIOT_AUTH_ERR_CLIENTID = 10434, /* ClientID与passwd中ClientID不匹配 */
  58. QIOT_AUTH_ERR_ACTION_FLAG = 10435, /* action flag不匹配(0注册,1登录,其他非法) */
  59. //QIOT_AUTH_ERR_PSWORD = 10436, /* 登录用户名错误 */
  60. //QIOT_AUTH_ERR_DEVICE_INFO = 10438, /* 没有找到设备信息 */
  61. QIOT_AUTH_ERR_DEVICE_INSIDE = 10450, /* 设备内部错误(连接失败)*/
  62. //QIOT_AUTH_ERR_SERVER_NOTFOUND = 10466, /* 引导服务器地址未找到(连接失败)*/
  63. QIOT_AUTH_ERR_FAIL = 10500, /* 设备认证失败(系统发生未知异常)*/
  64. QIOT_AUTH_ERR_UNKNOWN = 10300, /* 其他错误 */
  65. };
  66. enum
  67. {
  68. QIOT_CONN_SUCC = 10200, /* 接入成功 */
  69. QIOT_CONN_ERR_DMP_INSIDE = 10404, /* DMP内部接口调用失败 */
  70. QIOT_CONN_ERR_DS_INVALID = 10430, /* 设备密钥不正确(连接失败)*/
  71. QIOT_CONN_ERR_DEVICE_FORBID = 10431, /* 设备被禁用(连接失败)*/
  72. QIOT_CONN_ERR_FLAG = 10433, /* Flag不符合规则;仅0000与0001其他非法 */
  73. QIOT_CONN_ERR_CLIENTID = 10434, /* ClientID与passwd中ClientID不匹配 */
  74. QIOT_CONN_ERR_ACTION_FLAG = 10435, /* action flag不匹配(0注册,1登录,其他非法) */
  75. //QIOT_CONN_ERR_PSWORD = 10436, /* 登录用户名错误 */
  76. QIOT_CONN_ERR_DS = 10437, /* 设备DS错误 */
  77. //QIOT_CONN_ERR_DEVICE_INFO = 10438, /* 没有找到设备信息 */
  78. QIOT_CONN_ERR_DEVICE_INSIDE = 10450, /* 设备内部错误(连接失败)*/
  79. QIOT_CONN_ERR_VERSION_NOTFOUND = 10471, /* 实现方案版本不支持(连接失败)*/
  80. QIOT_CONN_ERR_PING = 10473, /* 接入心跳异常 */
  81. QIOT_CONN_ERR_NET = 10474, /* 网络异常 */
  82. QIOT_CONN_ERR_SERVER_CHANGE = 10475, /* 服务器发生改变 */
  83. QIOT_CONN_ERR_AP = 10476, /* 连接AP异常 */
  84. QIOT_CONN_ERR_UNKNOW = 10500, /* 接入失败(系统发生未知异常)*/
  85. };
  86. enum
  87. {
  88. QIOT_SUBCRIBE_SUCC = 10200, /* 订阅成功 */
  89. QIOT_SUBCRIBE_ERR = 10300, /* 订阅失败 */
  90. };
  91. enum
  92. {
  93. QIOT_SEND_SUCC_TRANS = 10200, /* 透传数据发送成功 */
  94. QIOT_SEND_ERR_TRANS = 10300, /* 透传数据发送失败 */
  95. QIOT_SEND_SUCC_PHYMODEL = 10210, /* 物模型数据发送成功 */
  96. QIOT_SEND_ERR_PHYMODEL = 10310, /* 物模型数据发送失败 */
  97. QIOT_SEND_SUCC_LOC = 10220, /* 定位数据发送成功 */
  98. QIOT_SEND_ERR_FAIL_LOC = 10320, /* 定位数据发送失败 */
  99. QIOT_SEND_SUCC_STATE = 10230, /* 状态数据发送成功 */
  100. QIOT_SEND_ERR_STATE = 10330, /* 状态数据发送失败 */
  101. QIOT_SEND_SUCC_INFO = 10240, /* 设备信息发送成功 */
  102. QIOT_SEND_ERR_INFO = 10340, /* 设备信息发送失败 */
  103. };
  104. enum
  105. {
  106. QIOT_RECV_SUCC_TRANS = 10200, /* 收到透传数据 */
  107. QIOT_RECV_SUCC_PHYMODEL_RECV = 10210, /* 收到物模型下发数据 */
  108. QIOT_RECV_SUCC_PHYMODEL_REQ = 10211, /* 收到物模型请求数据 */
  109. QIOT_RECV_SUCC_SUB_STATE_REQ = 10220, /* 收到子设备状态请求数据 */
  110. QIOT_RECV_SUCC_SUB_INFO_REQ = 10230, /* 收到子设备信息请求数据 */
  111. QIOT_RECV_ERR_BUFFER = 10473, /* 接收失败,收到数据但长度超过模组buffer限制,AT非缓存模式下有效*/
  112. QIOT_RECV_ERR_LIMIT = 10428, /* 数据接收失败,设备被限制消息通信,缓存模式下有效 */
  113. };
  114. enum
  115. {
  116. QIOT_LOGOUT_SUCC = 10200, /* 断开连接成功 */
  117. };
  118. enum
  119. {
  120. QIOT_OTA_TASK_NOTIFY = 10700, /* 有升级任务 */
  121. QIOT_OTA_START = 10701, /* 模组开始下载 */
  122. QIOT_OTA_DOWNLOADING = 10702, /* 包下载中 */
  123. QIOT_OTA_DOWNLOADED = 10703, /* 包下载完成 */
  124. QIOT_OTA_UPDATING = 10704, /* 包更新中 */
  125. QIOT_OTA_UPDATE_OK = 10705, /* 包更新完成 */
  126. QIOT_OTA_UPDATE_FAIL = 10706, /* 包更新失败 */
  127. QIOT_OTA_UPDATE_FLAG = 10707, /* 首个设备操作结果广播 */
  128. };
  129. enum
  130. {
  131. QIOT_SERVER_ERRCODE_RATE_LIMIT = 10428,
  132. QIOT_SERVER_ERRCODE_QUANTITY_LIMIT = 10429,
  133. };
  134. enum
  135. {
  136. QIOT_SUB_DEV_ERR_No_ASSOCIATION = 10440, /* 子设备与当前网关没有关联关系 */
  137. QIOT_SUB_DEV_ERR_ALREADY_CONN = 10441, /* 子设备重复登录 */
  138. QIOT_SUB_DEV_ERR_UNLOGIN = 10442, /* 子设备未登录 */
  139. };
  140. /* ql_iotDp.h */
  141. typedef enum
  142. {
  143. QIOT_DPCMD_TYPE_SYS = 0, /* sys类型命令 */
  144. QIOT_DPCMD_TYPE_BUS, /* 业务数据类型命令*/
  145. QIOT_DPCMD_TYPE_OTA, /* OTA类型命令 */
  146. QIOT_DPCMD_TYPE_LAN, /* LAN类型命令 */
  147. } QIot_dpCmdType_e;
  148. typedef enum
  149. {
  150. QIOT_DPDATA_TYPE_BOOL = 0,
  151. QIOT_DPDATA_TYPE_INT,
  152. QIOT_DPDATA_TYPE_FLOAT,
  153. QIOT_DPDATA_TYPE_BYTE,
  154. QIOT_DPDATA_TYPE_STRUCT,
  155. } QIot_dpDataType_e;
  156. void Ql_iotTtlvFree(void **ttlvHead);
  157. quint32_t Ql_iotTtlvCountGet(const void *ttlvHead);
  158. void *Ql_iotTtlvNodeGet(const void *ttlvHead, quint16_t index, quint16_t *id, QIot_dpDataType_e *type);
  159. qbool Ql_iotTtlvNodeGetType(const void *ttlvNode, QIot_dpDataType_e *type);
  160. qbool Ql_iotTtlvNodeGetBool(const void *ttlvNode, qbool *value);
  161. qbool Ql_iotTtlvNodeGetInt(const void *ttlvNode, qint64_t *value);
  162. qbool Ql_iotTtlvNodeGetFloat(const void *ttlvNode, double *value);
  163. char *Ql_iotTtlvNodeGetString(const void *ttlvNode);
  164. quint32_t Ql_iotTtlvNodeGetByte(const void *ttlvNode, quint8_t **value);
  165. void *Ql_iotTtlvNodeGetStruct(const void *ttlvNode);
  166. qbool Ql_iotTtlvIdGetType(const void *ttlvNode, quint16_t id, QIot_dpDataType_e *type);
  167. qbool Ql_iotTtlvIdGetBool(const void *ttlvHead, quint16_t id, qbool *value);
  168. qbool Ql_iotTtlvIdGetInt(const void *ttlvHead, quint16_t id, qint64_t *value);
  169. qbool Ql_iotTtlvIdGetFloat(const void *ttlvHead, quint16_t id, double *value);
  170. char *Ql_iotTtlvIdGetString(const void *ttlvHead, quint16_t id);
  171. quint32_t Ql_iotTtlvIdGetByte(const void *ttlvHead, quint16_t id, quint8_t **value);
  172. void *Ql_iotTtlvIdGetStruct(const void *ttlvHead, quint16_t id);
  173. /* id为0时即为添加数组节点 */
  174. qbool Ql_iotTtlvIdAddBool(void **ttlvHead, quint16_t id, qbool value);
  175. qbool Ql_iotTtlvIdAddInt(void **ttlvHead, quint16_t id, qint64_t num);
  176. qbool Ql_iotTtlvIdAddFloat(void **ttlvHead, quint16_t id, double num);
  177. qbool Ql_iotTtlvIdAddByte(void **ttlvHead, quint16_t id, const quint8_t *data, quint32_t len);
  178. qbool Ql_iotTtlvIdAddString(void **ttlvHead, quint16_t id, const char *data);
  179. qbool Ql_iotTtlvIdAddStruct(void **ttlvHead, quint16_t id, void *vStruct);
  180. /* ql_iotCmdBus.h */
  181. qbool Ql_iotCmdBusPassTransSend(quint16_t mode, quint8_t *payload, quint32_t len);
  182. qbool Ql_iotCmdBusPhymodelReport(quint16_t mode, const void *ttlvHead);
  183. qbool Ql_iotCmdBusPhymodelAck(quint16_t mode, quint16_t pkgId, const void *ttlvHead);
  184. /* ql_iotCmdLoc.h */
  185. qbool Ql_iotCmdBusLocReportInside(void *titleTtlv);
  186. qbool Ql_iotCmdBusLocReportOutside(void *nmeaTtlv);
  187. void *Ql_iotLocGetData(const void *titleTtlv);
  188. void *Ql_iotLocGetSupList(void);
  189. /* ql_iotCmdOTA.h */
  190. qbool Ql_iotCmdOtaRequest(quint32_t mode);
  191. qbool Ql_iotCmdOtaAction(quint8_t action);
  192. quint32_t Ql_iotCmdOtaMcuFWDataRead(quint32_t startAddr, quint8_t data[], quint32_t maxLen);
  193. /* ql_iotCmdSys.h */
  194. /* 设备状态 */
  195. enum
  196. {
  197. QIOT_DPID_STATUS_BATTERY = 1, /* 电量 */
  198. QIOT_DPID_STATUS_VOLTAGE = 2, /* 电压 */
  199. QIOT_DPID_STATUS_SIGNAL = 3, /* 信号强度 */
  200. QIOT_DPID_STATUS_FLASHFREE = 4, /* 剩余空间 */
  201. QIOT_DPID_STATUS_RSRP = 5, /* 参考信号接收功率 */
  202. QIOT_DPID_STATUS_RSRQ = 6, /* LTE参考信号接收质量 */
  203. QIOT_DPID_STATUS_SNR = 7, /* 信号与干扰加噪声比 */
  204. QIOT_DPID_STATUS_MAX,
  205. };
  206. /* 模组信息 */
  207. enum
  208. {
  209. QIOT_DPID_INFO_MODEL_TYPE = 1, /* 模组型号 */
  210. QIOT_DPID_INFO_MODEL_VER = 2, /* 模组版本 */
  211. QIOT_DPID_INFO_MCU_VER = 3, /* MCU版本 */
  212. QIOT_DPID_INFO_CELLID = 4, /* 基站id */
  213. QIOT_DPID_INFO_ICCID = 5, /* SIM卡号 */
  214. QIOT_DPID_INFO_MCC = 6, /* 移动国家代码 */
  215. QIOT_DPID_INFO_MNC = 7, /* 移动网络代码 */
  216. QIOT_DPID_INFO_LAC = 8, /* 位置区代码 */
  217. QIOT_DPID_INFO_PHONE_NUM = 9, /* phone号 */
  218. QIOT_DPID_INFO_SIM_NUM = 10, /* SIM号 */
  219. QIOT_DPID_INFO_SDK_VER = 11, /* quecthingSDK版本号*/
  220. QIOT_DPID_INFO_LOC_SUPLIST = 12, /* 定位功能支持列表 */
  221. QIOT_DPIO_INFO_DP_VER = 13, /* 数据协议版本 */
  222. QIOT_DPIO_INFO_CP_VER = 14, /* 通信协议版本号 */
  223. QIOT_DPID_INFO_MAX,
  224. };
  225. qbool Ql_iotCmdSysStatusReport(quint16_t ids[], quint32_t size);
  226. qbool Ql_iotCmdSysDevInfoReport(quint16_t ids[], quint32_t size);
  227. void *Ql_iotSysGetDevStatus(quint16_t ids[], quint32_t size);
  228. void *Ql_iotSysGetDevInfo(quint16_t ids[], quint32_t size);
  229. qbool Ql_iotDBindcodeSet(const char *bindcode);
  230. char *Ql_iotDBindcodeGet(void);
  231. /* ql_iotConn.h */
  232. enum
  233. {
  234. QIOT_DPAPP_M2M = (1 << 0),
  235. QIOT_DPAPP_SUBDEV = (1 << 1),
  236. QIOT_DPAPP_LANPHONE = (1 << 2),
  237. } ;
  238. typedef quint32_t QIot_dpAppType_e;
  239. /* ql_iotConfig.h */
  240. typedef enum
  241. {
  242. QIOT_CONNMODE_IDLE, /* 不连接IOT */
  243. QIOT_CONNMODE_REQ, /* 手动发起连接IOT */
  244. QIOT_CONNMODE_AUTO, /* 联网后主动连接IOT */
  245. } QIot_connMode_e;
  246. typedef enum
  247. {
  248. QIOT_PPROTOCOL_MQTT = 1,
  249. } QIot_protocolType_t;
  250. typedef enum
  251. {
  252. QIOT_STATE_UNINITIALIZE = 0,
  253. QIOT_STATE_INITIALIZED = 1,
  254. QIOT_STATE_AUTHENTICATING = 2,
  255. QIOT_STATE_AUTHENTICATED = 3,
  256. QIOT_STATE_AUTHENTICATE_FAILED = 4,
  257. QIOT_STATE_CONNECTING = 5,
  258. QIOT_STATE_CONNECTED = 6,
  259. QIOT_STATE_CONNECT_FAIL = 7,
  260. QIOT_STATE_SUBSCRIBED = 8,
  261. QIOT_STATE_SUBSCRIBE_FAIL = 9,
  262. QIOT_STATE_DISCONNECTING = 10,
  263. QIOT_STATE_DISCONNECTED = 11,
  264. QIOT_STATE_DISCONNECT_FAIL = 12,
  265. } QIot_state_e;
  266. qbool Ql_iotInit(void);
  267. qbool Ql_iotConfigSetConnmode(QIot_connMode_e mode);
  268. QIot_connMode_e Ql_iotConfigGetConnmode(void);
  269. qbool Ql_iotConfigSetProductinfo(const char *pk, const char *ps);
  270. void Ql_iotConfigGetProductinfo(char **pk, char **ps, char **ver);
  271. qbool Ql_iotConfigSetServer(QIot_protocolType_t type, const char *server_url);
  272. void Ql_iotConfigGetServer(QIot_protocolType_t *type, char **server_url);
  273. qbool Ql_iotConfigSetLifetime(quint32_t lifetime);
  274. quint32_t Ql_iotConfigGetLifetime(void);
  275. qbool Ql_iotConfigSetPdpContextId(quint8_t contextID);
  276. quint8_t Ql_iotConfigGetPdpContextId(void);
  277. qbool Ql_iotConfigSetSessionFlag(qbool flag);
  278. qbool Ql_iotConfigGetSessionFlag(void);
  279. qbool Ql_iotConfigSetAppVersion(const char *appVer); /* 对APP层只有openC方案可用 */
  280. char *Ql_iotConfigGetSoftVersion(void);
  281. qbool Ql_iotConfigSetMcuVersion(const char *compno, const char *version);
  282. quint32_t Ql_iotConfigGetMcuVersion(const char *compno, char **version);
  283. void Ql_iotConfigSetEventCB(void (*eventCb)(quint32_t event, qint32_t errcode, const void *value, quint32_t valLen)); /* 仅非openC方案有效 */
  284. QIot_state_e Ql_iotGetWorkState(void);
  285. qbool Ql_iotConfigSetDkDs(const char *dk, const char *ds);
  286. qbool Ql_iotConfigGetDkDs(char **dk, char **ds);
  287. /* ql_HOtaConfig.h */
  288. #ifdef QUEC_ENABLE_HTTP_OTA
  289. void Ql_iotHttpOtaSetEventCb(void (*eventCb)(quint32_t event, qint32_t errcode, const void *value, quint32_t valLen));
  290. qbool Ql_iotHttpOtaReq(quint8_t battery, quint8_t upmode,const char *pk,const char *ps, const char *url);
  291. void Ql_iotHttpOtaGet(quint8_t *battery, quint8_t *upmode,char **pk,char **ps, char **url);
  292. #endif
  293. /* ql_iotGwDev.h */
  294. #ifdef QUEC_ENABLE_GATEWAY
  295. void Ql_iotConfigSetSubDevEventCB(void (*eventCb)(quint32_t event, qint32_t errcode, const char *subPk, const char *subDk, const void *value, quint32_t valLen));
  296. qbool Ql_iotSubDevConn(const char *subPk, const char *subPs, const char *subDk, const char *subDs, quint8_t sessionType, quint16_t keepalive);
  297. qbool Ql_iotSubDevDisconn(const char *subPk, const char *subDk);
  298. qbool Ql_iotSubDevPassTransSend(const char *subPk, const char *subDk, quint8_t *payload, quint16_t payloadlen);
  299. qbool Ql_iotSubDevTslReport(const char *subPk, const char *subDk, const void *ttlvHead);
  300. qbool Ql_iotSubDevTslAck(const char *subPk, const char *subDk, quint16_t pkgId, const void *ttlvHead);
  301. qbool Ql_iotSubDevDeauth(const char *subPk, const char *subPs, const char *subDk, const char *subDs);
  302. qbool Ql_iotSubDevHTB(const char *subPk, const char *subDk);
  303. #endif
  304. #if (defined QUEC_ENABLE_MODBUS) && (defined QUEC_ENABLE_GATEWAY)
  305. typedef qbool (*QIot_MBSend_f)(quint16_t port, const quint8_t *buf, quint32_t bufLen);
  306. typedef void (*QIot_MBInitCb_f)(char *pk, char *ps,QIot_MBPortCfg_t *portInfo[], quint32_t portNum);
  307. qbool Ql_iotMBInit(quint16_t portList[],quint32_t portNum,QIot_MBSend_f sendFunc,QIot_MBInitCb_f initCb);
  308. qbool Ql_iotMBCloudRecv(const void *ttlvHead);
  309. qbool Ql_iotMBLocalRecv(quint16_t port,quint8_t *data,quint32_t len);
  310. qbool Ql_iotMBDeinit(void);
  311. #endif
  312. #endif