Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make reboot pw_rpc take a delay_ms argument #29550

Merged
merged 6 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion examples/common/pigweed/protos/device_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ message MetadataForProvider {
bytes tlv = 1;
}

message RebootRequest {
uint32 delay_ms = 1;
}

service Device {
rpc FactoryReset(pw.protobuf.Empty) returns (pw.protobuf.Empty){}
rpc Reboot(pw.protobuf.Empty) returns (pw.protobuf.Empty){}
rpc Reboot(RebootRequest) returns (pw.protobuf.Empty){}
rpc TriggerOta(pw.protobuf.Empty) returns (pw.protobuf.Empty){}
rpc SetOtaMetadataForProvider(MetadataForProvider) returns (pw.protobuf.Empty){}
rpc GetDeviceInfo(pw.protobuf.Empty) returns (DeviceInfo){}
Expand Down
2 changes: 1 addition & 1 deletion examples/common/pigweed/rpc_services/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class Device : public pw_rpc::nanopb::Device::Service<Device>
return pw::OkStatus();
}

virtual pw::Status Reboot(const pw_protobuf_Empty & request, pw_protobuf_Empty & response)
virtual pw::Status Reboot(const chip_rpc_RebootRequest & request, pw_protobuf_Empty & response)
{
return pw::Status::Unimplemented();
}
Expand Down
17 changes: 14 additions & 3 deletions examples/platform/ameba/Rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,26 @@ class AmebaButton final : public Button
class AmebaDevice final : public Device
{
public:
pw::Status Reboot(const pw_protobuf_Empty & request, pw_protobuf_Empty & response) override
pw::Status Reboot(const chip_rpc_RebootRequest & request, pw_protobuf_Empty & response) override
{
mRebootTimer = xTimerCreateStatic("Reboot", kRebootTimerPeriodTicks, false, nullptr, RebootHandler, &mRebootTimerBuffer);
TickType_t delayMs = kRebootTimerPeriodMs;
if (request.delay_ms != 0)
{
delayMs = request.delay_ms;
}
else
{
ChipLogProgress(NotSpecified, "Did not receive a reboot delay. Defaulting to %d ms",
static_cast<int>(kRebootTimerPeriodMs));
}
mRebootTimer =
xTimerCreateStatic("Reboot", pdMS_TO_TICKS(kRebootTimerPeriodMs), false, nullptr, RebootHandler, &mRebootTimerBuffer);
xTimerStart(mRebootTimer, 0);
return pw::OkStatus();
}

private:
static constexpr TickType_t kRebootTimerPeriodTicks = 1000;
static constexpr uint32_t kRebootTimerPeriodMs = 1000;
TimerHandle_t mRebootTimer;
StaticTimer_t mRebootTimerBuffer;

Expand Down
36 changes: 25 additions & 11 deletions examples/platform/bouffalolab/common/rpc/Rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,31 +94,45 @@ class BouffaloButton final : public Button
class BouffaloDevice final : public Device
{
public:
pw::Status Reboot(const pw_protobuf_Empty & request, pw_protobuf_Empty & response) override
pw::Status Reboot(const chip_rpc_RebootRequest & request, pw_protobuf_Empty & response) override
{
if (!mRebootTimer)
if (mRebootTimer)
{
mRebootTimer =
xTimerCreateStatic("Reboot", kRebootTimerPeriodTicks, false, nullptr, RebootHandler, &mRebootTimerBuffer);
xTimerStart(mRebootTimer, 0);
return pw::Status::Unavailable();
}

TickType_t delayMs = kRebootTimerPeriodMs;
if (request.delay_ms != 0)
{
delayMs = request.delay_ms;
}
else
{
ChipLogProgress(NotSpecified, "Did not receive a reboot delay. Defaulting to %d ms",
static_cast<int>(kRebootTimerPeriodMs));
}
mRebootTimer = xTimerCreateStatic("Reboot", pdMS_TO_TICKS(delayMs), false, nullptr, RebootHandler, &mRebootTimerBuffer);
xTimerStart(mRebootTimer, 0);
return pw::OkStatus();
}

pw::Status FactoryReset(const pw_protobuf_Empty & request, pw_protobuf_Empty & response) override
{
if (!mRebootTimer)
if (mRebootTimer)
{
mRebootTimer = xTimerCreateStatic("FactoryReset", kRebootTimerPeriodTicks, false, nullptr, FactoryResetHandler,
&mRebootTimerBuffer);
xTimerStart(mRebootTimer, 0);
return pw::Status::Unavailable();
}

// Notice: reboot delay not configurable here
mRebootTimer = xTimerCreateStatic("FactoryReset", pdMS_TO_TICKS(kRebootTimerPeriodMs), false, nullptr, FactoryResetHandler,
&mRebootTimerBuffer);
xTimerStart(mRebootTimer, 0);
return pw::OkStatus();
}

private:
static constexpr TickType_t kRebootTimerPeriodTicks = 1000;
TimerHandle_t mRebootTimer;
static constexpr uint32_t kRebootTimerPeriodMs = 1000;
TimerHandle_t mRebootTimer = 0;
StaticTimer_t mRebootTimerBuffer;

static void RebootHandler(TimerHandle_t) { bl_sys_reset_por(); }
Expand Down
17 changes: 14 additions & 3 deletions examples/platform/esp32/Rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,26 @@ class Esp32Button final : public Button
class Esp32Device final : public Device
{
public:
pw::Status Reboot(const pw_protobuf_Empty & request, pw_protobuf_Empty & response) override
pw::Status Reboot(const chip_rpc_RebootRequest & request, pw_protobuf_Empty & response) override
{
mRebootTimer = xTimerCreateStatic("Reboot", kRebootTimerPeriodTicks, false, nullptr, RebootHandler, &mRebootTimerBuffer);
TickType_t delayMs = kRebootTimerPeriodMs;
if (request.delay_ms != 0)
{
delayMs = request.delay_ms;
}
else
{
ChipLogProgress(NotSpecified, "Did not receive a reboot delay. Defaulting to %d ms",
static_cast<int>(kRebootTimerPeriodMs));
}
mRebootTimer = xTimerCreateStatic("Reboot", pdMS_TO_TICKS(delayMs), false, nullptr, RebootHandler, &mRebootTimerBuffer);

xTimerStart(mRebootTimer, 0);
return pw::OkStatus();
}

private:
static constexpr TickType_t kRebootTimerPeriodTicks = 1000;
static constexpr uint32_t kRebootTimerPeriodMs = 1000;
TimerHandle_t mRebootTimer;
StaticTimer_t mRebootTimerBuffer;

Expand Down
15 changes: 13 additions & 2 deletions examples/platform/nrfconnect/Rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,20 @@ K_TIMER_DEFINE(reboot_timer, reboot_timer_handler, NULL);
class NrfDevice final : public Device
{
public:
pw::Status Reboot(const pw_protobuf_Empty & request, pw_protobuf_Empty & response) override
pw::Status Reboot(const chip_rpc_RebootRequest & request, pw_protobuf_Empty & response) override
{
k_timer_start(&reboot_timer, K_SECONDS(1), K_FOREVER);
k_timeout_t delay;
if (request.delay_ms != 0)
{
delay = K_MSEC(request.delay_ms);
}
else
{
ChipLogProgress(NotSpecified, "Did not receive a reboot delay. Defaulting to 1s");
delay = K_SECONDS(1);
}

k_timer_start(&reboot_timer, delay, K_FOREVER);
return pw::OkStatus();
}
};
Expand Down
20 changes: 17 additions & 3 deletions examples/platform/qpg/Rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,31 @@ class QpgButton final : public Button
class QpgDevice final : public Device
{
public:
pw::Status Reboot(const pw_protobuf_Empty & request, pw_protobuf_Empty & response)
pw::Status Reboot(const chip_rpc_RebootRequest & request, pw_protobuf_Empty & response)
{
qvCHIP_ResetSystem();
// WILL NOT RETURN
Clock::Timeout delay;

if (request.delay_ms != 0)
{
delay = System::Clock::Milliseconds64(request.delay_ms);
}
else
{
delay = System::Clock::Seconds32(1);
ChipLogProgress(NotSpecified, "Did not receive a reboot delay. Defaulting to 1s");
}

DeviceLayer::SystemLayer().StartTimer(delay, RebootImpl, nullptr);
return pw::OkStatus();
}
pw::Status TriggerOta(const pw_protobuf_Empty & request, pw_protobuf_Empty & response)
{
TriggerOTAQuery();
return pw::OkStatus();
}

private:
static void RebootImpl(System::Layer *, void *) { qvCHIP_ResetSystem(); }
};
#endif // defined(PW_RPC_DEVICE_SERVICE) && PW_RPC_DEVICE_SERVICE

Expand Down
18 changes: 14 additions & 4 deletions examples/platform/silabs/Rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,25 @@ class Efr32Button final : public Button
class Efr32Device final : public Device
{
public:
pw::Status Reboot(const pw_protobuf_Empty & request, pw_protobuf_Empty & response) override
pw::Status Reboot(const chip_rpc_RebootRequest & request, pw_protobuf_Empty & response) override
{
mRebootTimer = xTimerCreateStatic("Reboot", kRebootTimerPeriodTicks, false, nullptr, RebootHandler, &mRebootTimerBuffer);
xTimerStart(mRebootTimer, pdMS_TO_TICKS(0));
TickType_t delayMs = kRebootTimerPeriodMs;
if (request.delay_ms != 0)
{
delayMs = request.delay_ms;
}
else
{
ChipLogProgress(NotSpecified, "Did not receive a reboot delay. Defaulting to %d ms",
static_cast<int>(kRebootTimerPeriodMs));
}
mRebootTimer = xTimerCreateStatic("Reboot", pdMS_TO_TICKS(delayMs), false, nullptr, RebootHandler, &mRebootTimerBuffer);
xTimerStart(mRebootTimer, 0);
return pw::OkStatus();
}

private:
static constexpr TickType_t kRebootTimerPeriodTicks = 1000;
static constexpr uint32_t kRebootTimerPeriodMs = 1000;
TimerHandle_t mRebootTimer;
StaticTimer_t mRebootTimerBuffer;

Expand Down
15 changes: 13 additions & 2 deletions examples/platform/telink/Rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,20 @@ K_TIMER_DEFINE(reboot_timer, reboot_timer_handler, NULL);
class TelinkDevice final : public Device
{
public:
pw::Status Reboot(const pw_protobuf_Empty & request, pw_protobuf_Empty & response) override
pw::Status Reboot(const chip_rpc_RebootRequest & request, pw_protobuf_Empty & response) override
{
k_timer_start(&reboot_timer, K_SECONDS(1), K_FOREVER);
k_timeout_t delay;
if (request.delay_ms != 0)
{
delay = K_MSEC(request.delay_ms);
}
else
{
ChipLogProgress(NotSpecified, "Did not receive a reboot delay. Defaulting to 1s");
delay = K_SECONDS(1);
}

k_timer_start(&reboot_timer, delay, K_FOREVER);
return pw::OkStatus();
}
};
Expand Down