-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ESP32] CLI option to set delayed action time in OTA Provider app and…
… restart OTA Requestor once ApplyUpdate is successful (#13620) * [ESP32] CLI option to set delayedActionTime in OTA Provider app Also, modify Linux OTA Provider help for delayedActionTime cli option * [ESP32] Schedule the restart once OTA image apply is successful Also, Apply suggestion from #13484 in lighting-app * Review comments * Fix a small typo * Apply suggestions from code review Co-authored-by: Carol Yang <[email protected]> Co-authored-by: Carol Yang <[email protected]>
- Loading branch information
1 parent
7e09d15
commit dd209ce
Showing
12 changed files
with
185 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
examples/ota-provider-app/esp32/main/OTAProviderCommands.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* | ||
* Copyright (c) 2022 Project CHIP Authors | ||
* | ||
* 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. | ||
*/ | ||
|
||
#include <OTAProviderCommands.h> | ||
#include <lib/shell/Commands.h> | ||
#include <lib/shell/Engine.h> | ||
#include <lib/shell/commands/Help.h> | ||
#include <lib/support/logging/CHIPLogging.h> | ||
|
||
namespace chip { | ||
namespace Shell { | ||
namespace { | ||
|
||
OTAProviderExample * exampleOTAProvider = nullptr; | ||
Shell::Engine sSubShell; | ||
|
||
CHIP_ERROR DelayedActionTimeHandler(int argc, char ** argv) | ||
{ | ||
VerifyOrReturnError(argc == 1, CHIP_ERROR_INVALID_ARGUMENT); | ||
VerifyOrReturnError(exampleOTAProvider != nullptr, CHIP_ERROR_INCORRECT_STATE); | ||
|
||
const uint32_t delay = strtoul(argv[0], nullptr, 10); | ||
exampleOTAProvider->SetDelayedActionTimeSec(delay); | ||
return CHIP_NO_ERROR; | ||
} | ||
|
||
CHIP_ERROR OTAProviderHandler(int argc, char ** argv) | ||
{ | ||
if (argc == 0) | ||
{ | ||
sSubShell.ForEachCommand(PrintCommandHelp, nullptr); | ||
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; | ||
} | ||
} // namespace | ||
|
||
void OTAProviderCommands::Register() | ||
{ | ||
// These commands can be moved to src/lib/shell/commands/Ota.cpp along with the other OTA commands. | ||
// But as of now only Linux and ESP32 platforms supports OTA provider | ||
|
||
// Register subcommands of the `OTAProvider` commands. | ||
static const shell_command_t subCommands[] = { | ||
{ &DelayedActionTimeHandler, "delay", | ||
"Set delayed action time for QueryImageResponse and ApplyUpdateResponse\n" | ||
"Usage: OTAProvider delay <delay in seconds>" }, | ||
}; | ||
|
||
sSubShell.RegisterCommands(subCommands, ArraySize(subCommands)); | ||
|
||
// Register the root `OTA Provider` command in the top-level shell. | ||
static const shell_command_t otaProviderCommand = { &OTAProviderHandler, "OTAProvider", "OTA Provider commands" }; | ||
|
||
Engine::Root().RegisterCommands(&otaProviderCommand, 1); | ||
} | ||
|
||
// Set Example OTA provider | ||
void OTAProviderCommands::SetExampleOTAProvider(OTAProviderExample * otaProvider) | ||
{ | ||
exampleOTAProvider = otaProvider; | ||
} | ||
|
||
} // namespace Shell | ||
} // namespace chip |
51 changes: 51 additions & 0 deletions
51
examples/ota-provider-app/esp32/main/include/OTAProviderCommands.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* | ||
* Copyright (c) 2022 Project CHIP Authors | ||
* | ||
* 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. | ||
*/ | ||
|
||
#pragma once | ||
#include <ota-provider-common/OTAProviderExample.h> | ||
|
||
namespace chip { | ||
namespace Shell { | ||
|
||
class OTAProviderCommands | ||
{ | ||
public: | ||
// delete the copy constructor | ||
OTAProviderCommands(const OTAProviderCommands &) = delete; | ||
// delete the move constructor | ||
OTAProviderCommands(OTAProviderCommands &&) = delete; | ||
// delete the assignment operator | ||
OTAProviderCommands & operator=(const OTAProviderCommands &) = delete; | ||
|
||
static OTAProviderCommands & GetInstance() | ||
{ | ||
static OTAProviderCommands instance; | ||
return instance; | ||
} | ||
|
||
// Register the OTA provider commands | ||
void Register(); | ||
|
||
// Set Example OTA provider | ||
void SetExampleOTAProvider(OTAProviderExample * otaProvider); | ||
|
||
private: | ||
OTAProviderCommands() {} | ||
}; | ||
|
||
} // namespace Shell | ||
} // namespace chip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters