Просмотр исходного кода

add: 添加antbot库的集成, 由蚂蚁集团提供,已确认可使用MIT协议

https://gitee.com/openLuat/luatos-soc-2022/issues/I8P4SX
Wendal Chen 2 лет назад
Родитель
Сommit
894e5963be

+ 322 - 0
components/antbot/binding/luat_lib_antbot.c

@@ -0,0 +1,322 @@
+/**
+@module antbot
+@summary 蚂蚁链
+@catalog 扩展API
+@version 1.0
+@date    2022.12.18
+@demo antbot
+@tag LUAT_USE_ANTBOT
+@copyright Copyright (C) 2015-2023 Ant Group Holding Limited
+@usage
+
+-- 本模块由蚂蚁链提供实现并开放给用户使用
+-- 具体用法请查阅demo,并联系蚂蚁链获取技术支持
+ */
+#include "luat_base.h"
+#include "rotable2.h"
+#include "luat_zbuff.h"
+#include "luat_lib_antbot.h"
+#include "bot_api.h"
+
+#define LUAT_LOG_TAG "antbot"
+#include "luat_log.h"
+
+#define BOT_DATA_PAC_OUT_MAX_SIZE   1024
+
+bot_msg_type_e g_bot_status = BOT_MSG_UNAVAILABLE;
+
+static const char *bot_app_sta_notify_str[] = {
+    "BOT_MSG_UNAVAILABLE",
+    "BOT_MSG_INIT_FAILED",
+    "BOT_MSG_INIT_SUCESS",
+    "BOT_MSG_REG_FAILED",
+    "BOT_MSG_REG_SUCESS",
+    "BOT_MSG_PUB_FAILED",
+    "BOT_MSG_PUB_SUCESS",
+    "BOT_MSG_DATA_VERIFY_FAILED"
+};
+
+static void bot_msg_notify_cb(bot_msg_type_e notify_type, void *args)
+{
+    if (g_bot_status != notify_type) {
+        LLOGD("----------------------------------------------------------------------------------");
+        LLOGD("state change: %s ---> %s", bot_app_sta_notify_str[g_bot_status], bot_app_sta_notify_str[notify_type]);
+        LLOGD("----------------------------------------------------------------------------------");
+        g_bot_status = notify_type;
+    }
+}
+
+/*
+初始化
+@api antbot.init()
+@return int 0:成功 其他值为失败
+@usage
+
+-- 初始化蚂蚁链的底层适配
+antbot.init()
+*/
+static int luat_bot_init(lua_State *L)
+{
+    bot_msg_notify_callback_register(bot_msg_notify_cb, NULL);
+    int ret = bot_init();
+    lua_pushinteger(L, ret);
+    return 1;
+}
+
+/*
+获取客户端状态
+@api antbot.app_sta_get()
+@return int 状态码
+*/
+static int luat_bot_app_sta_get(lua_State *L)
+{
+    LLOGD("bot_app_sta_get lua: %d", g_bot_status);
+    lua_pushinteger(L, g_bot_status);
+    return 1;
+}
+
+/*
+获取SDK版本号
+@api antbot.version_get()
+@return string 版本号,如果获取失败返回nil
+*/
+static int luat_bot_version_get(lua_State *L)
+{
+    const char *version = bot_version_get();
+
+    if (!version)
+        return 0;
+    else
+        lua_pushstring(L, version);
+
+    LLOGD("version: %s", version);
+    return 1;
+}
+
+/*
+asset资源注册
+@api antbot.asset_register(asset_id, asset_type, asset_dataver)
+@string asset_id 资源ID
+@string asset_type 资源类型
+@string asset_dataver 资源数据版本
+@return int 0:成功 其他值为失败
+*/
+static int luat_bot_asset_register(lua_State *L)
+{
+    int ret = -1;
+    size_t size = 0;
+
+    int num_args = lua_gettop(L);
+    if (num_args != 3) {
+        goto exit;
+    }
+
+    if (!lua_isstring(L, 1) || !lua_isstring(L, 2) || !lua_isstring(L, 3)) {
+        LLOGE("asset_register parameters are invalid type, shoule be string.");
+        goto exit;
+    }
+
+    const char *asset_id = luaL_checklstring(L, 1, &size);
+    const char *asset_type = luaL_checklstring(L, 2, &size);
+    const char *asset_dataver = luaL_checklstring(L, 3, &size);
+    ret = bot_asset_register(asset_id, asset_type, asset_dataver);
+
+exit:
+    lua_pushinteger(L, ret);
+    return 1;
+}
+
+/*
+asset资源发布
+@api antbot.asset_data_publish(data)
+@string data 资源数据
+@return int 0:成功 其他值为失败
+*/
+static int luat_bot_data_publish(lua_State *L)
+{
+    int ret = -1;
+    uint8_t *data;
+    size_t data_len;
+    int len;
+
+    data = luaL_checklstring(L, 1, &data_len);
+    ret = bot_data_publish(data, data_len);
+
+exit:
+    lua_pushinteger(L, ret);
+    return 1;
+}
+
+/*
+获取设备状态
+@api antbot.device_status_get()
+@return int 设备状态
+*/
+static int luat_bot_device_status_get(lua_State *L)
+{
+    lua_pushinteger(L, bot_device_status_get());
+    return 1;
+}
+
+/*
+获取assset状态
+@api antbot.asset_status_get(asset_id)
+@string asset_id 资源ID
+@return int 资源状态
+*/
+static luat_bot_asset_status_get(lua_State *L)
+{
+    int ret = -1;
+    if (!lua_isstring(L, 1)) {
+        LLOGE("asset_status_get parameter is invalid type, shoule be string.");
+        goto exit;
+    }
+
+    size_t size = 0;
+    const char *asset_id = luaL_checklstring(L, 1, &size);
+    ret = bot_asset_status_get(asset_id);
+
+exit:
+    lua_pushinteger(L, ret);
+    return 1;
+}
+
+/*
+切换channel
+@api antbot.channel_switch(cmd)
+@int 0 - 关闭, 1 - 开启
+@return int 0:成功 其他值为失败
+*/
+static luat_bot_channel_switch(lua_State *L)
+{
+    int ret = -1;
+    if (!lua_isinteger(L, 1)) {
+        LLOGE("channel_switch parameter is invalid type, shoule be int.");
+        goto exit;
+    }
+
+    size_t size = 0;
+    int cmd = luaL_checkinteger(L, 1);
+    ret = bot_channel_switch(cmd);
+
+exit:
+    lua_pushinteger(L, ret);
+    return 1;
+}
+
+/*
+配置设备
+@api antbot.config_set(config)
+@string config 配置内容
+@return int 0:成功 其他值为失败
+*/
+static luat_bot_config_set(lua_State *L)
+{
+    int ret = -1;
+    if (!lua_isstring(L, 1)) {
+        LLOGE("config_set parameter is invalid type, shoule be string.");
+        goto exit;
+    }
+
+    size_t size = 0;
+    const char *config = luaL_checklstring(L, 1, &size);
+    ret = bot_config_set(config);
+
+exit:
+    lua_pushinteger(L, ret);
+    return 1;
+}
+
+/*
+获取设备配置
+@api antbot.config_get()
+@return string 配置内容
+*/
+static luat_bot_config_get(lua_State *L)
+{
+    int ret = -1;
+
+    if (!lua_isinteger(L, 1)) {
+        LLOGE("config_get parameter are invalid type!");
+        goto exit;
+    }
+
+    int len = luaL_checkinteger(L, 1);
+    if (len < BOT_CONFIG_BUF_MIN_LEN) {
+        LLOGE("config_get len must be greater than BOT_CONFIG_BUF_MIN_LEN");
+        goto exit;
+    }
+
+    char *config = luat_heap_malloc(len);
+    if (!config) {
+        LLOGE("config_get out of memory");
+        goto exit;
+    }
+
+    ret = bot_config_get(config, len);
+    lua_pushinteger(L, ret);
+    lua_pushlstring(L, config, len);
+    luat_heap_free(config);
+    return 2;
+
+exit:
+    lua_pushinteger(L, ret);
+    return 1;
+}
+
+static luat_bot_data_pac(lua_State *L)
+{
+    int ret = -1;
+    int num_args = lua_gettop(L);
+    if (num_args != 2) {
+        goto exit;
+    }
+
+    if (!lua_isinteger(L, 1) || !lua_isstring(L, 2)) {
+        LLOGE("data_pac parameters are invalid type!");
+        goto exit;
+    }
+
+    int format = luaL_checkinteger(L, 1);
+    size_t data_len;
+    uint8_t *data_in = luaL_checklstring(L, 2, &data_len);
+
+    int outlen = BOT_DATA_PAC_OUT_MAX_SIZE;
+    uint8_t *data_out = luat_heap_malloc(outlen); // TODO 改成 lua_Buff
+    if (!data_out) {
+        LLOGE("data_pack out of memory");
+        goto exit;
+    }
+
+    ret = bot_data_pac(format, data_in, data_len, data_out, &outlen);
+    lua_pushinteger(L, ret);
+    lua_pushlstring(L, (const char *)data_out, outlen);
+    lua_pushinteger(L, outlen);
+    luat_heap_free(data_out);
+    return 3;
+
+exit:
+    lua_pushinteger(L, ret);
+    return 1;
+}
+
+static const rotable_Reg_t reg_antbot[] = {
+    { "version_get",        ROREG_FUNC(luat_bot_version_get)},
+    { "init",               ROREG_FUNC(luat_bot_init)},
+    { "app_sta_get",        ROREG_FUNC(luat_bot_app_sta_get)},
+    { "asset_register",     ROREG_FUNC(luat_bot_asset_register)},
+    { "data_publish",       ROREG_FUNC(luat_bot_data_publish)},
+    { "device_status_get",  ROREG_FUNC(luat_bot_device_status_get)},
+    { "asset_status_get",   ROREG_FUNC(luat_bot_asset_status_get)},
+    { "channel_switch",     ROREG_FUNC(luat_bot_channel_switch)},
+    { "config_set",         ROREG_FUNC(luat_bot_config_set)},
+    { "config_get",         ROREG_FUNC(luat_bot_config_get)},
+    { "data_pac",           ROREG_FUNC(luat_bot_data_pac)},
+    { NULL,                 ROREG_INT(0)}
+};
+
+LUAMOD_API int luaopen_antbot(lua_State *L)
+{
+    luat_newlib2(L, reg_antbot);
+    return 1;
+}

+ 213 - 0
components/antbot/include/bot_api.h

@@ -0,0 +1,213 @@
+/**
+ * @file bot_api.h
+ * @brief blockchain of things core api
+ * @copyright Copyright (C) 2015-2022 Ant Group Holding Limited
+ */
+#ifndef __BOT_API_H__
+#define __BOT_API_H__
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+#include "bot_typedef.h"
+
+/** @def BOT_CONFIG_BUF_MIN_LEN
+    @brief the minimum length of the @ref bot_config_get buf
+*/
+#define BOT_CONFIG_BUF_MIN_LEN (128)
+
+///bot msg notify type
+typedef enum {
+    /**
+     * @brief initial invalid value
+     */
+    BOT_MSG_UNAVAILABLE = 0,
+    /**
+     * @brief asset initialization fails, please follow the steps below to check:
+     * 1. check if the network is connected
+     * 2. check if imei number is provided to ant
+     */
+    BOT_MSG_INIT_FAILED,
+    /**
+     * @brief asset initialization succeeded, please use the API as follows:
+     * 1. call @ref bot_asset_status_get to query the registration status
+     * 2. if status is not equal to 1, call @ref bot_asset_register for asset registration
+     */
+    BOT_MSG_INIT_SUCESS,
+    /**
+     * @brief Asset registration failed, please follow the steps below to troubleshoot:
+     * 1. check asset_id format
+     * 2. check asset_type format
+     * 3. check asset_dataver format
+     * 4. provide error codes to ant to assist in troubleshooting
+     */
+    BOT_MSG_REG_FAILED,
+    /**
+     * @brief asset registration is successful, now you can call @ref bot_data_publish to send data
+     */
+    BOT_MSG_REG_SUCESS,
+    /**
+    * @brief bot_data_publish failed to report, asynchronous callback result
+    */
+    BOT_MSG_PUB_FAILED,
+    /**
+     * @brief bot_data_publish reported successfully, asynchronous callback result
+     */
+    BOT_MSG_PUB_SUCESS,
+    /**
+     * @brief internal use
+     */
+    BOT_MSG_DATA_VERIFY_FAILED
+} bot_msg_type_e;
+
+
+
+/** @typedef void (*bot_msg_notify_callback_t)(bot_msg_type_e, void *)
+ *
+ *  @brief message notification callback function pointer
+ *
+ *  @param[in] bot_msg_type_e msg notefy type, for more information please refer to @ref bot_msg_type_e
+ *  @param[in] void*  reserve
+*/
+typedef void (*bot_msg_notify_callback_t)(bot_msg_type_e, void *);
+
+
+/**
+ * @brief init bot(blockchain of things) service
+ *
+ * @return int
+ * @retval 0 success
+ * @retval otherwise failed see @ref bot_errno.h
+ */
+int bot_init(void);
+
+/**
+ * @brief register message notify callback
+ *
+ * @param[in]  notify  the type of register message callback.
+ * @param[in]  args    the reserved arg
+ *
+ * @return int
+ * @retval 0 success
+ * @retval otherwise failed see @ref bot_errno.h
+ */
+int bot_msg_notify_callback_register(bot_msg_notify_callback_t notify, void *args);
+
+/**
+ * @brief get bot(blockchain of things) sdk version
+ *
+ * @return const char*
+ * @retval NULL get sdk version fail
+ * @return otherwise sdk version
+ */
+const char *bot_version_get(void);
+
+/**
+ * @brief start bot(blockchain of things) asset registration
+ *
+ * @param[in]  asset_id asset ID,must to be unique, the length is greater than 0 and less than 64 bytes,
+ * and can only contain uppercase and lowercase letters, numbers, and symbols "_", ".", "-"
+ * @param[in]  asset_type device type, the format is "xxxx-yyyy"
+ *                        xxxx: equipment type code, refer to the project information table
+ *                        yyyy: device model, a user-defined character string,
+ *                              which can only contain uppercase and lowercase letters, numbers, and symbols "_", "."
+ * @param[in]  asset_dataver data version of asset to register. the default value is "ADV1.0"
+ *
+ * @return int
+ * @retval >=0 success
+ * @retval otherwise failed see @ref bot_errno.h
+ */
+int bot_asset_register(char *asset_id, char *asset_type, char *asset_dataver);
+
+/**
+ * @brief publish data to the bot(blockchain of things)
+ *
+ * @param[in]  data  data to publish, it must be cjson format in string.
+ * @param[in]  len   the data length must be less than 1024
+ *
+ * @return int
+ * @retval >=0 success, >0 indicates msg_id
+ * @retval otherwise failed see @ref bot_errno.h
+ */
+int bot_data_publish(uint8_t *data, int len);
+
+/**
+ * @brief query device connection status
+ *
+ * @return int
+ * @retval 0 disconnect, channel enabled
+ * @retval 1 connect, channel enabled
+ * @retval 2 disconnect, channel disabled
+ * @retval 3 invalid
+ */
+int bot_device_status_get(void);
+
+/**
+ * @brief query asset registration status
+ *
+ * @param[in]  asset_id ID of the asset to register,asset_id must to be unique
+ *
+ * @return int
+ * @retval 0 - Module not activated, asset not registered
+ * @retval 1 - Module activated, asset registered,
+ * @retval 2 - Module activated, asset not registered
+ * @retval other value means error see @ref bot_errno.h
+ *
+ */
+int bot_asset_status_get(char *asset_id);
+
+/**
+ * @brief bot(blockchain of things) channel switch
+ *
+ * @param[in]  cmd  command for channel switch, 0 to off, 1 to on
+ *
+ * @return int
+ * @retval 0 success
+ * @retval otherwise failed see @ref bot_errno.h
+ */
+int bot_channel_switch(int cmd);
+
+/**
+ * @brief set product information
+ *
+ * @param[in]  config  obtained in the project information sheet
+ *
+ * @return int
+ * @retval 0 success
+ * @retval otherwise failed see @ref bot_errno.h
+ */
+int bot_config_set(const char *config);
+
+/**
+ * @brief get product information
+ *
+ * @param[in]   buf_len the length of the config array, must be greater than @ref BOT_CONFIG_BUF_MIN_LEN
+ * @param[out]  config  get product information
+ *
+ * @return int
+ * @retval 0 success
+ * @retval otherwise failed see @ref bot_errno.h
+ */
+int bot_config_get(char *config, int buf_len);
+
+/**
+ * @brief pac data of the bot(blockchain of things)
+ *
+ * @param[in]      format    1:JSON, 0: Binary
+ * @param[in]      data_in   data to be packed
+ * @param[in]      inlen     the length of input data
+ * @param[out]     data_out  data after packing
+ * @param[in out]  outlen    in: the length of the output buffer. out: the real length of the data.
+ *
+ * @return int
+ * @retval 0 success
+ * @retval otherwise failed see @ref bot_errno.h
+ */
+int bot_data_pac(int format, uint8_t *data_in, int inlen, uint8_t *data_out, int *outlen);
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* __BOT_API_H__ */

+ 67 - 0
components/antbot/include/bot_default_config.h

@@ -0,0 +1,67 @@
+/**
+ * @file bot_default_config.h
+ * @brief bot config header file
+ * @details This header file defines the config of bot
+ *
+ * @copyright Copyright (C) 2015-2022 Ant Group Holding Limited
+ */
+
+#ifndef __BOT_DEFAULT_CONFIG_H__
+#define __BOT_DEFAULT_CONFIG_H__
+
+#include "bot_platform_user_config.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/* stimer config */
+#ifndef  BOT_COMP_STIMER
+#define  BOT_COMP_STIMER   1
+#endif
+
+/* LOG config */
+#ifndef  BOT_COMP_LOG
+#define  BOT_COMP_LOG   0
+#endif
+
+/* LOG macro config */
+#if BOT_COMP_LOG == 1
+#ifndef  BOT_LOG_USE
+#define  BOT_LOG_USE   1
+#endif
+#endif
+
+/* KV config */
+#ifndef  BOT_COMP_KV
+#define  BOT_COMP_KV    0
+#endif
+
+/* AT config */
+#ifndef  BOT_COMP_AT
+#define  BOT_COMP_AT    0
+#endif
+
+/* GNSS config */
+#ifndef  BOT_COMP_GNSS
+#define  BOT_COMP_GNSS  0
+#endif
+
+/* MEM config */
+#ifndef  BOT_COMP_MEM
+#define  BOT_COMP_MEM   0
+#endif
+
+#ifdef BOT_DEBUG
+#define BOT_LOG_GLOBAL_LVL                LOG_DEBUG
+#else
+#define BOT_LOG_GLOBAL_LVL                LOG_INFO
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BOT_CONFIG_H__ */
+

+ 511 - 0
components/antbot/include/bot_errno.h

@@ -0,0 +1,511 @@
+/**
+ * @file bot_errno.h
+ * @brief bot error number header file
+ *
+ * @copyright Copyright (C) 2015-2022 Ant Group Holding Limited
+ */
+
+#ifndef __BOT_ERRNO_H__
+#define __BOT_ERRNO_H__
+
+#include "bot_typedef.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* -------------- General Error Code --------------------------- */
+#define BOT_EMAAS_OK      0    /**< There is no error */
+#define BOT_EMAAS_ERROR   -1    /**< A generic error happens */
+#define BOT_EMAAS_NOMEM   -2    /**< No memory */
+#define BOT_EMAAS_INVAL   -3    /**< Invalid argument */
+/* ------------------------------------------------------------  */
+
+
+/* -------------- Components&Service Error Code -----------------*/
+#define BOT_ETYPE_NORMAL (0x00U << 24)
+#define BOT_ETYPE_WARN   (0x01U << 24)
+#define BOT_ETYPE_ERROR  (0x02U << 24)
+#define BOT_ETYPE_FATAL  (0x03U << 24)
+
+/* The MID represent each module */
+typedef enum {
+    BOT_MID_COMP_AT          = 0x00, /* AT component. */
+    BOT_MID_COMP_CRYPTO      = 0x01, /* Crypto component. */
+    BOT_MID_COMP_GNSS        = 0x02, /* GNSS component. */
+    BOT_MID_COMP_KV          = 0x03, /* KV component. */
+    BOT_MID_COMP_LOG         = 0x04, /* LOG component. */
+    BOT_MID_COMP_MEM         = 0x05, /* MEM component. */
+    BOT_MID_COMP_NET         = 0x06, /* NET component. */
+    BOT_MID_COMP_TLV         = 0x07, /* TLV component. */
+    BOT_MID_COMP_UTILS       = 0x08, /* UTILS component. */
+    BOT_MID_COMP_CHAIN       = 0x09, /* UTILS component. */
+
+    BOT_MID_SRV_DTC          = 0x30, /* Service : Data to Cloud/Chain*/
+    BOT_MID_SRV_NTP          = 0x31, /* Service : NTP*/
+    BOT_MID_MAX
+} bot_module_id;
+
+/* ------ Coin Macros for three Comp&Service Error Code segments. -------*/
+/* Define bot fatal error, 32-bit unsigned integer error code */
+#define BOT_ERRNO_FATAL(MID, ERRNO) \
+    (-(BOT_ETYPE_FATAL |  ((uint32_t)(MID) << 16) | ((uint32_t)(ERRNO))))
+
+/* Define bot critical error, 32-bit unsigned integer error code */
+#define BOT_ERRNO_ERROR(MID, ERRNO) \
+    (-(BOT_ETYPE_ERROR | ((uint32_t)(MID) << 16) | ((uint32_t)(ERRNO))))
+
+/* Define bot warn, 32-bit unsigned integer error code */
+#define BOT_ERRNO_WARN(MID, ERRNO) \
+    (-(BOT_ETYPE_WARN | ((uint32_t)(MID) << 16) | ((uint32_t)(ERRNO))))
+
+/* Define bot info, 32-bit unsigned integer error code */
+#define BOT_ERRNO_NORMAL(MID, ERRNO) \
+    (-(BOT_ETYPE_NORMAL | ((uint32_t)(MID) << 16) | ((uint32_t)(ERRNO))))
+/* -------------------------------------------------------------------- */
+
+/* It's a helper macro for record log, post to clond, etc. */
+#define __BOT_ERROR_HANDLER(para1, para2, func, line) \
+    BOT_LOGE(" [Func: %s] [Line: %d] 0X%08X 0X%08X\r\n",func, line, para1, para2)
+
+#define __BOT_ERROR_RET_INT(errno, para1, para2, func, line) \
+do{ \
+    __BOT_ERROR_HANDLER(para1, para2, func, line); \
+    return errno; \
+}while(0)
+
+#define __BOT_ERROR_RET_VOID(para1, para2, func, line) \
+do{ \
+    __BOT_ERROR_HANDLER(para1, para2, func, line); \
+    return;\
+}while(0)
+
+#define __BOT_ERROR_RECORD(para1, para2, func, line) \
+do{ \
+    __BOT_ERROR_HANDLER(para1, para2, func, line); \
+}while(0)
+
+/*
+ * Error Handle Macros . Record and return errcode.
+ * @errno: errcode. signed interger.
+ * @para1: user's parameter, signed integer.
+ * @para2: user's parameter, signed integer.
+ */
+#define BOT_ERROR_RET_INT(errno, para1, para2)   __BOT_ERROR_RET_INT(errno, para1, para2, __func__, __LINE__)
+
+/*
+ * Error Handle Macros . Record and return void.
+ * @para1: user's parameter, signed integer.
+ * @para2: user's parameter, signed integer.
+ */
+#define BOT_ERROR_RET_VOID(para1, para2)         __BOT_ERROR_RET_VOID(para1, para2, __func__, __LINE__)
+
+/*
+ * Error Handle Macros . Record only.
+ * @para1: user's parameter, signed integer.
+ * @para2: user's parameter, signed integer.
+ */
+#define BOT_ERROR_RECORD(para1, para2)           __BOT_ERROR_RECORD(para1, para2, __func__, __LINE__)
+
+/*
+ * Assert-like macro to check, record and return errcode (for example, interface's return-code).
+ * @pred: predicate (for example, ret!=0, ret!=NULL, a>b, etc.)
+ * @ret: the return-code of checked interface or other variables.
+ * @para1: user's parameter, signed integer.
+ * @para2: user's parameter, signed integer.
+ */
+#define BOT_ERROR_PARA_RETINT_ASSERT(pred, ret, para1, para2) \
+if (pred){ \
+    __BOT_ERROR_HANDLER(para1, para2, __func__, __LINE__); \
+    return ret; \
+}
+
+/*
+ * Assert-like macro to check, record and return void.
+ * @pred: predicate (for example, ret!=0, ret!=NULL, a>b, etc.)
+ * @para1: user's parameter, signed integer.
+ * @para2: user's parameter, signed integer.
+ */
+#define BOT_ERROR_PARA_RETVOID_ASSERT(pred, para1, para2) \
+if (pred) { \
+    __BOT_ERROR_HANDLER(para1, para2, __func__, __LINE__); \
+    return; \
+}
+
+/*
+ * Assert-like macro to check, record but not return .
+ * @pred: predicate (for example, ret!=0, ret!=NULL, a>b, etc.)
+ * @para1: user's parameter, signed integer.
+ * @para2: user's parameter, signed integer.
+ */
+#define BOT_ERROR_PARA_RECORD_ASSERT(pred, para1, para2) \
+if (pred) { \
+    __BOT_ERROR_HANDLER(para1, para2, __func__, __LINE__); \
+}
+
+/*
+ * Example:
+ * =======>
+ *      ret = bot_device_register_adv_check(...);
+ *      if (ret != BOT_EMAAS_OK){
+ *          BOT_LOGE("bot_device_register_adv_check fail %d \r\n", ret);
+            return ret;
+ *      }
+ * =======>
+ *      ret = bot_device_register_adv_check(...);
+ *      BOT_ERROR_STR_RETINT_ASSERT(ret, "bot_device_register_adv_check fail");
+ */
+/*
+ * Assert-like macro to check, record and return errcode if "if statement" is true.
+ * @ret: the return-code of checked interface or other variables.
+ * @desc: the description of ret that is a errcode.
+ */
+#define BOT_ERROR_STR_RETINT_ASSERT(ret, desc) \
+if (ret != BOT_EMAAS_OK){ \
+    BOT_LOGE(" [Func: %s] [Line: %d] %s\r\n",__func__, __LINE__, desc); \
+    return ret; \
+}
+/*
+ * Assert-like macro to check, record and return void if "if statement" is true.
+ * @ret: the return-code of checked interface or other variables.
+ * @desc: the description of ret that is a errcode.
+ */
+#define BOT_ERROR_STR_RETVOID_ASSERT(ret, desc) \
+if (ret != BOT_EMAAS_OK){ \
+    BOT_LOGE("[Func: %s] [Line: %d] %s\r\n",__func__, __LINE__, desc); \
+    return; \
+}
+
+/*
+ * Assert-like macro to check, record but not return if "if statement" is true.
+ * @ret: the return-code of checked interface or other variables.
+ * @desc: the description of ret that is a errcode.
+ */
+#define BOT_ERROR_STR_RECORD_ASSERT(ret, desc) \
+if (ret != BOT_EMAAS_OK){ \
+    BOT_LOGE("[Func: %s] [Line: %d] %s\r\n",__func__, __LINE__, desc); \
+}
+
+/* -------------------------------------------------------------------------------*/
+
+/*
+ * Name Format: BOT_E<MODULE_NAME>_<ERRCODE_NAME> .
+ */
+/* -------------------------- AT Components Errcode ------------------------------*/
+#define BOT_EAT_OK                          BOT_ERRNO_ERROR(BOT_MID_COMP_AT, 0X0000) /* -0x02000000 */
+#define BOT_EAT_PARA_NULL                   BOT_ERRNO_ERROR(BOT_MID_COMP_AT, 0X0001) /* -0x02000001 */
+#define BOT_EAT_NUM_INV                     BOT_ERRNO_ERROR(BOT_MID_COMP_AT, 0X0002) /* -0x02000002 */
+#define BOT_EAT_CMD_INV                     BOT_ERRNO_ERROR(BOT_MID_COMP_AT, 0X0003) /* -0x02000003 */
+#define BOT_EAT_UART_INIT                   BOT_ERRNO_ERROR(BOT_MID_COMP_AT, 0X0004) /* -0x02000004 */
+#define BOT_EAT_UART_CB_REG                 BOT_ERRNO_ERROR(BOT_MID_COMP_AT, 0X0005) /* -0x02000005 */
+#define BOT_EAT_CMD_CB_REG                  BOT_ERRNO_ERROR(BOT_MID_COMP_AT, 0X0006) /* -0x02000006 */
+#define BOT_EAT_TASK_CRT_FAIL               BOT_ERRNO_ERROR(BOT_MID_COMP_AT, 0X0007) /* -0x02000007 */
+#define BOT_EAT_RE_INITIALIZE               BOT_ERRNO_ERROR(BOT_MID_COMP_AT, 0X0008) /* -0x02000008 */
+/* -------------------------------------------------------------------------------*/
+
+/* ------------------------- CRYPTO Components Errcode -------------------------- */
+/* The ECDSA key input parameters are not complete */
+#define BOT_ECRYPTO_KEYGEN_NULL             BOT_ERRNO_ERROR(BOT_MID_COMP_CRYPTO, 0X0000) /* -0x02010000 */
+/* Failed to generate the ECDSA key */
+#define BOT_ECRYPTO_KEYGEN                  BOT_ERRNO_ERROR(BOT_MID_COMP_CRYPTO, 0X0001) /* -0x02010001 */
+/* Failed to generate the ECDSA signature */
+#define BOT_ECRYPTO_SIGNGEN                 BOT_ERRNO_ERROR(BOT_MID_COMP_CRYPTO, 0X0002) /* -0x02010002 */
+/* The input type error which is not in keypair and signature */
+#define BOT_ECRYPTO_DATA_TYPE               BOT_ERRNO_ERROR(BOT_MID_COMP_CRYPTO, 0X0003) /* -0x02010003 */
+/* Failed to save keypair or signature file */
+#define BOT_ECRYPTO_SAVE_FILE               BOT_ERRNO_ERROR(BOT_MID_COMP_CRYPTO, 0X0004) /* -0x02010004 */
+/* Failed to read keypair or signature file */
+#define BOT_ECRYPTO_READ_FILE               BOT_ERRNO_ERROR(BOT_MID_COMP_CRYPTO, 0X0005) /* -0x02010005 */
+/* Output is NULL */
+#define BOT_ECRYPTO_OUTPUT_NULL             BOT_ERRNO_ERROR(BOT_MID_COMP_CRYPTO, 0X0006) /* -0x02010006 */
+/* -------------------------------------------------------------------------------*/
+
+/* ------------------------- GNSS Components Errcode ---------------------------- */
+//#define BOT_EGNSS_XX                      BOT_ERRNO_ERROR(BOT_MID_COMP_GNSS, 0X0001) /* -0x02020001 */
+//#define BOT_EGNSS_YY                      BOT_ERRNO_ERROR(BOT_MID_COMP_GNSS, 0X0002) /* -0x02020002 */
+/* -------------------------------------------------------------------------------*/
+
+/* ------------------------- KV Components Errcode ------------------------------ */
+/* The space is out of range */
+#define BOT_EKV_NO_SPACE                    BOT_ERRNO_ERROR(BOT_MID_COMP_KV, 0X0001) /* -0x02030001 */
+/* The parameter is invalid */
+#define BOT_EKV_INVALID_PARAM               BOT_ERRNO_ERROR(BOT_MID_COMP_KV, 0X0002) /* -0x02030002 */
+/* The os memory malloc error */
+#define BOT_EKV_MALLOC_FAILED               BOT_ERRNO_ERROR(BOT_MID_COMP_KV, 0X0003) /* -0x02030003 */
+/* Could not found the item */
+#define BOT_EKV_NOT_FOUND                   BOT_ERRNO_ERROR(BOT_MID_COMP_KV, 0X0004) /* -0x02030004 */
+/* The flash read operation error */
+#define BOT_EKV_FLASH_READ                  BOT_ERRNO_ERROR(BOT_MID_COMP_KV, 0X0005) /* -0x02030005 */
+/* The flash write operation error */
+#define BOT_EKV_FLASH_WRITE                 BOT_ERRNO_ERROR(BOT_MID_COMP_KV, 0X0006) /* -0x02030006 */
+/* The flash erase operation error */
+#define BOT_EKV_FLASH_ERASE                 BOT_ERRNO_ERROR(BOT_MID_COMP_KV, 0X0007) /* -0x02030007 */
+/* The error related to os lock */
+#define BOT_EKV_OS_LOCK                     BOT_ERRNO_ERROR(BOT_MID_COMP_KV, 0X0008) /* -0x02030008 */
+/* The error related to os semaphose */
+#define BOT_EKV_OS_SEM                      BOT_ERRNO_ERROR(BOT_MID_COMP_KV, 0X0009) /* -0x02030009 */
+
+/* Data encryption error */
+#define BOT_EKV_ENCRYPT                     BOT_ERRNO_ERROR(BOT_MID_COMP_KV, 0X000A) /* -0x0203000A */
+/* Data decryption error */
+#define BOT_EKV_DECRYPT                     BOT_ERRNO_ERROR(BOT_MID_COMP_KV, 0X000B) /* -0x0203000B */
+/* The function is not support yet */
+#define BOT_EKV_NOT_SUPPORT                 BOT_ERRNO_ERROR(BOT_MID_COMP_KV, 0X000C) /* -0x0203000C */
+/* File open fail */
+#define BOT_EKV_FILE_OPEN                   BOT_ERRNO_ERROR(BOT_MID_COMP_KV, 0X000D) /* -0x0203000D */
+/* File read fail */
+#define BOT_EKV_FILE_READ                   BOT_ERRNO_ERROR(BOT_MID_COMP_KV, 0X000E) /* -0x0203000E */
+/* File write fail */
+#define BOT_EKV_FILE_WRITE                  BOT_ERRNO_ERROR(BOT_MID_COMP_KV, 0X000F) /* -0x0203000F */
+/* File seek fail */
+#define BOT_EKV_FILE_SEEK                   BOT_ERRNO_ERROR(BOT_MID_COMP_KV, 0X0010) /* -0x02030010 */
+/* ------------------------------------------------------------------------------ */
+
+/* ------------------------- LOG Components Errcode ----------------------------- */
+//#define BOT_ELOG_XX                       BOT_ERRNO_ERROR(BOT_MID_COMP_LOG, 0X0001) /* -0x02040001 */
+//#define BOT_ELOG_YY                       BOT_ERRNO_ERROR(BOT_MID_COMP_LOG, 0X0002) /* -0x02040002 */
+/* ------------------------------------------------------------------------------ */
+
+/* ------------------------- MEM Components Errcode ----------------------------- */
+/* mem module mem infomation get failed */
+#define BOT_EMEM_INFO_GET                   BOT_ERRNO_ERROR(BOT_MID_COMP_MEM, 0X0001) /* -0x02050001 */
+/* mem module infomation with invalid para */
+#define BOT_EMEM_INFO_PARA                  BOT_ERRNO_ERROR(BOT_MID_COMP_MEM, 0X0002) /* -0x02050002 */
+/* mem module init len invalid */
+#define BOT_EMEM_INIT_LEN_INV               BOT_ERRNO_ERROR(BOT_MID_COMP_MEM, 0X0003) /* -0x02050003 */
+/* mem module region add len invalid */
+#define BOT_EMEM_REGION_ADD_LEN_INV         BOT_ERRNO_ERROR(BOT_MID_COMP_MEM, 0X0004) /* -0x02050004 */
+/* mem module alloc size zero */
+#define BOT_EMEM_ALLOC_SIZE_ZERO            BOT_ERRNO_ERROR(BOT_MID_COMP_MEM, 0X0005) /* -0x02050005 */
+/* mem module alloc size invalid */
+#define BOT_EMEM_ALLOC_SIZE_INV             BOT_ERRNO_ERROR(BOT_MID_COMP_MEM, 0X0006) /* -0x02050006 */
+/* mem module partition head invalid */
+#define BOT_EMEM_PT_HEAD_INV                BOT_ERRNO_ERROR(BOT_MID_COMP_MEM, 0X0007) /* -0x02050007 */
+/* mem module no valid mem block */
+#define BOT_EMEM_NO_VALID_BLK               BOT_ERRNO_ERROR(BOT_MID_COMP_MEM, 0X0008) /* -0x02050008 */
+/* mem module free ptr is NULL */
+#define BOT_EMEM_FREE_PTR_NULL              BOT_ERRNO_ERROR(BOT_MID_COMP_MEM, 0X0009) /* -0x02050009 */
+/* mem module realloc size invalid */
+#define BOT_EMEM_REALLOC_SIZE_INV           BOT_ERRNO_ERROR(BOT_MID_COMP_MEM, 0X000A) /* -0x0205000A */
+/* ------------------------------------------------------------------------------ */
+
+/* ------------------------- NET Componnets Errcode ----------------------------- */
+/* network module imei id get failed */
+#define BOT_ENET_MQTT_PARAMETER_ERR         BOT_ERRNO_ERROR(BOT_MID_COMP_NET, 0X0001) /* -0x02060001 */
+/* network module mqtt data model init failed */
+#define BOT_ENET_MQTT_DM_INIT_ERR           BOT_ERRNO_ERROR(BOT_MID_COMP_NET, 0X0002) /* -0x02060002 */
+/* network module mqtt init failed */
+#define BOT_ENET_MQTT_INIT_ERR              BOT_ERRNO_ERROR(BOT_MID_COMP_NET, 0X0003) /* -0x02060003 */
+/* network module mqtt connect failed */
+#define BOT_ENET_MQTT_CONNECT_ERR           BOT_ERRNO_ERROR(BOT_MID_COMP_NET, 0X0004) /* -0x02060004 */
+/* network module mqtt disconnect failed */
+#define BOT_ENET_MQTT_DISCONNECT_ERR        BOT_ERRNO_ERROR(BOT_MID_COMP_NET, 0X0005) /* -0x02060005 */
+/* network module mqtt send data failed */
+#define BOT_ENET_MQTT_SEND_DATA_ERR         BOT_ERRNO_ERROR(BOT_MID_COMP_NET, 0X0006) /* -0x02060006 */
+/* network module json create failed */
+#define BOT_ENET_JSON_CREATE_ERR            BOT_ERRNO_ERROR(BOT_MID_COMP_NET, 0X0007) /* -0x02060007 */
+/* network module json get failed */
+#define BOT_ENET_JSON_GET_ERR               BOT_ERRNO_ERROR(BOT_MID_COMP_NET, 0X0008) /* -0x02060008 */
+/* network module json parse failed */
+#define BOT_ENET_JSON_PARSE_ERR             BOT_ERRNO_ERROR(BOT_MID_COMP_NET, 0X0009) /* -0x02060009 */
+
+/* network module dynamic registration init failed */
+#define BOT_ENET_DYNREG_INIT_ERR            BOT_ERRNO_ERROR(BOT_MID_COMP_NET, 0X000A) /* -0x0206000A */
+/* network module dynamic registration deinit failed */
+#define BOT_ENET_DYNREG_DEINIT_ERR          BOT_ERRNO_ERROR(BOT_MID_COMP_NET, 0X000B) /* -0x0206000B */
+/* network module dynamic registration send failed */
+#define BOT_ENET_DYNREG_SEND_ERR            BOT_ERRNO_ERROR(BOT_MID_COMP_NET, 0X000C) /* -0x0206000C */
+/* network module dynamic registration receive failed */
+#define BOT_ENET_DYNREG_RECV_ERR            BOT_ERRNO_ERROR(BOT_MID_COMP_NET, 0X000D) /* -0x0206000D */
+/* network module dynamic registration already */
+#define BOT_ENET_DYNREG_ALREADY_REG         BOT_ERRNO_ERROR(BOT_MID_COMP_NET, 0X000E) /* -0x0206000E */
+
+/* network module coap init failed */
+#define BOT_ENET_COAP_INIT_ERR              BOT_ERRNO_ERROR(BOT_MID_COMP_NET, 0X000F) /* -0x0205000F */
+/* network module coap connect failed */
+#define BOT_ENET_COAP_CONNECT_ERR           BOT_ERRNO_ERROR(BOT_MID_COMP_NET, 0X0010) /* -0x02050010 */
+/* network module coap disconnect failed */
+#define BOT_ENET_COAP_DISCONNECT_ERR        BOT_ERRNO_ERROR(BOT_MID_COMP_NET, 0X0011) /* -0x02050011 */
+/* network module coap send data failed */
+#define BOT_ENET_COAP_SEND_DATA_ERR         BOT_ERRNO_ERROR(BOT_MID_COMP_NET, 0X0012) /* -0x02050012 */
+/* network module coap request auth token filed */
+#define BOT_ENET_COAP_AUTH_TOKEN_ERR        BOT_ERRNO_ERROR(BOT_MID_COMP_NET, 0X0013) /* -0x02050013 */
+/* ------------------------------------------------------------------------------ */
+
+/* ------------------------- TLV Components Errcode ----------------------------- */
+/* TLV module put object failed */
+#define BOT_ETLV_PUT_OBJ                    BOT_ERRNO_ERROR(BOT_MID_COMP_TLV, 0X0001) /* -0x02070001 */
+/* TLV module key list add failed, key is already existed */
+#define BOT_ETLV_KEY_LIST_ADD               BOT_ERRNO_ERROR(BOT_MID_COMP_TLV, 0X0002) /* -0x02070002 */
+/* TLV module serialize failed */
+#define BOT_ETLV_SERIALIZE                  BOT_ERRNO_ERROR(BOT_MID_COMP_TLV, 0X0003) /* -0x02070003 */
+/* TLV module key node get failed, node is not found */
+#define BOT_ETLV_KEY_LIST_NODE_GET          BOT_ERRNO_ERROR(BOT_MID_COMP_TLV, 0X0004) /* -0x02070004 */
+/* TLV module get bytes failed */
+#define BOT_ETLV_BOX_GET_BYTES              BOT_ERRNO_ERROR(BOT_MID_COMP_TLV, 0X0005) /* -0x02070005 */
+/* TLV module get types failed */
+#define BOT_ETLV_BOX_GET_TYPES              BOT_ERRNO_ERROR(BOT_MID_COMP_TLV, 0X0006) /* -0x02070006 */
+/* TLV create failed */
+#define BOT_ETLV_CREATE_ERR                 BOT_ERRNO_ERROR(BOT_MID_COMP_TLV, 0X0007) /* -0x02070007 */
+/* ------------------------------------------------------------------------------ */
+
+/* ------------------------- UTILS Components Errcode --------------------------- */
+/* utils get current time fail */
+#define BOT_EUTILS_CUR_TIME_GET             BOT_ERRNO_ERROR(BOT_MID_COMP_UTILS, 0X0001) /* -0x02080001 */
+/* utils gmtime fail */
+#define BOT_EUTILS_GMTIME                   BOT_ERRNO_ERROR(BOT_MID_COMP_UTILS, 0X0002) /* -0x02080002 */
+/* ------------------------------------------------------------------------------ */
+
+/* ------------------------- CHAIN Components Errcode --------------------------- */
+/* chain module get ecc curve fail */
+#define BOT_ECHAIN_ALG_TYPE_ERR             BOT_ERRNO_ERROR(BOT_MID_COMP_CHAIN, 0X0003) /* -0x02080003 */
+/* chain module sign with ecc fail */
+#define BOT_ECHAIN_ECC_SIGN_ERR             BOT_ERRNO_ERROR(BOT_MID_COMP_CHAIN, 0X0004) /* -0x02080004 */
+/* chain module get random number fail */
+#define BOT_ECHAIN_RAND_ERR                 BOT_ERRNO_ERROR(BOT_MID_COMP_CHAIN, 0X0005) /* -0x02080005 */
+
+/* chain module net connect fail */
+#define BOT_ECHAIN_NET_CONNECT_ERR          BOT_ERRNO_ERROR(BOT_MID_COMP_CHAIN, 0X0010) /* -0x02080010 */
+/* chain module net send fail */
+#define BOT_ECHAIN_NET_SEND_ERR             BOT_ERRNO_ERROR(BOT_MID_COMP_CHAIN, 0X0011) /* -0x02080011 */
+/* chain module net receive fail */
+#define BOT_ECHAIN_NET_RECV_ERR             BOT_ERRNO_ERROR(BOT_MID_COMP_CHAIN, 0X0012) /* -0x02080012 */
+/* chain module packet head get fail */
+#define BOT_ECHAIN_HEAD_RECV_ERR            BOT_ERRNO_ERROR(BOT_MID_COMP_CHAIN, 0X0013) /* -0x02080013 */
+/* chain module packet head verify fail */
+#define BOT_ECHAIN_HEAD_VERIFY_ERR          BOT_ERRNO_ERROR(BOT_MID_COMP_CHAIN, 0X0014) /* -0x02080014 */
+/* chain module handshake fail */
+#define BOT_ECHAIN_HANDSHAKE_ERR            BOT_ERRNO_ERROR(BOT_MID_COMP_CHAIN, 0X0015) /* -0x02080015 */
+
+/* chain module response return error */
+#define BOT_ECHAIN_RESP_ERR                 BOT_ERRNO_ERROR(BOT_MID_COMP_CHAIN, 0X0020) /* -0x02080020 */
+/* chain module recepit return error */
+#define BOT_ECHAIN_RECEPIT_ERR              BOT_ERRNO_ERROR(BOT_MID_COMP_CHAIN, 0X0021) /* -0x02080021 */
+/* chain module transaction response parse fail */
+#define BOT_ECHAIN_TRANS_RESP_PARSE_ERR     BOT_ERRNO_ERROR(BOT_MID_COMP_CHAIN, 0X0022) /* -0x02080022 */
+/* chain module deposit data fail */
+#define BOT_ECHAIN_DEPOSIT_DATA_ERR         BOT_ERRNO_ERROR(BOT_MID_COMP_CHAIN, 0X0023) /* -0x02080023 */
+/* chain module message not defined */
+#define BOT_ECHAIN_NO_DEFINED_MSG           BOT_ERRNO_ERROR(BOT_MID_COMP_CHAIN, 0X0024) /* -0x02080024 */
+/* chain module transaction parse fail */
+#define BOT_ECHAIN_TRANS_PARSE_ERR          BOT_ERRNO_ERROR(BOT_MID_COMP_CHAIN, 0X0025) /* -0x02080025 */
+/* chain module data to be deposited is too long*/
+#define BOT_ECHAIN_TRANS_DATA_OVERSIZE      BOT_ERRNO_ERROR(BOT_MID_COMP_CHAIN, 0X0026) /* -0x02080026 */
+/* chain module rlp decode fail, too few itms */
+#define BOT_ECHAIN_MISSING_ITEMS            BOT_ERRNO_ERROR(BOT_MID_COMP_CHAIN, 0X0027) /* -0x02080027 */
+/* chain module response type mimatch */
+#define BOT_ECHAIN_RESP_TYPE_MISMATCH       BOT_ERRNO_ERROR(BOT_MID_COMP_CHAIN, 0X0028) /* -0x02080028 */
+/* ------------------------------------------------------------------------------ */
+
+/* ------------------------- DTC Service Errcode -------------------------------- */
+/* zero config encryption flag bit is abnormal */
+#define BOT_EDTC_CONFIG_FLAG                BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0200) /* -0x02300200 */
+/* zero config disable */
+#define BOT_EDTC_CONFIG_DISABLE             BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0201) /* -0x02300201 */
+/* zero config handler not found */
+#define BOT_EDTC_CONFIG_HANDLER             BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0202) /* -0x02300202 */
+/* zero config invalid pk */
+#define BOT_EDTC_CONFIG_PK                  BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0203) /* -0x02300203 */
+/* zero config set pk fail */
+#define BOT_EDTC_CONFIG_SET_PK              BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0204) /* -0x02300204 */
+/* zero config invalid ps */
+#define BOT_EDTC_CONFIG_PS                  BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0205) /* -0x02300205 */
+/* zero config set ps fail */
+#define BOT_EDTC_CONFIG_SET_PS              BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0206) /* -0x02300206 */
+/* zero config get pk fail */
+#define BOT_EDTC_CONFIG_GET_PK              BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0207) /* -0x02300207 */
+/* zero config get ps fail */
+#define BOT_EDTC_CONFIG_GET_PS              BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0208) /* -0x02300208 */
+/* zero config get array size too small */
+#define BOT_EDTC_CONFIG_GET_BUF             BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0209) /* -0x02300209 */
+/* zero config invalid pn(product name) */
+#define BOT_EDTC_CONFIG_PN                  BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X020A) /* -0x0230020A */
+/* zero config set pn fail */
+#define BOT_EDTC_CONFIG_SET_PN              BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X020B) /* -0x0230020B */
+/* zero config get pn fail */
+#define BOT_EDTC_CONFIG_GET_PN              BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X020C) /* -0x0230020C */
+/* zero config repeat */
+#define BOT_EDTC_CONFIG_REPEAT              BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X020D) /* -0x0230020D */
+/* zero config decrypto fail */
+#define BOT_EDTC_CONFIG_DECRYPTO            BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X020E) /* -0x0230020E */
+/* zero config encrypto fail */
+#define BOT_EDTC_CONFIG_ENCRYPTO            BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X020F) /* -0x0230020F */
+/* zero config decode fail */
+#define BOT_EDTC_CONFIG_DECODE              BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0210) /* -0x02300210 */
+/* zero config encode fail */
+#define BOT_EDTC_CONFIG_ENCODE              BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0211) /* -0x02300211 */
+/* zero config encode fail */
+#define BOT_EDTC_CONFIG_CRC_CHECK           BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0212) /* -0x02300212 */
+/* zero config encode fail */
+#define BOT_EDTC_CONFIG_SEM_CREAT           BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0213) /* -0x02300213 */
+/* zero config device info init fail */
+#define BOT_EDTC_CONFIG_DEV_INFO            BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0214) /* -0x02300214 */
+/* zero config init fail */
+#define BOT_EDTC_CONFIG_INIT                BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0215) /* -0x02300215 */
+/* zero config invalid instance id */
+#define BOT_EDTC_CONFIG_IID                 BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0216) /* -0x02300216 */
+/* zero config set instance id fail */
+#define BOT_EDTC_CONFIG_SET_IID             BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0217) /* -0x02300217 */
+/* zero config get instance id fail */
+#define BOT_EDTC_CONFIG_GET_IID             BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0218) /* -0x02300218 */
+
+/* The asset ID format is incorrect */
+#define BOT_EDTC_ASSET_ID                   BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0300) /* -0x02300300 */
+/* The asset Type format is incorrect */
+#define BOT_EDTC_ASSET_TYPE                 BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0301) /* -0x02300301 */
+/* ADV format error */
+#define BOT_EDTC_ADV                        BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0302) /* -0x02300302 */
+/* Asset registration interval is too short */
+#define BOT_EDTC_REG_BUSY                   BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0303) /* -0x02300303 */
+/* Asset registration config invalid */
+#define BOT_EDTC_REG_CONFIG_ERR             BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0304) /* -0x02300304 */
+
+/* Network anomalies */
+#define BOT_EDTC_NET                        BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0400) /* -0x02300400 */
+/* The server is not connected */
+#define BOT_EDTC_NOT_CONNECT                BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0401) /* -0x02300401 */
+/* The key is invalid */
+#define BOT_EDTC_SIGNATURE                  BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0402) /* -0x02300402 */
+/* Abnormal dm_handle */
+#define BOT_EDTC_DM                         BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0403) /* -0x02300403 */
+/* Signature generation exception */
+#define BOT_EDTC_GENERATE_SIG               BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0404) /* -0x02300404 */
+/* Failed to set kv parameters */
+#define BOT_EDTC_KV                         BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0405) /* -0x02300405 */
+/* Device not registered */
+#define BOT_EDTC_UNREGIST                   BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0406) /* -0x02300406 */
+/* Json format error */
+#define BOT_EDTC_JSON                       BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0407) /* -0x02300407 */
+/* The uploaded data does not contain an assert ID */
+#define BOT_EDTC_ASSERT_ID                  BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0408) /* -0x02300408 */
+/* Abnormal deviceinfo_handle */
+#define BOT_EDTC_DI                         BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0409) /* -0x02300409 */
+/* Debug info decode error */
+#define BOT_EDTC_DECODE_ERROR               BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0500) /* -0x02300500 */
+/* Debug command error */
+#define BOT_EDTC_DEBUG_CMD_INV              BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0501) /* -0x02300501 */
+/* Fail to clear the device info */
+#define BOT_EDTC_DEV_CLR_ERROR              BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0502) /* -0x02300502 */
+/* Fail to clear the connect info */
+#define BOT_EDTC_CONN_CLR_ERROR             BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0503) /* -0x02300503 */
+/* Send queue is full, please try again later */
+#define BOT_EDTC_BUSY                       BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0504) /* -0x02300504 */
+/* Acknowledgment received timed out */
+#define BOT_EDTC_ACK_TIMEOUT                BOT_ERRNO_ERROR(BOT_MID_SRV_DTC, 0X0505) /* -0x02300505 */
+/* ------------------------------------------------------------------------------ */
+
+/* ------------------------- NTP Service Errcode --------------------------- */
+/* ntp service init fail */
+#define BOT_ENTP_INIT                       BOT_ERRNO_ERROR(BOT_MID_SRV_NTP, 0X0001) /* -0x02310001 */
+/* ntp service setopt fail */
+#define BOT_ENTP_SET                        BOT_ERRNO_ERROR(BOT_MID_SRV_NTP, 0X0002) /* -0x02310002 */
+/* ntp service send fail */
+#define BOT_ENTP_SEND                       BOT_ERRNO_ERROR(BOT_MID_SRV_NTP, 0X0003) /* -0x02310003 */
+/* ------------------------------------------------------------------------------ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BOT_ERRNO_H__ */
+

+ 62 - 0
components/antbot/include/bot_platform.h

@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2020-2021 Alibaba Group Holding Limited
+ */
+#ifndef __BOT_PLATFORM_H
+#define __BOT_PLATFORM_H
+
+#include <stdio.h>
+#include <stdbool.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <sys/time.h>
+#include <time.h>
+
+#include "lfs.h"
+#include "errno.h"
+#include "sockets.h"
+#include "netdb.h"
+#include "FreeRTOS.h"
+#include "queue.h"
+#include "semphr.h"
+#include "luat_fs.h"
+#include "netdb.h"
+
+#define BOT_FS_USER_DIR "\bot"              ///< bot storage folder
+#define BOT_UT_MAL_CELL_PDP_OFF 
+
+#define BOT_O_RDONLY        LFS_O_RDONLY        ///< open file as read-only
+#define BOT_O_WRONLY        LFS_O_WRONLY        ///< open the file for writing only
+#define BOT_O_RDWR          LFS_O_RDWR          ///< Open the file for reading and writing. The above three flags are mutually exclusive, that is, they cannot be used at the same time, but they can be combined with the following flags using the OR (|) operator.
+#define BOT_O_APPEND        LFS_O_APPEND        ///< When reading and writing a file, it will move from the end of the file, that is, the written data will be added to the back of the file in an additional way.
+#define BOT_O_CREAT         LFS_O_CREAT         ///< If the file to be opened does not exist, it will be created automatically.
+#define BOT_O_TRUNC         LFS_O_TRUNC         ///< If the file exists and is opened in a writable mode, this flag will clear the file length to 0, and the data originally stored in the file will also disappear.
+
+/* micro defination about file system, used for bot_fseek()'s/bot_seek()'s whence */
+#define BOT_SEEK_SET        LFS_SEEK_SET        ///< beginning of file
+#define BOT_SEEK_CUR        LFS_SEEK_CUR        ///< current position
+#define BOT_SEEK_END        LFS_SEEK_END        ///< end of file
+
+#define LUAT_RTOS_PRIORITY_HIGH              95
+#define LUAT_RTOS_PRIORITY_ABOVE_NORMAL      75
+#define LUAT_RTOS_PRIORITY_NORMAL            55
+#define LUAT_RTOS_PRIORITY_BELOW_NORMAL      35
+#define LUAT_RTOS_PRIORITY_LOW               15
+
+
+/* bot error code defination */
+#define BOT_E_EINTR         EINTR           ///< 4, Interrupted system call
+#define BOT_E_EAGAIN        EAGAIN          ///< 11, Try again
+#define BOT_E_EPIPE         EPIPE           ///< 32, Broken pipe
+#define BOT_E_EWOULDBLOCK   EWOULDBLOCK     ///< like, EAGAIN, Operation would block
+#define BOT_E_ECONNRESET    ECONNRESET      ///< 104, FConnection reset by peer
+
+// /* socket macros */
+#define BOT_AF_UNSPEC       AF_UNSPEC         ///< AF_UNSPEC
+#define BOT_SOCK_STREAM     SOCK_STREAM       ///< Stream sockets
+#define BOT_SOCK_DGRAM      SOCK_DGRAM        ///< Datagram sockets
+#define BOT_IPPROTO_TCP     IPPROTO_TCP       ///< TCP protocol
+#define BOT_IPPROTO_UDP     IPPROTO_UDP       ///< UDP protocol
+
+
+#endif /* __BOT_PLATFORM_H */

+ 23 - 0
components/antbot/include/bot_platform_user_config.h

@@ -0,0 +1,23 @@
+/* Generated by Kconfiglib (https://github.com/ulfalizer/Kconfiglib) */
+#define BOT_APP 1
+#define BOT_DOUBLE_CHANNEL 1
+#define BOT_APP_BMS 1
+#define BOT_PLAFTORM_ADAPTER 1
+#define BOT_PLATFORM_SYMBEL_RENAME_CONFIG 1
+#define BOT_PLATFORM_MULTI_LIB_CONFIG 1
+#define BOT_SERVICE 1
+#define BOT_SERVICE_POST_DEFAULT_ASYNC 1
+#define BOT_COMP_CRYPTO 1
+#define BOT_COMP_KV 1
+#define BOT_COMP_KV_FS_CONFIG 1
+#define BOT_COMP_LOG 1
+#define BOT_LOG_USE 1
+#define BOT_COMP_STIMER 1
+#define BOT_COMP_MEM 1
+#define BOT_COMP_MEM_DEFAULT_HEAP_SIZE 73728
+#define BOT_COMP_UTILS 1
+#define BOT_DEBUG 1
+#define BOT_COMP_TLV 1
+#define BOT_3RDPARTS_CJSON 1
+#define BOT_3RDPARTS_LINKSDK 1
+#define BOT_3RDPARTS_MBEDTLS 1

+ 21 - 0
components/antbot/include/bot_sdk_config.h

@@ -0,0 +1,21 @@
+/**
+ * @file bot_sdk_config.h
+ * @brief Automatically-generated file. Do not edit! 
+ * @copyright Copyright (C) 2015-2022 Ant Group Holding Limited
+ */
+
+
+#ifndef __BOT_SDK_CONFIG_H__
+#define __BOT_SDK_CONFIG_H__
+
+
+/* automatically generated app firmware information! */
+#define RELEASE_TYPE                    "release"
+#define MAAS_VERSION                    "3.1.2"
+#define MODULE_ID                       "air780e"
+#define PLATFORM_AIR780E                                 1
+#define DATETIME_STRING                 "20231215212101"
+
+
+
+#endif

+ 42 - 0
components/antbot/include/bot_typedef.h

@@ -0,0 +1,42 @@
+/**
+ * @file bot_typedef.h
+ * @brief bot type define header file
+ *
+ * @copyright Copyright (C) 2015-2022 Ant Group Holding Limited
+ */
+
+#ifndef __BOT_TYPEDEF_H__
+#define __BOT_TYPEDEF_H__
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+/***********************************************************************************************************************
+ * Including File
+***********************************************************************************************************************/
+/* head file of C standard library */
+#include <stddef.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdarg.h>
+#include <string.h>
+#include <stdlib.h>
+
+#ifndef _IN_
+#define _IN_            /* indicating input parameter */
+#endif
+#ifndef _OUT_
+#define _OUT_           /* indicating output parameter */
+#endif
+#ifndef _INOUT_
+#define _INOUT_         /* indicating input/output parameter */
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BOT_TYPEDEF_H__ */
+

+ 108 - 0
components/antbot/include/bot_vendor.h

@@ -0,0 +1,108 @@
+/**
+ * @file bot_vendor.h
+ * @brief Standard Mode Adaptation Interface
+ *
+ * @copyright Copyright (C) 2015-2022 Ant Group Holding Limited
+ */
+#ifndef __BOT_VENDOR_H__
+#define __BOT_VENDOR_H__
+
+#include "bot_network.h"
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+
+/**
+ * @brief get network register mode.
+ * @return netctrl status
+ * @retval 0 manual mode
+ * @retval 1 auto mode
+ */
+int bot_network_netctrl_status_get(void);
+
+/**
+ * @brief set network register mode.
+ * @param[in] status 1: auto mode, 0: manual mode.
+ * @return set result
+ * @retval 0 success
+ * @retval others failed
+ */
+int bot_network_netctrl_status_set(int status);
+
+/**
+ * @brief get network status.
+ * @return see @ref bot_net_status_e
+ */
+bot_net_status_e bot_network_status_get(void);
+
+/**
+ * @brief set maas channel sim id and cid, must be called before @ref bot_maas_init
+ * @note  maas channel default sim id is 0, cid is 3
+ *  users can set their own cid, but do not conflict with the existing cid
+ *
+ * @param[in] sim sim card index
+ * @param[in] cid PDP channel index
+ *
+ * @return set result
+ * @retval 0 success
+ * @retval others failed
+ *
+ */
+int bot_network_sim_cid_set(int sim, int cid);
+
+/**
+ * @brief get maas channel sim id and cid
+ *
+ * @param[out] sim sim card index
+ * @param[out] cid PDP channel index
+ *
+ * @return set result
+ * @retval 0 success
+ * @retval others failed
+ *
+ */
+int bot_network_sim_cid_get(int *sim, int *cid);
+
+/**
+ * @brief Format the input error code to string
+ *
+ * @param[in] error_code error code number
+ * @param[out] errno_buff: buffer to store the formatted string, buffer length is not less than 12
+ * @param[in] len length of errno_buff
+ *
+ * @return format result
+ * @retval 0 success
+ * @retval -1 failed
+ */
+int bot_errno_fmt(int error_code, char *errno_buff, unsigned int len);
+
+/**
+ * @brief Get the test cmd return of AT command
+ *
+ * @param[in] cmd_str AT command (example: AT+MAASREGSTATUS)
+ * @return test string (example: +MAASREGSTATUS: 64)
+ * @retval NULL failed
+ * @retval others string pointer
+ */
+const char *bot_at_test_cmd_get(const char *cmd_str);
+
+/**
+ * @brief MaaS debug set/get
+ *
+ * @param[in] para_in input para, string format
+ * @param[out] para_out address to store output para, at least 512 Bytes
+ * @param[in/out] out_len: [in] the length of address; [out] the length of the output para;
+
+ * @return command execution result On success, return 0
+ * @retval 0 success
+ * @retval others failed
+ */
+int bot_maas_debug(const char *para_in, char *para_out, unsigned int *out_len);
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif

+ 13 - 0
components/antbot/include/luat_lib_antbot.h

@@ -0,0 +1,13 @@
+/**
+ * @file luat_lib_antbot.h
+ * @brief antbot luat api
+ * @copyright Copyright (C) 2015-2023 Ant Group Holding Limited
+ */
+#ifndef LUAT_LIB_ANTBOT_H
+#define LUAT_LIB_ANTBOT_H
+
+#include "luat_base.h"  // 必须引入
+
+LUAMOD_API int luaopen_antbot(lua_State *L);
+
+#endif

+ 131 - 0
demo/antbot/bot_app_ebike.lua

@@ -0,0 +1,131 @@
+local bot_asset = require("bot_asset")
+
+local bot_app_ebike = {}
+
+-- EBike 数据上报格式
+local ebike_pub_data_fmt = [[
+{
+  "assetId": "%s",
+  "vehStatus": %d,
+  "mileage": %d,
+  "batteryCap": %d,
+  "soh": %d,
+  "soc": %d,
+  "voltage": %d,
+  "temperature": %d,
+  "fullChargeCycles": %d,
+  "batteryStatus": %d,
+  "dataTime": "%s",
+  "coordinateSystem": %d,
+  "longitude": %f,
+  "latitude": %f,
+  "altitude": %f,
+  "source": %d
+}
+]]
+
+-- EBike 资产类型code
+local asset_type_code_ebike = {
+    EBICYCLE_TYPE_OTHERS  = 1011,           -- 其他
+    EBICYCLE_TYPE_BICYCLE = 1012,           -- 单车
+    EBICYCLE_TYPE_PEDELEC = 1013            -- 助力车
+}
+
+-- EBike 数据结构
+local function create_asset_data()
+    return {
+        vehStatus = 0,                      -- 车辆状态           
+        mileage = 0,                        -- 单次里程,单位:米
+        batteryCap = 0,                     -- 电池剩余容量,单位:mAh
+        soh = 0,                            -- 电池健康状态,取值范围:[0-100]
+        soc = 0,                            -- 电池电量,取值范围:[0-100]
+        voltage = 0,                        -- 电池电压,单位:0.01V 
+        temperature = 0,                    -- 电池温度,单位:0.01℃
+        fullChargeCycles = 0,               -- 累计充放电次数
+        batteryStatus = 0,                  -- 电池状态,0-搁置,1-充电,2-放电,3-预留
+        dataTime = "",                      -- 数据采集时间,"20211103173632"表示2021/11/03 17:36:32
+        location = bot_asset.locationInfo() -- 地理位置信息
+    }
+end
+
+local function user_asset_id_get()
+    -- 资产编号,作为资产的唯一标识, 根据实际修改, "BOT-TEST" 仅用于测试 
+    -- 需用户按实际情况填写
+    return "BOT-TEST"
+end
+
+
+function bot_app_ebike.user_asset_config_get()
+    local asset_config = bot_asset.configInfo()
+
+    -- /***************** 以下信息需用户按实际情况填写 *******************************/
+
+    local asset_id = user_asset_id_get()
+    local asset_type_code = asset_type_code_ebike.EBICYCLE_TYPE_PEDELEC
+    -- 表示资产型号, 内容为自定义字符串(且不能带有符号"-")
+    local asset_model = "WD215"
+
+    -- /***************** 以上信息需用户按实际情况填写 *******************************/
+
+    asset_config.id = asset_id
+    asset_config.type = tostring(asset_type_code) .. "-" .. asset_model
+    asset_config.adv = BOT_ASSET_DATA_VERSION
+
+    return asset_config
+end
+
+
+function bot_app_ebike.user_asset_data_get()
+    local ebike_data = create_asset_data()
+
+    -- /***************** 以下信息需用户按实际情况填写 *******************************/ 
+
+    -- /* !!!必填项,详细说明请参考项目信息表 */
+    -- /* 业务数据,需要填入实际运行数据,缺省字段请不要删除,int型默认传入: -1,string默认传入: "-" */
+    ebike_data.vehStatus = 12               -- /* 车辆状态 */
+    ebike_data.mileage = 5000               -- /* 单次里程,单位:米 */
+    ebike_data.batteryCap = 20000           -- /* 电池剩余容量,单位:mAh */
+    ebike_data.soh = 90                     -- /* 电池健康状态,取值范围:[0-100] */
+    ebike_data.soc = 90                     -- /* 电池电量,取值范围:[0-100] */
+    ebike_data.voltage = 3000               -- /* 电池电压,单位:0.01V */
+    ebike_data.temperature = 3000           -- /* 电池温度,单位:0.01℃ */
+    ebike_data.fullChargeCycles = 12        -- /* 累计充放电次数 */
+    ebike_data.batteryStatus = 1            -- /* 电池状态,0-搁置,1-充电,2-放电,3-预留 */
+    ebike_data.dataTime = "20221027173632"  -- /* 数据采集时间,"20211103173632"表示2021/11/03 17:36:32 */
+
+    -- /* 非必填项 */
+    -- /* 地理位置信息,若没有地理位置信息数据,请不要删除字段,默认传入:-1 */
+    ebike_data.location.coordinateSystem = 2    --  /* 坐标系,1-WGS_84,2-GCJ_02 */
+    ebike_data.location.longitude = 121.5065267 -- /* 经度 */
+    ebike_data.location.latitude = 31.2173088   -- /* 纬度 */
+    ebike_data.location.altitude = 30.04        -- /* 海拔高度 */
+    ebike_data.location.source = 0              -- /* 定位源 */
+
+    -- /***************** 以上信息需用户按实际情况填写 *******************************/
+
+    -- /* 此处为信息组包,用户无需关注 */
+    local data = string.format(ebike_pub_data_fmt,
+        user_asset_id_get(),
+        ebike_data.vehStatus,
+        ebike_data.mileage,
+        ebike_data.batteryCap,
+        ebike_data.soh,
+        ebike_data.soc,
+        ebike_data.voltage,
+        ebike_data.temperature,
+        ebike_data.fullChargeCycles,
+        ebike_data.batteryStatus,
+        ebike_data.dataTime,
+        ebike_data.location.coordinateSystem,
+        ebike_data.location.longitude,
+        ebike_data.location.latitude,
+        ebike_data.location.altitude,
+        ebike_data.location.source
+    )
+
+    print("bot user data: " .. data, "len " .. #data)
+
+    return data
+end
+
+return bot_app_ebike

+ 38 - 0
demo/antbot/bot_asset.lua

@@ -0,0 +1,38 @@
+local bot_asset = {}
+--测试使用的配置Token,量产Token请找蚂蚁同学获取
+BOT_CONFIG_TOKEN = "iBot-rawData&RUBDPmYzoj2ftkNLEUKBbLjYUNoVHtFZUj0fKTgF8fpkXZbQcbOaNkFuL69rPZ3M0g=="
+
+-- 资产数据字段版本号(assetDataVersion)由蚂蚁定义,默认值为"ADV1.0",无需修改
+BOT_ASSET_DATA_VERSION = "ADV1.0"
+-- 资产编号最大长度
+BOT_ASSET_ID_MAX_SIZE = 64
+-- 资产类型最大长度
+BOT_ASSET_TYPE_MAX_SIZE = 64
+-- 资产数据版本最大长度
+BOT_ASSET_ADV_MAX_SIZE = 16
+-- 业务数据包最大长度
+BOT_USER_DATA_STRING_MAX_SIZE = 1024
+-- 注册失败时最大重试次数
+BOT_REG_RETRY_COUNT_MAX = 3
+
+-- 通用资产配置数据结构
+function bot_asset.configInfo()
+    return {
+        id = "",
+        type = "",
+        adv = ""
+    }
+end
+
+-- 通用地理位置数据结构
+function bot_asset.locationInfo()
+    return {
+        coordinateSystem = 0,
+        longitude = 0.0,
+        latitude = 0.0,
+        altitude = 0.0,
+        source = 0
+    }
+end
+
+return bot_asset

+ 114 - 0
demo/antbot/main.lua

@@ -0,0 +1,114 @@
+-- LuaTools需要PROJECT和VERSION这两个信息
+PROJECT = "antbot_lua"
+VERSION = "1.0.0"
+
+log.info("main", PROJECT, VERSION)
+
+_G.sys = require("sys")
+
+-- 引入 ebike 应用示例模块
+local bot_app_ebike = require("bot_app_ebike")
+
+-- antbot.app_sta_get 固定返回值类型
+local bot_msg_type = {
+    BOT_MSG_UNAVAILABLE = 0,
+    BOT_MSG_INIT_FAILED = 1,
+    BOT_MSG_INIT_SUCESS = 2,
+    BOT_MSG_REG_FAILED = 3,
+    BOT_MSG_REG_SUCESS = 4,
+    BOT_MSG_PUB_FAILED = 5,
+    BOT_MSG_PUB_SUCESS = 6,
+    BOT_MSG_DATA_VERIFY_FAILED = 7
+}
+-- 用户资产数据上报
+function bot_app_asset_data_report()
+    local bot_user_data = bot_app_ebike.user_asset_data_get()
+    if #bot_user_data > BOT_USER_DATA_STRING_MAX_SIZE then
+        log.error("bot_user_data length out of range")
+        return
+    end
+
+    log.debug("bot start publishing bot data")
+
+    local ret = antbot.data_publish(bot_user_data, #bot_user_data)
+    if ret < 0 then
+        log.error("It was fail to publish bot data, ret: -0x", string.format("%x", -ret))
+        return
+    end
+
+    log.info("successfully published bot data, cnt:", ret)
+end
+
+sys.taskInit(function()
+    sys.wait(3000)
+
+    local version = antbot.version_get();
+    log.debug("antbot.version_get: ", version)
+
+    log.debug("antbot initialization")
+    local ret = antbot.init()
+    if ret ~= 0 then
+        log.error("antbot initialization failed.")
+        return
+    end
+
+    log.debug("antbot config_set")
+    ret = antbot.config_set(BOT_CONFIG_TOKEN)
+    if ret ~= 0 then
+        log.error("antbot config_set failed.")
+        return
+    end
+
+    local asset_config = bot_app_ebike.user_asset_config_get()
+    local reg_retry_count = 0;
+    local bot_sta = bot_msg_type.BOT_MSG_UNAVAILABLE
+    local bot_msg = bot_msg_type.BOT_MSG_UNAVAILABLE
+    local count = 1
+    while 1 do
+        log.debug("antbot app_sta_get")
+        if bot_sta ~= antbot.app_sta_get() then
+            bot_sta = antbot.app_sta_get()
+            bot_msg = bot_sta
+        end
+
+        log.info("luatos", "hi", count, os.date())
+        log.info("lua", rtos.meminfo())         -- lua内存
+        log.info("sys", rtos.meminfo("sys"))    -- sys内存
+        count = count + 1
+
+        if bot_msg == bot_msg_type.BOT_MSG_INIT_SUCESS then
+            log.debug("bot init success")
+            if antbot.asset_status_get(asset_config.id) == 1 then
+                log.info("asset already register")
+                bot_msg = bot_msg_type.BOT_MSG_REG_SUCESS
+            else
+                reg_retry_count = 0
+                antbot.asset_register(asset_config.id, asset_config.type, asset_config.adv)
+                bot_msg = bot_msg_type.BOT_MSG_UNAVAILABLE;
+                -- 注册间隔需要大于2s
+                -- sys.wait(2 * 1000)
+            end
+        elseif bot_msg == bot_msg_type.BOT_MSG_REG_FAILED then
+            log.debug("bot register fail")
+            sys.wait(10 * 1000)
+            if reg_retry_count < BOT_REG_RETRY_COUNT_MAX then
+                reg_retry_count = reg_retry_count + 1
+                antbot.asset_register(asset_config.id, asset_config.type, asset_config.adv)
+                log.info("msg notify BOT_MSG_REG_FAILED retry_count: ", reg_retry_count)
+            end
+        elseif bot_msg == bot_msg_type.BOT_MSG_REG_SUCESS or
+            bot_msg == bot_msg_type.BOT_MSG_PUB_SUCESS or
+            bot_msg == bot_msg_type.BOT_MSG_PUB_FAILED then
+            log.debug("bot register success or pub success or pub failed")
+
+            bot_app_asset_data_report();
+
+            sys.wait(20 * 1000);
+        else
+            sys.wait(1 * 1000)
+        end
+    end
+    
+end)
+
+sys.run()

+ 4 - 0
luat/include/luat_libs.h

@@ -164,4 +164,8 @@ LUAMOD_API int luaopen_ws2812( lua_State *L );
 
 
 LUAMOD_API int luaopen_onewire( lua_State *L );
 LUAMOD_API int luaopen_onewire( lua_State *L );
 
 
+LUAMOD_API int luaopen_antbot( lua_State *L );
+
+
+
 #endif
 #endif