at_param.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913
  1. /* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _AT_PARAM_H_
  13. #define _AT_PARAM_H_
  14. #include <stdint.h>
  15. #include <stdbool.h>
  16. #include "osi_vsmap.h"
  17. #include "quec_proj_config.h"
  18. #ifndef CONFIG_QUEC_PROJECT_FEATURE_ATC_PARSE
  19. /**
  20. * parsed AT command parameter
  21. */
  22. typedef struct
  23. {
  24. uint8_t type; ///< parameter type, used by AT engine internally
  25. uint16_t length; ///< value length
  26. char value[1]; ///< value, the real size is variable
  27. } atCmdParam_t;
  28. /**
  29. * extract uint parameter
  30. *
  31. * When \a *paramok is false, it will do nothing. On failure, \a *param
  32. * will be set to false on return.
  33. *
  34. * @param param parameter pointer
  35. * @param paramok in/out parameter parsing ok flag
  36. * @return
  37. * - uint parameter
  38. * - 0 on failed
  39. * - \a *paramok is false at input
  40. * - \a param is empty
  41. * - \a param is not integer number
  42. */
  43. uint32_t atParamUint(atCmdParam_t *param, bool *paramok);
  44. /**
  45. * extract optional uint parameter
  46. *
  47. * When \a *paramok is false, it will do nothing. On failure, \a *param
  48. * will be set to false on return.
  49. *
  50. * When \a param is empty, \a defval is returned. Otherwise, it is the
  51. * same as \a atParamUint.
  52. *
  53. * @param param parameter pointer
  54. * @param defval default value
  55. * @param paramok in/out parameter parsing ok flag
  56. * @return
  57. * - uint parameter
  58. * - 0 on failed
  59. * - \a *paramok is false at input
  60. * - \a param is not integer number
  61. */
  62. uint32_t atParamDefUint(atCmdParam_t *param, uint32_t defval, bool *paramok);
  63. /**
  64. * extract uint parameter, and check range
  65. *
  66. * When \a *paramok is false, it will do nothing. On failure, \a *param
  67. * will be set to false on return.
  68. *
  69. * @param param parameter pointer
  70. * @param minval minimum valid value, inclusive
  71. * @param maxval maximum valid value, inclusive
  72. * @param paramok in/out parameter parsing ok flag
  73. * @return
  74. * - uint parameter
  75. * - 0 on failed
  76. * - \a *paramok is false at input
  77. * - \a param is empty
  78. * - \a param is not integer number
  79. * - \a param is not in range
  80. */
  81. uint32_t atParamUintInRange(atCmdParam_t *param, uint32_t minval, uint32_t maxval, bool *paramok);
  82. /**
  83. * extract optional uint parameter, and check range
  84. *
  85. * When \a *paramok is false, it will do nothing. On failure, \a *param
  86. * will be set to false on return.
  87. *
  88. * When \a param is empty, \a defval is returned. Otherwise, it is the
  89. * same as \a atParamUintInRange. The \a defval is not required in the
  90. * range.
  91. *
  92. * @param param parameter pointer
  93. * @param defval default value
  94. * @param minval minimum valid value, inclusive
  95. * @param maxval maximum valid value, inclusive
  96. * @param paramok in/out parameter parsing ok flag
  97. * @return
  98. * - uint parameter
  99. * - 0 on failed
  100. * - \a *paramok is false at input
  101. * - \a param is not integer number
  102. * - \a param is not in range
  103. */
  104. uint32_t atParamDefUintInRange(atCmdParam_t *param, uint32_t defval, uint32_t minval, uint32_t maxval, bool *paramok);
  105. /**
  106. * extract uint parameter, and check in list
  107. *
  108. * When \a *paramok is false, it will do nothing. On failure, \a *param
  109. * will be set to false on return.
  110. *
  111. * @param param parameter pointer
  112. * @param list array of valid values
  113. * @param count valid value count
  114. * @param paramok in/out parameter parsing ok flag
  115. * @return
  116. * - uint parameter
  117. * - 0 on failed
  118. * - \a *paramok is false at input
  119. * - \a param is empty
  120. * - \a param is not integer number
  121. * - \a param is not in list
  122. */
  123. uint32_t atParamUintInList(atCmdParam_t *param, const uint32_t *list, unsigned count, bool *paramok);
  124. /**
  125. * extract optional uint parameter, and check in list
  126. *
  127. * When \a *paramok is false, it will do nothing. On failure, \a *param
  128. * will be set to false on return.
  129. *
  130. * When \a param is empty, \a defval is returned. Otherwise, it is the
  131. * same as \a atParamUintInList. The \a defval is not required in the
  132. * list.
  133. *
  134. * @param param parameter pointer
  135. * @param defval default value
  136. * @param list array of valid values
  137. * @param count valid value count
  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. * - \a param is not in list
  145. */
  146. uint32_t atParamDefUintInList(atCmdParam_t *param, uint32_t defval, const uint32_t *list, unsigned count, bool *paramok);
  147. /**
  148. * extract int parameter
  149. *
  150. * When \a *paramok is false, it will do nothing. On failure, \a *param
  151. * will be set to false on return.
  152. *
  153. * @param param parameter pointer
  154. * @param paramok in/out parameter parsing ok flag
  155. * @return
  156. * - int parameter
  157. * - 0 on failed
  158. * - \a *paramok is false at input
  159. * - \a param is empty
  160. * - \a param is not integer number
  161. */
  162. int atParamInt(atCmdParam_t *param, bool *paramok);
  163. /**
  164. * extract optional int parameter
  165. *
  166. * When \a *paramok is false, it will do nothing. On failure, \a *param
  167. * will be set to false on return.
  168. *
  169. * When \a param is empty, \a defval is returned. Otherwise, it is the
  170. * same as \a atParamUint.
  171. *
  172. * @param param parameter pointer
  173. * @param defval default value
  174. * @param paramok in/out parameter parsing ok flag
  175. * @return
  176. * - int parameter
  177. * - 0 on failed
  178. * - \a *paramok is false at input
  179. * - \a param is not integer number
  180. */
  181. int atParamDefInt(atCmdParam_t *param, int defval, bool *paramok);
  182. /**
  183. * extract int parameter, and check range
  184. *
  185. * When \a *paramok is false, it will do nothing. On failure, \a *param
  186. * will be set to false on return.
  187. *
  188. * @param param parameter pointer
  189. * @param minval minimum valid value, inclusive
  190. * @param maxval maximum valid value, inclusive
  191. * @param paramok in/out parameter parsing ok flag
  192. * @return
  193. * - int parameter
  194. * - 0 on failed
  195. * - \a *paramok is false at input
  196. * - \a param is empty
  197. * - \a param is not integer number
  198. * - \a param is not in range
  199. */
  200. int atParamIntInRange(atCmdParam_t *param, int minval, int maxval, bool *paramok);
  201. /**
  202. * extract optional int parameter, and check range
  203. *
  204. * When \a *paramok is false, it will do nothing. On failure, \a *param
  205. * will be set to false on return.
  206. *
  207. * When \a param is empty, \a defval is returned. Otherwise, it is the
  208. * same as \a atParamUintInRange. The \a defval is not required in the
  209. * range.
  210. *
  211. * @param param parameter pointer
  212. * @param defval default value
  213. * @param minval minimum valid value, inclusive
  214. * @param maxval maximum valid value, inclusive
  215. * @param paramok in/out parameter parsing ok flag
  216. * @return
  217. * - int parameter
  218. * - 0 on failed
  219. * - \a *paramok is false at input
  220. * - \a param is not integer number
  221. * - \a param is not in range
  222. */
  223. int atParamDefIntInRange(atCmdParam_t *param, int defval, int minval, int maxval, bool *paramok);
  224. /**
  225. * extract int parameter, and check in list
  226. *
  227. * When \a *paramok is false, it will do nothing. On failure, \a *param
  228. * will be set to false on return.
  229. *
  230. * @param param parameter pointer
  231. * @param list array of valid values
  232. * @param count valid value count
  233. * @param paramok in/out parameter parsing ok flag
  234. * @return
  235. * - int parameter
  236. * - 0 on failed
  237. * - \a *paramok is false at input
  238. * - \a param is empty
  239. * - \a param is not integer number
  240. * - \a param is not in list
  241. */
  242. int atParamIntInList(atCmdParam_t *param, const int *list, unsigned count, bool *paramok);
  243. /**
  244. * extract optional int parameter, and check in list
  245. *
  246. * When \a *paramok is false, it will do nothing. On failure, \a *param
  247. * will be set to false on return.
  248. *
  249. * When \a param is empty, \a defval is returned. Otherwise, it is the
  250. * same as \a atParamUintInList. The \a defval is not required in the
  251. * list.
  252. *
  253. * @param param parameter pointer
  254. * @param defval default value
  255. * @param list array of valid values
  256. * @param count valid value count
  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. * - \a param is not in list
  264. */
  265. int atParamDefIntInList(atCmdParam_t *param, int defval, const int *list, unsigned count, bool *paramok);
  266. /**
  267. * extract uint64 parameter
  268. *
  269. * When \a *paramok is false, it will do nothing. On failure, \a *param
  270. * will be set to false on return.
  271. *
  272. * @param param parameter pointer
  273. * @param paramok in/out parameter parsing ok flag
  274. * @return
  275. * - uint parameter
  276. * - 0 on failed
  277. * - \a *paramok is false at input
  278. * - \a param is empty
  279. * - \a param is not integer number
  280. */
  281. uint64_t atParamUint64(atCmdParam_t *param, bool *paramok);
  282. /**
  283. * extract optional uint64 parameter
  284. *
  285. * When \a *paramok is false, it will do nothing. On failure, \a *param
  286. * will be set to false on return.
  287. *
  288. * When \a param is empty, \a defval is returned. Otherwise, it is the
  289. * same as \a atParamUint.
  290. *
  291. * @param param parameter pointer
  292. * @param defval default value
  293. * @param paramok in/out parameter parsing ok flag
  294. * @return
  295. * - uint parameter
  296. * - 0 on failed
  297. * - \a *paramok is false at input
  298. * - \a param is not integer number
  299. */
  300. uint64_t atParamDefUint64(atCmdParam_t *param, uint64_t defval, bool *paramok);
  301. /**
  302. * extract uint64 parameter, and check range
  303. *
  304. * When \a *paramok is false, it will do nothing. On failure, \a *param
  305. * will be set to false on return.
  306. *
  307. * @param param parameter pointer
  308. * @param minval minimum valid value, inclusive
  309. * @param maxval maximum valid value, inclusive
  310. * @param paramok in/out parameter parsing ok flag
  311. * @return
  312. * - uint parameter
  313. * - 0 on failed
  314. * - \a *paramok is false at input
  315. * - \a param is empty
  316. * - \a param is not integer number
  317. * - \a param is not in range
  318. */
  319. uint64_t atParamUint64InRange(atCmdParam_t *param, uint64_t minval, uint64_t maxval, bool *paramok);
  320. /**
  321. * extract optional uint64 parameter, and check range
  322. *
  323. * When \a *paramok is false, it will do nothing. On failure, \a *param
  324. * will be set to false on return.
  325. *
  326. * When \a param is empty, \a defval is returned. Otherwise, it is the
  327. * same as \a atParamUintInRange. The \a defval is not required in the
  328. * range.
  329. *
  330. * @param param parameter pointer
  331. * @param defval default value
  332. * @param minval minimum valid value, inclusive
  333. * @param maxval maximum valid value, inclusive
  334. * @param paramok in/out parameter parsing ok flag
  335. * @return
  336. * - uint parameter
  337. * - 0 on failed
  338. * - \a *paramok is false at input
  339. * - \a param is not integer number
  340. * - \a param is not in range
  341. */
  342. uint64_t atParamDefUint64InRange(atCmdParam_t *param, uint64_t defval, uint64_t minval, uint64_t maxval, bool *paramok);
  343. /**
  344. * extract uint64 parameter, and check in list
  345. *
  346. * When \a *paramok is false, it will do nothing. On failure, \a *param
  347. * will be set to false on return.
  348. *
  349. * @param param parameter pointer
  350. * @param list array of valid values
  351. * @param count valid value count
  352. * @param paramok in/out parameter parsing ok flag
  353. * @return
  354. * - uint parameter
  355. * - 0 on failed
  356. * - \a *paramok is false at input
  357. * - \a param is empty
  358. * - \a param is not integer number
  359. * - \a param is not in list
  360. */
  361. uint64_t atParamUint64InList(atCmdParam_t *param, const uint64_t *list, unsigned count, bool *paramok);
  362. /**
  363. * extract optional uint64 parameter, and check in list
  364. *
  365. * When \a *paramok is false, it will do nothing. On failure, \a *param
  366. * will be set to false on return.
  367. *
  368. * When \a param is empty, \a defval is returned. Otherwise, it is the
  369. * same as \a atParamUintInList. The \a defval is not required in the
  370. * list.
  371. *
  372. * @param param parameter pointer
  373. * @param defval default value
  374. * @param list array of valid values
  375. * @param count valid value count
  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. * - \a param is not in list
  383. */
  384. uint64_t atParamDefUint64InList(atCmdParam_t *param, uint64_t defval, const uint64_t *list, unsigned count, bool *paramok);
  385. /**
  386. * extract int64 parameter
  387. *
  388. * When \a *paramok is false, it will do nothing. On failure, \a *param
  389. * will be set to false on return.
  390. *
  391. * @param param parameter pointer
  392. * @param paramok in/out parameter parsing ok flag
  393. * @return
  394. * - int parameter
  395. * - 0 on failed
  396. * - \a *paramok is false at input
  397. * - \a param is empty
  398. * - \a param is not integer number
  399. */
  400. int64_t atParamInt64(atCmdParam_t *param, bool *paramok);
  401. /**
  402. * extract optional int64 parameter
  403. *
  404. * When \a *paramok is false, it will do nothing. On failure, \a *param
  405. * will be set to false on return.
  406. *
  407. * When \a param is empty, \a defval is returned. Otherwise, it is the
  408. * same as \a atParamUint.
  409. *
  410. * @param param parameter pointer
  411. * @param defval default value
  412. * @param paramok in/out parameter parsing ok flag
  413. * @return
  414. * - int parameter
  415. * - 0 on failed
  416. * - \a *paramok is false at input
  417. * - \a param is not integer number
  418. */
  419. int64_t atParamDefInt64(atCmdParam_t *param, int64_t defval, bool *paramok);
  420. /**
  421. * extract int64 parameter, and check range
  422. *
  423. * When \a *paramok is false, it will do nothing. On failure, \a *param
  424. * will be set to false on return.
  425. *
  426. * @param param parameter pointer
  427. * @param minval minimum valid value, inclusive
  428. * @param maxval maximum valid value, inclusive
  429. * @param paramok in/out parameter parsing ok flag
  430. * @return
  431. * - int parameter
  432. * - 0 on failed
  433. * - \a *paramok is false at input
  434. * - \a param is empty
  435. * - \a param is not integer number
  436. * - \a param is not in range
  437. */
  438. int64_t atParamInt64InRange(atCmdParam_t *param, int64_t minval, int64_t maxval, bool *paramok);
  439. /**
  440. * extract optional int64 parameter, and check range
  441. *
  442. * When \a *paramok is false, it will do nothing. On failure, \a *param
  443. * will be set to false on return.
  444. *
  445. * When \a param is empty, \a defval is returned. Otherwise, it is the
  446. * same as \a atParamUintInRange. The \a defval is not required in the
  447. * range.
  448. *
  449. * @param param parameter pointer
  450. * @param defval default value
  451. * @param minval minimum valid value, inclusive
  452. * @param maxval maximum valid value, inclusive
  453. * @param paramok in/out parameter parsing ok flag
  454. * @return
  455. * - int parameter
  456. * - 0 on failed
  457. * - \a *paramok is false at input
  458. * - \a param is not integer number
  459. * - \a param is not in range
  460. */
  461. int64_t atParamDefInt64InRange(atCmdParam_t *param, int64_t defval, int64_t minval, int64_t maxval, bool *paramok);
  462. /**
  463. * extract int64 parameter, and check in list
  464. *
  465. * When \a *paramok is false, it will do nothing. On failure, \a *param
  466. * will be set to false on return.
  467. *
  468. * @param param parameter pointer
  469. * @param list array of valid values
  470. * @param count valid value count
  471. * @param paramok in/out parameter parsing ok flag
  472. * @return
  473. * - int parameter
  474. * - 0 on failed
  475. * - \a *paramok is false at input
  476. * - \a param is empty
  477. * - \a param is not integer number
  478. * - \a param is not in list
  479. */
  480. int64_t atParamInt64InList(atCmdParam_t *param, const int64_t *list, unsigned count, bool *paramok);
  481. /**
  482. * extract optional int64 parameter, and check in list
  483. *
  484. * When \a *paramok is false, it will do nothing. On failure, \a *param
  485. * will be set to false on return.
  486. *
  487. * When \a param is empty, \a defval is returned. Otherwise, it is the
  488. * same as \a atParamUintInList. The \a defval is not required in the
  489. * list.
  490. *
  491. * @param param parameter pointer
  492. * @param defval default value
  493. * @param list array of valid values
  494. * @param count valid value count
  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. * - \a param is not in list
  502. */
  503. int64_t atParamDefInt64InList(atCmdParam_t *param, int64_t defval, const int64_t *list, unsigned count, bool *paramok);
  504. /**
  505. * extract string parameter
  506. *
  507. * When \a *paramok is false, it will do nothing. On failure, \a *param
  508. * will be set to false on return.
  509. *
  510. * String parameter is parameter started and ended with double quotation.
  511. * The escape defined in V.250 is \\HH. For example, \30 for '0'.
  512. *
  513. * It is possible that the internal storage will be changed during this
  514. * function call. So, don't call other parameter APIs for the same
  515. * parameter after it is called. However, this function itself can be
  516. * called again.
  517. *
  518. * The output pointer will be valid till the parameter itself is deleted.
  519. *
  520. * The output string is ended with null byte for end of string.
  521. *
  522. * @param param parameter pointer
  523. * @param paramok in/out parameter parsing ok flag
  524. * @return
  525. * - parsed string
  526. * - NULL on failed
  527. * - \a *paramok is false at input
  528. * - \a param is empty
  529. * - \a param is not string (start and end with double quotation)
  530. */
  531. const char *atParamStr(atCmdParam_t *param, bool *paramok);
  532. /**
  533. * extract hex or str parameter from raw text
  534. *
  535. * When \a *paramok is false, it will do nothing. On failure, \a *param
  536. * will be set to false on return.
  537. *
  538. * Raw text parameter is parameter started and ended without double quotation.
  539. * The escape defined in V.250 is \\HH. For example, \30 for '0'.
  540. *
  541. * It is possible that the internal storage will be changed during this
  542. * function call. So, don't call other parameter APIs for the same
  543. * parameter after it is called. However, this function itself can be
  544. * called again.
  545. *
  546. * The output pointer will be valid till the parameter itself is deleted.
  547. *
  548. * The output string is ended with null byte for end of string.
  549. *
  550. * @param param parameter pointer
  551. * @param len the length of the parameter
  552. * @param paramok in/out parameter parsing ok flag
  553. * @return
  554. * - parsed string
  555. * - NULL on failed
  556. * - \a *paramok is false at input
  557. * - \a param is empty
  558. * - \a param is string (start and end with double quotation)
  559. */
  560. const char *atParamHexData(atCmdParam_t *param, uint32_t len, bool *paramok);
  561. /**
  562. * extract hex parameter from raw text
  563. *
  564. * When \a *paramok is false, it will do nothing. On failure, \a *param
  565. * will be set to false on return.
  566. *
  567. * Raw text parameter is parameter started and ended without double quotation.
  568. * The escape defined in V.250 is \\HH. For example, \30 for '0'.
  569. *
  570. * It is possible that the internal storage will be changed during this
  571. * function call. So, don't call other parameter APIs for the same
  572. * parameter after it is called. However, this function itself can be
  573. * called again.
  574. *
  575. * The output pointer will be valid till the parameter itself is deleted.
  576. *
  577. * The output string is ended with null byte for end of string.
  578. *
  579. * @param param parameter pointer
  580. * @param len the length of the parameter
  581. * @param paramok in/out parameter parsing ok flag
  582. * @return
  583. * - parsed string
  584. * - NULL on failed
  585. * - \a *paramok is false at input
  586. * - \a param is empty
  587. * - \a param is string (start and end with double quotation)
  588. */
  589. const char *atParamHexRawText(atCmdParam_t *param, uint32_t len, bool *paramok);
  590. /**
  591. * extract string parameter
  592. *
  593. * When \a *paramok is false, it will do nothing. On failure, \a *param
  594. * will be set to false on return.
  595. *
  596. * String parameter is parameter started and ended with double quotation.
  597. * The escape defined in V.250 is \\HH. For example, \30 for '0'.
  598. *
  599. * It is possible that the internal storage will be changed during this
  600. * function call. So, don't call other parameter APIs for the same
  601. * parameter after it is called. However, this function itself can be
  602. * called again.
  603. *
  604. * The output pointer will be valid till the parameter itself is deleted.
  605. *
  606. * The output string is ended with null byte for end of string.
  607. *
  608. * @param param parameter pointer
  609. * @param paramok in/out parameter parsing ok flag
  610. * @return
  611. * - parsed string
  612. * - NULL on failed
  613. * - \a *paramok is false at input
  614. * - \a param is empty
  615. * - \a param is not string (start and end with double quotation)
  616. */
  617. const char *atParamOptStr(atCmdParam_t *param, bool *paramok);
  618. /**
  619. * extract optional string parameter
  620. *
  621. * When \a *paramok is false, it will do nothing. On failure, \a *param
  622. * will be set to false on return.
  623. *
  624. * When \a param is empty, \a defval is returned. Otherwise, it is the
  625. * same as \a atParamStr.
  626. *
  627. * It is possible that the internal storage will be changed during this
  628. * function call. So, don't call other parameter APIs for the same
  629. * parameter after it is called. However, this function itself can be
  630. * called again.
  631. *
  632. * @param param parameter pointer
  633. * @param defval default value
  634. * @param paramok in/out parameter parsing ok flag
  635. * @return
  636. * - parsed string
  637. * - NULL on failed
  638. * - \a *paramok is false at input
  639. * - \a param is not string (start and end with double quotation)
  640. */
  641. const char *atParamDefStr(atCmdParam_t *param, const char *defval, bool *paramok);
  642. /**
  643. * extract raw parameter
  644. *
  645. * When \a *paramok is false, it will do nothing. On failure, \a *param
  646. * will be set to false on return.
  647. *
  648. * The raw parameter is not parsed. For example, the double quotation of
  649. * string parameter will be kept, and the escape in string parameter is
  650. * untouched.
  651. *
  652. * The output string is ended with null byte as end of string.
  653. *
  654. * @param param parameter pointer
  655. * @param paramok in/out parameter parsing ok flag
  656. * @return
  657. * - parsed string
  658. * - NULL on failed
  659. * - \a *paramok is false at input
  660. * - \a param is empty
  661. */
  662. const char *atParamRawText(atCmdParam_t *param, bool *paramok);
  663. /**
  664. * extract floating point parameter
  665. *
  666. * When \a *paramok is false, it will do nothing. On failure, \a *param
  667. * will be set to false on return.
  668. *
  669. * @param param parameter pointer
  670. * @param paramok in/out parameter parsing ok flag
  671. * @return
  672. * - floating point parameter
  673. * - NULL on failed
  674. * - \a *paramok is false at input
  675. * - \a param is empty
  676. * - \a param is not double
  677. */
  678. double atParamDouble(atCmdParam_t *param, bool *paramok);
  679. /**
  680. * extract DTMF parameter
  681. *
  682. * When \a *paramok is false, it will do nothing. On failure, \a *param
  683. * will be set to false on return.
  684. *
  685. * There are 2 kinds of DTMF parameter:
  686. * - one DTMF character without double quotation
  687. * - multiple DTMF chaeacters with double quotation
  688. * In both case, the return value is DTMF character string with null byte
  689. * as the string end.
  690. *
  691. * It will not check whether DTMF characters inside the string is valid
  692. * DTMF character. Application should validate them.
  693. *
  694. * It is possible that the internal storage will be changed during this
  695. * function call. So, don't call other parameter APIs for the same
  696. * parameter after it is called. However, this function itself can be
  697. * called again.
  698. *
  699. * @param param parameter pointer
  700. * @param paramok in/out parameter parsing ok flag
  701. * @return
  702. * - parsed DTMF string
  703. * - NULL on failed
  704. * - \a *paramok is false at input
  705. * - \a param is empty
  706. * - \a param is not DTMF
  707. */
  708. const char *atParamDtmf(atCmdParam_t *param, bool *paramok);
  709. /**
  710. * extract string parameter and return mapped uint
  711. *
  712. * When \a *paramok is false, it will do nothing. On failure, \a *param
  713. * will be set to false on return.
  714. *
  715. * It is just a wrapper to:
  716. * - extract string parameter
  717. * - map to uint
  718. *
  719. * @param param parameter pointer
  720. * @param vsmap integer/string map, ended with NULL string value
  721. * @param paramok in/out parameter parsing ok flag
  722. * @return
  723. * - uint parameter
  724. * - NULL on failed
  725. * - \a *paramok is false at input
  726. * - \a param is empty
  727. * - \a param is not in map
  728. */
  729. uint32_t atParamUintByStrMap(atCmdParam_t *param, const osiValueStrMap_t *vsmap, bool *paramok);
  730. /**
  731. * extract optional string parameter and return mapped uint
  732. *
  733. * When \a *paramok is false, it will do nothing. On failure, \a *param
  734. * will be set to false on return.
  735. *
  736. * When \a param is empty, \a defval is returned. Otherwise, it is the
  737. * same as \a atParamUintByStrMap. The \a defval is not required in the
  738. * map.
  739. *
  740. * @param param parameter pointer
  741. * @param defval default value
  742. * @param vsmap integer/string map, ended with NULL string value
  743. * @param paramok in/out parameter parsing ok flag
  744. * @return
  745. * - uint parameter
  746. * - NULL on failed
  747. * - \a *paramok is false at input
  748. * - \a param is not in map
  749. */
  750. uint32_t atParamDefUintByStrMap(atCmdParam_t *param, uint32_t defval, const osiValueStrMap_t *vsmap, bool *paramok);
  751. /**
  752. * extract uint parameter by hex string
  753. *
  754. * When \a *paramok is false, it will do nothing. On failure, \a *param
  755. * will be set to false on return.
  756. *
  757. * The valid parameter is the output of:
  758. * \code{.cpp}
  759. * printf("\"%x\"", value)
  760. * \endcode
  761. *
  762. * For example, parameter "12345" will be parsed as 0x12345.
  763. *
  764. * @param param parameter pointer
  765. * @param paramok in/out parameter parsing ok flag
  766. * @return
  767. * - uint parameter
  768. * - NULL on failed
  769. * - \a *paramok is false at input
  770. * - \a param is empty
  771. * - \a param is not the needed format
  772. */
  773. uint32_t atParamHexStrUint(atCmdParam_t *param, bool *paramok);
  774. /**
  775. * trim tailing characters at the end of parameter
  776. *
  777. * This shall be called before the parameter isn't parsed. \p atParamRawText
  778. * won't parse the parameter, so it is safe to call it after \p atParamRawText.
  779. *
  780. * It will change the internal storage of parameter directly. So, only call
  781. * it when absolutely needed, and you know what you are doing.
  782. *
  783. * @param param parameter pointer
  784. * @param len length after trim
  785. * @return
  786. * - true on success
  787. * - false on failed
  788. * - \p param type is not raw text
  789. * - the length of parameter is shorter than \p len
  790. */
  791. bool atParamTrimTail(atCmdParam_t *param, uint32_t len);
  792. /**
  793. * check whether the parameter is empty
  794. *
  795. * Both not specified and skipped parameter are empty. For example:
  796. * - AT+CMD=123
  797. * - AT+CMD=123,
  798. * - AT+CMD=123,,456
  799. *
  800. * In all of the above cases, params[1] is empty.
  801. *
  802. * @param param parameter pointer
  803. * @return
  804. * - true if the parameter is empty
  805. * - false otherwise
  806. */
  807. bool atParamIsEmpty(atCmdParam_t *param);
  808. #ifdef CONFIG_QUEC_PROJECT_FEATURE
  809. /**
  810. * extract hex int64_t parameter, and check range
  811. *
  812. * When \a *paramok is false, it will do nothing. On failure, \a *param
  813. * will be set to false on return.
  814. *
  815. * @param param parameter pointer
  816. * @param minval minimum valid value, inclusive
  817. * @param maxval maximum valid value, inclusive
  818. * @param paramok in/out parameter parsing ok flag
  819. * @return
  820. * - uint parameter
  821. * - 0 on failed
  822. * - \a *paramok is false at input
  823. * - \a param is empty
  824. * - \a param is not integer number
  825. * - \a param is not in range
  826. */
  827. int64_t atParamHexInt64InRange(atCmdParam_t *param, int64_t minval, int64_t maxval, bool *paramok);
  828. #endif
  829. #else
  830. #include "quec_at_param.h"
  831. typedef ql_at_param_t atCmdParam_t;
  832. #define atParamUint quec_atParamUint
  833. #define atParamDefUint quec_atParamDefUint
  834. #define atParamUintInRange quec_atParamUintInRange
  835. #define atParamDefUintInRange quec_atParamDefUintInRange
  836. #define atParamUintInList quec_atParamUintInList
  837. #define atParamDefUintInList quec_atParamDefUintInList
  838. #define atParamInt quec_atParamInt
  839. #define atParamDefInt quec_atParamDefInt
  840. #define atParamIntInRange quec_atParamIntInRange
  841. #define atParamDefIntInRange quec_atParamDefIntInRange
  842. #define atParamIntInList quec_atParamIntInList
  843. #define atParamDefIntInList quec_atParamDefIntInList
  844. #define atParamUint64 quec_atParamUint64
  845. #define atParamDefUint64 quec_atParamDefUint64
  846. #define atParamUint64InRange quec_atParamUint64InRange
  847. #define atParamDefUint64InRange quec_atParamDefUint64InRange
  848. #define atParamUint64InList quec_atParamUint64InList
  849. #define atParamDefUint64InList quec_atParamDefUint64InList
  850. #define atParamInt64 quec_atParamInt64
  851. #define atParamDefInt64 quec_atParamDefInt64
  852. #define atParamInt64InRange quec_atParamInt64InRange
  853. #define atParamDefInt64InRange quec_atParamDefInt64InRange
  854. #define atParamInt64InList quec_atParamInt64InList
  855. #define atParamDefInt64InList quec_atParamDefInt64InList
  856. #define atParamStr quec_atParamStr
  857. #define atParamDefStr quec_atParamDefStr
  858. #define atParamRawText quec_atParamRawText
  859. #define atParamOptStr quec_atParamOptStr
  860. #define atParamIsEmpty quec_atParamIsEmpty
  861. #define atParamHexRawText quec_atParamHexRawText
  862. #define atParamTrimTail quec_atParamTrimTail
  863. #define atParamHexData quec_atParamHexData
  864. #define atParamUintByStrMap(param, vsmap, paramok)\
  865. quec_atParamUintByStrMap(param, (const quec_ValueStrMap_t *)vsmap, paramok)
  866. #define atParamDefUintByStrMap(param, defval, vsmap, paramok)\
  867. quec_atParamDefUintByStrMap(param, defval, (const quec_ValueStrMap_t *)vsmap, paramok)
  868. #endif
  869. #endif