Skip to content

Commit

Permalink
[shell] Clean OTA commands & remove base64 commands (#32396)
Browse files Browse the repository at this point in the history
* [shell] Clean OTA commands

1. Remove obsolete "apply" and "notify" commands. These
   actions are invoked automatically by OTA requestor.
2. Do not post tasks onto CHIP thread - shell commands
   are already run on CHIP thread.
3. Do not print error codes. They are already printed
   by shell core.

* [shell] Remove base64 commands

Base64 encoding/decoding is not specific to Matter so base64
shell commands are not useful on actual Matter devices.
  • Loading branch information
Damian-Nordic authored Apr 2, 2024
1 parent fb25b0b commit d3e3d97
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 221 deletions.
2 changes: 0 additions & 2 deletions docs/guides/silabs_cli_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,6 @@ OTA commands
```bash
matterCli> ota
query Query for a new image. Usage: ota query
apply Apply the current update. Usage: ota apply
notify Notify the new image has been applied. Usage: ota notify <version>
state Gets state of a current image update process. Usage: ota state
progress Gets progress of a current image update process. Usage: ota progress
```
Expand Down
6 changes: 0 additions & 6 deletions src/lib/shell/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@
namespace chip {
namespace Shell {

/**
* This function registers the base64 encode/decode commands.
*
*/
void RegisterBase64Commands();

/**
* This function registers the BLE commands.
*
Expand Down
1 change: 0 additions & 1 deletion src/lib/shell/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ CHIP_ERROR Engine::ExecCommand(int argc, char * argv[])

void Engine::RegisterDefaultCommands()
{
RegisterBase64Commands();
RegisterMetaCommands();
#if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
RegisterBLECommands();
Expand Down
1 change: 0 additions & 1 deletion src/lib/shell/commands/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import("${chip_root}/src/system/system.gni")

source_set("commands") {
sources = [
"Base64.cpp",
"Help.cpp",
"Help.h",
"Meta.cpp",
Expand Down
113 changes: 0 additions & 113 deletions src/lib/shell/commands/Base64.cpp

This file was deleted.

136 changes: 38 additions & 98 deletions src/lib/shell/commands/Ota.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@
*/

#include <app/clusters/ota-requestor/OTARequestorInterface.h>
#include <lib/core/DataModelTypes.h>
#include <lib/shell/Commands.h>
#include <lib/shell/Engine.h>
#include <lib/shell/commands/Help.h>
#include <lib/support/logging/CHIPLogging.h>
#include <platform/CHIPDeviceLayer.h>
#include <platform/OTAImageProcessor.h>

using namespace chip::DeviceLayer;

Expand All @@ -32,98 +31,35 @@ namespace {
Shell::Engine sSubShell;

CHIP_ERROR QueryImageHandler(int argc, char ** argv)
{
VerifyOrReturnError(GetRequestorInstance() != nullptr, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(argc == 0, CHIP_ERROR_INVALID_ARGUMENT);
PlatformMgr().ScheduleWork([](intptr_t) { GetRequestorInstance()->TriggerImmediateQuery(); });
return CHIP_NO_ERROR;
}

CHIP_ERROR ApplyImageHandler(int argc, char ** argv)
{
VerifyOrReturnError(GetRequestorInstance() != nullptr, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(argc == 0, CHIP_ERROR_INVALID_ARGUMENT);
PlatformMgr().ScheduleWork([](intptr_t) { GetRequestorInstance()->ApplyUpdate(); });
return CHIP_NO_ERROR;
}

CHIP_ERROR NotifyImageHandler(int argc, char ** argv)
{
VerifyOrReturnError(GetRequestorInstance() != nullptr, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(argc == 0, CHIP_ERROR_INVALID_ARGUMENT);

PlatformMgr().ScheduleWork([](intptr_t) { GetRequestorInstance()->NotifyUpdateApplied(); });
return CHIP_NO_ERROR;
return GetRequestorInstance()->TriggerImmediateQuery();
}

static void HandleState(intptr_t context)
const char * UpdateStateToString(app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum state)
{
app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum state;
CHIP_ERROR err = GetRequestorInstance()->GetUpdateStateAttribute(0, state);

if (err == CHIP_NO_ERROR)
switch (state)
{
streamer_printf(streamer_get(), "Update state: ");
switch (state)
{
case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kUnknown:
streamer_printf(streamer_get(), "unknown");
break;
case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kIdle:
streamer_printf(streamer_get(), "idle");
break;
case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kQuerying:
streamer_printf(streamer_get(), "querying");
break;
case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kDelayedOnQuery:
streamer_printf(streamer_get(), "delayed on query");
break;
case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kDownloading:
streamer_printf(streamer_get(), "downloading");
break;
case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kApplying:
streamer_printf(streamer_get(), "applying");
break;
case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kDelayedOnApply:
streamer_printf(streamer_get(), "delayed on apply");
break;
case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kRollingBack:
streamer_printf(streamer_get(), "rolling back");
break;
case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kDelayedOnUserConsent:
streamer_printf(streamer_get(), "delayed on user consent");
break;
default:
streamer_printf(streamer_get(), "invalid");
break;
}
streamer_printf(streamer_get(), "\r\n");
}
else
{
streamer_printf(streamer_get(), "Error: %" CHIP_ERROR_FORMAT "\r\n", err.Format());
}
}

static void HandleProgress(intptr_t context)
{
chip::app::DataModel::Nullable<uint8_t> progress;
CHIP_ERROR err = GetRequestorInstance()->GetUpdateStateProgressAttribute(0, progress);

if (err == CHIP_NO_ERROR)
{
if (progress.IsNull())
{
streamer_printf(streamer_get(), "Update progress: NULL\r\n");
}
else
{
streamer_printf(streamer_get(), "Update progress: %d %%\r\n", progress.Value());
}
}
else
{
streamer_printf(streamer_get(), "Error: %" CHIP_ERROR_FORMAT "\r\n", err.Format());
case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kIdle:
return "idle";
case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kQuerying:
return "querying";
case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kDelayedOnQuery:
return "delayed on query";
case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kDownloading:
return "downloading";
case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kApplying:
return "applying";
case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kDelayedOnApply:
return "delayed on apply";
case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kRollingBack:
return "rolling back";
case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kDelayedOnUserConsent:
return "delayed on user consent";
default:
return "unknown";
}
}

Expand All @@ -132,7 +68,10 @@ CHIP_ERROR StateHandler(int argc, char ** argv)
VerifyOrReturnError(GetRequestorInstance() != nullptr, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(argc == 0, CHIP_ERROR_INVALID_ARGUMENT);

PlatformMgr().ScheduleWork(HandleState, reinterpret_cast<intptr_t>(nullptr));
app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum state;
ReturnErrorOnFailure(GetRequestorInstance()->GetUpdateStateAttribute(kRootEndpointId, state));

streamer_printf(streamer_get(), "Update state: %s\r\n", UpdateStateToString(state));

return CHIP_NO_ERROR;
}
Expand All @@ -142,7 +81,17 @@ CHIP_ERROR ProgressHandler(int argc, char ** argv)
VerifyOrReturnError(GetRequestorInstance() != nullptr, CHIP_ERROR_INCORRECT_STATE);
VerifyOrReturnError(argc == 0, CHIP_ERROR_INVALID_ARGUMENT);

PlatformMgr().ScheduleWork(HandleProgress, reinterpret_cast<intptr_t>(nullptr));
app::DataModel::Nullable<uint8_t> progress;
ReturnErrorOnFailure(GetRequestorInstance()->GetUpdateStateProgressAttribute(kRootEndpointId, progress));

if (progress.IsNull())
{
streamer_printf(streamer_get(), "Update progress: unknown\r\n");
}
else
{
streamer_printf(streamer_get(), "Update progress: %d %%\r\n", progress.Value());
}

return CHIP_NO_ERROR;
}
Expand All @@ -155,14 +104,7 @@ CHIP_ERROR OtaHandler(int argc, char ** argv)
return CHIP_NO_ERROR;
}

CHIP_ERROR error = sSubShell.ExecCommand(argc, argv);

if (error != CHIP_NO_ERROR)
{
streamer_printf(streamer_get(), "Error: %" CHIP_ERROR_FORMAT "\r\n", error.Format());
}

return error;
return sSubShell.ExecCommand(argc, argv);
}
} // namespace

Expand All @@ -171,8 +113,6 @@ void RegisterOtaCommands()
// Register subcommands of the `ota` commands.
static const shell_command_t subCommands[] = {
{ &QueryImageHandler, "query", "Query for a new image. Usage: ota query" },
{ &ApplyImageHandler, "apply", "Apply the current update. Usage: ota apply" },
{ &NotifyImageHandler, "notify", "Notify the new image has been applied. Usage: ota notify <version>" },
{ &StateHandler, "state", "Gets state of a current image update process. Usage: ota state" },
{ &ProgressHandler, "progress", "Gets progress of a current image update process. Usage: ota progress" }
};
Expand Down

0 comments on commit d3e3d97

Please sign in to comment.