Link Kit C-SDK  4.0.0
| 宏定义 | 函数 | 变量
aiot_mqtt_upload_api.c 文件参考

MQTT UPLOAD模块头文件, 提供通过mqtt进行文件上传的能力 更多...

#include "mqtt_upload_private.h"
aiot_mqtt_upload_api.c 的引用(Include)关系图:

struct  _upload_sub_topic_map_t
 

宏定义

#define UPLOAD_GET_U16BIT(h, l)   (((h << 8) | l) & 0xFFFF)
 
#define UPLOAD_GET_U16BIT_HIGH(n)   ((n & 0xFF00) >> 8)
 
#define UPLOAD_GET_U16BIT_LOW(n)   (n & 0x00FF)
 

函数

static int32_t _mqtt_upload_filelist_insert (mqtt_upload_handle_t *up_handle, upload_file_task_handle_t *up_task)
 
static void _mqtt_upload_filelist_destroy (mqtt_upload_handle_t *up_handle)
 
static int32_t _mqtt_upload_resend_pub (mqtt_upload_handle_t *up_handle, upload_file_task_handle_t *up_task)
 
static void _mqtt_upload_up_task_free (aiot_sysdep_portfile_t *sysdep, upload_file_task_handle_t *up_task)
 
static void _mqtt_upload_receive_init_response_handler (void *handle, const aiot_mqtt_recv_t *const packet, void *userdata)
 
static void _mqtt_upload_receive_upload_response_handler (void *handle, const aiot_mqtt_recv_t *const packet, void *userdata)
 
static void _mqtt_upload_receive_cancel_response_handler (void *handle, const aiot_mqtt_recv_t *const packet, void *userdata)
 
static uint16_t crc_ibm (uint8_t const *buffer, size_t len)
 
static int32_t _mqtt_upload_get_payload (aiot_sysdep_portfile_t *sysdep, char *params, char **out)
 
static int32_t _mqtt_upload_get_topic (mqtt_upload_handle_t *up_handle, char **topic, char *fmt)
 
static int32_t _mqtt_upload_data_encode_package (uint8_t *data, uint32_t data_len, char *head_payload, uint8_t *payload)
 
static int32_t _mqtt_upload_creat_string_malloc (aiot_sysdep_portfile_t *sysdep, const char *ch, uint32_t size, char **out)
 
static int32_t _mqtt_upload_file_task_init (aiot_sysdep_portfile_t *sysdep, upload_file_task_handle_t *up_task, const char *file_name, const uint32_t file_size, const char *mode, const char *digest, aiot_mqtt_upload_read_handler_t read_data_handler, void *userdata)
 
static int32_t _mqtt_upload_send_request_init (mqtt_upload_handle_t *up_handle, upload_file_task_handle_t *up_task, char *file_name, uint32_t file_size, const char *mode, const char *digest)
 
static int32_t _mqtt_upload_send_block_file (mqtt_upload_handle_t *up_handle, upload_file_task_handle_t *up_task, uint8_t *data, const uint32_t block_size, const uint32_t offset)
 
static int32_t _mqtt_upload_send_request_cancel (mqtt_upload_handle_t *up_handle, upload_file_task_handle_t *up_task)
 
static void _mqtt_upload_core_mqtt_process_handler (void *context, aiot_mqtt_event_t *event, core_mqtt_event_t *core_event)
 
static int32_t _mqtt_upload_mqtt_operate_process_handler (mqtt_upload_handle_t *up_handle, core_mqtt_option_t option)
 
static int32_t _mqtt_upload_parse_json (aiot_sysdep_portfile_t *sysdep, void *input, uint32_t input_len, char *key_word, char **out)
 
static uint8_t _mqtt_upload_block_size_is_valid (uint32_t block_size, uint8_t is_final)
 
static void _mqtt_upload_recv_response_process (void *handle, aiot_mqtt_upload_recv_t *packet, upload_file_task_handle_t *up_task)
 
static void _mqtt_upload_desc_free (aiot_sysdep_portfile_t *sysdep, aiot_mqtt_upload_recv_t *msg)
 
static int32_t _mqtt_upload_subscribe (void *mqtt_handle, mqtt_upload_handle_t *up_handle)
 
static int32_t _mqtt_upload_unsubscribe (mqtt_upload_handle_t *up_handle)
 
void * aiot_mqtt_upload_init (void)
 创建MQTT UPLOAD会话实例, 并以默认值配置会话参数 更多...
 
int32_t aiot_mqtt_upload_deinit (void **handle)
 结束MQTT UPLOAD会话, 销毁实例并回收资源 更多...
 
int32_t aiot_mqtt_upload_setopt (void *handle, aiot_mqtt_upload_option_t option, void *data)
 配置MQTT UPLOAD会话 更多...
 
int32_t aiot_mqtt_upload_open_stream (void *handle, char *file_name, uint32_t file_size, const char *mode, void *digest, aiot_mqtt_upload_read_handler_t read_data_handler, void *userdata)
 向MQTT UPLOAD 服务请求发送文件 更多...
 
int32_t aiot_mqtt_upload_cancel_stream (void *handle, char *file_name)
 向mqtt_upload服务器请求关闭MQTT通道数据上传命令 更多...
 
aiot_mqtt_upload_result_t aiot_mqtt_upload_process (void *handle)
 MQTT Upload 处理函数,处理超时和重发逻辑,返回对应文件的执行的状态 更多...
 

变量

static _upload_sub_topic_map_t g_upload_sub_topic_map [MQTT_UPLOAD_DEFAULT_SUBTOPIC_NUM]
 
static const uint16_t crc_ibm_table [256]
 

详细描述

MQTT UPLOAD模块头文件, 提供通过mqtt进行文件上传的能力

宏定义说明

#define UPLOAD_GET_U16BIT (   h,
 
)    (((h << 8) | l) & 0xFFFF)
#define UPLOAD_GET_U16BIT_HIGH (   n)    ((n & 0xFF00) >> 8)
#define UPLOAD_GET_U16BIT_LOW (   n)    (n & 0x00FF)

函数说明

static int32_t _mqtt_upload_filelist_insert ( mqtt_upload_handle_t *  up_handle,
upload_file_task_handle_t *  up_task 
)
static

函数调用图:

static void _mqtt_upload_filelist_destroy ( mqtt_upload_handle_t *  up_handle)
static

函数调用图:

static int32_t _mqtt_upload_resend_pub ( mqtt_upload_handle_t *  up_handle,
upload_file_task_handle_t *  up_task 
)
static

函数调用图:

static void _mqtt_upload_up_task_free ( aiot_sysdep_portfile_t sysdep,
upload_file_task_handle_t *  up_task 
)
static
static void _mqtt_upload_receive_init_response_handler ( void *  handle,
const aiot_mqtt_recv_t *const  packet,
void *  userdata 
)
static

函数调用图:

static void _mqtt_upload_receive_upload_response_handler ( void *  handle,
const aiot_mqtt_recv_t *const  packet,
void *  userdata 
)
static

函数调用图:

static void _mqtt_upload_receive_cancel_response_handler ( void *  handle,
const aiot_mqtt_recv_t *const  packet,
void *  userdata 
)
static

函数调用图:

static uint16_t crc_ibm ( uint8_t const *  buffer,
size_t  len 
)
static
static int32_t _mqtt_upload_get_payload ( aiot_sysdep_portfile_t sysdep,
char *  params,
char **  out 
)
static
static int32_t _mqtt_upload_get_topic ( mqtt_upload_handle_t *  up_handle,
char **  topic,
char *  fmt 
)
static

函数调用图:

static int32_t _mqtt_upload_data_encode_package ( uint8_t *  data,
uint32_t  data_len,
char *  head_payload,
uint8_t *  payload 
)
static

函数调用图:

static int32_t _mqtt_upload_creat_string_malloc ( aiot_sysdep_portfile_t sysdep,
const char *  ch,
uint32_t  size,
char **  out 
)
static
static int32_t _mqtt_upload_file_task_init ( aiot_sysdep_portfile_t sysdep,
upload_file_task_handle_t *  up_task,
const char *  file_name,
const uint32_t  file_size,
const char *  mode,
const char *  digest,
aiot_mqtt_upload_read_handler_t  read_data_handler,
void *  userdata 
)
static

函数调用图:

static int32_t _mqtt_upload_send_request_init ( mqtt_upload_handle_t *  up_handle,
upload_file_task_handle_t *  up_task,
char *  file_name,
uint32_t  file_size,
const char *  mode,
const char *  digest 
)
static

函数调用图:

static int32_t _mqtt_upload_send_block_file ( mqtt_upload_handle_t *  up_handle,
upload_file_task_handle_t *  up_task,
uint8_t *  data,
const uint32_t  block_size,
const uint32_t  offset 
)
static

函数调用图:

static int32_t _mqtt_upload_send_request_cancel ( mqtt_upload_handle_t *  up_handle,
upload_file_task_handle_t *  up_task 
)
static

函数调用图:

static void _mqtt_upload_core_mqtt_process_handler ( void *  context,
aiot_mqtt_event_t event,
core_mqtt_event_t *  core_event 
)
static
static int32_t _mqtt_upload_mqtt_operate_process_handler ( mqtt_upload_handle_t *  up_handle,
core_mqtt_option_t  option 
)
static

函数调用图:

static int32_t _mqtt_upload_parse_json ( aiot_sysdep_portfile_t sysdep,
void *  input,
uint32_t  input_len,
char *  key_word,
char **  out 
)
static
static uint8_t _mqtt_upload_block_size_is_valid ( uint32_t  block_size,
uint8_t  is_final 
)
static
static void _mqtt_upload_recv_response_process ( void *  handle,
aiot_mqtt_upload_recv_t packet,
upload_file_task_handle_t *  up_task 
)
static

函数调用图:

static void _mqtt_upload_desc_free ( aiot_sysdep_portfile_t sysdep,
aiot_mqtt_upload_recv_t msg 
)
static
static int32_t _mqtt_upload_subscribe ( void *  mqtt_handle,
mqtt_upload_handle_t *  up_handle 
)
static

函数调用图:

static int32_t _mqtt_upload_unsubscribe ( mqtt_upload_handle_t *  up_handle)
static

函数调用图:

void* aiot_mqtt_upload_init ( void  )

创建MQTT UPLOAD会话实例, 并以默认值配置会话参数

返回
void *
返回值
非NULL,返回mqtt_upload_handle_t实例的句柄
NULL初始化失败, 一般是内存分配失败导致

函数调用图:

int32_t aiot_mqtt_upload_deinit ( void **  handle)

结束MQTT UPLOAD会话, 销毁实例并回收资源

参数
[in]handle指向MQTT UPLOAD会话句柄的指针
返回
int32_t
返回值
<STATE_SUCCESS执行失败
>=STATE_SUCCESS执行成功

函数调用图:

int32_t aiot_mqtt_upload_setopt ( void *  handle,
aiot_mqtt_upload_option_t  option,
void *  data 
)

配置MQTT UPLOAD会话

参数
[in]handleMQTT UPLOAD会话句柄
[in]option配置选项, 更多信息请参考 aiot_mqtt_upload_option_t
[in]data配置选项数据, 更多信息请参考 aiot_mqtt_upload_option_t
返回
int32_t
返回值
STATE_SUCCESS参数配置成功
STATE_USER_INPUT_NULL_POINTER入参handle或data为NULL
STATE_USER_INPUT_OUT_RANGE入参optioin的枚举值>=AIOT_DMOPT_MAX
others参考 aiot_state_api.h

函数调用图:

int32_t aiot_mqtt_upload_open_stream ( void *  handle,
char *  file_name,
uint32_t  file_size,
const char *  mode,
void *  digest,
aiot_mqtt_upload_read_handler_t  read_data_handler,
void *  userdata 
)

向MQTT UPLOAD 服务请求发送文件

参数
[in]handleMQTT UPLOAD会话句柄
[in]file_name需要在服务端创建的文件名
[in]file_size需要上传的文件大小
[in]mode同名的文件的处理策略, 更多信息请参考 AIOT_MQTT_UPLOAD_FILE_MODE_OVERWRITE AIOT_MQTT_UPLOAD_FILE_MODE_APPEND AIOT_MQTT_UPLOAD_FILE_MODE_FAIL
[in]digest文件完整的CRC64,不需要完整性校验则为NULL
[in]read_data_handler读取用户文件数据的回调函数, 更多信息请参考 aiot_mqtt_upload_read_handler_t
[in]userdata用户上下文
返回
int32_t
返回值
<STATE_SUCCESS请求发送失败
>=STATE_SUCCESS请求发送成功
others参考aiot_state_api.hSTATE_MQTT_UPLOAD_BASE 中对应的错误码说明
注解

函数调用图:

int32_t aiot_mqtt_upload_cancel_stream ( void *  handle,
char *  file_name 
)

向mqtt_upload服务器请求关闭MQTT通道数据上传命令

参数
[in]handleMQTT UPLOAD会话句柄
[in]file_name需要取消继续上传的文件名
返回
int32_t
返回值
<STATE_SUCCESS请求发送失败
>=STATE_SUCCESS请求发送成功
others参考aiot_state_api.hSTATE_MQTT_UPLOAD_BASE 中对应的错误码说明

函数调用图:

aiot_mqtt_upload_result_t aiot_mqtt_upload_process ( void *  handle)

MQTT Upload 处理函数,处理超时和重发逻辑,返回对应文件的执行的状态

参数
[in]handleMQTT UPLOAD 会话句柄
返回
aiot_mqtt_upload_result_t 返回消息包括两个code, file_name; 更多信息请参考 aiot_mqtt_upload_result_t
返回值
STATE_MQTT_UPLOAD_NONE无任何状态,未开始进行文件上传的处理
STATE_MQTT_UPLOAD_REQUEST_INIT请求服务端进行文件上传,等待服务端返回结果
STATE_MQTT_UPLOAD_IS_UPLOADING正在执行文件上传任务
STATE_MQTT_UPLOAD_REQUEST_CANCEL通知服务端取消文件上传
STATE_MQTT_UPLOAD_CANCEL_SUCCESS文件上传,取消上传任务成功,取消成功后会销毁对应的upload task释放内存资源
STATE_MQTT_UPLOAD_CANCEL_FAILED文件上传,取消上传任务失败
STATE_MQTT_UPLOAD_FAILED文件上传失败
STATE_MQTT_UPLOAD_FAILED_TIMEOUT文件上传超时失败
STATE_MQTT_UPLOAD_FAILED_WHOLE_CHECK文件完整性校验失败
STATE_MQTT_UPLOAD_FINISHED已经完成文件上传的任务,完成文件上传后会销毁对应的upload task释放内存资源

函数调用图:

变量说明

_upload_sub_topic_map_t g_upload_sub_topic_map[MQTT_UPLOAD_DEFAULT_SUBTOPIC_NUM]
static
初始值:
= {
{
MQTT_UPLOAD_UPLOAD_INIT_REPLY,
},
{
MQTT_UPLOAD_UPLOAD_FILE_REPLY,
},
{
MQTT_UPLOAD_UPLOAD_CANCEL_REPLY,
}
}
static void _mqtt_upload_receive_cancel_response_handler(void *handle, const aiot_mqtt_recv_t *const packet, void *userdata)
Definition: aiot_mqtt_upload_api.c:814
static void _mqtt_upload_receive_init_response_handler(void *handle, const aiot_mqtt_recv_t *const packet, void *userdata)
Definition: aiot_mqtt_upload_api.c:565
static void _mqtt_upload_receive_upload_response_handler(void *handle, const aiot_mqtt_recv_t *const packet, void *userdata)
Definition: aiot_mqtt_upload_api.c:688
const uint16_t crc_ibm_table[256]
static