Skip to content

Commit 124b59d

Browse files
committed
[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.
1 parent c1ae85c commit 124b59d

File tree

2 files changed

+38
-100
lines changed

2 files changed

+38
-100
lines changed

docs/guides/silabs_cli_guide.md

-2
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,6 @@ OTA commands
197197
```bash
198198
matterCli> ota
199199
query Query for a new image. Usage: ota query
200-
apply Apply the current update. Usage: ota apply
201-
notify Notify the new image has been applied. Usage: ota notify <version>
202200
state Gets state of a current image update process. Usage: ota state
203201
progress Gets progress of a current image update process. Usage: ota progress
204202
```

src/lib/shell/commands/Ota.cpp

+38-98
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616
*/
1717

1818
#include <app/clusters/ota-requestor/OTARequestorInterface.h>
19+
#include <lib/core/DataModelTypes.h>
1920
#include <lib/shell/Commands.h>
2021
#include <lib/shell/Engine.h>
2122
#include <lib/shell/commands/Help.h>
2223
#include <lib/support/logging/CHIPLogging.h>
23-
#include <platform/CHIPDeviceLayer.h>
24-
#include <platform/OTAImageProcessor.h>
2524

2625
using namespace chip::DeviceLayer;
2726

@@ -32,98 +31,35 @@ namespace {
3231
Shell::Engine sSubShell;
3332

3433
CHIP_ERROR QueryImageHandler(int argc, char ** argv)
35-
{
36-
VerifyOrReturnError(GetRequestorInstance() != nullptr, CHIP_ERROR_INCORRECT_STATE);
37-
VerifyOrReturnError(argc == 0, CHIP_ERROR_INVALID_ARGUMENT);
38-
PlatformMgr().ScheduleWork([](intptr_t) { GetRequestorInstance()->TriggerImmediateQuery(); });
39-
return CHIP_NO_ERROR;
40-
}
41-
42-
CHIP_ERROR ApplyImageHandler(int argc, char ** argv)
43-
{
44-
VerifyOrReturnError(GetRequestorInstance() != nullptr, CHIP_ERROR_INCORRECT_STATE);
45-
VerifyOrReturnError(argc == 0, CHIP_ERROR_INVALID_ARGUMENT);
46-
PlatformMgr().ScheduleWork([](intptr_t) { GetRequestorInstance()->ApplyUpdate(); });
47-
return CHIP_NO_ERROR;
48-
}
49-
50-
CHIP_ERROR NotifyImageHandler(int argc, char ** argv)
5134
{
5235
VerifyOrReturnError(GetRequestorInstance() != nullptr, CHIP_ERROR_INCORRECT_STATE);
5336
VerifyOrReturnError(argc == 0, CHIP_ERROR_INVALID_ARGUMENT);
5437

55-
PlatformMgr().ScheduleWork([](intptr_t) { GetRequestorInstance()->NotifyUpdateApplied(); });
56-
return CHIP_NO_ERROR;
38+
return GetRequestorInstance()->TriggerImmediateQuery();
5739
}
5840

59-
static void HandleState(intptr_t context)
41+
const char * UpdateStateToString(app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum state)
6042
{
61-
app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum state;
62-
CHIP_ERROR err = GetRequestorInstance()->GetUpdateStateAttribute(0, state);
63-
64-
if (err == CHIP_NO_ERROR)
43+
switch (state)
6544
{
66-
streamer_printf(streamer_get(), "Update state: ");
67-
switch (state)
68-
{
69-
case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kUnknown:
70-
streamer_printf(streamer_get(), "unknown");
71-
break;
72-
case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kIdle:
73-
streamer_printf(streamer_get(), "idle");
74-
break;
75-
case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kQuerying:
76-
streamer_printf(streamer_get(), "querying");
77-
break;
78-
case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kDelayedOnQuery:
79-
streamer_printf(streamer_get(), "delayed on query");
80-
break;
81-
case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kDownloading:
82-
streamer_printf(streamer_get(), "downloading");
83-
break;
84-
case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kApplying:
85-
streamer_printf(streamer_get(), "applying");
86-
break;
87-
case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kDelayedOnApply:
88-
streamer_printf(streamer_get(), "delayed on apply");
89-
break;
90-
case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kRollingBack:
91-
streamer_printf(streamer_get(), "rolling back");
92-
break;
93-
case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kDelayedOnUserConsent:
94-
streamer_printf(streamer_get(), "delayed on user consent");
95-
break;
96-
default:
97-
streamer_printf(streamer_get(), "invalid");
98-
break;
99-
}
100-
streamer_printf(streamer_get(), "\r\n");
101-
}
102-
else
103-
{
104-
streamer_printf(streamer_get(), "Error: %" CHIP_ERROR_FORMAT "\r\n", err.Format());
105-
}
106-
}
107-
108-
static void HandleProgress(intptr_t context)
109-
{
110-
chip::app::DataModel::Nullable<uint8_t> progress;
111-
CHIP_ERROR err = GetRequestorInstance()->GetUpdateStateProgressAttribute(0, progress);
112-
113-
if (err == CHIP_NO_ERROR)
114-
{
115-
if (progress.IsNull())
116-
{
117-
streamer_printf(streamer_get(), "Update progress: NULL\r\n");
118-
}
119-
else
120-
{
121-
streamer_printf(streamer_get(), "Update progress: %d %%\r\n", progress.Value());
122-
}
123-
}
124-
else
125-
{
126-
streamer_printf(streamer_get(), "Error: %" CHIP_ERROR_FORMAT "\r\n", err.Format());
45+
case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kIdle:
46+
return "idle";
47+
case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kQuerying:
48+
return "querying";
49+
case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kDelayedOnQuery:
50+
return "delayed on query";
51+
case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kDownloading:
52+
return "downloading";
53+
case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kApplying:
54+
return "applying";
55+
case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kDelayedOnApply:
56+
return "delayed on apply";
57+
case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kRollingBack:
58+
return "rolling back";
59+
case app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum::kDelayedOnUserConsent:
60+
return "delayed on user consent";
61+
default:
62+
return "unknown";
12763
}
12864
}
12965

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

135-
PlatformMgr().ScheduleWork(HandleState, reinterpret_cast<intptr_t>(nullptr));
71+
app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum state;
72+
ReturnErrorOnFailure(GetRequestorInstance()->GetUpdateStateAttribute(kRootEndpointId, state));
73+
74+
streamer_printf(streamer_get(), "Update state: %s\r\n", UpdateStateToString(state));
13675

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

145-
PlatformMgr().ScheduleWork(HandleProgress, reinterpret_cast<intptr_t>(nullptr));
84+
app::DataModel::Nullable<uint8_t> progress;
85+
ReturnErrorOnFailure(GetRequestorInstance()->GetUpdateStateProgressAttribute(kRootEndpointId, progress));
86+
87+
if (progress.IsNull())
88+
{
89+
streamer_printf(streamer_get(), "Update progress: unknown\r\n");
90+
}
91+
else
92+
{
93+
streamer_printf(streamer_get(), "Update progress: %d %%\r\n", progress.Value());
94+
}
14695

14796
return CHIP_NO_ERROR;
14897
}
@@ -155,14 +104,7 @@ CHIP_ERROR OtaHandler(int argc, char ** argv)
155104
return CHIP_NO_ERROR;
156105
}
157106

158-
CHIP_ERROR error = sSubShell.ExecCommand(argc, argv);
159-
160-
if (error != CHIP_NO_ERROR)
161-
{
162-
streamer_printf(streamer_get(), "Error: %" CHIP_ERROR_FORMAT "\r\n", error.Format());
163-
}
164-
165-
return error;
107+
return sSubShell.ExecCommand(argc, argv);
166108
}
167109
} // namespace
168110

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

0 commit comments

Comments
 (0)