quec_at_param.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967
  1. /*================================================================
  2. Copyright (c) 2021, Quectel Wireless Solutions Co., Ltd. All rights reserved.
  3. Quectel Wireless Solutions Proprietary and Confidential.
  4. =================================================================*/
  5. #ifndef _QUEC_AT_PARAM_H_
  6. #define _QUEC_AT_PARAM_H_
  7. #include "stdio.h"
  8. #include "string.h"
  9. #include "stdlib.h"
  10. #include "ctype.h"
  11. #include "ql_api_common.h"
  12. #include "ql_uart_internal.h"
  13. #include "quec_atc_common.h"
  14. /*************************************************************************
  15. * Define
  16. **************************************************************************/
  17. #define AT_BUFFER_SIZE (3*1024)
  18. #define AT_NAME_LEN_MAX 24 //at名称的最大长度,如"cfun"
  19. #ifdef CONFIG_QUEC_PROJECT_FEATURE_HW_IOT_DEVICE_SDK_AT
  20. #define AT_PARMA_LEN_MAX 2048*2 //at命令的最大总长度
  21. #else
  22. #define AT_PARMA_LEN_MAX 2048 //at命令的最大总长度
  23. #endif
  24. #define AT_MAX_LEN (AT_PARMA_LEN_MAX+AT_NAME_LEN_MAX)
  25. #define AT_MAX_PARAM_CNT 24 //at命令的参数个数
  26. #define AT_LF_TIMEOUT 10 //CR后若无数据,则等 AT_LF_TIMEOUT ms
  27. /*************************************************************************
  28. * Enum
  29. **************************************************************************/
  30. typedef enum
  31. {
  32. AT_PARAM_TYPE_EMPTY,
  33. AT_PARAM_TYPE_RAW,
  34. AT_PARAM_TYPE_STRING,
  35. } ql_at_param_type_e;
  36. typedef enum
  37. {
  38. QUEC_AT_CONSTRAIN_MIN = 100,
  39. QUEC_AT_CONSTRAIN_CJSON,
  40. QUEC_AT_CONSTRAIN_MAX
  41. } QUEC_AT_CONSTRAIN_E;
  42. /*************************************************************************
  43. * Struct
  44. **************************************************************************/
  45. typedef struct ql_at_cmd ql_at_cmd_t;
  46. typedef void (*async_ctx_destory)(struct ql_at_cmd *cmd);
  47. typedef void (*quec_at_timeout_cb_t)(ql_at_cmd_t *cmd);
  48. typedef void (*quec_at_cb_t)(void *ctx);
  49. typedef struct ql_at_desc
  50. {
  51. char *name; ///< AT command name, such as "+IPR"
  52. void (*handler)(struct ql_at_cmd*); ///< At command handler
  53. uint32_t constrains; ///< AT command constrains
  54. } ql_at_desc_t;
  55. typedef struct
  56. {
  57. uint8_t type; ///< parameter type, used by AT engine internally
  58. uint16_t length; ///< value length
  59. char *value; ///< value, the real size is variable
  60. } ql_at_param_t;
  61. typedef struct
  62. {
  63. quec_at_cb_t cb;
  64. void *ctx;
  65. }ql_at_cb_param_t;
  66. typedef struct ql_at_cmd
  67. {
  68. ql_dispatch_t *engine; //当前AT端口的dispatch(等同于dev,作用为兼容8910)
  69. quec_dev_e dev; //当前端口的端口号
  70. uint8 param_count; //当前AT的参数个数
  71. atCmdType_t type; //AT命令的类型
  72. ql_at_desc_t *desc; //AT命令信息
  73. bool resp_flag; //当前AT是否已经进行过AT回复
  74. bool err_flag; //当前AT在执行过程中是否遇到错误
  75. ql_at_param_t *params[AT_MAX_PARAM_CNT]; //参数
  76. uint16_t uti;
  77. void *async_ctx;
  78. async_ctx_destory async_ctx_destroy;
  79. } ql_at_cmd_t;
  80. typedef struct
  81. {
  82. uint32_t minval; ///< minimal value
  83. uint32_t maxval; ///< maximum value
  84. } quec_UintRange_t;
  85. typedef struct
  86. {
  87. int minval; ///< minimal value
  88. int maxval; ///< maximum value
  89. } quec_IntRange_t;
  90. typedef struct
  91. {
  92. uint64_t minval; ///< minimal value
  93. uint64_t maxval; ///< maximum value
  94. } quec_Uint64Range_t;
  95. /**
  96. * data structure to define a signed 64bits integer range
  97. */
  98. typedef struct
  99. {
  100. int64_t minval; ///< minimal value
  101. int64_t maxval; ///< maximum value
  102. } quec_Int64Range_t;
  103. typedef struct
  104. {
  105. uint32_t value; ///< integer value
  106. const char *str; ///< string value
  107. } quec_ValueStrMap_t;
  108. /*************************************************************************
  109. * Function
  110. **************************************************************************/
  111. /**
  112. * extract uint parameter
  113. *
  114. * When \a *paramok is false, it will do nothing. On failure, \a *param
  115. * will be set to false on return.
  116. *
  117. * @param param parameter pointer
  118. * @param paramok in/out parameter parsing ok flag
  119. * @return
  120. * - uint parameter
  121. * - 0 on failed
  122. * - \a *paramok is false at input
  123. * - \a param is empty
  124. * - \a param is not integer number
  125. */
  126. uint32_t quec_atParamUint(ql_at_param_t *param, bool *paramok);
  127. /**
  128. * extract optional uint parameter
  129. *
  130. * When \a *paramok is false, it will do nothing. On failure, \a *param
  131. * will be set to false on return.
  132. *
  133. * When \a param is empty, \a defval is returned. Otherwise, it is the
  134. * same as \a quec_atParamUint.
  135. *
  136. * @param param parameter pointer
  137. * @param defval default value
  138. * @param paramok in/out parameter parsing ok flag
  139. * @return
  140. * - uint parameter
  141. * - 0 on failed
  142. * - \a *paramok is false at input
  143. * - \a param is not integer number
  144. */
  145. uint32_t quec_atParamDefUint(ql_at_param_t *param, uint32_t defval, bool *paramok);
  146. /**
  147. * extract uint parameter, and check range
  148. *
  149. * When \a *paramok is false, it will do nothing. On failure, \a *param
  150. * will be set to false on return.
  151. *
  152. * @param param parameter pointer
  153. * @param minval minimum valid value, inclusive
  154. * @param maxval maximum valid value, inclusive
  155. * @param paramok in/out parameter parsing ok flag
  156. * @return
  157. * - uint parameter
  158. * - 0 on failed
  159. * - \a *paramok is false at input
  160. * - \a param is empty
  161. * - \a param is not integer number
  162. * - \a param is not in range
  163. */
  164. uint32_t quec_atParamUintInRange(ql_at_param_t *param, uint32_t minval, uint32_t maxval, bool *paramok);
  165. /**
  166. * extract optional uint parameter, and check range
  167. *
  168. * When \a *paramok is false, it will do nothing. On failure, \a *param
  169. * will be set to false on return.
  170. *
  171. * When \a param is empty, \a defval is returned. Otherwise, it is the
  172. * same as \a quec_atParamUintInRange. The \a defval is not required in the
  173. * range.
  174. *
  175. * @param param parameter pointer
  176. * @param defval default value
  177. * @param minval minimum valid value, inclusive
  178. * @param maxval maximum valid value, inclusive
  179. * @param paramok in/out parameter parsing ok flag
  180. * @return
  181. * - uint parameter
  182. * - 0 on failed
  183. * - \a *paramok is false at input
  184. * - \a param is not integer number
  185. * - \a param is not in range
  186. */
  187. uint32_t quec_atParamDefUintInRange(ql_at_param_t *param, uint32_t defval, uint32_t minval, uint32_t maxval, bool *paramok);
  188. /**
  189. * extract uint parameter, and check in list
  190. *
  191. * When \a *paramok is false, it will do nothing. On failure, \a *param
  192. * will be set to false on return.
  193. *
  194. * @param param parameter pointer
  195. * @param list array of valid values
  196. * @param count valid value count
  197. * @param paramok in/out parameter parsing ok flag
  198. * @return
  199. * - uint parameter
  200. * - 0 on failed
  201. * - \a *paramok is false at input
  202. * - \a param is empty
  203. * - \a param is not integer number
  204. * - \a param is not in list
  205. */
  206. uint32_t quec_atParamUintInList(ql_at_param_t *param, const uint32_t *list, unsigned count, bool *paramok);
  207. /**
  208. * extract optional uint parameter, and check in list
  209. *
  210. * When \a *paramok is false, it will do nothing. On failure, \a *param
  211. * will be set to false on return.
  212. *
  213. * When \a param is empty, \a defval is returned. Otherwise, it is the
  214. * same as \a quec_atParamUintInList. The \a defval is not required in the
  215. * list.
  216. *
  217. * @param param parameter pointer
  218. * @param defval default value
  219. * @param list array of valid values
  220. * @param count valid value count
  221. * @param paramok in/out parameter parsing ok flag
  222. * @return
  223. * - uint parameter
  224. * - 0 on failed
  225. * - \a *paramok is false at input
  226. * - \a param is not integer number
  227. * - \a param is not in list
  228. */
  229. uint32_t quec_atParamDefUintInList(ql_at_param_t *param, uint32_t defval, const uint32_t *list, unsigned count, bool *paramok);
  230. /**
  231. * extract int parameter
  232. *
  233. * When \a *paramok is false, it will do nothing. On failure, \a *param
  234. * will be set to false on return.
  235. *
  236. * @param param parameter pointer
  237. * @param paramok in/out parameter parsing ok flag
  238. * @return
  239. * - int parameter
  240. * - 0 on failed
  241. * - \a *paramok is false at input
  242. * - \a param is empty
  243. * - \a param is not integer number
  244. */
  245. int quec_atParamInt(ql_at_param_t *param, bool *paramok);
  246. /**
  247. * extract optional int parameter
  248. *
  249. * When \a *paramok is false, it will do nothing. On failure, \a *param
  250. * will be set to false on return.
  251. *
  252. * When \a param is empty, \a defval is returned. Otherwise, it is the
  253. * same as \a quec_atParamUint.
  254. *
  255. * @param param parameter pointer
  256. * @param defval default value
  257. * @param paramok in/out parameter parsing ok flag
  258. * @return
  259. * - int parameter
  260. * - 0 on failed
  261. * - \a *paramok is false at input
  262. * - \a param is not integer number
  263. */
  264. int quec_atParamDefInt(ql_at_param_t *param, int defval, bool *paramok);
  265. /**
  266. * extract int parameter, and check range
  267. *
  268. * When \a *paramok is false, it will do nothing. On failure, \a *param
  269. * will be set to false on return.
  270. *
  271. * @param param parameter pointer
  272. * @param minval minimum valid value, inclusive
  273. * @param maxval maximum valid value, inclusive
  274. * @param paramok in/out parameter parsing ok flag
  275. * @return
  276. * - int parameter
  277. * - 0 on failed
  278. * - \a *paramok is false at input
  279. * - \a param is empty
  280. * - \a param is not integer number
  281. * - \a param is not in range
  282. */
  283. int quec_atParamIntInRange(ql_at_param_t *param, int minval, int maxval, bool *paramok);
  284. /**
  285. * extract optional int parameter, and check range
  286. *
  287. * When \a *paramok is false, it will do nothing. On failure, \a *param
  288. * will be set to false on return.
  289. *
  290. * When \a param is empty, \a defval is returned. Otherwise, it is the
  291. * same as \a quec_atParamUintInRange. The \a defval is not required in the
  292. * range.
  293. *
  294. * @param param parameter pointer
  295. * @param defval default value
  296. * @param minval minimum valid value, inclusive
  297. * @param maxval maximum valid value, inclusive
  298. * @param paramok in/out parameter parsing ok flag
  299. * @return
  300. * - int parameter
  301. * - 0 on failed
  302. * - \a *paramok is false at input
  303. * - \a param is not integer number
  304. * - \a param is not in range
  305. */
  306. int quec_atParamDefIntInRange(ql_at_param_t *param, int defval, int minval, int maxval, bool *paramok);
  307. /**
  308. * extract int parameter, and check in list
  309. *
  310. * When \a *paramok is false, it will do nothing. On failure, \a *param
  311. * will be set to false on return.
  312. *
  313. * @param param parameter pointer
  314. * @param list array of valid values
  315. * @param count valid value count
  316. * @param paramok in/out parameter parsing ok flag
  317. * @return
  318. * - int parameter
  319. * - 0 on failed
  320. * - \a *paramok is false at input
  321. * - \a param is empty
  322. * - \a param is not integer number
  323. * - \a param is not in list
  324. */
  325. int quec_atParamIntInList(ql_at_param_t *param, const int *list, unsigned count, bool *paramok);
  326. /**
  327. * extract optional int parameter, and check in list
  328. *
  329. * When \a *paramok is false, it will do nothing. On failure, \a *param
  330. * will be set to false on return.
  331. *
  332. * When \a param is empty, \a defval is returned. Otherwise, it is the
  333. * same as \a quec_atParamUintInList. The \a defval is not required in the
  334. * list.
  335. *
  336. * @param param parameter pointer
  337. * @param defval default value
  338. * @param list array of valid values
  339. * @param count valid value count
  340. * @param paramok in/out parameter parsing ok flag
  341. * @return
  342. * - int parameter
  343. * - 0 on failed
  344. * - \a *paramok is false at input
  345. * - \a param is not integer number
  346. * - \a param is not in list
  347. */
  348. int quec_atParamDefIntInList(ql_at_param_t *param, int defval, const int *list, unsigned count, bool *paramok);
  349. /**
  350. * extract uint64 parameter
  351. *
  352. * When \a *paramok is false, it will do nothing. On failure, \a *param
  353. * will be set to false on return.
  354. *
  355. * @param param parameter pointer
  356. * @param paramok in/out parameter parsing ok flag
  357. * @return
  358. * - uint parameter
  359. * - 0 on failed
  360. * - \a *paramok is false at input
  361. * - \a param is empty
  362. * - \a param is not integer number
  363. */
  364. uint64_t quec_atParamUint64(ql_at_param_t *param, bool *paramok);
  365. /**
  366. * extract optional uint64 parameter
  367. *
  368. * When \a *paramok is false, it will do nothing. On failure, \a *param
  369. * will be set to false on return.
  370. *
  371. * When \a param is empty, \a defval is returned. Otherwise, it is the
  372. * same as \a quec_atParamUint.
  373. *
  374. * @param param parameter pointer
  375. * @param defval default value
  376. * @param paramok in/out parameter parsing ok flag
  377. * @return
  378. * - uint parameter
  379. * - 0 on failed
  380. * - \a *paramok is false at input
  381. * - \a param is not integer number
  382. */
  383. uint64_t quec_atParamDefUint64(ql_at_param_t *param, uint64_t defval, bool *paramok);
  384. /**
  385. * extract uint64 parameter, and check range
  386. *
  387. * When \a *paramok is false, it will do nothing. On failure, \a *param
  388. * will be set to false on return.
  389. *
  390. * @param param parameter pointer
  391. * @param minval minimum valid value, inclusive
  392. * @param maxval maximum valid value, inclusive
  393. * @param paramok in/out parameter parsing ok flag
  394. * @return
  395. * - uint parameter
  396. * - 0 on failed
  397. * - \a *paramok is false at input
  398. * - \a param is empty
  399. * - \a param is not integer number
  400. * - \a param is not in range
  401. */
  402. uint64_t quec_atParamUint64InRange(ql_at_param_t *param, uint64_t minval, uint64_t maxval, bool *paramok);
  403. /**
  404. * extract optional uint64 parameter, and check range
  405. *
  406. * When \a *paramok is false, it will do nothing. On failure, \a *param
  407. * will be set to false on return.
  408. *
  409. * When \a param is empty, \a defval is returned. Otherwise, it is the
  410. * same as \a quec_atParamUintInRange. The \a defval is not required in the
  411. * range.
  412. *
  413. * @param param parameter pointer
  414. * @param defval default value
  415. * @param minval minimum valid value, inclusive
  416. * @param maxval maximum valid value, inclusive
  417. * @param paramok in/out parameter parsing ok flag
  418. * @return
  419. * - uint parameter
  420. * - 0 on failed
  421. * - \a *paramok is false at input
  422. * - \a param is not integer number
  423. * - \a param is not in range
  424. */
  425. uint64_t quec_atParamDefUint64InRange(ql_at_param_t *param, uint64_t defval, uint64_t minval, uint64_t maxval, bool *paramok);
  426. /**
  427. * extract uint64 parameter, and check in list
  428. *
  429. * When \a *paramok is false, it will do nothing. On failure, \a *param
  430. * will be set to false on return.
  431. *
  432. * @param param parameter pointer
  433. * @param list array of valid values
  434. * @param count valid value count
  435. * @param paramok in/out parameter parsing ok flag
  436. * @return
  437. * - uint parameter
  438. * - 0 on failed
  439. * - \a *paramok is false at input
  440. * - \a param is empty
  441. * - \a param is not integer number
  442. * - \a param is not in list
  443. */
  444. uint64_t quec_atParamUint64InList(ql_at_param_t *param, const uint64_t *list, unsigned count, bool *paramok);
  445. /**
  446. * extract optional uint64 parameter, and check in list
  447. *
  448. * When \a *paramok is false, it will do nothing. On failure, \a *param
  449. * will be set to false on return.
  450. *
  451. * When \a param is empty, \a defval is returned. Otherwise, it is the
  452. * same as \a quec_atParamUintInList. The \a defval is not required in the
  453. * list.
  454. *
  455. * @param param parameter pointer
  456. * @param defval default value
  457. * @param list array of valid values
  458. * @param count valid value count
  459. * @param paramok in/out parameter parsing ok flag
  460. * @return
  461. * - uint parameter
  462. * - 0 on failed
  463. * - \a *paramok is false at input
  464. * - \a param is not integer number
  465. * - \a param is not in list
  466. */
  467. uint64_t quec_atParamDefUint64InList(ql_at_param_t *param, uint64_t defval, const uint64_t *list, unsigned count, bool *paramok);
  468. /**
  469. * extract int64 parameter
  470. *
  471. * When \a *paramok is false, it will do nothing. On failure, \a *param
  472. * will be set to false on return.
  473. *
  474. * @param param parameter pointer
  475. * @param paramok in/out parameter parsing ok flag
  476. * @return
  477. * - int parameter
  478. * - 0 on failed
  479. * - \a *paramok is false at input
  480. * - \a param is empty
  481. * - \a param is not integer number
  482. */
  483. int64_t quec_atParamInt64(ql_at_param_t *param, bool *paramok);
  484. /**
  485. * extract optional int64 parameter
  486. *
  487. * When \a *paramok is false, it will do nothing. On failure, \a *param
  488. * will be set to false on return.
  489. *
  490. * When \a param is empty, \a defval is returned. Otherwise, it is the
  491. * same as \a quec_atParamUint.
  492. *
  493. * @param param parameter pointer
  494. * @param defval default value
  495. * @param paramok in/out parameter parsing ok flag
  496. * @return
  497. * - int parameter
  498. * - 0 on failed
  499. * - \a *paramok is false at input
  500. * - \a param is not integer number
  501. */
  502. int64_t quec_atParamDefInt64(ql_at_param_t *param, int64_t defval, bool *paramok);
  503. /**
  504. * extract int64 parameter, and check range
  505. *
  506. * When \a *paramok is false, it will do nothing. On failure, \a *param
  507. * will be set to false on return.
  508. *
  509. * @param param parameter pointer
  510. * @param minval minimum valid value, inclusive
  511. * @param maxval maximum valid value, inclusive
  512. * @param paramok in/out parameter parsing ok flag
  513. * @return
  514. * - int parameter
  515. * - 0 on failed
  516. * - \a *paramok is false at input
  517. * - \a param is empty
  518. * - \a param is not integer number
  519. * - \a param is not in range
  520. */
  521. int64_t quec_atParamInt64InRange(ql_at_param_t *param, int64_t minval, int64_t maxval, bool *paramok);
  522. /**
  523. * extract optional int64 parameter, and check range
  524. *
  525. * When \a *paramok is false, it will do nothing. On failure, \a *param
  526. * will be set to false on return.
  527. *
  528. * When \a param is empty, \a defval is returned. Otherwise, it is the
  529. * same as \a quec_atParamUintInRange. The \a defval is not required in the
  530. * range.
  531. *
  532. * @param param parameter pointer
  533. * @param defval default value
  534. * @param minval minimum valid value, inclusive
  535. * @param maxval maximum valid value, inclusive
  536. * @param paramok in/out parameter parsing ok flag
  537. * @return
  538. * - int parameter
  539. * - 0 on failed
  540. * - \a *paramok is false at input
  541. * - \a param is not integer number
  542. * - \a param is not in range
  543. */
  544. int64_t quec_atParamDefInt64InRange(ql_at_param_t *param, int64_t defval, int64_t minval, int64_t maxval, bool *paramok);
  545. /**
  546. * extract int64 parameter, and check in list
  547. *
  548. * When \a *paramok is false, it will do nothing. On failure, \a *param
  549. * will be set to false on return.
  550. *
  551. * @param param parameter pointer
  552. * @param list array of valid values
  553. * @param count valid value count
  554. * @param paramok in/out parameter parsing ok flag
  555. * @return
  556. * - int parameter
  557. * - 0 on failed
  558. * - \a *paramok is false at input
  559. * - \a param is empty
  560. * - \a param is not integer number
  561. * - \a param is not in list
  562. */
  563. int64_t quec_atParamInt64InList(ql_at_param_t *param, const int64_t *list, unsigned count, bool *paramok);
  564. /**
  565. * extract optional int64 parameter, and check in list
  566. *
  567. * When \a *paramok is false, it will do nothing. On failure, \a *param
  568. * will be set to false on return.
  569. *
  570. * When \a param is empty, \a defval is returned. Otherwise, it is the
  571. * same as \a quec_atParamUintInList. The \a defval is not required in the
  572. * list.
  573. *
  574. * @param param parameter pointer
  575. * @param defval default value
  576. * @param list array of valid values
  577. * @param count valid value count
  578. * @param paramok in/out parameter parsing ok flag
  579. * @return
  580. * - int parameter
  581. * - 0 on failed
  582. * - \a *paramok is false at input
  583. * - \a param is not integer number
  584. * - \a param is not in list
  585. */
  586. int64_t quec_atParamDefInt64InList(ql_at_param_t *param, int64_t defval, const int64_t *list, unsigned count, bool *paramok);
  587. /**
  588. * extract string parameter
  589. *
  590. * When \a *paramok is false, it will do nothing. On failure, \a *param
  591. * will be set to false on return.
  592. *
  593. * String parameter is parameter started and ended with double quotation.
  594. * The escape defined in V.250 is \\HH. For example, \30 for '0'.
  595. *
  596. * It is possible that the internal storage will be changed during this
  597. * function call. So, don't call other parameter APIs for the same
  598. * parameter after it is called. However, this function itself can be
  599. * called again.
  600. *
  601. * The output pointer will be valid till the parameter itself is deleted.
  602. *
  603. * The output string is ended with null byte for end of string.
  604. *
  605. * @param param parameter pointer
  606. * @param paramok in/out parameter parsing ok flag
  607. * @return
  608. * - parsed string
  609. * - NULL on failed
  610. * - \a *paramok is false at input
  611. * - \a param is empty
  612. * - \a param is not string (start and end with double quotation)
  613. */
  614. const char *quec_atParamStr(ql_at_param_t *param, bool *paramok);
  615. /**
  616. * extract hex or str parameter from raw text
  617. *
  618. * When \a *paramok is false, it will do nothing. On failure, \a *param
  619. * will be set to false on return.
  620. *
  621. * Raw text parameter is parameter started and ended without double quotation.
  622. * The escape defined in V.250 is \\HH. For example, \30 for '0'.
  623. *
  624. * It is possible that the internal storage will be changed during this
  625. * function call. So, don't call other parameter APIs for the same
  626. * parameter after it is called. However, this function itself can be
  627. * called again.
  628. *
  629. * The output pointer will be valid till the parameter itself is deleted.
  630. *
  631. * The output string is ended with null byte for end of string.
  632. *
  633. * @param param parameter pointer
  634. * @param len the length of the parameter
  635. * @param paramok in/out parameter parsing ok flag
  636. * @return
  637. * - parsed string
  638. * - NULL on failed
  639. * - \a *paramok is false at input
  640. * - \a param is empty
  641. * - \a param is string (start and end with double quotation)
  642. */
  643. const char *quec_atParamHexData(ql_at_param_t *param, uint32_t len, bool *paramok);
  644. /**
  645. * extract hex parameter from raw text
  646. *
  647. * When \a *paramok is false, it will do nothing. On failure, \a *param
  648. * will be set to false on return.
  649. *
  650. * Raw text parameter is parameter started and ended without double quotation.
  651. * The escape defined in V.250 is \\HH. For example, \30 for '0'.
  652. *
  653. * It is possible that the internal storage will be changed during this
  654. * function call. So, don't call other parameter APIs for the same
  655. * parameter after it is called. However, this function itself can be
  656. * called again.
  657. *
  658. * The output pointer will be valid till the parameter itself is deleted.
  659. *
  660. * The output string is ended with null byte for end of string.
  661. *
  662. * @param param parameter pointer
  663. * @param len the length of the parameter
  664. * @param paramok in/out parameter parsing ok flag
  665. * @return
  666. * - parsed string
  667. * - NULL on failed
  668. * - \a *paramok is false at input
  669. * - \a param is empty
  670. * - \a param is string (start and end with double quotation)
  671. */
  672. const char *quec_atParamHexRawText(ql_at_param_t *param, uint32_t len, bool *paramok);
  673. /**
  674. * extract string parameter
  675. *
  676. * When \a *paramok is false, it will do nothing. On failure, \a *param
  677. * will be set to false on return.
  678. *
  679. * String parameter is parameter started and ended with double quotation.
  680. * The escape defined in V.250 is \\HH. For example, \30 for '0'.
  681. *
  682. * It is possible that the internal storage will be changed during this
  683. * function call. So, don't call other parameter APIs for the same
  684. * parameter after it is called. However, this function itself can be
  685. * called again.
  686. *
  687. * The output pointer will be valid till the parameter itself is deleted.
  688. *
  689. * The output string is ended with null byte for end of string.
  690. *
  691. * @param param parameter pointer
  692. * @param paramok in/out parameter parsing ok flag
  693. * @return
  694. * - parsed string
  695. * - NULL on failed
  696. * - \a *paramok is false at input
  697. * - \a param is empty
  698. * - \a param is not string (start and end with double quotation)
  699. */
  700. const char *quec_atParamOptStr(ql_at_param_t *param, bool *paramok);
  701. /**
  702. * extract optional string parameter
  703. *
  704. * When \a *paramok is false, it will do nothing. On failure, \a *param
  705. * will be set to false on return.
  706. *
  707. * When \a param is empty, \a defval is returned. Otherwise, it is the
  708. * same as \a quec_atParamStr.
  709. *
  710. * It is possible that the internal storage will be changed during this
  711. * function call. So, don't call other parameter APIs for the same
  712. * parameter after it is called. However, this function itself can be
  713. * called again.
  714. *
  715. * @param param parameter pointer
  716. * @param defval default value
  717. * @param paramok in/out parameter parsing ok flag
  718. * @return
  719. * - parsed string
  720. * - NULL on failed
  721. * - \a *paramok is false at input
  722. * - \a param is not string (start and end with double quotation)
  723. */
  724. const char *quec_atParamDefStr(ql_at_param_t *param, const char *defval, bool *paramok);
  725. /**
  726. * extract raw parameter
  727. *
  728. * When \a *paramok is false, it will do nothing. On failure, \a *param
  729. * will be set to false on return.
  730. *
  731. * The raw parameter is not parsed. For example, the double quotation of
  732. * string parameter will be kept, and the escape in string parameter is
  733. * untouched.
  734. *
  735. * The output string is ended with null byte as end of string.
  736. *
  737. * @param param parameter pointer
  738. * @param paramok in/out parameter parsing ok flag
  739. * @return
  740. * - parsed string
  741. * - NULL on failed
  742. * - \a *paramok is false at input
  743. * - \a param is empty
  744. */
  745. const char *quec_atParamRawText(ql_at_param_t *param, bool *paramok);
  746. /**
  747. * extract floating point parameter
  748. *
  749. * When \a *paramok is false, it will do nothing. On failure, \a *param
  750. * will be set to false on return.
  751. *
  752. * @param param parameter pointer
  753. * @param paramok in/out parameter parsing ok flag
  754. * @return
  755. * - floating point parameter
  756. * - NULL on failed
  757. * - \a *paramok is false at input
  758. * - \a param is empty
  759. * - \a param is not double
  760. */
  761. double quec_atParamDouble(ql_at_param_t *param, bool *paramok);
  762. /**
  763. * extract DTMF parameter
  764. *
  765. * When \a *paramok is false, it will do nothing. On failure, \a *param
  766. * will be set to false on return.
  767. *
  768. * There are 2 kinds of DTMF parameter:
  769. * - one DTMF character without double quotation
  770. * - multiple DTMF chaeacters with double quotation
  771. * In both case, the return value is DTMF character string with null byte
  772. * as the string end.
  773. *
  774. * It will not check whether DTMF characters inside the string is valid
  775. * DTMF character. Application should validate them.
  776. *
  777. * It is possible that the internal storage will be changed during this
  778. * function call. So, don't call other parameter APIs for the same
  779. * parameter after it is called. However, this function itself can be
  780. * called again.
  781. *
  782. * @param param parameter pointer
  783. * @param paramok in/out parameter parsing ok flag
  784. * @return
  785. * - parsed DTMF string
  786. * - NULL on failed
  787. * - \a *paramok is false at input
  788. * - \a param is empty
  789. * - \a param is not DTMF
  790. */
  791. const char *quec_atParamDtmf(ql_at_param_t *param, bool *paramok);
  792. /**
  793. * extract string parameter and return mapped uint
  794. *
  795. * When \a *paramok is false, it will do nothing. On failure, \a *param
  796. * will be set to false on return.
  797. *
  798. * It is just a wrapper to:
  799. * - extract string parameter
  800. * - map to uint
  801. *
  802. * @param param parameter pointer
  803. * @param vsmap integer/string map, ended with NULL string value
  804. * @param paramok in/out parameter parsing ok flag
  805. * @return
  806. * - uint parameter
  807. * - NULL on failed
  808. * - \a *paramok is false at input
  809. * - \a param is empty
  810. * - \a param is not in map
  811. */
  812. uint32_t quec_atParamUintByStrMap(ql_at_param_t *param, const quec_ValueStrMap_t *vsmap, bool *paramok);
  813. /**
  814. * extract optional string parameter and return mapped uint
  815. *
  816. * When \a *paramok is false, it will do nothing. On failure, \a *param
  817. * will be set to false on return.
  818. *
  819. * When \a param is empty, \a defval is returned. Otherwise, it is the
  820. * same as \a quec_atParamUintByStrMap. The \a defval is not required in the
  821. * map.
  822. *
  823. * @param param parameter pointer
  824. * @param defval default value
  825. * @param vsmap integer/string map, ended with NULL string value
  826. * @param paramok in/out parameter parsing ok flag
  827. * @return
  828. * - uint parameter
  829. * - NULL on failed
  830. * - \a *paramok is false at input
  831. * - \a param is not in map
  832. */
  833. uint32_t quec_atParamDefUintByStrMap(ql_at_param_t *param, uint32_t defval, const quec_ValueStrMap_t *vsmap, bool *paramok);
  834. /**
  835. * extract uint parameter by hex string
  836. *
  837. * When \a *paramok is false, it will do nothing. On failure, \a *param
  838. * will be set to false on return.
  839. *
  840. * The valid parameter is the output of:
  841. * \code{.cpp}
  842. * printf("\"%x\"", value)
  843. * \endcode
  844. *
  845. * For example, parameter "12345" will be parsed as 0x12345.
  846. *
  847. * @param param parameter pointer
  848. * @param paramok in/out parameter parsing ok flag
  849. * @return
  850. * - uint parameter
  851. * - NULL on failed
  852. * - \a *paramok is false at input
  853. * - \a param is empty
  854. * - \a param is not the needed format
  855. */
  856. uint32_t quec_atParamHexStrUint(ql_at_param_t *param, bool *paramok);
  857. /**
  858. * trim tailing characters at the end of parameter
  859. *
  860. * This shall be called before the parameter isn't parsed. \p quec_atParamRawText
  861. * won't parse the parameter, so it is safe to call it after \p quec_atParamRawText.
  862. *
  863. * It will change the internal storage of parameter directly. So, only call
  864. * it when absolutely needed, and you know what you are doing.
  865. *
  866. * @param param parameter pointer
  867. * @param paramok in/out parameter parsing ok flag
  868. * @return
  869. * - true on success
  870. * - false on failed
  871. * - \p param type is not raw text
  872. * - the length of parameter is shorter than \p len
  873. */
  874. bool quec_atParamTrimTail(ql_at_param_t *param, uint32_t len);
  875. /**
  876. * check whether the parameter is empty
  877. *
  878. * Both not specified and skipped parameter are empty. For example:
  879. * - AT+CMD=123
  880. * - AT+CMD=123,
  881. * - AT+CMD=123,,456
  882. *
  883. * In all of the above cases, params[1] is empty.
  884. *
  885. * @param param parameter pointer
  886. * @return
  887. * - true if the parameter is empty
  888. * - false otherwise
  889. */
  890. bool quec_atParamIsEmpty(ql_at_param_t *param);
  891. /**
  892. * extract hex int64_t parameter, and check range
  893. *
  894. * When \a *paramok is false, it will do nothing. On failure, \a *param
  895. * will be set to false on return.
  896. *
  897. * @param param parameter pointer
  898. * @param minval minimum valid value, inclusive
  899. * @param maxval maximum valid value, inclusive
  900. * @param paramok in/out parameter parsing ok flag
  901. * @return
  902. * - uint parameter
  903. * - 0 on failed
  904. * - \a *paramok is false at input
  905. * - \a param is empty
  906. * - \a param is not integer number
  907. * - \a param is not in range
  908. */
  909. int64_t quec_atParamHexInt64InRange(ql_at_param_t *param, int64_t minval, int64_t maxval, bool *paramok);
  910. #endif