|
Link Kit C-SDK
4.1.0
|
OTA模块接口实现文件, 其中包含了OTA的所有用户API. 更多...
#include "aiot_ota_api.h"#include "core_mqtt.h"#include "core_string.h"#include "core_sha256.h"#include "ota_md5.h"#include "ota_private.h"#include "core_log.h"#include "core_global.h"
函数 | |
| static int32_t | _ota_subscribe (void *mqtt_handle, void *ota_handle) |
| static void | _ota_mqtt_process (void *handle, const aiot_mqtt_recv_t *const packet, void *userdata) |
| static int32_t | _ota_parse_json (aiot_sysdep_portfile_t *sysdep, void *in, uint32_t in_len, char *key_word, char **out) |
| static int32_t | _ota_parse_list_array (char *str, int32_t str_len, ota_list_json *array) |
| static int32_t | _process_single_file (aiot_sysdep_portfile_t *sysdep, char *data, uint32_t data_len, int type, aiot_download_task_desc_t *task_desc, ota_handle_t *ota_handle) |
| static void * | _download_deep_copy_base (aiot_sysdep_portfile_t *sysdep, char *in) |
| static void | _ota_core_mqtt_process_handler (void *context, aiot_mqtt_event_t *event, core_mqtt_event_t *core_event) |
| static int32_t | _ota_core_mqtt_operate_process_handler (ota_handle_t *ota_handle, core_mqtt_option_t option) |
| void * | aiot_ota_init (void) |
| 创建一个OTA实例 更多... | |
| int32_t | aiot_ota_deinit (void **handle) |
| 销毁ota实例句柄 更多... | |
| int32_t | aiot_ota_setopt (void *handle, aiot_ota_option_t option, void *data) |
| 设置ota句柄的参数 更多... | |
| int32_t | aiot_ota_report_version (void *handle, char *version) |
| 上报普通设备(非网关中的子设备)的版本号 更多... | |
| int32_t | aiot_ota_report_version_ext (void *handle, char *product_key, char *device_name, char *version) |
| 用于网关中的子设备上报版本号 更多... | |
| int32_t | aiot_ota_query_firmware (void *handle) |
| 设备端主动向云端查询升级任务 更多... | |
| int32_t | _download_deep_free_task_desc (aiot_sysdep_portfile_t *sysdep, void *data) |
| int32_t | _ota_prase_topic (aiot_sysdep_portfile_t *sysdep, char *topic, uint8_t topic_len, ota_type_t *type, char **product_key, char **device_name) |
| void * | _download_deep_copy_task_desc (aiot_sysdep_portfile_t *sysdep, void *data) |
| int32_t | _ota_publish_base (void *handle, char *topic_prefix, char *product_key, char *device_name, char *suffix, char *params) |
变量 | |
| static aiot_mqtt_topic_map_t | g_ota_topic_map [OTA_TOPIC_NUM] |
OTA模块接口实现文件, 其中包含了OTA的所有用户API.
|
static |

|
static |

|
static |
|
static |
|
static |

|
static |
|
static |
|
static |

| void* aiot_ota_init | ( | ) |
创建一个OTA实例
| 非NULL | ota实例句柄 |
| NULL | 初始化失败, 或者是因为没有设置portfile, 或者是内存分配失败导致 |

| int32_t aiot_ota_deinit | ( | void ** | handle | ) |
销毁ota实例句柄
| [in] | handle | 指向ota实例句柄的指针 |
| STATE_OTA_DEINIT_HANDLE_IS_NULL | handle或者handle所指向的地址为空 |
| STATE_SUCCESS | 执行成功 |

| int32_t aiot_ota_setopt | ( | void * | handle, |
| aiot_ota_option_t | option, | ||
| void * | data | ||
| ) |
设置ota句柄的参数
对OTA会话进行配置, 常见的配置选项包括
AIOT_OTAOPT_MQTT_HANDLE: 把 aiot_mqtt_init 返回的MQTT会话句柄跟OTA会话关联起来AIOT_OTAOPT_RECV_HANDLER: 设置OTA消息的数据处理回调, 这个用户回调在有OTA消息的时候, 会被 aiot_mqtt_recv 调用到| [in] | handle | ota句柄 |
| [in] | option | 配置选项, 更多信息请参考aiot_ota_option_t |
| [in] | data | 配置选项数据, 更多信息请参考aiot_ota_option_t |
| STATE_OTA_SETOPT_HANDLE_IS_NULL | ota句柄为空 |
| STATE_OTA_SETOPT_DATA_IS_NULL | 参数data字段为空 |
| STATE_USER_INPUT_UNKNOWN_OPTION | option不支持 |
| STATE_SUCCESS | 参数设置成功 |

| int32_t aiot_ota_report_version | ( | void * | handle, |
| char * | version | ||
| ) |
上报普通设备(非网关中的子设备)的版本号
如果云端不知道某台设备当前的固件版本号, 就不会为其提供OTA服务, 而如果不知道设备的新版本号, 也不会认为它升级成功
所以OTA要正常工作, 一般会要求设备在每次开机之后, 就调用这个接口, 将当前运行的固件版本号字符串上报给云端
参数的handle通过aiot_ota_init 得到, 比如, 上报当前版本号为"1.0.0"的代码写作
| [in] | handle | 指向ota实例句柄的指针 |
| [in] | version | 待上报的版本号 |
| STATE_OTA_REPORT_HANDLE_IS_NULL | ota句柄为空 |
| STATE_OTA_REPORT_VERSION_IS_NULL | 用户输入的版本号为空 |
| STATE_OTA_REPORT_MQTT_HANDLE_IS_NULL | ota_handle句柄中的mqtt句柄为空 |
| STATE_OTA_REPORT_FAILED | 中止执行上报 |
| STATE_SUCCESS | 执行成功 |

| int32_t aiot_ota_report_version_ext | ( | void * | handle, |
| char * | product_key, | ||
| char * | device_name, | ||
| char * | version | ||
| ) |
用于网关中的子设备上报版本号
| [in] | handle | ota实例句柄 |
| [in] | product_key | 设备的product_key |
| [in] | device_name | 设备的名称 |
| [in] | version | 版本号 |
| STATE_SUCCESS | 上报成功 |
| STATE_OTA_REPORT_EXT_HANELD_IS_NULL | ota句柄为空 |
| STATE_OTA_REPORT_EXT_VERSION_NULL | 用户输入的版本号为空 |
| STATE_OTA_REPORT_EXT_PRODUCT_KEY_IS_NULL | 子设备的product_key输入为空 |
| STATE_OTA_REPORT_EXT_DEVICE_NAME_IS_NULL | 子设备的device_name输入为空 |
| STATE_OTA_REPORT_EXT_MQTT_HANDLE_IS_NULL | ota句柄中的mqtt_handle为空 |
| STATE_OTA_REPORT_FAILED | 中止执行上报 |

| int32_t aiot_ota_query_firmware | ( | void * | handle | ) |
设备端主动向云端查询升级任务
设备上线后, 云端如果部署了OTA任务, SDK会通过aiot_ota_recv_handler_t 将该任务透给用户. 出于当前业务繁忙等原因, 这个OTA任务可能被暂时忽略, 那么用户可以在业务空闲的时候通过调用本api来让云端再次下推这个OTA任务. 同样地, SDK会从aiot_ota_recv_handler_t 将该OTA任务透给用户
| STATE_SUCCESS | 发送请求成功 |
| STATE_OTA_QUERY_FIRMWARE_HANDLE_IS_NULL | 作为入参的handle句柄没有经过初始化, 需要调用aiot_ota_init 来进行初始化 |

| int32_t _download_deep_free_task_desc | ( | aiot_sysdep_portfile_t * | sysdep, |
| void * | data | ||
| ) |
| int32_t _ota_prase_topic | ( | aiot_sysdep_portfile_t * | sysdep, |
| char * | topic, | ||
| uint8_t | topic_len, | ||
| ota_type_t * | type, | ||
| char ** | product_key, | ||
| char ** | device_name | ||
| ) |
| void* _download_deep_copy_task_desc | ( | aiot_sysdep_portfile_t * | sysdep, |
| void * | data | ||
| ) |

| int32_t _ota_publish_base | ( | void * | handle, |
| char * | topic_prefix, | ||
| char * | product_key, | ||
| char * | device_name, | ||
| char * | suffix, | ||
| char * | params | ||
| ) |

|
static |
1.8.11