cmiot_cmd.c 源码
2026/7/20大约 2 分钟附录源码附录OTA
cmiot_cmd.c — OTA 升级命令实现
路径: components/ota/cmiot/port/oneos/cmiot_cmd.c
功能: OTA 远程升级组件的 Shell 命令实现,注册 cmiot_cv 和 cmiot_ru 两个 Shell 命令,分别用于启动升级流程和上报升级结果。
引用章节: 7.8 OTA 远程升级组件
完整源码
/**
***********************************************************************************************************************
* Copyright (c) 2020, China Mobile Communications Group Co.,Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* @file ota_cmd.c
*
* @brief Implement commond functions
*
* @revision
* Date Author Notes
* 2020-06-16 OneOS Team First Version
***********************************************************************************************************************
*/
#include "cmiot_cmd.h"
#include "cmiot_cfg.h"
#include "cmiot_main.h"
#ifdef OS_USING_SHELL
#include "shell.h"
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#if defined(OS_USING_SHELL) && !defined(CMIOT_USING_MULTI_SLAVE)
/**
* @brief This function will start the upgrade process
*/
os_err_t cmiot_cv(int argc, char **argv)
{
cmiot_int8 rst = cmiot_upgrade();
os_kprintf("start upgrade result:%d\r\n", rst);
return 0;
}
SH_CMD_EXPORT(cmiot_cv, cmiot_cv, "start the upgrade process");
/**
* @brief This function will start the report upgrade process
*/
os_err_t cmiot_ru(int argc, char **argv)
{
cmiot_int8 rst = cmiot_report_upgrade();
os_kprintf("start report upgrade result:%d\r\n", rst);
return 0;
}
SH_CMD_EXPORT(cmiot_ru, cmiot_ru, "start the report upgrade process");
#ifdef CMIOT_USING_MULTI_MASTER
/**
* @brief This function will start the upgrade process for slave
*/
os_err_t cmiot_cv_slave(int argc, char **argv)
{
if (argc < 2)
{
os_kprintf("At least input one param.\r\n");
return 0;
}
cmiot_int8 rst = cmiot_upgrade_slave(atoi(argv[1]));
os_kprintf("start upgrade result:%d\r\n", rst);
return 0;
}
SH_CMD_EXPORT(cmiot_cv_slave, cmiot_cv_slave, "start the upgrade process for slave");
/**
* @brief This function will start the report upgrade process for slave
*/
os_err_t cmiot_ru_slave(int argc, char **argv)
{
if (argc < 2)
{
os_kprintf("At least input one param.\r\n");
return 0;
}
cmiot_int8 rst = cmiot_report_upgrade_slave(atoi(argv[1]));
os_kprintf("start report upgrade result:%d\r\n", rst);
return 0;
}
SH_CMD_EXPORT(cmiot_ru_slave, cmiot_ru_slave, "start the report upgrade process for slave");
#endif
#endif关键说明
| 模块 | 说明 |
|---|---|
| Shell 命令 | 使用 SH_CMD_EXPORT 宏注册 Shell 命令,支持在终端中手动触发升级 |
| cmiot_cv | 调用 cmiot_upgrade() 启动完整升级流程(下载 → 校验 → 写入 → 激活) |
| cmiot_ru | 调用 cmiot_report_upgrade() 向云端上报当前版本和升级状态 |
| 多主模式 | 支持从设备升级, |