16
16
*/
17
17
18
18
#include < app/clusters/ota-requestor/OTARequestorInterface.h>
19
+ #include < lib/core/DataModelTypes.h>
19
20
#include < lib/shell/Commands.h>
20
21
#include < lib/shell/Engine.h>
21
22
#include < lib/shell/commands/Help.h>
22
23
#include < lib/support/logging/CHIPLogging.h>
23
- #include < platform/CHIPDeviceLayer.h>
24
- #include < platform/OTAImageProcessor.h>
25
24
26
25
using namespace chip ::DeviceLayer;
27
26
@@ -32,98 +31,35 @@ namespace {
32
31
Shell::Engine sSubShell ;
33
32
34
33
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)
51
34
{
52
35
VerifyOrReturnError (GetRequestorInstance () != nullptr , CHIP_ERROR_INCORRECT_STATE);
53
36
VerifyOrReturnError (argc == 0 , CHIP_ERROR_INVALID_ARGUMENT);
54
37
55
- PlatformMgr ().ScheduleWork ([](intptr_t ) { GetRequestorInstance ()->NotifyUpdateApplied (); });
56
- return CHIP_NO_ERROR;
38
+ return GetRequestorInstance ()->TriggerImmediateQuery ();
57
39
}
58
40
59
- static void HandleState ( intptr_t context )
41
+ const char * UpdateStateToString (app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum state )
60
42
{
61
- app::Clusters::OtaSoftwareUpdateRequestor::OTAUpdateStateEnum state;
62
- CHIP_ERROR err = GetRequestorInstance ()->GetUpdateStateAttribute (0 , state);
63
-
64
- if (err == CHIP_NO_ERROR)
43
+ switch (state)
65
44
{
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" ;
127
63
}
128
64
}
129
65
@@ -132,7 +68,10 @@ CHIP_ERROR StateHandler(int argc, char ** argv)
132
68
VerifyOrReturnError (GetRequestorInstance () != nullptr , CHIP_ERROR_INCORRECT_STATE);
133
69
VerifyOrReturnError (argc == 0 , CHIP_ERROR_INVALID_ARGUMENT);
134
70
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));
136
75
137
76
return CHIP_NO_ERROR;
138
77
}
@@ -142,7 +81,17 @@ CHIP_ERROR ProgressHandler(int argc, char ** argv)
142
81
VerifyOrReturnError (GetRequestorInstance () != nullptr , CHIP_ERROR_INCORRECT_STATE);
143
82
VerifyOrReturnError (argc == 0 , CHIP_ERROR_INVALID_ARGUMENT);
144
83
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
+ }
146
95
147
96
return CHIP_NO_ERROR;
148
97
}
@@ -155,14 +104,7 @@ CHIP_ERROR OtaHandler(int argc, char ** argv)
155
104
return CHIP_NO_ERROR;
156
105
}
157
106
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);
166
108
}
167
109
} // namespace
168
110
@@ -171,8 +113,6 @@ void RegisterOtaCommands()
171
113
// Register subcommands of the `ota` commands.
172
114
static const shell_command_t subCommands[] = {
173
115
{ &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>" },
176
116
{ &StateHandler, " state" , " Gets state of a current image update process. Usage: ota state" },
177
117
{ &ProgressHandler, " progress" , " Gets progress of a current image update process. Usage: ota progress" }
178
118
};
0 commit comments