Skip to content

Commit 24288ec

Browse files
authored
Make reboot pw_rpc take a delay_ms argument (project-chip#29550)
* Add delay_ms to reboot commands, fix wpg * Fix efr32 build * Restyle * Fix type for boufallolab * Ensure 0 initialization for member variable used in checks * Restyle
1 parent 3100cbe commit 24288ec

File tree

9 files changed

+116
-30
lines changed

9 files changed

+116
-30
lines changed

examples/common/pigweed/protos/device_service.proto

+5-1
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,13 @@ message MetadataForProvider {
4545
bytes tlv = 1;
4646
}
4747

48+
message RebootRequest {
49+
uint32 delay_ms = 1;
50+
}
51+
4852
service Device {
4953
rpc FactoryReset(pw.protobuf.Empty) returns (pw.protobuf.Empty){}
50-
rpc Reboot(pw.protobuf.Empty) returns (pw.protobuf.Empty){}
54+
rpc Reboot(RebootRequest) returns (pw.protobuf.Empty){}
5155
rpc TriggerOta(pw.protobuf.Empty) returns (pw.protobuf.Empty){}
5256
rpc SetOtaMetadataForProvider(MetadataForProvider) returns (pw.protobuf.Empty){}
5357
rpc GetDeviceInfo(pw.protobuf.Empty) returns (DeviceInfo){}

examples/common/pigweed/rpc_services/Device.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ class Device : public pw_rpc::nanopb::Device::Service<Device>
217217
return pw::OkStatus();
218218
}
219219

220-
virtual pw::Status Reboot(const pw_protobuf_Empty & request, pw_protobuf_Empty & response)
220+
virtual pw::Status Reboot(const chip_rpc_RebootRequest & request, pw_protobuf_Empty & response)
221221
{
222222
return pw::Status::Unimplemented();
223223
}

examples/platform/ameba/Rpc.cpp

+14-3
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,26 @@ class AmebaButton final : public Button
7676
class AmebaDevice final : public Device
7777
{
7878
public:
79-
pw::Status Reboot(const pw_protobuf_Empty & request, pw_protobuf_Empty & response) override
79+
pw::Status Reboot(const chip_rpc_RebootRequest & request, pw_protobuf_Empty & response) override
8080
{
81-
mRebootTimer = xTimerCreateStatic("Reboot", kRebootTimerPeriodTicks, false, nullptr, RebootHandler, &mRebootTimerBuffer);
81+
TickType_t delayMs = kRebootTimerPeriodMs;
82+
if (request.delay_ms != 0)
83+
{
84+
delayMs = request.delay_ms;
85+
}
86+
else
87+
{
88+
ChipLogProgress(NotSpecified, "Did not receive a reboot delay. Defaulting to %d ms",
89+
static_cast<int>(kRebootTimerPeriodMs));
90+
}
91+
mRebootTimer =
92+
xTimerCreateStatic("Reboot", pdMS_TO_TICKS(kRebootTimerPeriodMs), false, nullptr, RebootHandler, &mRebootTimerBuffer);
8293
xTimerStart(mRebootTimer, 0);
8394
return pw::OkStatus();
8495
}
8596

8697
private:
87-
static constexpr TickType_t kRebootTimerPeriodTicks = 1000;
98+
static constexpr uint32_t kRebootTimerPeriodMs = 1000;
8899
TimerHandle_t mRebootTimer;
89100
StaticTimer_t mRebootTimerBuffer;
90101

examples/platform/bouffalolab/common/rpc/Rpc.cpp

+25-11
Original file line numberDiff line numberDiff line change
@@ -94,31 +94,45 @@ class BouffaloButton final : public Button
9494
class BouffaloDevice final : public Device
9595
{
9696
public:
97-
pw::Status Reboot(const pw_protobuf_Empty & request, pw_protobuf_Empty & response) override
97+
pw::Status Reboot(const chip_rpc_RebootRequest & request, pw_protobuf_Empty & response) override
9898
{
99-
if (!mRebootTimer)
99+
if (mRebootTimer)
100100
{
101-
mRebootTimer =
102-
xTimerCreateStatic("Reboot", kRebootTimerPeriodTicks, false, nullptr, RebootHandler, &mRebootTimerBuffer);
103-
xTimerStart(mRebootTimer, 0);
101+
return pw::Status::Unavailable();
104102
}
103+
104+
TickType_t delayMs = kRebootTimerPeriodMs;
105+
if (request.delay_ms != 0)
106+
{
107+
delayMs = request.delay_ms;
108+
}
109+
else
110+
{
111+
ChipLogProgress(NotSpecified, "Did not receive a reboot delay. Defaulting to %d ms",
112+
static_cast<int>(kRebootTimerPeriodMs));
113+
}
114+
mRebootTimer = xTimerCreateStatic("Reboot", pdMS_TO_TICKS(delayMs), false, nullptr, RebootHandler, &mRebootTimerBuffer);
115+
xTimerStart(mRebootTimer, 0);
105116
return pw::OkStatus();
106117
}
107118

108119
pw::Status FactoryReset(const pw_protobuf_Empty & request, pw_protobuf_Empty & response) override
109120
{
110-
if (!mRebootTimer)
121+
if (mRebootTimer)
111122
{
112-
mRebootTimer = xTimerCreateStatic("FactoryReset", kRebootTimerPeriodTicks, false, nullptr, FactoryResetHandler,
113-
&mRebootTimerBuffer);
114-
xTimerStart(mRebootTimer, 0);
123+
return pw::Status::Unavailable();
115124
}
125+
126+
// Notice: reboot delay not configurable here
127+
mRebootTimer = xTimerCreateStatic("FactoryReset", pdMS_TO_TICKS(kRebootTimerPeriodMs), false, nullptr, FactoryResetHandler,
128+
&mRebootTimerBuffer);
129+
xTimerStart(mRebootTimer, 0);
116130
return pw::OkStatus();
117131
}
118132

119133
private:
120-
static constexpr TickType_t kRebootTimerPeriodTicks = 1000;
121-
TimerHandle_t mRebootTimer;
134+
static constexpr uint32_t kRebootTimerPeriodMs = 1000;
135+
TimerHandle_t mRebootTimer = 0;
122136
StaticTimer_t mRebootTimerBuffer;
123137

124138
static void RebootHandler(TimerHandle_t) { bl_sys_reset_por(); }

examples/platform/esp32/Rpc.cpp

+14-3
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,26 @@ class Esp32Button final : public Button
112112
class Esp32Device final : public Device
113113
{
114114
public:
115-
pw::Status Reboot(const pw_protobuf_Empty & request, pw_protobuf_Empty & response) override
115+
pw::Status Reboot(const chip_rpc_RebootRequest & request, pw_protobuf_Empty & response) override
116116
{
117-
mRebootTimer = xTimerCreateStatic("Reboot", kRebootTimerPeriodTicks, false, nullptr, RebootHandler, &mRebootTimerBuffer);
117+
TickType_t delayMs = kRebootTimerPeriodMs;
118+
if (request.delay_ms != 0)
119+
{
120+
delayMs = request.delay_ms;
121+
}
122+
else
123+
{
124+
ChipLogProgress(NotSpecified, "Did not receive a reboot delay. Defaulting to %d ms",
125+
static_cast<int>(kRebootTimerPeriodMs));
126+
}
127+
mRebootTimer = xTimerCreateStatic("Reboot", pdMS_TO_TICKS(delayMs), false, nullptr, RebootHandler, &mRebootTimerBuffer);
128+
118129
xTimerStart(mRebootTimer, 0);
119130
return pw::OkStatus();
120131
}
121132

122133
private:
123-
static constexpr TickType_t kRebootTimerPeriodTicks = 1000;
134+
static constexpr uint32_t kRebootTimerPeriodMs = 1000;
124135
TimerHandle_t mRebootTimer;
125136
StaticTimer_t mRebootTimerBuffer;
126137

examples/platform/nrfconnect/Rpc.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,20 @@ K_TIMER_DEFINE(reboot_timer, reboot_timer_handler, NULL);
9595
class NrfDevice final : public Device
9696
{
9797
public:
98-
pw::Status Reboot(const pw_protobuf_Empty & request, pw_protobuf_Empty & response) override
98+
pw::Status Reboot(const chip_rpc_RebootRequest & request, pw_protobuf_Empty & response) override
9999
{
100-
k_timer_start(&reboot_timer, K_SECONDS(1), K_FOREVER);
100+
k_timeout_t delay;
101+
if (request.delay_ms != 0)
102+
{
103+
delay = K_MSEC(request.delay_ms);
104+
}
105+
else
106+
{
107+
ChipLogProgress(NotSpecified, "Did not receive a reboot delay. Defaulting to 1s");
108+
delay = K_SECONDS(1);
109+
}
110+
111+
k_timer_start(&reboot_timer, delay, K_FOREVER);
101112
return pw::OkStatus();
102113
}
103114
};

examples/platform/qpg/Rpc.cpp

+17-3
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,31 @@ class QpgButton final : public Button
6363
class QpgDevice final : public Device
6464
{
6565
public:
66-
pw::Status Reboot(const pw_protobuf_Empty & request, pw_protobuf_Empty & response)
66+
pw::Status Reboot(const chip_rpc_RebootRequest & request, pw_protobuf_Empty & response)
6767
{
68-
qvCHIP_ResetSystem();
69-
// WILL NOT RETURN
68+
Clock::Timeout delay;
69+
70+
if (request.delay_ms != 0)
71+
{
72+
delay = System::Clock::Milliseconds64(request.delay_ms);
73+
}
74+
else
75+
{
76+
delay = System::Clock::Seconds32(1);
77+
ChipLogProgress(NotSpecified, "Did not receive a reboot delay. Defaulting to 1s");
78+
}
79+
80+
DeviceLayer::SystemLayer().StartTimer(delay, RebootImpl, nullptr);
7081
return pw::OkStatus();
7182
}
7283
pw::Status TriggerOta(const pw_protobuf_Empty & request, pw_protobuf_Empty & response)
7384
{
7485
TriggerOTAQuery();
7586
return pw::OkStatus();
7687
}
88+
89+
private:
90+
static void RebootImpl(System::Layer *, void *) { qvCHIP_ResetSystem(); }
7791
};
7892
#endif // defined(PW_RPC_DEVICE_SERVICE) && PW_RPC_DEVICE_SERVICE
7993

examples/platform/silabs/Rpc.cpp

+14-4
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,25 @@ class Efr32Button final : public Button
9292
class Efr32Device final : public Device
9393
{
9494
public:
95-
pw::Status Reboot(const pw_protobuf_Empty & request, pw_protobuf_Empty & response) override
95+
pw::Status Reboot(const chip_rpc_RebootRequest & request, pw_protobuf_Empty & response) override
9696
{
97-
mRebootTimer = xTimerCreateStatic("Reboot", kRebootTimerPeriodTicks, false, nullptr, RebootHandler, &mRebootTimerBuffer);
98-
xTimerStart(mRebootTimer, pdMS_TO_TICKS(0));
97+
TickType_t delayMs = kRebootTimerPeriodMs;
98+
if (request.delay_ms != 0)
99+
{
100+
delayMs = request.delay_ms;
101+
}
102+
else
103+
{
104+
ChipLogProgress(NotSpecified, "Did not receive a reboot delay. Defaulting to %d ms",
105+
static_cast<int>(kRebootTimerPeriodMs));
106+
}
107+
mRebootTimer = xTimerCreateStatic("Reboot", pdMS_TO_TICKS(delayMs), false, nullptr, RebootHandler, &mRebootTimerBuffer);
108+
xTimerStart(mRebootTimer, 0);
99109
return pw::OkStatus();
100110
}
101111

102112
private:
103-
static constexpr TickType_t kRebootTimerPeriodTicks = 1000;
113+
static constexpr uint32_t kRebootTimerPeriodMs = 1000;
104114
TimerHandle_t mRebootTimer;
105115
StaticTimer_t mRebootTimerBuffer;
106116

examples/platform/telink/Rpc.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,20 @@ K_TIMER_DEFINE(reboot_timer, reboot_timer_handler, NULL);
9696
class TelinkDevice final : public Device
9797
{
9898
public:
99-
pw::Status Reboot(const pw_protobuf_Empty & request, pw_protobuf_Empty & response) override
99+
pw::Status Reboot(const chip_rpc_RebootRequest & request, pw_protobuf_Empty & response) override
100100
{
101-
k_timer_start(&reboot_timer, K_SECONDS(1), K_FOREVER);
101+
k_timeout_t delay;
102+
if (request.delay_ms != 0)
103+
{
104+
delay = K_MSEC(request.delay_ms);
105+
}
106+
else
107+
{
108+
ChipLogProgress(NotSpecified, "Did not receive a reboot delay. Defaulting to 1s");
109+
delay = K_SECONDS(1);
110+
}
111+
112+
k_timer_start(&reboot_timer, delay, K_FOREVER);
102113
return pw::OkStatus();
103114
}
104115
};

0 commit comments

Comments
 (0)