更新时间:2022-11-24 09:20:29下载pdf
本文主要介绍 MCU OTA 服务的接口以及 Demo。
/**
* MCU 升级初始化
* @param handle_cb Upgrade data callback function registration parameters
* @param pack_len The length of data transferred to the user per pull packet swap
* @return Function Operation Result OPRT_OK is ok other is fail
*/
OPERATE_RET tuya_svc_mcu_ota_serve_init(IN TY_OTA_CB_HANDLE_S handle_cb,IN UINT_T pack_len);
/**
* Inform the MCU to upgrade and continue to pull packets,while choice OTA_PACK_WAIT
* @return Function Operation Result OPRT_OK is ok other is fail
*/
OPERATE_RET tuya_svc_mcu_ota_wait_type_post(IN TY_OTA_POST_RESULT_E result);
/**
* Start the MCU upgrade service, input parameters need to be obtained in the IOT specified callback
* @param p_ug_info Information about the upgraded file
* @return Function Operation Result OPRT_OK is ok other is fail
*/
OPERATE_RET tuya_svc_mcu_ota_serve_start(IN CONST FW_UG_S *p_ug_info);
/**
* Upgrade the packet processing callback function
* Rereport the changed MCU version number after the system upgrade
* HTTP report will start after 1S after the interface is used. If it fails, 5S retry
* @param p_mcu_ver Upgraded file information pointer
* @return Function Operation Result OPRT_OK is ok other is fail
*/
OPERATE_RET tuya_svc_mcu_ota_ver_report_syn(IN CONST CHAR_T *p_mcu_ver);
/**
* MCU upgrades subcontract length Settings
* @param pack_len The length of data transferred to the user per pull packet swap,256,512,1024
* @return Function Operation Result OPRT_OK is ok other is fail
*/
OPERATE_RET tuya_svc_mcu_ota_pack_len_set(IN UINT_T pack_len);
手机 OTA 升级界面会弹窗提示。点击升级会提醒设备唤醒后进行升级。
待设备唤醒后连接入云,会有云端升级回调接口下发升级信息(此处对应代码中的的 API 回调函数 dev_ug_inform_cb
)。
进行升级。
升级后,会有升级结束回调。
针对 MCU OTA 升级完成之后,MCU 必须控制模组重启一次,进行 MCU 新版本上报。
STATIC OPERATE_RET ty_uart_mcu_ota_start_cb(IN CONST FW_UG_S *p_ug_info,OUT TY_OTA_PACK_E *action_type);
STATIC OPERATE_RET ty_uart_mcu_ota_data_cb(IN CONST UCHAR_T *p_data, IN CONST UINT_T len,IN UINT_T offset, OUT TY_OTA_PACK_E *action_type);
STATIC OPERATE_RET ty_uart_mcu_ota_end_status_cb(IN TY_OTA_END_STATUS_E status,IN UINT_T offset);
STATIC TY_OTA_CB_HANDLE_S g_ota_msg = {\
.iot_dev_ota_start_cb = ty_uart_mcu_ota_start_cb,\
.iot_dev_ota_data_cb = ty_uart_mcu_ota_data_cb,\
.iot_dev_ota_end_sta_cb = ty_uart_mcu_ota_end_status_cb,\
};
STATIC OPERATE_RET ty_uart_mcu_ota_start_cb(IN CONST FW_UG_S *p_ug_info,OUT TY_OTA_PACK_E *action_type)
{
OPERATE_RET op_ret = OPRT_OK;
// 在此处是升级前回调
// todo
*action_type = OTA_PACK_GO_ON; // 此处如果是 OTA_PACK_WAIT,组件需要等待 tuya_svc_mcu_ota_wait_type_post发送
return op_ret;
}
STATIC OPERATE_RET ty_uart_mcu_ota_data_cb(IN CONST UCHAR_T *p_data, IN CONST UINT_T len,IN UINT_T offset, OUT TY_OTA_PACK_E *action_type)
{
OPERATE_RET op_ret = OPRT_OK;
// 在此处是升级数据回调
// todo
*action_type = OTA_PACK_GO_ON; // 此处如果是 OTA_PACK_WAIT,组件需要等待 tuya_svc_mcu_ota_wait_type_post 发送 ,实现下载过程中的控制
return op_ret;
}
STATIC OPERATE_RET ty_uart_mcu_ota_end_status_cb(IN TY_OTA_END_STATUS_E status,IN UINT_T offset)
{
OPERATE_RET op_ret = OPRT_OK;
// 在此处是升级结束回调
// todo
return op_ret;
}
OPERATE_RET tuya_ota_service_init(VOID)
{
OPERATE_RET op_ret = OPRT_OK;
op_ret = tuya_svc_mcu_ota_serve_init(g_ota_msg,256);
if(OPRT_OK != op_ret) {
PR_ERR("svc_mcu_ota_serve_init err:%d",op_ret);
return op_ret;
}
}
//此回调函数为系统 OTA 回调函数
OPERATE_RET dev_ug_inform_cb(IN CONST FW_UG_S *fw)
{
OPERATE_RET op_ret = OPRT_OK;
PR_DEBUG("Rev GW Upgrade Info");
PR_DEBUG("fw->fw_url:%s", fw->fw_url);
PR_DEBUG("fw->sw_ver:%s", fw->sw_ver);
PR_DEBUG("fw->file_size:%d", fw->file_size);
//开始 MCU OTA 升级
op_ret = tuya_svc_mcu_ota_serve_start(fw);
if(OPRT_OK != op_ret) {
PR_ERR("tuya_svc_mcu_ota_serve_start err:%d",op_ret);
}
return op_ret;
}
OPERATE_RET tuya_uart_cloud_init(void)
{
OPERATE_RET op_ret = OPRT_COM_ERROR;
TY_IOT_CBS_S wf_cbs = {
.gw_status_cb = status_changed_cb,\
.gw_ug_cb = gw_ug_inform_cb,\
.gw_reset_cb = dev_reset_cb,\
.dev_obj_dp_cb = dev_obj_dp_cb,\
.dev_raw_dp_cb = dev_raw_dp_cb,\
.dev_dp_query_cb = dev_dp_query_cb,\
.dev_ug_cb = dev_ug_inform_cb, \
.pre_gw_ug_cb = pre_gw_ug_inform_cb
};
op_ret = tuya_iot_wf_mcu_dev_init(GWCM_LOW_POWER,WF_START_SMART_AP_CONCURRENT,\
&wf_cbs,firmware_key,product_id,firmware_version,mcu_sw_ver);
if(OPRT_OK != op_ret) {
PR_ERR("tuya iot wifi init faild ! err:%d",op_ret);
return op_ret;
}
return OPRT_OK;
}
OPERATE_RET device_init(VOID)
{
tuya_uart_cloud_init();
}
该内容对您有帮助吗?
是意见反馈该内容对您有帮助吗?
是意见反馈