@@ -86,12 +86,18 @@ void RvcOperationalStateDelegate::HandlePauseStateCallback(GenericOperationalErr
86
86
return ;
87
87
}
88
88
89
+ if (state != OperationalState::OperationalStateEnum::kRunning )
90
+ {
91
+ ChipLogDetail (DeviceLayer, " HandlePauseStateCallback: RVC not running. Current state = %d. Returning." ,
92
+ to_underlying (state));
93
+ err.Set (to_underlying (OperationalState::ErrorStateEnum::kCommandInvalidInState ));
94
+ return ;
95
+ }
96
+
89
97
// placeholder implementation
90
98
auto error = gRvcOperationalStateInstance ->SetOperationalState (to_underlying (OperationalState::OperationalStateEnum::kPaused ));
91
99
if (error == CHIP_NO_ERROR)
92
100
{
93
- (void ) DeviceLayer::SystemLayer ().StartTimer (System::Clock::Seconds16 (1 ), onOperationalStateTimerTick, GetInstance ());
94
- GetInstance ()->UpdateCountdownTimeFromDelegate ();
95
101
err.Set (to_underlying (OperationalState::ErrorStateEnum::kNoError ));
96
102
}
97
103
else
@@ -111,12 +117,18 @@ void RvcOperationalStateDelegate::HandleResumeStateCallback(GenericOperationalEr
111
117
return ;
112
118
}
113
119
120
+ if (state != OperationalState::OperationalStateEnum::kPaused )
121
+ {
122
+ ChipLogDetail (DeviceLayer, " HandleResumeStateCallback: RVC not in paused state. Current state = %d. Returning." ,
123
+ to_underlying (state));
124
+ err.Set (to_underlying (OperationalState::ErrorStateEnum::kCommandInvalidInState ));
125
+ return ;
126
+ }
127
+
114
128
// placeholder implementation
115
129
auto error = gRvcOperationalStateInstance ->SetOperationalState (to_underlying (OperationalState::OperationalStateEnum::kRunning ));
116
130
if (error == CHIP_NO_ERROR)
117
131
{
118
- (void ) DeviceLayer::SystemLayer ().StartTimer (System::Clock::Seconds16 (1 ), onOperationalStateTimerTick, GetInstance ());
119
- GetInstance ()->UpdateCountdownTimeFromDelegate ();
120
132
err.Set (to_underlying (OperationalState::ErrorStateEnum::kNoError ));
121
133
}
122
134
else
@@ -136,12 +148,34 @@ void RvcOperationalStateDelegate::HandleStartStateCallback(GenericOperationalErr
136
148
return ;
137
149
}
138
150
151
+ RvcOperationalState::OperationalStateEnum current_state =
152
+ static_cast <RvcOperationalState::OperationalStateEnum>(gRvcOperationalStateInstance ->GetCurrentOperationalState ());
153
+
154
+ if (current_state == RvcOperationalState::OperationalStateEnum::kRunning ||
155
+ current_state == RvcOperationalState::OperationalStateEnum::kPaused )
156
+ {
157
+ ChipLogDetail (DeviceLayer, " HandleStartStateCallback: RVC is already started. Current state = %d. Returning." ,
158
+ to_underlying (current_state));
159
+ err.Set (to_underlying (OperationalState::ErrorStateEnum::kNoError ));
160
+ return ;
161
+ }
162
+
163
+ if (to_underlying (current_state) != to_underlying (RvcOperationalState::OperationalStateEnum::kCharging ) &&
164
+ to_underlying (current_state) != to_underlying (RvcOperationalState::OperationalStateEnum::kStopped ))
165
+ {
166
+ ChipLogError (
167
+ DeviceLayer,
168
+ " HandleStartStateCallback: RVC must be in either charging or stopped state before starting. current state = %d" ,
169
+ to_underlying (current_state));
170
+ err.Set (to_underlying (OperationalState::ErrorStateEnum::kCommandInvalidInState ));
171
+ return ;
172
+ }
139
173
// placeholder implementation
140
174
auto error = GetInstance ()->SetOperationalState (to_underlying (OperationalState::OperationalStateEnum::kRunning ));
141
175
if (error == CHIP_NO_ERROR)
142
176
{
177
+ // Start RVC run cycle.
143
178
(void ) DeviceLayer::SystemLayer ().StartTimer (System::Clock::Seconds16 (1 ), onOperationalStateTimerTick, GetInstance ());
144
- GetInstance ()->UpdateCountdownTimeFromDelegate ();
145
179
err.Set (to_underlying (OperationalState::ErrorStateEnum::kNoError ));
146
180
}
147
181
else
@@ -152,12 +186,23 @@ void RvcOperationalStateDelegate::HandleStartStateCallback(GenericOperationalErr
152
186
153
187
void RvcOperationalStateDelegate::HandleStopStateCallback (GenericOperationalError & err)
154
188
{
189
+
190
+ RvcOperationalState::OperationalStateEnum current_state =
191
+ static_cast <RvcOperationalState::OperationalStateEnum>(gRvcOperationalStateInstance ->GetCurrentOperationalState ());
192
+
193
+ if (current_state != RvcOperationalState::OperationalStateEnum::kRunning &&
194
+ current_state != RvcOperationalState::OperationalStateEnum::kPaused )
195
+ {
196
+ ChipLogDetail (DeviceLayer, " HandleStopStateCallback: RVC not started. Current state = %d. Returning." ,
197
+ to_underlying (current_state));
198
+ err.Set (to_underlying (OperationalState::ErrorStateEnum::kNoError ));
199
+ return ;
200
+ }
155
201
// placeholder implementation
156
202
auto error = GetInstance ()->SetOperationalState (to_underlying (OperationalState::OperationalStateEnum::kStopped ));
157
203
if (error == CHIP_NO_ERROR)
158
204
{
159
205
(void ) DeviceLayer::SystemLayer ().CancelTimer (onOperationalStateTimerTick, this );
160
- GetInstance ()->UpdateCountdownTimeFromDelegate ();
161
206
162
207
OperationalState::GenericOperationalError current_err (to_underlying (OperationalState::ErrorStateEnum::kNoError ));
163
208
GetInstance ()->GetCurrentOperationalError (current_err);
@@ -171,12 +216,41 @@ void RvcOperationalStateDelegate::HandleStopStateCallback(GenericOperationalErro
171
216
mPausedTime = 0 ;
172
217
mCountdownTime .SetNull ();
173
218
err.Set (to_underlying (OperationalState::ErrorStateEnum::kNoError ));
219
+ GetInstance ()->UpdateCountdownTimeFromDelegate ();
174
220
}
175
221
else
176
222
{
177
223
err.Set (to_underlying (OperationalState::ErrorStateEnum::kUnableToCompleteOperation ));
178
224
}
179
225
}
226
+
227
+ void RvcOperationalStateDelegate::HandleGoHomeCommandCallback (OperationalState::GenericOperationalError & err)
228
+ {
229
+
230
+ RvcOperationalState::OperationalStateEnum current_state =
231
+ static_cast <RvcOperationalState::OperationalStateEnum>(gRvcOperationalStateInstance ->GetCurrentOperationalState ());
232
+
233
+ if (current_state == RvcOperationalState::OperationalStateEnum::kRunning ||
234
+ current_state == RvcOperationalState::OperationalStateEnum::kPaused )
235
+ {
236
+ ChipLogDetail (DeviceLayer, " HandleGoHomeCommandCallback: RVC was started, current state = %d. Stopping RVC." ,
237
+ to_underlying (current_state));
238
+ gRvcOperationalStateDelegate ->HandleStopStateCallback (err);
239
+ }
240
+
241
+ // Skip SeekingCharger and Docking states and directly go into charging.
242
+ auto error =
243
+ gRvcOperationalStateInstance ->SetOperationalState (to_underlying (RvcOperationalState::OperationalStateEnum::kCharging ));
244
+ if (error == CHIP_NO_ERROR)
245
+ {
246
+ err.Set (to_underlying (OperationalState::ErrorStateEnum::kNoError ));
247
+ }
248
+ else
249
+ {
250
+ err.Set (to_underlying (OperationalState::ErrorStateEnum::kUnableToCompleteOperation ));
251
+ }
252
+ }
253
+
180
254
static void onOperationalStateTimerTick (System::Layer * systemLayer, void * data)
181
255
{
182
256
RvcOperationalStateDelegate * delegate = reinterpret_cast <RvcOperationalStateDelegate *>(data);
@@ -185,7 +259,8 @@ static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data
185
259
OperationalState::OperationalStateEnum state =
186
260
static_cast <OperationalState::OperationalStateEnum>(instance->GetCurrentOperationalState ());
187
261
188
- if (state == OperationalState::OperationalStateEnum::kStopped ) // Do not continue the timer when RVC has stopped.
262
+ if (state != OperationalState::OperationalStateEnum::kRunning &&
263
+ state != OperationalState::OperationalStateEnum::kPaused ) // Timer shouldn't run when RVC is not in Running or Paused.
189
264
{
190
265
return ;
191
266
}
@@ -198,6 +273,12 @@ static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data
198
273
static_cast <uint32_t >(gRvcOperationalStateDelegate ->kExampleCountDown ));
199
274
gRvcOperationalStateDelegate ->mRunningTime = 0 ;
200
275
gRvcOperationalStateDelegate ->mPausedTime = 0 ;
276
+ instance->UpdateCountdownTimeFromDelegate ();
277
+ }
278
+ else
279
+ { // kPaused
280
+ ChipLogError (DeviceLayer, " RVC timer tick: Invalid state. Device is in kPaused but mCountdownTime is NULL." );
281
+ return ;
201
282
}
202
283
}
203
284
@@ -213,6 +294,14 @@ static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data
213
294
uint32_t mPausedTime = gRvcOperationalStateDelegate ->mPausedTime ;
214
295
uint32_t mRunningTime = gRvcOperationalStateDelegate ->mRunningTime ;
215
296
297
+ ChipLogDetail (DeviceLayer, " RVC timer tick: Current state = %d. CountdownTime = %d. PauseTime = %d. RunningTime = %d." ,
298
+ to_underlying (state), gRvcOperationalStateDelegate ->mCountdownTime .Value (), mPausedTime , mRunningTime );
299
+ if (state == OperationalState::OperationalStateEnum::kRunning )
300
+ {
301
+ // Reported CountDownTime is the remaining time to run = mCountdownTime.Value() - mRunningTime.
302
+ instance->UpdateCountdownTimeFromDelegate ();
303
+ }
304
+
216
305
if (gRvcOperationalStateDelegate ->mCountdownTime .Value () > mRunningTime )
217
306
{
218
307
(void ) DeviceLayer::SystemLayer ().StartTimer (System::Clock::Seconds16 (1 ), onOperationalStateTimerTick, delegate);
@@ -237,6 +326,7 @@ static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data
237
326
gRvcOperationalStateDelegate ->mRunningTime = 0 ;
238
327
gRvcOperationalStateDelegate ->mPausedTime = 0 ;
239
328
gRvcOperationalStateDelegate ->mCountdownTime .SetNull ();
329
+ instance->UpdateCountdownTimeFromDelegate ();
240
330
241
331
#ifdef MATTER_DM_PLUGIN_RVC_RUN_MODE_SERVER
242
332
getRvcRunModeInstance ()->UpdateCurrentMode (RvcRunMode::ModeIdle);
0 commit comments