Skip to content

Commit

Permalink
Add timer to reboot RPC for NRF lighting example (#6892)
Browse files Browse the repository at this point in the history
Add a timer to reboot after the RPC returns, this ensures the host
code knows the RPC command was succesfully recieved before the
device reboots.

Also reboot after doing a FDR.
  • Loading branch information
rgoliver authored and pull[bot] committed Jul 7, 2021
1 parent 7692671 commit 1021647
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
10 changes: 5 additions & 5 deletions examples/lighting-app/nrfconnect/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,11 @@ Semiconductor's kit you own.

### Building with Pigweed RPCs

The RPCs in `lighting-common/pigweed-lighting.proto` can be used to control
various functionalities of the lighting app from a USB-connected host computer.
To build the example with the RPC server, run the following command with
_build-target_ replaced with the build target name of the Nordic Semiconductor's
kit you own:
The RPCs in `lighting-common/lighting_service/lighting_service.proto` can be
used to control various functionalities of the lighting app from a USB-connected
host computer. To build the example with the RPC server, run the following
command with _build-target_ replaced with the build target name of the Nordic
Semiconductor's kit you own:

$ west build -b build-target -- -DOVERLAY_CONFIG=rpc.overlay

Expand Down
15 changes: 13 additions & 2 deletions examples/lighting-app/nrfconnect/main/Rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ LOG_MODULE_DECLARE(app);
namespace chip {
namespace rpc {

namespace {

void reboot_timer_handler(struct k_timer * dummy)
{
NVIC_SystemReset();
}
K_TIMER_DEFINE(reboot_timer, reboot_timer_handler, NULL);

} // namespace

class Lighting final : public generated::Lighting<Lighting>
{
public:
Expand Down Expand Up @@ -75,12 +85,13 @@ class Device final : public generated::Device<Device>
{
// TODO: Clear data from KVS
DeviceLayer::ConfigurationMgr().InitiateFactoryReset();
// Reboot device after clearing data
k_timer_start(&reboot_timer, K_SECONDS(1), K_FOREVER);
return pw::OkStatus();
}
pw::Status Reboot(ServerContext & ctx, const pw_protobuf_Empty & request, pw_protobuf_Empty & response)
{
NVIC_SystemReset();
// WILL NOT RETURN
k_timer_start(&reboot_timer, K_SECONDS(1), K_FOREVER);
return pw::OkStatus();
}
pw::Status TriggerOta(ServerContext & ctx, const pw_protobuf_Empty & request, pw_protobuf_Empty & response)
Expand Down

0 comments on commit 1021647

Please sign in to comment.