Skip to content

Commit 346a3df

Browse files
authored
Merge pull request #26 from erwinpan1/mvd_3rd_fix_rvc_crash_due_to_countdowntime
Mvd 3rd fix rvc crash due to countdowntime
2 parents 3a2f6a1 + 80de34e commit 346a3df

File tree

12 files changed

+1169
-43
lines changed

12 files changed

+1169
-43
lines changed

.github/workflows/build.yaml

+10-6
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ on:
2424
run-codeql:
2525
required: false
2626
type: boolean
27-
27+
2828
concurrency:
2929
group: ${{ github.ref }}-${{ github.workflow }}-${{ (github.event_name == 'pull_request' && github.event.number) || (github.event_name == 'workflow_dispatch' && github.run_number) || github.sha }}
3030
cancel-in-progress: true
3131

3232
env:
3333
CHIP_NO_LOG_TIMESTAMPS: true
34-
34+
3535
jobs:
3636
build_linux_gcc_debug:
3737
name: Build on Linux (gcc_debug)
@@ -206,7 +206,7 @@ jobs:
206206
./scripts/run_in_build_env.sh \
207207
"./scripts/run-clang-tidy-on-compile-commands.py \
208208
--compile-database out/sanitizers/compile_commands.json \
209-
--file-exclude-regex '/(repo|zzz_generated|lwip/standalone)/|-ReadImpl|-InvokeSubscribeImpl' \
209+
--file-exclude-regex '/(repo|zzz_generated|lwip/standalone)/|-ReadImpl|-InvokeSubscribeImpl|CodegenDataModel_Write|QuieterReporting' \
210210
check \
211211
"
212212
- name: Clean output
@@ -239,7 +239,7 @@ jobs:
239239
run: |
240240
rm -rf ./zzz_pregenerated
241241
mv scripts/codegen.py.renamed scripts/codegen.py
242-
mv scripts/tools/zap/generate.py.renamed scripts/tools/zap/generate.py
242+
mv scripts/tools/zap/generate.py.renamed scripts/tools/zap/generate.py
243243
- name: Run fake linux tests with build_examples
244244
run: |
245245
./scripts/run_in_build_env.sh \
@@ -249,7 +249,7 @@ jobs:
249249
uses: ./.github/actions/perform-codeql-analysis
250250
with:
251251
language: cpp
252-
252+
253253
- name: Uploading core files
254254
uses: actions/upload-artifact@v4
255255
if: ${{ failure() && !env.ACT }}
@@ -424,6 +424,10 @@ jobs:
424424
./scripts/run_in_build_env.sh \
425425
"./scripts/run-clang-tidy-on-compile-commands.py \
426426
--compile-database out/default/compile_commands.json \
427+
<<<<<<< HEAD
428+
=======
429+
--file-exclude-regex '/(repo|zzz_generated|lwip/standalone)/|CodegenDataModel_Write|QuieterReporting' \
430+
>>>>>>> f83d67bac4 (Introduce a building block usable for all Q attributes (#34266))
427431
check \
428432
"
429433
- name: Uploading diagnostic logs
@@ -438,7 +442,7 @@ jobs:
438442
uses: ./.github/actions/perform-codeql-analysis
439443
with:
440444
language: cpp
441-
445+
442446
# TODO Log Upload https://github.com/project-chip/connectedhomeip/issues/2227
443447
# TODO https://github.com/project-chip/connectedhomeip/issues/1512
444448

examples/chef/common/chef-rvc-operational-state-delegate.cpp

+83-16
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data
3535

3636
DataModel::Nullable<uint32_t> RvcOperationalStateDelegate::GetCountdownTime()
3737
{
38-
if (mRunningTime > mPhaseDuration.Value())
38+
if (mCountdownTime.IsNull() || mRunningTime > mCountdownTime.Value())
3939
return DataModel::NullNullable;
4040

41-
return DataModel::MakeNullable((uint32_t) (mPhaseDuration.Value() - mRunningTime));
41+
return DataModel::MakeNullable((uint32_t) (mCountdownTime.Value() - mRunningTime));
4242
}
4343

4444
CHIP_ERROR RvcOperationalStateDelegate::GetOperationalStateAtIndex(size_t index, GenericOperationalState & operationalState)
@@ -62,10 +62,27 @@ CHIP_ERROR RvcOperationalStateDelegate::GetOperationalPhaseAtIndex(size_t index,
6262

6363
void RvcOperationalStateDelegate::HandlePauseStateCallback(GenericOperationalError & err)
6464
{
65+
OperationalState::OperationalStateEnum state =
66+
static_cast<OperationalState::OperationalStateEnum>(gRvcOperationalStateInstance->GetCurrentOperationalState());
67+
68+
if (state == OperationalState::OperationalStateEnum::kPaused)
69+
{
70+
err.Set(to_underlying(OperationalState::ErrorStateEnum::kNoError));
71+
return;
72+
}
73+
74+
if (state == OperationalState::OperationalStateEnum::kStopped || state == OperationalState::OperationalStateEnum::kError)
75+
{
76+
err.Set(to_underlying(OperationalState::ErrorStateEnum::kCommandInvalidInState));
77+
return;
78+
}
79+
6580
// placeholder implementation
66-
auto error = GetInstance()->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kPaused));
81+
auto error = gRvcOperationalStateInstance->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kPaused));
6782
if (error == CHIP_NO_ERROR)
6883
{
84+
(void) DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds16(1), onOperationalStateTimerTick, GetInstance());
85+
GetInstance()->UpdateCountdownTimeFromDelegate();
6986
err.Set(to_underlying(OperationalState::ErrorStateEnum::kNoError));
7087
}
7188
else
@@ -76,10 +93,21 @@ void RvcOperationalStateDelegate::HandlePauseStateCallback(GenericOperationalErr
7693

7794
void RvcOperationalStateDelegate::HandleResumeStateCallback(GenericOperationalError & err)
7895
{
96+
OperationalState::OperationalStateEnum state =
97+
static_cast<OperationalState::OperationalStateEnum>(gRvcOperationalStateInstance->GetCurrentOperationalState());
98+
99+
if (state == OperationalState::OperationalStateEnum::kStopped || state == OperationalState::OperationalStateEnum::kError)
100+
{
101+
err.Set(to_underlying(OperationalState::ErrorStateEnum::kUnableToStartOrResume));
102+
return;
103+
}
104+
79105
// placeholder implementation
80-
auto error = GetInstance()->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kRunning));
106+
auto error = gRvcOperationalStateInstance->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kRunning));
81107
if (error == CHIP_NO_ERROR)
82108
{
109+
(void) DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds16(1), onOperationalStateTimerTick, GetInstance());
110+
GetInstance()->UpdateCountdownTimeFromDelegate();
83111
err.Set(to_underlying(OperationalState::ErrorStateEnum::kNoError));
84112
}
85113
else
@@ -103,7 +131,8 @@ void RvcOperationalStateDelegate::HandleStartStateCallback(GenericOperationalErr
103131
auto error = GetInstance()->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kRunning));
104132
if (error == CHIP_NO_ERROR)
105133
{
106-
(void) DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds16(1), onOperationalStateTimerTick, this);
134+
(void) DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds16(1), onOperationalStateTimerTick, GetInstance());
135+
GetInstance()->UpdateCountdownTimeFromDelegate();
107136
err.Set(to_underlying(OperationalState::ErrorStateEnum::kNoError));
108137
}
109138
else
@@ -119,6 +148,7 @@ void RvcOperationalStateDelegate::HandleStopStateCallback(GenericOperationalErro
119148
if (error == CHIP_NO_ERROR)
120149
{
121150
(void) DeviceLayer::SystemLayer().CancelTimer(onOperationalStateTimerTick, this);
151+
GetInstance()->UpdateCountdownTimeFromDelegate();
122152

123153
OperationalState::GenericOperationalError current_err(to_underlying(OperationalState::ErrorStateEnum::kNoError));
124154
GetInstance()->GetCurrentOperationalError(current_err);
@@ -130,6 +160,7 @@ void RvcOperationalStateDelegate::HandleStopStateCallback(GenericOperationalErro
130160

131161
mRunningTime = 0;
132162
mPausedTime = 0;
163+
mCountdownTime.SetNull();
133164
err.Set(to_underlying(OperationalState::ErrorStateEnum::kNoError));
134165
}
135166
else
@@ -145,27 +176,54 @@ static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data
145176
OperationalState::OperationalStateEnum state =
146177
static_cast<OperationalState::OperationalStateEnum>(instance->GetCurrentOperationalState());
147178

148-
auto countdown_time = delegate->GetCountdownTime();
149-
150-
if (countdown_time.ValueOr(1) > 0)
179+
if (gRvcOperationalStateDelegate->mCountdownTime.IsNull())
151180
{
152181
if (state == OperationalState::OperationalStateEnum::kRunning)
153182
{
154-
delegate->mRunningTime++;
155-
}
156-
else if (state == OperationalState::OperationalStateEnum::kPaused)
157-
{
158-
delegate->mPausedTime++;
183+
gRvcOperationalStateDelegate->mCountdownTime.SetNonNull(
184+
static_cast<uint32_t>(gRvcOperationalStateDelegate->kExampleCountDown));
185+
gRvcOperationalStateDelegate->mRunningTime = 0;
186+
gRvcOperationalStateDelegate->mPausedTime = 0;
159187
}
160188
}
161189

162-
if (state == OperationalState::OperationalStateEnum::kRunning || state == OperationalState::OperationalStateEnum::kPaused)
190+
if (state == OperationalState::OperationalStateEnum::kRunning)
191+
{
192+
gRvcOperationalStateDelegate->mRunningTime++;
193+
}
194+
else if (state == OperationalState::OperationalStateEnum::kPaused)
195+
{
196+
gRvcOperationalStateDelegate->mPausedTime++;
197+
}
198+
199+
uint32_t mPausedTime = gRvcOperationalStateDelegate->mPausedTime;
200+
uint32_t mRunningTime = gRvcOperationalStateDelegate->mRunningTime;
201+
202+
if (gRvcOperationalStateDelegate->mCountdownTime.Value() > mRunningTime)
163203
{
164204
(void) DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds16(1), onOperationalStateTimerTick, delegate);
165205
}
166206
else
167207
{
168208
(void) DeviceLayer::SystemLayer().CancelTimer(onOperationalStateTimerTick, delegate);
209+
210+
CHIP_ERROR err =
211+
gRvcOperationalStateInstance->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kStopped));
212+
if (err == CHIP_NO_ERROR)
213+
{
214+
OperationalState::GenericOperationalError current_err(to_underlying(OperationalState::ErrorStateEnum::kNoError));
215+
gRvcOperationalStateInstance->GetCurrentOperationalError(current_err);
216+
217+
Optional<DataModel::Nullable<uint32_t>> totalTime((DataModel::Nullable<uint32_t>(mPausedTime + mRunningTime)));
218+
Optional<DataModel::Nullable<uint32_t>> pausedTime((DataModel::Nullable<uint32_t>(mPausedTime)));
219+
220+
gRvcOperationalStateInstance->OnOperationCompletionDetected(static_cast<uint8_t>(current_err.errorStateID), totalTime,
221+
pausedTime);
222+
223+
gRvcOperationalStateDelegate->mRunningTime = 0;
224+
gRvcOperationalStateDelegate->mPausedTime = 0;
225+
gRvcOperationalStateDelegate->mCountdownTime.SetNull();
226+
}
169227
}
170228
}
171229

@@ -200,8 +258,17 @@ chip::Protocols::InteractionModel::Status chefRvcOperationalStateWriteCallback(c
200258
}
201259
break;
202260
case chip::app::Clusters::RvcOperationalState::Attributes::OperationalState::Id: {
203-
uint8_t m = static_cast<uint8_t>(buffer[0]);
204-
CHIP_ERROR err = gRvcOperationalStateInstance->SetOperationalState(m);
261+
uint8_t currentState = gRvcOperationalStateInstance->GetCurrentOperationalState();
262+
uint8_t m = static_cast<uint8_t>(buffer[0]);
263+
CHIP_ERROR err = gRvcOperationalStateInstance->SetOperationalState(m);
264+
265+
if (currentState == to_underlying(OperationalState::OperationalStateEnum::kStopped) &&
266+
m == to_underlying(OperationalState::OperationalStateEnum::kRunning))
267+
{
268+
gRvcOperationalStateDelegate->mCountdownTime.SetNonNull(
269+
static_cast<uint32_t>(gRvcOperationalStateDelegate->kExampleCountDown));
270+
}
271+
205272
if (CHIP_NO_ERROR == err)
206273
{
207274
break;

examples/chef/common/chef-rvc-operational-state-delegate.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ class RvcOperationalStateDelegate : public RvcOperationalState::Delegate
9595

9696
uint32_t mRunningTime = 0;
9797
uint32_t mPausedTime = 0;
98-
app::DataModel::Nullable<uint32_t> mPhaseDuration;
98+
app::DataModel::Nullable<uint32_t> mCountdownTime;
99+
const uint32_t kExampleCountDown = 30;
99100

100101
private:
101102
Span<const OperationalState::GenericOperationalState> mOperationalStateList;

src/BUILD.gn

+3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ if (chip_build_tests) {
5555
chip_test_group("tests") {
5656
deps = []
5757
tests = [
58+
"${chip_root}/src/app/data-model/tests",
59+
"${chip_root}/src/app/cluster-building-blocks/tests",
60+
"${chip_root}/src/app/data-model-interface/tests",
5861
"${chip_root}/src/access/tests",
5962
"${chip_root}/src/crypto/tests",
6063
"${chip_root}/src/inet/tests",
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright (c) 2024 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
import("//build_overrides/chip.gni")
15+
16+
source_set("cluster-building-blocks") {
17+
sources = [ "QuieterReporting.h" ]
18+
19+
public_deps = [
20+
"${chip_root}/src/app/data-model:nullable",
21+
"${chip_root}/src/lib/support:support",
22+
"${chip_root}/src/system",
23+
]
24+
}

0 commit comments

Comments
 (0)