Skip to content

Commit

Permalink
Merge pull request #26 from erwinpan1/mvd_3rd_fix_rvc_crash_due_to_co…
Browse files Browse the repository at this point in the history
…untdowntime

Mvd 3rd fix rvc crash due to countdowntime
  • Loading branch information
GinyWang authored Nov 12, 2024
2 parents 3a2f6a1 + 80de34e commit 346a3df
Show file tree
Hide file tree
Showing 12 changed files with 1,169 additions and 43 deletions.
16 changes: 10 additions & 6 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ on:
run-codeql:
required: false
type: boolean

concurrency:
group: ${{ github.ref }}-${{ github.workflow }}-${{ (github.event_name == 'pull_request' && github.event.number) || (github.event_name == 'workflow_dispatch' && github.run_number) || github.sha }}
cancel-in-progress: true

env:
CHIP_NO_LOG_TIMESTAMPS: true

jobs:
build_linux_gcc_debug:
name: Build on Linux (gcc_debug)
Expand Down Expand Up @@ -206,7 +206,7 @@ jobs:
./scripts/run_in_build_env.sh \
"./scripts/run-clang-tidy-on-compile-commands.py \
--compile-database out/sanitizers/compile_commands.json \
--file-exclude-regex '/(repo|zzz_generated|lwip/standalone)/|-ReadImpl|-InvokeSubscribeImpl' \
--file-exclude-regex '/(repo|zzz_generated|lwip/standalone)/|-ReadImpl|-InvokeSubscribeImpl|CodegenDataModel_Write|QuieterReporting' \
check \
"
- name: Clean output
Expand Down Expand Up @@ -239,7 +239,7 @@ jobs:
run: |
rm -rf ./zzz_pregenerated
mv scripts/codegen.py.renamed scripts/codegen.py
mv scripts/tools/zap/generate.py.renamed scripts/tools/zap/generate.py
mv scripts/tools/zap/generate.py.renamed scripts/tools/zap/generate.py
- name: Run fake linux tests with build_examples
run: |
./scripts/run_in_build_env.sh \
Expand All @@ -249,7 +249,7 @@ jobs:
uses: ./.github/actions/perform-codeql-analysis
with:
language: cpp

- name: Uploading core files
uses: actions/upload-artifact@v4
if: ${{ failure() && !env.ACT }}
Expand Down Expand Up @@ -424,6 +424,10 @@ jobs:
./scripts/run_in_build_env.sh \
"./scripts/run-clang-tidy-on-compile-commands.py \
--compile-database out/default/compile_commands.json \
<<<<<<< HEAD
=======
--file-exclude-regex '/(repo|zzz_generated|lwip/standalone)/|CodegenDataModel_Write|QuieterReporting' \
>>>>>>> f83d67bac4 (Introduce a building block usable for all Q attributes (#34266))
check \
"
- name: Uploading diagnostic logs
Expand All @@ -438,7 +442,7 @@ jobs:
uses: ./.github/actions/perform-codeql-analysis
with:
language: cpp
# TODO Log Upload https://github.com/project-chip/connectedhomeip/issues/2227
# TODO https://github.com/project-chip/connectedhomeip/issues/1512
Expand Down
99 changes: 83 additions & 16 deletions examples/chef/common/chef-rvc-operational-state-delegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data

DataModel::Nullable<uint32_t> RvcOperationalStateDelegate::GetCountdownTime()
{
if (mRunningTime > mPhaseDuration.Value())
if (mCountdownTime.IsNull() || mRunningTime > mCountdownTime.Value())
return DataModel::NullNullable;

return DataModel::MakeNullable((uint32_t) (mPhaseDuration.Value() - mRunningTime));
return DataModel::MakeNullable((uint32_t) (mCountdownTime.Value() - mRunningTime));
}

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

void RvcOperationalStateDelegate::HandlePauseStateCallback(GenericOperationalError & err)
{
OperationalState::OperationalStateEnum state =
static_cast<OperationalState::OperationalStateEnum>(gRvcOperationalStateInstance->GetCurrentOperationalState());

if (state == OperationalState::OperationalStateEnum::kPaused)
{
err.Set(to_underlying(OperationalState::ErrorStateEnum::kNoError));
return;
}

if (state == OperationalState::OperationalStateEnum::kStopped || state == OperationalState::OperationalStateEnum::kError)
{
err.Set(to_underlying(OperationalState::ErrorStateEnum::kCommandInvalidInState));
return;
}

// placeholder implementation
auto error = GetInstance()->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kPaused));
auto error = gRvcOperationalStateInstance->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kPaused));
if (error == CHIP_NO_ERROR)
{
(void) DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds16(1), onOperationalStateTimerTick, GetInstance());
GetInstance()->UpdateCountdownTimeFromDelegate();
err.Set(to_underlying(OperationalState::ErrorStateEnum::kNoError));
}
else
Expand All @@ -76,10 +93,21 @@ void RvcOperationalStateDelegate::HandlePauseStateCallback(GenericOperationalErr

void RvcOperationalStateDelegate::HandleResumeStateCallback(GenericOperationalError & err)
{
OperationalState::OperationalStateEnum state =
static_cast<OperationalState::OperationalStateEnum>(gRvcOperationalStateInstance->GetCurrentOperationalState());

if (state == OperationalState::OperationalStateEnum::kStopped || state == OperationalState::OperationalStateEnum::kError)
{
err.Set(to_underlying(OperationalState::ErrorStateEnum::kUnableToStartOrResume));
return;
}

// placeholder implementation
auto error = GetInstance()->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kRunning));
auto error = gRvcOperationalStateInstance->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kRunning));
if (error == CHIP_NO_ERROR)
{
(void) DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds16(1), onOperationalStateTimerTick, GetInstance());
GetInstance()->UpdateCountdownTimeFromDelegate();
err.Set(to_underlying(OperationalState::ErrorStateEnum::kNoError));
}
else
Expand All @@ -103,7 +131,8 @@ void RvcOperationalStateDelegate::HandleStartStateCallback(GenericOperationalErr
auto error = GetInstance()->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kRunning));
if (error == CHIP_NO_ERROR)
{
(void) DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds16(1), onOperationalStateTimerTick, this);
(void) DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds16(1), onOperationalStateTimerTick, GetInstance());
GetInstance()->UpdateCountdownTimeFromDelegate();
err.Set(to_underlying(OperationalState::ErrorStateEnum::kNoError));
}
else
Expand All @@ -119,6 +148,7 @@ void RvcOperationalStateDelegate::HandleStopStateCallback(GenericOperationalErro
if (error == CHIP_NO_ERROR)
{
(void) DeviceLayer::SystemLayer().CancelTimer(onOperationalStateTimerTick, this);
GetInstance()->UpdateCountdownTimeFromDelegate();

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

mRunningTime = 0;
mPausedTime = 0;
mCountdownTime.SetNull();
err.Set(to_underlying(OperationalState::ErrorStateEnum::kNoError));
}
else
Expand All @@ -145,27 +176,54 @@ static void onOperationalStateTimerTick(System::Layer * systemLayer, void * data
OperationalState::OperationalStateEnum state =
static_cast<OperationalState::OperationalStateEnum>(instance->GetCurrentOperationalState());

auto countdown_time = delegate->GetCountdownTime();

if (countdown_time.ValueOr(1) > 0)
if (gRvcOperationalStateDelegate->mCountdownTime.IsNull())
{
if (state == OperationalState::OperationalStateEnum::kRunning)
{
delegate->mRunningTime++;
}
else if (state == OperationalState::OperationalStateEnum::kPaused)
{
delegate->mPausedTime++;
gRvcOperationalStateDelegate->mCountdownTime.SetNonNull(
static_cast<uint32_t>(gRvcOperationalStateDelegate->kExampleCountDown));
gRvcOperationalStateDelegate->mRunningTime = 0;
gRvcOperationalStateDelegate->mPausedTime = 0;
}
}

if (state == OperationalState::OperationalStateEnum::kRunning || state == OperationalState::OperationalStateEnum::kPaused)
if (state == OperationalState::OperationalStateEnum::kRunning)
{
gRvcOperationalStateDelegate->mRunningTime++;
}
else if (state == OperationalState::OperationalStateEnum::kPaused)
{
gRvcOperationalStateDelegate->mPausedTime++;
}

uint32_t mPausedTime = gRvcOperationalStateDelegate->mPausedTime;
uint32_t mRunningTime = gRvcOperationalStateDelegate->mRunningTime;

if (gRvcOperationalStateDelegate->mCountdownTime.Value() > mRunningTime)
{
(void) DeviceLayer::SystemLayer().StartTimer(System::Clock::Seconds16(1), onOperationalStateTimerTick, delegate);
}
else
{
(void) DeviceLayer::SystemLayer().CancelTimer(onOperationalStateTimerTick, delegate);

CHIP_ERROR err =
gRvcOperationalStateInstance->SetOperationalState(to_underlying(OperationalState::OperationalStateEnum::kStopped));
if (err == CHIP_NO_ERROR)
{
OperationalState::GenericOperationalError current_err(to_underlying(OperationalState::ErrorStateEnum::kNoError));
gRvcOperationalStateInstance->GetCurrentOperationalError(current_err);

Optional<DataModel::Nullable<uint32_t>> totalTime((DataModel::Nullable<uint32_t>(mPausedTime + mRunningTime)));
Optional<DataModel::Nullable<uint32_t>> pausedTime((DataModel::Nullable<uint32_t>(mPausedTime)));

gRvcOperationalStateInstance->OnOperationCompletionDetected(static_cast<uint8_t>(current_err.errorStateID), totalTime,
pausedTime);

gRvcOperationalStateDelegate->mRunningTime = 0;
gRvcOperationalStateDelegate->mPausedTime = 0;
gRvcOperationalStateDelegate->mCountdownTime.SetNull();
}
}
}

Expand Down Expand Up @@ -200,8 +258,17 @@ chip::Protocols::InteractionModel::Status chefRvcOperationalStateWriteCallback(c
}
break;
case chip::app::Clusters::RvcOperationalState::Attributes::OperationalState::Id: {
uint8_t m = static_cast<uint8_t>(buffer[0]);
CHIP_ERROR err = gRvcOperationalStateInstance->SetOperationalState(m);
uint8_t currentState = gRvcOperationalStateInstance->GetCurrentOperationalState();
uint8_t m = static_cast<uint8_t>(buffer[0]);
CHIP_ERROR err = gRvcOperationalStateInstance->SetOperationalState(m);

if (currentState == to_underlying(OperationalState::OperationalStateEnum::kStopped) &&
m == to_underlying(OperationalState::OperationalStateEnum::kRunning))
{
gRvcOperationalStateDelegate->mCountdownTime.SetNonNull(
static_cast<uint32_t>(gRvcOperationalStateDelegate->kExampleCountDown));
}

if (CHIP_NO_ERROR == err)
{
break;
Expand Down
3 changes: 2 additions & 1 deletion examples/chef/common/chef-rvc-operational-state-delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ class RvcOperationalStateDelegate : public RvcOperationalState::Delegate

uint32_t mRunningTime = 0;
uint32_t mPausedTime = 0;
app::DataModel::Nullable<uint32_t> mPhaseDuration;
app::DataModel::Nullable<uint32_t> mCountdownTime;
const uint32_t kExampleCountDown = 30;

private:
Span<const OperationalState::GenericOperationalState> mOperationalStateList;
Expand Down
3 changes: 3 additions & 0 deletions src/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ if (chip_build_tests) {
chip_test_group("tests") {
deps = []
tests = [
"${chip_root}/src/app/data-model/tests",
"${chip_root}/src/app/cluster-building-blocks/tests",
"${chip_root}/src/app/data-model-interface/tests",
"${chip_root}/src/access/tests",
"${chip_root}/src/crypto/tests",
"${chip_root}/src/inet/tests",
Expand Down
24 changes: 24 additions & 0 deletions src/app/cluster-building-blocks/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (c) 2024 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build_overrides/chip.gni")

source_set("cluster-building-blocks") {
sources = [ "QuieterReporting.h" ]

public_deps = [
"${chip_root}/src/app/data-model:nullable",
"${chip_root}/src/lib/support:support",
"${chip_root}/src/system",
]
}
Loading

0 comments on commit 346a3df

Please sign in to comment.