app_mw_ant.c 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868
  1. /**
  2. * Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #include <stdint.h>
  41. #include "ant_interface.h"
  42. #include "ble_serialization.h"
  43. #include "ant_app.h"
  44. #include "ser_sd_transport.h"
  45. #include "app_error.h"
  46. static void * mp_out_params[3];
  47. static void tx_buf_alloc(uint8_t * * p_data, uint32_t * p_len)
  48. {
  49. uint32_t err_code;
  50. uint16_t len16;
  51. do
  52. {
  53. err_code = ser_sd_transport_tx_alloc(p_data, &len16);
  54. }
  55. while (err_code != NRF_SUCCESS);
  56. *p_data[0] = SER_PKT_TYPE_ANT_CMD;
  57. *p_len = (uint32_t)len16 - 1;
  58. }
  59. /**@brief Command response callback function for @ref sd_ant_enable ANT command.
  60. *
  61. * Callback for decoding the output parameters and the command response return code.
  62. *
  63. * @param[in] p_buffer Pointer to begin of command response buffer.
  64. * @param[in] length Length of data in bytes.
  65. *
  66. * @return Decoded command response return code.
  67. */
  68. static uint32_t enable_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  69. {
  70. uint32_t result_code;
  71. const uint32_t err_code = ant_enable_rsp_dec(p_buffer,
  72. length,
  73. &result_code);
  74. //@note: Should never fail.
  75. APP_ERROR_CHECK(err_code);
  76. return result_code;
  77. }
  78. uint32_t sd_ant_enable(ANT_ENABLE * const p_ant_enable)
  79. {
  80. uint8_t * p_buffer;
  81. uint32_t buffer_length;
  82. tx_buf_alloc(&p_buffer, &buffer_length);
  83. const uint32_t err_code = ant_enable_req_enc(p_ant_enable,
  84. &(p_buffer[1]),
  85. &buffer_length);
  86. APP_ERROR_CHECK(err_code);
  87. //@note: Increment buffer length as internally managed packet type field must be included.
  88. return ser_sd_transport_cmd_write(p_buffer,
  89. (++buffer_length),
  90. enable_rsp_dec);
  91. }
  92. /**@brief Command response callback function for @ref sd_ant_channel_assign ANT command.
  93. *
  94. * Callback for decoding the output parameters and the command response return code.
  95. *
  96. * @param[in] p_buffer Pointer to begin of command response buffer.
  97. * @param[in] length Length of data in bytes.
  98. *
  99. * @return Decoded command response return code.
  100. */
  101. static uint32_t channel_assign_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  102. {
  103. uint32_t result_code;
  104. const uint32_t err_code = ant_channel_assign_rsp_dec(p_buffer,
  105. length,
  106. &result_code);
  107. //@note: Should never fail.
  108. APP_ERROR_CHECK(err_code);
  109. return result_code;
  110. }
  111. uint32_t sd_ant_channel_assign(uint8_t channel, uint8_t channel_type, uint8_t network, uint8_t ext_assign)
  112. {
  113. uint8_t * p_buffer;
  114. uint32_t buffer_length;
  115. tx_buf_alloc(&p_buffer, &buffer_length);
  116. const uint32_t err_code = ant_channel_assign_req_enc(channel,
  117. channel_type,
  118. network,
  119. ext_assign,
  120. &(p_buffer[1]),
  121. &buffer_length);
  122. APP_ERROR_CHECK(err_code);
  123. //@note: Increment buffer length as internally managed packet type field must be included.
  124. return ser_sd_transport_cmd_write(p_buffer,
  125. (++buffer_length),
  126. channel_assign_rsp_dec);
  127. }
  128. /**@brief Command response callback function for @ref sd_ant_channel_open_with_offset ANT command.
  129. *
  130. * Callback for decoding the output parameters and the command response return code.
  131. *
  132. * @param[in] p_buffer Pointer to begin of command response buffer.
  133. * @param[in] length Length of data in bytes.
  134. *
  135. * @return Decoded command response return code.
  136. */
  137. static uint32_t channel_open_with_offset_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  138. {
  139. uint32_t result_code;
  140. const uint32_t err_code = ant_channel_open_with_offset_rsp_dec(p_buffer,
  141. length,
  142. &result_code);
  143. //@note: Should never fail.
  144. APP_ERROR_CHECK(err_code);
  145. return result_code;
  146. }
  147. uint32_t sd_ant_channel_open_with_offset(uint8_t channel, uint16_t usOffset)
  148. {
  149. uint8_t * p_buffer;
  150. uint32_t buffer_length;
  151. tx_buf_alloc(&p_buffer, &buffer_length);
  152. const uint32_t err_code = ant_channel_open_with_offset_req_enc(channel,
  153. usOffset,
  154. &(p_buffer[1]),
  155. &buffer_length);
  156. APP_ERROR_CHECK(err_code);
  157. //@note: Increment buffer length as internally managed packet type field must be included.
  158. return ser_sd_transport_cmd_write(p_buffer,
  159. (++buffer_length),
  160. channel_open_with_offset_rsp_dec);
  161. }
  162. /**@brief Command response callback function for @ref sd_ant_channel_id_set ANT command.
  163. *
  164. * Callback for decoding the output parameters and the command response return code.
  165. *
  166. * @param[in] p_buffer Pointer to begin of command response buffer.
  167. * @param[in] length Length of data in bytes.
  168. *
  169. * @return Decoded command response return code.
  170. */
  171. static uint32_t channel_id_set_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  172. {
  173. uint32_t result_code;
  174. const uint32_t err_code = ant_channel_id_set_rsp_dec(p_buffer,
  175. length,
  176. &result_code);
  177. //@note: Should never fail.
  178. APP_ERROR_CHECK(err_code);
  179. return result_code;
  180. }
  181. uint32_t sd_ant_channel_id_set (uint8_t channel, uint16_t device_number, uint8_t device_type, uint8_t transmit_type)
  182. {
  183. uint8_t * p_buffer;
  184. uint32_t buffer_length;
  185. tx_buf_alloc(&p_buffer, &buffer_length);
  186. const uint32_t err_code = ant_channel_id_set_req_enc(channel,
  187. device_number,
  188. device_type,
  189. transmit_type,
  190. &(p_buffer[1]),
  191. &buffer_length);
  192. APP_ERROR_CHECK(err_code);
  193. //@note: Increment buffer length as internally managed packet type field must be included.
  194. return ser_sd_transport_cmd_write(p_buffer,
  195. (++buffer_length),
  196. channel_id_set_rsp_dec);
  197. }
  198. /**@brief Command response callback function for @ref sd_ant_channel_period_set ANT command.
  199. *
  200. * Callback for decoding the output parameters and the command response return code.
  201. *
  202. * @param[in] p_buffer Pointer to begin of command response buffer.
  203. * @param[in] length Length of data in bytes.
  204. *
  205. * @return Decoded command response return code.
  206. */
  207. static uint32_t channel_period_set_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  208. {
  209. uint32_t result_code;
  210. const uint32_t err_code = ant_channel_period_set_rsp_dec(p_buffer,
  211. length,
  212. &result_code);
  213. //@note: Should never fail.
  214. APP_ERROR_CHECK(err_code);
  215. return result_code;
  216. }
  217. uint32_t sd_ant_channel_period_set(uint8_t channel, uint16_t period)
  218. {
  219. uint8_t * p_buffer;
  220. uint32_t buffer_length;
  221. tx_buf_alloc(&p_buffer, &buffer_length);
  222. const uint32_t err_code = ant_channel_period_set_req_enc(channel,
  223. period,
  224. &(p_buffer[1]),
  225. &buffer_length);
  226. APP_ERROR_CHECK(err_code);
  227. //@note: Increment buffer length as internally managed packet type field must be included.
  228. return ser_sd_transport_cmd_write(p_buffer,
  229. (++buffer_length),
  230. channel_period_set_rsp_dec);
  231. }
  232. /**@brief Command response callback function for @ref sd_ant_channel_radio_freq_set ANT command.
  233. *
  234. * Callback for decoding the output parameters and the command response return code.
  235. *
  236. * @param[in] p_buffer Pointer to begin of command response buffer.
  237. * @param[in] length Length of data in bytes.
  238. *
  239. * @return Decoded command response return code.
  240. */
  241. static uint32_t channel_radio_freq_set_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  242. {
  243. uint32_t result_code;
  244. const uint32_t err_code = ant_channel_radio_freq_set_rsp_dec(p_buffer,
  245. length,
  246. &result_code);
  247. //@note: Should never fail.
  248. APP_ERROR_CHECK(err_code);
  249. return result_code;
  250. }
  251. uint32_t sd_ant_channel_radio_freq_set (uint8_t channel, uint8_t freq)
  252. {
  253. uint8_t * p_buffer;
  254. uint32_t buffer_length;
  255. tx_buf_alloc(&p_buffer, &buffer_length);
  256. const uint32_t err_code = ant_channel_radio_freq_set_req_enc(channel,
  257. freq,
  258. &(p_buffer[1]),
  259. &buffer_length);
  260. APP_ERROR_CHECK(err_code);
  261. //@note: Increment buffer length as internally managed packet type field must be included.
  262. return ser_sd_transport_cmd_write(p_buffer,
  263. (++buffer_length),
  264. channel_radio_freq_set_rsp_dec);
  265. }
  266. /**@brief Command response callback function for @ref sd_ant_broadcast_message_tx ANT command.
  267. *
  268. * Callback for decoding the output parameters and the command response return code.
  269. *
  270. * @param[in] p_buffer Pointer to begin of command response buffer.
  271. * @param[in] length Length of data in bytes.
  272. *
  273. * @return Decoded command response return code.
  274. */
  275. static uint32_t broadcast_message_tx_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  276. {
  277. uint32_t result_code;
  278. const uint32_t err_code = ant_broadcast_message_tx_rsp_dec(p_buffer,
  279. length,
  280. &result_code);
  281. //@note: Should never fail.
  282. APP_ERROR_CHECK(err_code);
  283. return result_code;
  284. }
  285. uint32_t sd_ant_broadcast_message_tx(uint8_t channel, uint8_t size, uint8_t * p_mesg)
  286. {
  287. uint8_t * p_buffer;
  288. uint32_t buffer_length;
  289. tx_buf_alloc(&p_buffer, &buffer_length);
  290. const uint32_t err_code = ant_broadcast_message_tx_req_enc(channel,
  291. size,
  292. p_mesg,
  293. &(p_buffer[1]),
  294. &buffer_length);
  295. APP_ERROR_CHECK(err_code);
  296. //@note: Increment buffer length as internally managed packet type field must be included.
  297. return ser_sd_transport_cmd_write(p_buffer,
  298. (++buffer_length),
  299. broadcast_message_tx_rsp_dec);
  300. }
  301. /**@brief Command response callback function for @ref sd_ant_acknowledge_message_tx ANT command.
  302. *
  303. * Callback for decoding the output parameters and the command response return code.
  304. *
  305. * @param[in] p_buffer Pointer to begin of command response buffer.
  306. * @param[in] length Length of data in bytes.
  307. *
  308. * @return Decoded command response return code.
  309. */
  310. static uint32_t acknowledge_message_tx_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  311. {
  312. uint32_t result_code;
  313. const uint32_t err_code = ant_acknowledge_message_tx_rsp_dec(p_buffer,
  314. length,
  315. &result_code);
  316. //@note: Should never fail.
  317. APP_ERROR_CHECK(err_code);
  318. return result_code;
  319. }
  320. uint32_t sd_ant_acknowledge_message_tx(uint8_t channel, uint8_t size, uint8_t * p_mesg)
  321. {
  322. uint8_t * p_buffer;
  323. uint32_t buffer_length;
  324. tx_buf_alloc(&p_buffer, &buffer_length);
  325. const uint32_t err_code = ant_acknowledge_message_tx_req_enc(channel,
  326. size,
  327. p_mesg,
  328. &(p_buffer[1]),
  329. &buffer_length);
  330. APP_ERROR_CHECK(err_code);
  331. //@note: Increment buffer length as internally managed packet type field must be included.
  332. return ser_sd_transport_cmd_write(p_buffer,
  333. (++buffer_length),
  334. acknowledge_message_tx_rsp_dec);
  335. }
  336. /**@brief Command response callback function for @ref sd_ant_channel_unassign ANT command.
  337. *
  338. * Callback for decoding the output parameters and the command response return code.
  339. *
  340. * @param[in] p_buffer Pointer to begin of command response buffer.
  341. * @param[in] length Length of data in bytes.
  342. *
  343. * @return Decoded command response return code.
  344. */
  345. static uint32_t channel_unassign_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  346. {
  347. uint32_t result_code;
  348. const uint32_t err_code = ant_channel_unassign_rsp_dec(p_buffer,
  349. length,
  350. &result_code);
  351. //@note: Should never fail.
  352. APP_ERROR_CHECK(err_code);
  353. return result_code;
  354. }
  355. uint32_t sd_ant_channel_unassign(uint8_t channel)
  356. {
  357. uint8_t * p_buffer;
  358. uint32_t buffer_length;
  359. tx_buf_alloc(&p_buffer, &buffer_length);
  360. const uint32_t err_code = ant_channel_unassign_req_enc(channel,
  361. &(p_buffer[1]),
  362. &buffer_length);
  363. APP_ERROR_CHECK(err_code);
  364. //@note: Increment buffer length as internally managed packet type field must be included.
  365. return ser_sd_transport_cmd_write(p_buffer,
  366. (++buffer_length),
  367. channel_unassign_rsp_dec);
  368. }
  369. /**@brief Command response callback function for @ref sd_ant_channel_close ANT command.
  370. *
  371. * Callback for decoding the output parameters and the command response return code.
  372. *
  373. * @param[in] p_buffer Pointer to begin of command response buffer.
  374. * @param[in] length Length of data in bytes.
  375. *
  376. * @return Decoded command response return code.
  377. */
  378. static uint32_t channel_close_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  379. {
  380. uint32_t result_code;
  381. const uint32_t err_code = ant_channel_close_rsp_dec(p_buffer,
  382. length,
  383. &result_code);
  384. //@note: Should never fail.
  385. APP_ERROR_CHECK(err_code);
  386. return result_code;
  387. }
  388. uint32_t sd_ant_channel_close(uint8_t channel)
  389. {
  390. uint8_t * p_buffer;
  391. uint32_t buffer_length;
  392. tx_buf_alloc(&p_buffer, &buffer_length);
  393. const uint32_t err_code = ant_channel_close_req_enc(channel,
  394. &(p_buffer[1]),
  395. &buffer_length);
  396. APP_ERROR_CHECK(err_code);
  397. //@note: Increment buffer length as internally managed packet type field must be included.
  398. return ser_sd_transport_cmd_write(p_buffer,
  399. (++buffer_length),
  400. channel_close_rsp_dec);
  401. }
  402. /**@brief Command response callback function for @ref sd_ant_network_address_set ANT command.
  403. *
  404. * Callback for decoding the output parameters and the command response return code.
  405. *
  406. * @param[in] p_buffer Pointer to begin of command response buffer.
  407. * @param[in] length Length of data in bytes.
  408. *
  409. * @return Decoded command response return code.
  410. */
  411. static uint32_t network_address_set_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  412. {
  413. uint32_t result_code;
  414. const uint32_t err_code = ant_network_address_set_rsp_dec(p_buffer,
  415. length,
  416. &result_code);
  417. //@note: Should never fail
  418. APP_ERROR_CHECK(err_code);
  419. return result_code;
  420. }
  421. uint32_t sd_ant_network_address_set(uint8_t network, const uint8_t * p_network_key)
  422. {
  423. uint8_t * p_buffer;
  424. uint32_t buffer_length;
  425. tx_buf_alloc(&p_buffer, &buffer_length);
  426. const uint32_t err_code = ant_network_address_set_req_enc(network,
  427. p_network_key,
  428. &(p_buffer[1]),
  429. &buffer_length);
  430. APP_ERROR_CHECK(err_code);
  431. //@note: Increment buffer length as internally managed packet type field must be included.
  432. return ser_sd_transport_cmd_write(p_buffer,
  433. (++buffer_length),
  434. network_address_set_rsp_dec);
  435. }
  436. /**@brief Command response callback function for @ref sd_ant_channel_radio_tx_power_set ANT command.
  437. *
  438. * Callback for decoding the output parameters and the command response return code.
  439. *
  440. * @param[in] p_buffer Pointer to begin of command response buffer.
  441. * @param[in] length Length of data in bytes.
  442. *
  443. * @return Decoded command response return code.
  444. */
  445. static uint32_t channel_radio_tx_power_set_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  446. {
  447. uint32_t result_code;
  448. const uint32_t err_code = ant_channel_radio_tx_power_set_rsp_dec(p_buffer,
  449. length,
  450. &result_code);
  451. //@note: Should never fail
  452. APP_ERROR_CHECK(err_code);
  453. return result_code;
  454. }
  455. uint32_t sd_ant_channel_radio_tx_power_set(uint8_t channel, uint8_t tx_power, uint8_t custom_tx_power)
  456. {
  457. uint8_t * p_buffer;
  458. uint32_t buffer_length;
  459. tx_buf_alloc(&p_buffer, &buffer_length);
  460. const uint32_t err_code = ant_channel_radio_tx_power_set_req_enc(channel,
  461. tx_power,
  462. custom_tx_power,
  463. &(p_buffer[1]),
  464. &buffer_length);
  465. APP_ERROR_CHECK(err_code);
  466. //@note: Increment buffer length as internally managed packet type field must be included.
  467. return ser_sd_transport_cmd_write(p_buffer,
  468. (++buffer_length),
  469. channel_radio_tx_power_set_rsp_dec);
  470. }
  471. /**@brief Command response callback function for @ref sd_ant_channel_rx_search_timeout_set ANT command.
  472. *
  473. * Callback for decoding the output parameters and the command response return code.
  474. *
  475. * @param[in] p_buffer Pointer to begin of command response buffer.
  476. * @param[in] length Length of data in bytes.
  477. *
  478. * @return Decoded command response return code.
  479. */
  480. static uint32_t channel_rx_search_timeout_set_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  481. {
  482. uint32_t result_code;
  483. const uint32_t err_code = ant_channel_rx_search_timeout_set_rsp_dec(p_buffer,
  484. length,
  485. &result_code);
  486. //@note: Should never fail
  487. APP_ERROR_CHECK(err_code);
  488. return result_code;
  489. }
  490. uint32_t sd_ant_channel_rx_search_timeout_set(uint8_t channel, uint8_t timeout)
  491. {
  492. uint8_t * p_buffer;
  493. uint32_t buffer_length;
  494. tx_buf_alloc(&p_buffer, &buffer_length);
  495. const uint32_t err_code = ant_channel_rx_search_timeout_set_req_enc(channel,
  496. timeout,
  497. &(p_buffer[1]),
  498. &buffer_length);
  499. APP_ERROR_CHECK(err_code);
  500. //@note: Increment buffer length as internally managed packet type field must be included.
  501. return ser_sd_transport_cmd_write(p_buffer,
  502. (++buffer_length),
  503. channel_rx_search_timeout_set_rsp_dec);
  504. }
  505. /**@brief Command response callback function for @ref sd_ant_channel_low_priority_rx_search_timeout_set ANT command.
  506. *
  507. * Callback for decoding the output parameters and the command response return code.
  508. *
  509. * @param[in] p_buffer Pointer to begin of command response buffer.
  510. * @param[in] length Length of data in bytes.
  511. *
  512. * @return Decoded command response return code.
  513. */
  514. static uint32_t channel_low_priority_rx_search_timeout_set_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  515. {
  516. uint32_t result_code;
  517. const uint32_t err_code = ant_channel_low_priority_rx_search_timeout_set_rsp_dec(p_buffer,
  518. length,
  519. &result_code);
  520. //@note: Should never fail
  521. APP_ERROR_CHECK(err_code);
  522. return result_code;
  523. }
  524. uint32_t sd_ant_channel_low_priority_rx_search_timeout_set(uint8_t channel, uint8_t timeout)
  525. {
  526. uint8_t * p_buffer;
  527. uint32_t buffer_length;
  528. tx_buf_alloc(&p_buffer, &buffer_length);
  529. const uint32_t err_code = ant_channel_low_priority_rx_search_timeout_set_req_enc(channel,
  530. timeout,
  531. &(p_buffer[1]),
  532. &buffer_length);
  533. APP_ERROR_CHECK(err_code);
  534. //@note: Increment buffer length as internally managed packet type field must be included.
  535. return ser_sd_transport_cmd_write(p_buffer,
  536. (++buffer_length),
  537. channel_low_priority_rx_search_timeout_set_rsp_dec);
  538. }
  539. /**@brief Command response callback function for @ref sd_ant_prox_search_set ANT command.
  540. *
  541. * Callback for decoding the output parameters and the command response return code.
  542. *
  543. * @param[in] p_buffer Pointer to begin of command response buffer.
  544. * @param[in] length Length of data in bytes.
  545. *
  546. * @return Decoded command response return code.
  547. */
  548. static uint32_t prox_search_set_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  549. {
  550. uint32_t result_code;
  551. const uint32_t err_code = ant_prox_search_set_rsp_dec(p_buffer,
  552. length,
  553. &result_code);
  554. //@note: Should never fail
  555. APP_ERROR_CHECK(err_code);
  556. return result_code;
  557. }
  558. uint32_t sd_ant_prox_search_set(uint8_t channel, uint8_t prox_threshold, uint8_t custom_prox_threshold)
  559. {
  560. uint8_t * p_buffer;
  561. uint32_t buffer_length;
  562. tx_buf_alloc(&p_buffer, &buffer_length);
  563. const uint32_t err_code = ant_prox_search_set_req_enc(channel,
  564. prox_threshold,
  565. custom_prox_threshold,
  566. &(p_buffer[1]),
  567. &buffer_length);
  568. APP_ERROR_CHECK(err_code);
  569. //@note: Increment buffer length as internally managed packet type field must be included.
  570. return ser_sd_transport_cmd_write(p_buffer,
  571. (++buffer_length),
  572. prox_search_set_rsp_dec);
  573. }
  574. /**@brief Command response callback function for @ref sd_ant_search_waveform_set ANT command.
  575. *
  576. * Callback for decoding the output parameters and the command response return code.
  577. *
  578. * @param[in] p_buffer Pointer to begin of command response buffer.
  579. * @param[in] length Length of data in bytes.
  580. *
  581. * @return Decoded command response return code.
  582. */
  583. static uint32_t search_waveform_set_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  584. {
  585. uint32_t result_code;
  586. const uint32_t err_code = ant_search_waveform_set_rsp_dec(p_buffer,
  587. length,
  588. &result_code);
  589. //@note: Should never fail
  590. APP_ERROR_CHECK(err_code);
  591. return result_code;
  592. }
  593. uint32_t sd_ant_search_waveform_set(uint8_t channel, uint16_t waveform)
  594. {
  595. uint8_t * p_buffer;
  596. uint32_t buffer_length;
  597. tx_buf_alloc(&p_buffer, &buffer_length);
  598. const uint32_t err_code = ant_search_waveform_set_req_enc(channel,
  599. waveform,
  600. &(p_buffer[1]),
  601. &buffer_length);
  602. APP_ERROR_CHECK(err_code);
  603. //@note: Increment buffer length as internally managed packet type field must be included.
  604. return ser_sd_transport_cmd_write(p_buffer,
  605. (++buffer_length),
  606. search_waveform_set_rsp_dec);
  607. }
  608. /**@brief Command response callback function for @ref sd_ant_channel_id_get ANT command.
  609. *
  610. * Callback for decoding the output parameters and the command response return code.
  611. *
  612. * @param[in] p_buffer Pointer to begin of command response buffer.
  613. * @param[in] length Length of data in bytes.
  614. *
  615. * @return Decoded command response return code.
  616. */
  617. static uint32_t channel_id_get_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  618. {
  619. uint32_t result_code;
  620. const uint32_t err_code = ant_channel_id_get_rsp_dec(p_buffer,
  621. length,
  622. mp_out_params[0],
  623. mp_out_params[1],
  624. mp_out_params[2],
  625. &result_code);
  626. //@note: Should never fail
  627. APP_ERROR_CHECK(err_code);
  628. return result_code;
  629. }
  630. uint32_t sd_ant_channel_id_get(uint8_t channel, uint16_t * p_device_number, uint8_t * p_device_type, uint8_t * p_transmit_type)
  631. {
  632. uint8_t * p_buffer;
  633. uint32_t buffer_length;
  634. tx_buf_alloc(&p_buffer, &buffer_length);
  635. mp_out_params[0] = p_device_number;
  636. mp_out_params[1] = p_device_type;
  637. mp_out_params[2] = p_transmit_type;
  638. const uint32_t err_code = ant_channel_id_get_req_enc(channel,
  639. &(p_buffer[1]),
  640. &buffer_length);
  641. APP_ERROR_CHECK(err_code);
  642. //@note: Increment buffer length as internally managed packet type field must be included.
  643. return ser_sd_transport_cmd_write(p_buffer,
  644. (++buffer_length),
  645. channel_id_get_rsp_dec);
  646. }
  647. /**@brief Command response callback function for @ref sd_ant_channel_radio_freq_get ANT command.
  648. *
  649. * Callback for decoding the output parameters and the command response return code.
  650. *
  651. * @param[in] p_buffer Pointer to begin of command response buffer.
  652. * @param[in] length Length of data in bytes.
  653. *
  654. * @return Decoded command response return code.
  655. */
  656. static uint32_t channel_radio_freq_get_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  657. {
  658. uint32_t result_code;
  659. const uint32_t err_code = ant_channel_radio_freq_get_rsp_dec(p_buffer,
  660. length,
  661. mp_out_params[0],
  662. &result_code);
  663. //@note: Should never fail
  664. APP_ERROR_CHECK(err_code);
  665. return result_code;
  666. }
  667. uint32_t sd_ant_channel_radio_freq_get(uint8_t channel, uint8_t * p_r_freq)
  668. {
  669. uint8_t * p_buffer;
  670. uint32_t buffer_length;
  671. tx_buf_alloc(&p_buffer, &buffer_length);
  672. mp_out_params[0] = p_r_freq;
  673. const uint32_t err_code = ant_channel_radio_freq_get_req_enc(channel,
  674. &(p_buffer[1]),
  675. &buffer_length);
  676. APP_ERROR_CHECK(err_code);
  677. //@note: Increment buffer length as internally managed packet type field must be included.
  678. return ser_sd_transport_cmd_write(p_buffer,
  679. (++buffer_length),
  680. channel_radio_freq_get_rsp_dec);
  681. }
  682. /**@brief Command response callback function for @ref sd_ant_channel_period_get ANT command.
  683. *
  684. * Callback for decoding the output parameters and the command response return code.
  685. *
  686. * @param[in] p_buffer Pointer to begin of command response buffer.
  687. * @param[in] length Length of data in bytes.
  688. *
  689. * @return Decoded command response return code.
  690. */
  691. static uint32_t channel_period_get_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  692. {
  693. uint32_t result_code;
  694. const uint32_t err_code = ant_channel_period_get_rsp_dec(p_buffer,
  695. length,
  696. mp_out_params[0],
  697. &result_code);
  698. //@note: Should never fail
  699. APP_ERROR_CHECK(err_code);
  700. return result_code;
  701. }
  702. uint32_t sd_ant_channel_period_get(uint8_t channel, uint16_t * p_period)
  703. {
  704. uint8_t * p_buffer;
  705. uint32_t buffer_length;
  706. tx_buf_alloc(&p_buffer, &buffer_length);
  707. mp_out_params[0] = p_period;
  708. const uint32_t err_code = ant_channel_period_get_req_enc(channel,
  709. &(p_buffer[1]),
  710. &buffer_length);
  711. APP_ERROR_CHECK(err_code);
  712. //@note: Increment buffer length as internally managed packet type field must be included.
  713. return ser_sd_transport_cmd_write(p_buffer,
  714. (++buffer_length),
  715. channel_period_get_rsp_dec);
  716. }
  717. /**@brief Command response callback function for @ref sd_ant_search_channel_priority_set ANT command.
  718. *
  719. * Callback for decoding the output parameters and the command response return code.
  720. *
  721. * @param[in] p_buffer Pointer to begin of command response buffer.
  722. * @param[in] length Length of data in bytes.
  723. *
  724. * @return Decoded command response return code.
  725. */
  726. static uint32_t search_channel_priority_set_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  727. {
  728. uint32_t result_code;
  729. const uint32_t err_code = ant_search_channel_priority_set_rsp_dec(p_buffer,
  730. length,
  731. &result_code);
  732. //@note: Should never fail
  733. APP_ERROR_CHECK(err_code);
  734. return result_code;
  735. }
  736. uint32_t sd_ant_search_channel_priority_set(uint8_t channel, uint8_t search_priority)
  737. {
  738. uint8_t * p_buffer;
  739. uint32_t buffer_length;
  740. tx_buf_alloc(&p_buffer, &buffer_length);
  741. const uint32_t err_code = ant_search_channel_priority_set_req_enc(channel,
  742. search_priority,
  743. &(p_buffer[1]),
  744. &buffer_length);
  745. APP_ERROR_CHECK(err_code);
  746. //@note: Increment buffer length as internally managed packet type field must be included.
  747. return ser_sd_transport_cmd_write(p_buffer,
  748. (++buffer_length),
  749. search_channel_priority_set_rsp_dec);
  750. }
  751. /**@brief Command response callback function for @ref sd_ant_active_search_sharing_cycles_set ANT command.
  752. *
  753. * Callback for decoding the output parameters and the command response return code.
  754. *
  755. * @param[in] p_buffer Pointer to begin of command response buffer.
  756. * @param[in] length Length of data in bytes.
  757. *
  758. * @return Decoded command response return code.
  759. */
  760. static uint32_t active_search_sharing_cycles_set_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  761. {
  762. uint32_t result_code;
  763. const uint32_t err_code = ant_active_search_sharing_cycles_set_rsp_dec(p_buffer,
  764. length,
  765. &result_code);
  766. //@note: Should never fail
  767. APP_ERROR_CHECK(err_code);
  768. return result_code;
  769. }
  770. uint32_t sd_ant_active_search_sharing_cycles_set(uint8_t channel, uint8_t cycles)
  771. {
  772. uint8_t * p_buffer;
  773. uint32_t buffer_length;
  774. tx_buf_alloc(&p_buffer, &buffer_length);
  775. const uint32_t err_code = ant_active_search_sharing_cycles_set_req_enc(channel,
  776. cycles,
  777. &(p_buffer[1]),
  778. &buffer_length);
  779. APP_ERROR_CHECK(err_code);
  780. //@note: Increment buffer length as internally managed packet type field must be included.
  781. return ser_sd_transport_cmd_write(p_buffer,
  782. (++buffer_length),
  783. active_search_sharing_cycles_set_rsp_dec);
  784. }
  785. /**@brief Command response callback function for @ref sd_ant_lib_config_set ANT command.
  786. *
  787. * Callback for decoding the output parameters and the command response return code.
  788. *
  789. * @param[in] p_buffer Pointer to begin of command response buffer.
  790. * @param[in] length Length of data in bytes.
  791. *
  792. * @return Decoded command response return code.
  793. */
  794. static uint32_t lib_config_set_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  795. {
  796. uint32_t result_code;
  797. const uint32_t err_code = ant_lib_config_set_rsp_dec(p_buffer,
  798. length,
  799. &result_code);
  800. //@note: Should never fail
  801. APP_ERROR_CHECK(err_code);
  802. return result_code;
  803. }
  804. uint32_t sd_ant_lib_config_set(uint8_t ant_lib_config)
  805. {
  806. uint8_t * p_buffer;
  807. uint32_t buffer_length;
  808. tx_buf_alloc(&p_buffer, &buffer_length);
  809. const uint32_t err_code = ant_lib_config_set_req_enc(ant_lib_config,
  810. &(p_buffer[1]),
  811. &buffer_length);
  812. APP_ERROR_CHECK(err_code);
  813. //@note: Increment buffer length as internally managed packet type field must be included.
  814. return ser_sd_transport_cmd_write(p_buffer,
  815. (++buffer_length),
  816. lib_config_set_rsp_dec);
  817. }
  818. /**@brief Command response callback function for @ref sd_ant_active_search_sharing_channels_get ANT command.
  819. *
  820. * Callback for decoding the output parameters and the command response return code.
  821. *
  822. * @param[in] p_buffer Pointer to begin of command response buffer.
  823. * @param[in] length Length of data in bytes.
  824. *
  825. * @return Decoded command response return code.
  826. */
  827. static uint32_t active_search_sharing_cycles_get_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  828. {
  829. uint32_t result_code;
  830. const uint32_t err_code = ant_active_search_sharing_cycles_get_rsp_dec(p_buffer,
  831. length,
  832. mp_out_params[0],
  833. &result_code);
  834. //@note: Should never fail
  835. APP_ERROR_CHECK(err_code);
  836. return result_code;
  837. }
  838. uint32_t sd_ant_active_search_sharing_cycles_get(uint8_t channel, uint8_t * p_cycles)
  839. {
  840. uint8_t * p_buffer;
  841. uint32_t buffer_length;
  842. tx_buf_alloc(&p_buffer, &buffer_length);
  843. mp_out_params[0] = p_cycles;
  844. const uint32_t err_code = ant_active_search_sharing_cycles_get_req_enc(channel,
  845. &(p_buffer[1]),
  846. &buffer_length);
  847. APP_ERROR_CHECK(err_code);
  848. //@note: Increment buffer length as internally managed packet type field must be included.
  849. return ser_sd_transport_cmd_write(p_buffer,
  850. (++buffer_length),
  851. active_search_sharing_cycles_get_rsp_dec);
  852. }
  853. /**@brief Command response callback function for @ref sd_ant_lib_config_get ANT command.
  854. *
  855. * Callback for decoding the output parameters and the command response return code.
  856. *
  857. * @param[in] p_buffer Pointer to begin of command response buffer.
  858. * @param[in] length Length of data in bytes.
  859. *
  860. * @return Decoded command response return code.
  861. */
  862. static uint32_t lib_config_get_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  863. {
  864. uint32_t result_code;
  865. const uint32_t err_code = ant_lib_config_get_rsp_dec(p_buffer,
  866. length,
  867. mp_out_params[0],
  868. &result_code);
  869. //@note: Should never fail
  870. APP_ERROR_CHECK(err_code);
  871. return result_code;
  872. }
  873. uint32_t sd_ant_lib_config_get(uint8_t * p_ant_lib_config)
  874. {
  875. uint8_t * p_buffer;
  876. uint32_t buffer_length;
  877. tx_buf_alloc(&p_buffer, &buffer_length);
  878. mp_out_params[0] = p_ant_lib_config;
  879. const uint32_t err_code = ant_lib_config_get_req_enc(&(p_buffer[1]),
  880. &buffer_length);
  881. APP_ERROR_CHECK(err_code);
  882. //@note: Increment buffer length as internally managed packet type field must be included.
  883. return ser_sd_transport_cmd_write(p_buffer,
  884. (++buffer_length),
  885. lib_config_get_rsp_dec);
  886. }
  887. /**@brief Command response callback function for @ref sd_ant_lib_config_clear ANT command.
  888. *
  889. * Callback for decoding the output parameters and the command response return code.
  890. *
  891. * @param[in] p_buffer Pointer to begin of command response buffer.
  892. * @param[in] length Length of data in bytes.
  893. *
  894. * @return Decoded command response return code.
  895. */
  896. static uint32_t lib_config_clear_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  897. {
  898. uint32_t result_code;
  899. const uint32_t err_code = ant_lib_config_clear_rsp_dec(p_buffer,
  900. length,
  901. &result_code);
  902. //@note: Should never fail
  903. APP_ERROR_CHECK(err_code);
  904. return result_code;
  905. }
  906. uint32_t sd_ant_lib_config_clear(uint8_t ant_lib_config)
  907. {
  908. uint8_t * p_buffer;
  909. uint32_t buffer_length;
  910. tx_buf_alloc(&p_buffer, &buffer_length);
  911. const uint32_t err_code = ant_lib_config_clear_req_enc(ant_lib_config,
  912. &(p_buffer[1]),
  913. &buffer_length);
  914. APP_ERROR_CHECK(err_code);
  915. //@note: Increment buffer length as internally managed packet type field must be included.
  916. return ser_sd_transport_cmd_write(p_buffer,
  917. (++buffer_length),
  918. lib_config_clear_rsp_dec);
  919. }
  920. /**@brief Command response callback function for @ref sd_ant_stack_reset ANT command.
  921. *
  922. * Callback for decoding the output parameters and the command response return code.
  923. *
  924. * @param[in] p_buffer Pointer to begin of command response buffer.
  925. * @param[in] length Length of data in bytes.
  926. *
  927. * @return Decoded command response return code.
  928. */
  929. static uint32_t stack_reset_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  930. {
  931. uint32_t result_code;
  932. const uint32_t err_code = ant_stack_reset_rsp_dec(p_buffer,
  933. length,
  934. &result_code);
  935. //@note: Should never fail
  936. APP_ERROR_CHECK(err_code);
  937. return result_code;
  938. }
  939. uint32_t sd_ant_stack_reset()
  940. {
  941. uint8_t * p_buffer;
  942. uint32_t buffer_length;
  943. tx_buf_alloc(&p_buffer, &buffer_length);
  944. const uint32_t err_code = ant_stack_reset_req_enc(&(p_buffer[1]),
  945. &buffer_length);
  946. APP_ERROR_CHECK(err_code);
  947. //@note: Increment buffer length as internally managed packet type field must be included.
  948. return ser_sd_transport_cmd_write(p_buffer,
  949. (++buffer_length),
  950. stack_reset_rsp_dec);
  951. }
  952. /**@brief Command response callback function for @ref sd_ant_rx_scan_mode_start ANT command.
  953. *
  954. * Callback for decoding the output parameters and the command response return code.
  955. *
  956. * @param[in] p_buffer Pointer to begin of command response buffer.
  957. * @param[in] length Length of data in bytes.
  958. *
  959. * @return Decoded command response return code.
  960. */
  961. static uint32_t rx_scan_mode_start_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  962. {
  963. uint32_t result_code;
  964. const uint32_t err_code = ant_rx_scan_mode_start_rsp_dec(p_buffer,
  965. length,
  966. &result_code);
  967. //@note: Should never fail
  968. APP_ERROR_CHECK(err_code);
  969. return result_code;
  970. }
  971. uint32_t sd_ant_rx_scan_mode_start(uint8_t sync_channel_packets_only)
  972. {
  973. uint8_t * p_buffer;
  974. uint32_t buffer_length;
  975. tx_buf_alloc(&p_buffer, &buffer_length);
  976. const uint32_t err_code = ant_rx_scan_mode_start_req_enc(sync_channel_packets_only,
  977. &(p_buffer[1]),
  978. &buffer_length);
  979. APP_ERROR_CHECK(err_code);
  980. //@note: Increment buffer length as internally managed packet type field must be included.
  981. return ser_sd_transport_cmd_write(p_buffer,
  982. (++buffer_length),
  983. rx_scan_mode_start_rsp_dec);
  984. }
  985. /**@brief Command response callback function for @ref sd_ant_id_list_add ANT command.
  986. *
  987. * Callback for decoding the output parameters and the command response return code.
  988. *
  989. * @param[in] p_buffer Pointer to begin of command response buffer.
  990. * @param[in] length Length of data in bytes.
  991. *
  992. * @return Decoded command response return code.
  993. */
  994. static uint32_t id_list_add_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  995. {
  996. uint32_t result_code;
  997. const uint32_t err_code = ant_id_list_add_rsp_dec(p_buffer,
  998. length,
  999. &result_code);
  1000. //@note: Should never fail
  1001. APP_ERROR_CHECK(err_code);
  1002. return result_code;
  1003. }
  1004. uint32_t sd_ant_id_list_add(uint8_t channel, uint8_t * p_dev_id, uint8_t list_index)
  1005. {
  1006. uint8_t * p_buffer;
  1007. uint32_t buffer_length;
  1008. tx_buf_alloc(&p_buffer, &buffer_length);
  1009. const uint32_t err_code = ant_id_list_add_req_enc(channel,
  1010. p_dev_id,
  1011. list_index,
  1012. &(p_buffer[1]),
  1013. &buffer_length);
  1014. APP_ERROR_CHECK(err_code);
  1015. //@note: Increment buffer length as internally managed packet type field must be included.
  1016. return ser_sd_transport_cmd_write(p_buffer,
  1017. (++buffer_length),
  1018. id_list_add_rsp_dec);
  1019. }
  1020. /**@brief Command response callback function for @ref sd_ant_id_list_config ANT command.
  1021. *
  1022. * Callback for decoding the output parameters and the command response return code.
  1023. *
  1024. * @param[in] p_buffer Pointer to begin of command response buffer.
  1025. * @param[in] length Length of data in bytes.
  1026. *
  1027. * @return Decoded command response return code.
  1028. */
  1029. static uint32_t id_list_config_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  1030. {
  1031. uint32_t result_code;
  1032. const uint32_t err_code = ant_id_list_config_rsp_dec(p_buffer,
  1033. length,
  1034. &result_code);
  1035. //@note: Should never fail
  1036. APP_ERROR_CHECK(err_code);
  1037. return result_code;
  1038. }
  1039. uint32_t sd_ant_id_list_config(uint8_t channel, uint8_t id_list_size, uint8_t inc_exc_flag)
  1040. {
  1041. uint8_t * p_buffer;
  1042. uint32_t buffer_length;
  1043. tx_buf_alloc(&p_buffer, &buffer_length);
  1044. const uint32_t err_code = ant_id_list_config_req_enc(channel,
  1045. id_list_size,
  1046. inc_exc_flag,
  1047. &(p_buffer[1]),
  1048. &buffer_length);
  1049. APP_ERROR_CHECK(err_code);
  1050. //@note: Increment buffer length as internally managed packet type field must be included.
  1051. return ser_sd_transport_cmd_write(p_buffer,
  1052. (++buffer_length),
  1053. id_list_config_rsp_dec);
  1054. }
  1055. /**@brief Command response callback function for @ref sd_ant_channel_status_get ANT command.
  1056. *
  1057. * Callback for decoding the output parameters and the command response return code.
  1058. *
  1059. * @param[in] p_buffer Pointer to begin of command response buffer.
  1060. * @param[in] length Length of data in bytes.
  1061. *
  1062. * @return Decoded command response return code.
  1063. */
  1064. static uint32_t channel_status_get_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  1065. {
  1066. uint32_t result_code;
  1067. const uint32_t err_code = ant_channel_status_get_rsp_dec(p_buffer,
  1068. length,
  1069. mp_out_params[0],
  1070. &result_code);
  1071. //@note: Should never fail
  1072. APP_ERROR_CHECK(err_code);
  1073. return result_code;
  1074. }
  1075. uint32_t sd_ant_channel_status_get(uint8_t channel, uint8_t * p_status)
  1076. {
  1077. uint8_t * p_buffer;
  1078. uint32_t buffer_length;
  1079. tx_buf_alloc(&p_buffer, &buffer_length);
  1080. mp_out_params[0] = p_status;
  1081. const uint32_t err_code = ant_channel_status_get_req_enc(channel,
  1082. &(p_buffer[1]),
  1083. &buffer_length);
  1084. APP_ERROR_CHECK(err_code);
  1085. //@note: Increment buffer length as internally managed packet type field must be included.
  1086. return ser_sd_transport_cmd_write(p_buffer,
  1087. (++buffer_length),
  1088. channel_status_get_rsp_dec);
  1089. }
  1090. /**@brief Command response callback function for @ref sd_ant_cw_test_mode_init ANT command.
  1091. *
  1092. * Callback for decoding the output parameters and the command response return code.
  1093. *
  1094. * @param[in] p_buffer Pointer to begin of command response buffer.
  1095. * @param[in] length Length of data in bytes.
  1096. *
  1097. * @return Decoded command response return code.
  1098. */
  1099. static uint32_t cw_test_mode_init_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  1100. {
  1101. uint32_t result_code;
  1102. const uint32_t err_code = ant_cw_test_mode_init_rsp_dec(p_buffer,
  1103. length,
  1104. &result_code);
  1105. //@note: Should never fail
  1106. APP_ERROR_CHECK(err_code);
  1107. return result_code;
  1108. }
  1109. uint32_t sd_ant_cw_test_mode_init()
  1110. {
  1111. uint8_t * p_buffer;
  1112. uint32_t buffer_length;
  1113. tx_buf_alloc(&p_buffer, &buffer_length);
  1114. const uint32_t err_code = ant_cw_test_mode_init_req_enc(&(p_buffer[1]),
  1115. &buffer_length);
  1116. APP_ERROR_CHECK(err_code);
  1117. //@note: Increment buffer length as internally managed packet type field must be included.
  1118. return ser_sd_transport_cmd_write(p_buffer,
  1119. (++buffer_length),
  1120. cw_test_mode_init_rsp_dec);
  1121. }
  1122. /**@brief Command response callback function for @ref sd_ant_cw_test_mode ANT command.
  1123. *
  1124. * Callback for decoding the output parameters and the command response return code.
  1125. *
  1126. * @param[in] p_buffer Pointer to begin of command response buffer.
  1127. * @param[in] length Length of data in bytes.
  1128. *
  1129. * @return Decoded command response return code.
  1130. */
  1131. static uint32_t cw_test_mode_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  1132. {
  1133. uint32_t result_code;
  1134. const uint32_t err_code = ant_cw_test_mode_rsp_dec(p_buffer,
  1135. length,
  1136. &result_code);
  1137. //@note: Should never fail
  1138. APP_ERROR_CHECK(err_code);
  1139. return result_code;
  1140. }
  1141. uint32_t sd_ant_cw_test_mode(uint8_t radio_freq, uint8_t tx_power, uint8_t custom_tx_power, uint8_t mode)
  1142. {
  1143. uint8_t * p_buffer;
  1144. uint32_t buffer_length;
  1145. tx_buf_alloc(&p_buffer, &buffer_length);
  1146. const uint32_t err_code = ant_cw_test_mode_req_enc(radio_freq,
  1147. tx_power,
  1148. custom_tx_power,
  1149. mode,
  1150. &(p_buffer[1]),
  1151. &buffer_length);
  1152. APP_ERROR_CHECK(err_code);
  1153. //@note: Increment buffer length as internally managed packet type field must be included.
  1154. return ser_sd_transport_cmd_write(p_buffer,
  1155. (++buffer_length),
  1156. cw_test_mode_rsp_dec);
  1157. }
  1158. /**@brief Command response callback function for @ref sd_ant_version_get ANT command.
  1159. *
  1160. * Callback for decoding the output parameters and the command response return code.
  1161. *
  1162. * @param[in] p_buffer Pointer to begin of command response buffer.
  1163. * @param[in] length Length of data in bytes.
  1164. *
  1165. * @return Decoded command response return code.
  1166. */
  1167. static uint32_t version_get_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  1168. {
  1169. uint32_t result_code;
  1170. const uint32_t err_code = ant_version_get_rsp_dec(p_buffer,
  1171. length,
  1172. &mp_out_params[0],
  1173. &result_code);
  1174. //@note: Should never fail
  1175. APP_ERROR_CHECK(err_code);
  1176. return result_code;
  1177. }
  1178. uint32_t sd_ant_version_get(uint8_t * p_version)
  1179. {
  1180. uint8_t * p_buffer;
  1181. uint32_t buffer_length;
  1182. tx_buf_alloc(&p_buffer, &buffer_length);
  1183. mp_out_params[0] = p_version;
  1184. const uint32_t err_code = ant_version_get_req_enc(&(p_buffer[1]),
  1185. &buffer_length);
  1186. APP_ERROR_CHECK(err_code);
  1187. //@note: Increment buffer length as internally managed packet type field must be included.
  1188. return ser_sd_transport_cmd_write(p_buffer,
  1189. (++buffer_length),
  1190. version_get_rsp_dec);
  1191. }
  1192. /**@brief Command response callback function for @ref sd_ant_capabilities_get ANT command.
  1193. *
  1194. * Callback for decoding the output parameters and the command response return code.
  1195. *
  1196. * @param[in] p_buffer Pointer to begin of command response buffer.
  1197. * @param[in] length Length of data in bytes.
  1198. *
  1199. * @return Decoded command response return code.
  1200. */
  1201. static uint32_t capabilities_get_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  1202. {
  1203. uint32_t result_code;
  1204. const uint32_t err_code = ant_capabilities_get_rsp_dec(p_buffer,
  1205. length,
  1206. &mp_out_params[0],
  1207. &result_code);
  1208. //@note: Should never fail
  1209. APP_ERROR_CHECK(err_code);
  1210. return result_code;
  1211. }
  1212. uint32_t sd_ant_capabilities_get(uint8_t * p_capabilities)
  1213. {
  1214. uint8_t * p_buffer;
  1215. uint32_t buffer_length;
  1216. tx_buf_alloc(&p_buffer, &buffer_length);
  1217. mp_out_params[0] = p_capabilities;
  1218. const uint32_t err_code = ant_capabilities_get_req_enc(&(p_buffer[1]),
  1219. &buffer_length);
  1220. APP_ERROR_CHECK(err_code);
  1221. //@note: Increment buffer length as internally managed packet type field must be included.
  1222. return ser_sd_transport_cmd_write(p_buffer,
  1223. (++buffer_length),
  1224. capabilities_get_rsp_dec);
  1225. }
  1226. /**@brief Command response callback function for @ref sd_ant_crypto_channel_enable ANT command.
  1227. *
  1228. * Callback for decoding the output parameters and the command response return code.
  1229. *
  1230. * @param[in] p_buffer Pointer to begin of command response buffer.
  1231. * @param[in] length Length of data in bytes.
  1232. *
  1233. * @return Decoded command response return code.
  1234. */
  1235. static uint32_t crypto_channel_enable_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  1236. {
  1237. uint32_t result_code;
  1238. const uint32_t err_code = ant_crypto_channel_enable_rsp_dec(p_buffer,
  1239. length,
  1240. &result_code);
  1241. //@note: Should never fail.
  1242. APP_ERROR_CHECK(err_code);
  1243. return result_code;
  1244. }
  1245. uint32_t sd_ant_crypto_channel_enable(uint8_t channel, uint8_t enable, uint8_t key_num, uint8_t decimation_rate)
  1246. {
  1247. uint8_t * p_buffer;
  1248. uint32_t buffer_length;
  1249. tx_buf_alloc(&p_buffer, &buffer_length);
  1250. const uint32_t err_code = ant_crypto_channel_enable_req_enc(channel,
  1251. enable,
  1252. key_num,
  1253. decimation_rate,
  1254. &(p_buffer[1]),
  1255. &buffer_length);
  1256. APP_ERROR_CHECK(err_code);
  1257. //@note: Increment buffer length as internally managed packet type field must be included.
  1258. return ser_sd_transport_cmd_write(p_buffer,
  1259. (++buffer_length),
  1260. crypto_channel_enable_rsp_dec);
  1261. }
  1262. /**@brief Command response callback function for @ref sd_ant_adv_burst_config_set ANT command.
  1263. *
  1264. * Callback for decoding the output parameters and the command response return code.
  1265. *
  1266. * @param[in] p_buffer Pointer to begin of command response buffer.
  1267. * @param[in] length Length of data in bytes.
  1268. *
  1269. * @return Decoded command response return code.
  1270. */
  1271. static uint32_t adv_burst_config_set_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  1272. {
  1273. uint32_t result_code;
  1274. const uint32_t err_code = ant_adv_burst_config_set_rsp_dec(p_buffer,
  1275. length,
  1276. &result_code);
  1277. //@note: Should never fail.
  1278. APP_ERROR_CHECK(err_code);
  1279. return result_code;
  1280. }
  1281. uint32_t sd_ant_adv_burst_config_set(uint8_t * p_config, uint8_t size)
  1282. {
  1283. uint8_t * p_buffer;
  1284. uint32_t buffer_length;
  1285. tx_buf_alloc(&p_buffer, &buffer_length);
  1286. const uint32_t err_code = ant_adv_burst_config_set_req_enc(p_config,
  1287. size,
  1288. &(p_buffer[1]),
  1289. &buffer_length);
  1290. APP_ERROR_CHECK(err_code);
  1291. //@note: Increment buffer length as internally managed packet type field must be included.
  1292. return ser_sd_transport_cmd_write(p_buffer,
  1293. (++buffer_length),
  1294. adv_burst_config_set_rsp_dec);
  1295. }
  1296. /**@brief Command response callback function for @ref sd_ant_crypto_key_set ANT command.
  1297. *
  1298. * Callback for decoding the output parameters and the command response return code.
  1299. *
  1300. * @param[in] p_buffer Pointer to begin of command response buffer.
  1301. * @param[in] length Length of data in bytes.
  1302. *
  1303. * @return Decoded command response return code.
  1304. */
  1305. static uint32_t crypto_key_set_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  1306. {
  1307. uint32_t result_code;
  1308. const uint32_t err_code = ant_crypto_key_set_rsp_dec(p_buffer,
  1309. length,
  1310. &result_code);
  1311. //@note: Should never fail.
  1312. APP_ERROR_CHECK(err_code);
  1313. return result_code;
  1314. }
  1315. uint32_t sd_ant_crypto_key_set(uint8_t key_num, uint8_t * p_key)
  1316. {
  1317. uint8_t * p_buffer;
  1318. uint32_t buffer_length;
  1319. tx_buf_alloc(&p_buffer, &buffer_length);
  1320. const uint32_t err_code = ant_crypto_key_set_req_enc(key_num,
  1321. p_key,
  1322. &(p_buffer[1]),
  1323. &buffer_length);
  1324. APP_ERROR_CHECK(err_code);
  1325. //@note: Increment buffer length as internally managed packet type field must be included.
  1326. return ser_sd_transport_cmd_write(p_buffer,
  1327. (++buffer_length),
  1328. crypto_key_set_rsp_dec);
  1329. }
  1330. /**@brief Command response callback function for @ref sd_ant_crypto_info_set ANT command.
  1331. *
  1332. * Callback for decoding the output parameters and the command response return code.
  1333. *
  1334. * @param[in] p_buffer Pointer to begin of command response buffer.
  1335. * @param[in] length Length of data in bytes.
  1336. *
  1337. * @return Decoded command response return code.
  1338. */
  1339. static uint32_t crypto_info_set_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  1340. {
  1341. uint32_t result_code;
  1342. const uint32_t err_code = ant_crypto_info_set_rsp_dec(p_buffer,
  1343. length,
  1344. &result_code);
  1345. //@note: Should never fail.
  1346. APP_ERROR_CHECK(err_code);
  1347. return result_code;
  1348. }
  1349. uint32_t sd_ant_crypto_info_set(uint8_t type, uint8_t * p_info)
  1350. {
  1351. uint8_t * p_buffer;
  1352. uint32_t buffer_length;
  1353. tx_buf_alloc(&p_buffer, &buffer_length);
  1354. const uint32_t err_code = ant_crypto_info_set_req_enc(type,
  1355. p_info,
  1356. &(p_buffer[1]),
  1357. &buffer_length);
  1358. APP_ERROR_CHECK(err_code);
  1359. //@note: Increment buffer length as internally managed packet type field must be included.
  1360. return ser_sd_transport_cmd_write(p_buffer,
  1361. (++buffer_length),
  1362. crypto_info_set_rsp_dec);
  1363. }
  1364. /**@brief Command response callback function for @ref sd_ant_crypto_info_get ANT command.
  1365. *
  1366. * Callback for decoding the output parameters and the command response return code.
  1367. *
  1368. * @param[in] p_buffer Pointer to begin of command response buffer.
  1369. * @param[in] length Length of data in bytes.
  1370. *
  1371. * @return Decoded command response return code.
  1372. */
  1373. static uint32_t crypto_info_get_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  1374. {
  1375. uint32_t result_code;
  1376. const uint32_t err_code = ant_crypto_info_get_rsp_dec(p_buffer,
  1377. length,
  1378. mp_out_params[0],
  1379. &result_code);
  1380. //@note: Should never fail.
  1381. APP_ERROR_CHECK(err_code);
  1382. return result_code;
  1383. }
  1384. uint32_t sd_ant_crypto_info_get(uint8_t type, uint8_t * p_info)
  1385. {
  1386. uint8_t * p_buffer;
  1387. uint32_t buffer_length;
  1388. tx_buf_alloc(&p_buffer, &buffer_length);
  1389. mp_out_params[0] = p_info;
  1390. const uint32_t err_code = ant_crypto_info_get_req_enc(type,
  1391. &(p_buffer[1]),
  1392. &buffer_length);
  1393. APP_ERROR_CHECK(err_code);
  1394. //@note: Increment buffer length as internally managed packet type field must be included.
  1395. return ser_sd_transport_cmd_write(p_buffer,
  1396. (++buffer_length),
  1397. crypto_info_get_rsp_dec);
  1398. }
  1399. /**@brief Command response callback function for @ref sd_ant_coex_config_set ANT command.
  1400. *
  1401. * Callback for decoding the output parameters and the command response return code.
  1402. *
  1403. * @param[in] p_buffer Pointer to begin of command response buffer.
  1404. * @param[in] length Length of data in bytes.
  1405. *
  1406. * @return Decoded command response return code.
  1407. */
  1408. static uint32_t coex_config_set_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  1409. {
  1410. uint32_t result_code;
  1411. const uint32_t err_code = ant_coex_config_set_rsp_dec(p_buffer,
  1412. length,
  1413. &result_code);
  1414. //@note: Should never fail.
  1415. APP_ERROR_CHECK(err_code);
  1416. return result_code;
  1417. }
  1418. uint32_t sd_ant_coex_config_set(uint8_t channel, ANT_BUFFER_PTR * p_coex_config, ANT_BUFFER_PTR * p_adv_coex_config)
  1419. {
  1420. uint8_t * p_buffer;
  1421. uint32_t buffer_length;
  1422. tx_buf_alloc(&p_buffer, &buffer_length);
  1423. const uint32_t err_code = ant_coex_config_set_req_enc(channel,
  1424. p_coex_config,
  1425. p_adv_coex_config,
  1426. &(p_buffer[1]),
  1427. &buffer_length);
  1428. APP_ERROR_CHECK(err_code);
  1429. //@note: Increment buffer length as internally managed packet type field must be included.
  1430. return ser_sd_transport_cmd_write(p_buffer,
  1431. (++buffer_length),
  1432. coex_config_set_rsp_dec);
  1433. }
  1434. /**@brief Command response callback function for @ref sd_ant_coex_config_get ANT command.
  1435. *
  1436. * Callback for decoding the output parameters and the command response return code.
  1437. *
  1438. * @param[in] p_buffer Pointer to begin of command response buffer.
  1439. * @param[in] length Length of data in bytes.
  1440. *
  1441. * @return Decoded command response return code.
  1442. */
  1443. static uint32_t coex_config_get_rsp_dec(const uint8_t * p_buffer, uint16_t length)
  1444. {
  1445. uint32_t result_code;
  1446. const uint32_t err_code = ant_coex_config_get_rsp_dec(p_buffer,
  1447. length,
  1448. mp_out_params[0],
  1449. mp_out_params[1],
  1450. &result_code);
  1451. //@note: Should never fail
  1452. APP_ERROR_CHECK(err_code);
  1453. return result_code;
  1454. }
  1455. uint32_t sd_ant_coex_config_get(uint8_t channel, ANT_BUFFER_PTR * p_coex_config, ANT_BUFFER_PTR * p_adv_coex_config)
  1456. {
  1457. uint8_t * p_buffer;
  1458. uint32_t buffer_length;
  1459. tx_buf_alloc(&p_buffer, &buffer_length);
  1460. mp_out_params[0] = p_coex_config;
  1461. mp_out_params[1] = p_adv_coex_config;
  1462. const uint32_t err_code = ant_coex_config_get_req_enc(channel,
  1463. &(p_buffer[1]),
  1464. &buffer_length);
  1465. APP_ERROR_CHECK(err_code);
  1466. //@note: Increment buffer length as internally managed packet type field must be included.
  1467. return ser_sd_transport_cmd_write(p_buffer,
  1468. (++buffer_length),
  1469. coex_config_get_rsp_dec);
  1470. }