diff --git a/examples/common/pigweed/protos/device_service.proto b/examples/common/pigweed/protos/device_service.proto index 19be27ab7f960e..0bd6680ef354c5 100644 --- a/examples/common/pigweed/protos/device_service.proto +++ b/examples/common/pigweed/protos/device_service.proto @@ -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){} diff --git a/examples/common/pigweed/rpc_services/Device.h b/examples/common/pigweed/rpc_services/Device.h index e82095a59a309e..611c85caa37db9 100644 --- a/examples/common/pigweed/rpc_services/Device.h +++ b/examples/common/pigweed/rpc_services/Device.h @@ -217,7 +217,7 @@ class Device : public pw_rpc::nanopb::Device::Service 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(); } diff --git a/examples/platform/ameba/Rpc.cpp b/examples/platform/ameba/Rpc.cpp index 55312d3a769620..cd33631f078155 100644 --- a/examples/platform/ameba/Rpc.cpp +++ b/examples/platform/ameba/Rpc.cpp @@ -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(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; diff --git a/examples/platform/bouffalolab/common/rpc/Rpc.cpp b/examples/platform/bouffalolab/common/rpc/Rpc.cpp index cead7e2e72913e..ba71648b68c42b 100644 --- a/examples/platform/bouffalolab/common/rpc/Rpc.cpp +++ b/examples/platform/bouffalolab/common/rpc/Rpc.cpp @@ -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(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(); } diff --git a/examples/platform/esp32/Rpc.cpp b/examples/platform/esp32/Rpc.cpp index f34172a05e0a98..57f01b8f60b2ae 100644 --- a/examples/platform/esp32/Rpc.cpp +++ b/examples/platform/esp32/Rpc.cpp @@ -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(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; diff --git a/examples/platform/nrfconnect/Rpc.cpp b/examples/platform/nrfconnect/Rpc.cpp index c89dd6c7e25de2..ec21fd7e379f05 100644 --- a/examples/platform/nrfconnect/Rpc.cpp +++ b/examples/platform/nrfconnect/Rpc.cpp @@ -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(); } }; diff --git a/examples/platform/qpg/Rpc.cpp b/examples/platform/qpg/Rpc.cpp index 45d31ccd2083cb..c57865ec4602d1 100644 --- a/examples/platform/qpg/Rpc.cpp +++ b/examples/platform/qpg/Rpc.cpp @@ -63,10 +63,21 @@ 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) @@ -74,6 +85,9 @@ class QpgDevice final : public Device TriggerOTAQuery(); return pw::OkStatus(); } + +private: + static void RebootImpl(System::Layer *, void *) { qvCHIP_ResetSystem(); } }; #endif // defined(PW_RPC_DEVICE_SERVICE) && PW_RPC_DEVICE_SERVICE diff --git a/examples/platform/silabs/Rpc.cpp b/examples/platform/silabs/Rpc.cpp index 55cc232c382617..c78426847c1a42 100644 --- a/examples/platform/silabs/Rpc.cpp +++ b/examples/platform/silabs/Rpc.cpp @@ -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(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; diff --git a/examples/platform/telink/Rpc.cpp b/examples/platform/telink/Rpc.cpp index e8c9500ab68291..104e7c453cbda2 100644 --- a/examples/platform/telink/Rpc.cpp +++ b/examples/platform/telink/Rpc.cpp @@ -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(); } };