bot_api.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /**
  2. * @file bot_api.h
  3. * @brief blockchain of things core api
  4. * @copyright Copyright (C) 2015-2022 Ant Group Holding Limited
  5. */
  6. #ifndef __BOT_API_H__
  7. #define __BOT_API_H__
  8. #if defined(__cplusplus)
  9. extern "C" {
  10. #endif
  11. #include "bot_typedef.h"
  12. /** @def BOT_CONFIG_BUF_MIN_LEN
  13. @brief the minimum length of the @ref bot_config_get buf
  14. */
  15. #define BOT_CONFIG_BUF_MIN_LEN (128)
  16. ///bot msg notify type
  17. typedef enum {
  18. /**
  19. * @brief initial invalid value
  20. */
  21. BOT_MSG_UNAVAILABLE = 0,
  22. /**
  23. * @brief asset initialization fails, please follow the steps below to check:
  24. * 1. check if the network is connected
  25. * 2. check if imei number is provided to ant
  26. */
  27. BOT_MSG_INIT_FAILED,
  28. /**
  29. * @brief asset initialization succeeded, please use the API as follows:
  30. * 1. call @ref bot_asset_status_get to query the registration status
  31. * 2. if status is not equal to 1, call @ref bot_asset_register for asset registration
  32. */
  33. BOT_MSG_INIT_SUCESS,
  34. /**
  35. * @brief Asset registration failed, please follow the steps below to troubleshoot:
  36. * 1. check asset_id format
  37. * 2. check asset_type format
  38. * 3. check asset_dataver format
  39. * 4. provide error codes to ant to assist in troubleshooting
  40. */
  41. BOT_MSG_REG_FAILED,
  42. /**
  43. * @brief asset registration is successful, now you can call @ref bot_data_publish to send data
  44. */
  45. BOT_MSG_REG_SUCESS,
  46. /**
  47. * @brief bot_data_publish failed to report, asynchronous callback result
  48. */
  49. BOT_MSG_PUB_FAILED,
  50. /**
  51. * @brief bot_data_publish reported successfully, asynchronous callback result
  52. */
  53. BOT_MSG_PUB_SUCESS,
  54. /**
  55. * @brief internal use
  56. */
  57. BOT_MSG_DATA_VERIFY_FAILED
  58. } bot_msg_type_e;
  59. /** @typedef void (*bot_msg_notify_callback_t)(bot_msg_type_e, void *)
  60. *
  61. * @brief message notification callback function pointer
  62. *
  63. * @param[in] bot_msg_type_e msg notefy type, for more information please refer to @ref bot_msg_type_e
  64. * @param[in] void* reserve
  65. */
  66. typedef void (*bot_msg_notify_callback_t)(bot_msg_type_e, void *);
  67. /**
  68. * @brief init bot(blockchain of things) service
  69. *
  70. * @return int
  71. * @retval 0 success
  72. * @retval otherwise failed see @ref bot_errno.h
  73. */
  74. int bot_init(void);
  75. /**
  76. * @brief register message notify callback
  77. *
  78. * @param[in] notify the type of register message callback.
  79. * @param[in] args the reserved arg
  80. *
  81. * @return int
  82. * @retval 0 success
  83. * @retval otherwise failed see @ref bot_errno.h
  84. */
  85. int bot_msg_notify_callback_register(bot_msg_notify_callback_t notify, void *args);
  86. /**
  87. * @brief get bot(blockchain of things) sdk version
  88. *
  89. * @return const char*
  90. * @retval NULL get sdk version fail
  91. * @return otherwise sdk version
  92. */
  93. const char *bot_version_get(void);
  94. /**
  95. * @brief start bot(blockchain of things) asset registration
  96. *
  97. * @param[in] asset_id asset ID,must to be unique, the length is greater than 0 and less than 64 bytes,
  98. * and can only contain uppercase and lowercase letters, numbers, and symbols "_", ".", "-"
  99. * @param[in] asset_type device type, the format is "xxxx-yyyy"
  100. * xxxx: equipment type code, refer to the project information table
  101. * yyyy: device model, a user-defined character string,
  102. * which can only contain uppercase and lowercase letters, numbers, and symbols "_", "."
  103. * @param[in] asset_dataver data version of asset to register. the default value is "ADV1.0"
  104. *
  105. * @return int
  106. * @retval >=0 success
  107. * @retval otherwise failed see @ref bot_errno.h
  108. */
  109. int bot_asset_register(char *asset_id, char *asset_type, char *asset_dataver);
  110. /**
  111. * @brief publish data to the bot(blockchain of things)
  112. *
  113. * @param[in] data data to publish, it must be cjson format in string.
  114. * @param[in] len the data length must be less than 1024
  115. *
  116. * @return int
  117. * @retval >=0 success, >0 indicates msg_id
  118. * @retval otherwise failed see @ref bot_errno.h
  119. */
  120. int bot_data_publish(uint8_t *data, int len);
  121. /**
  122. * @brief query device connection status
  123. *
  124. * @return int
  125. * @retval 0 disconnect, channel enabled
  126. * @retval 1 connect, channel enabled
  127. * @retval 2 disconnect, channel disabled
  128. * @retval 3 invalid
  129. */
  130. int bot_device_status_get(void);
  131. /**
  132. * @brief query asset registration status
  133. *
  134. * @param[in] asset_id ID of the asset to register,asset_id must to be unique
  135. *
  136. * @return int
  137. * @retval 0 - Module not activated, asset not registered
  138. * @retval 1 - Module activated, asset registered,
  139. * @retval 2 - Module activated, asset not registered
  140. * @retval other value means error see @ref bot_errno.h
  141. *
  142. */
  143. int bot_asset_status_get(char *asset_id);
  144. /**
  145. * @brief bot(blockchain of things) channel switch
  146. *
  147. * @param[in] cmd command for channel switch, 0 to off, 1 to on
  148. *
  149. * @return int
  150. * @retval 0 success
  151. * @retval otherwise failed see @ref bot_errno.h
  152. */
  153. int bot_channel_switch(int cmd);
  154. /**
  155. * @brief set product information
  156. *
  157. * @param[in] config obtained in the project information sheet
  158. *
  159. * @return int
  160. * @retval 0 success
  161. * @retval otherwise failed see @ref bot_errno.h
  162. */
  163. int bot_config_set(const char *config);
  164. /**
  165. * @brief get product information
  166. *
  167. * @param[in] buf_len the length of the config array, must be greater than @ref BOT_CONFIG_BUF_MIN_LEN
  168. * @param[out] config get product information
  169. *
  170. * @return int
  171. * @retval 0 success
  172. * @retval otherwise failed see @ref bot_errno.h
  173. */
  174. int bot_config_get(char *config, int buf_len);
  175. /**
  176. * @brief pac data of the bot(blockchain of things)
  177. *
  178. * @param[in] format 1:JSON, 0: Binary
  179. * @param[in] data_in data to be packed
  180. * @param[in] inlen the length of input data
  181. * @param[out] data_out data after packing
  182. * @param[in out] outlen in: the length of the output buffer. out: the real length of the data.
  183. *
  184. * @return int
  185. * @retval 0 success
  186. * @retval otherwise failed see @ref bot_errno.h
  187. */
  188. int bot_data_pac(int format, uint8_t *data_in, int inlen, uint8_t *data_out, int *outlen);
  189. #if defined(__cplusplus)
  190. }
  191. #endif
  192. #endif /* __BOT_API_H__ */