From c548636ea93f0992c9647b936544a9a468ec0345 Mon Sep 17 00:00:00 2001 From: andersbangGF <88383809+andersbangGF@users.noreply.github.com> Date: Wed, 15 Dec 2021 22:24:26 +0100 Subject: [PATCH] [pump-app] Correct default state of On/Off cluster (#12986) * Addeded init routines to the pump app so the OnOff cluster state is set correctly at boot. Added default timeout for extended discovery. * Correct spacing as pr. review * Removed blank line --- .../pump-app/cc13x2x7_26x2x7/main/AppTask.cpp | 27 ++++++++++++++++--- .../cc13x2x7_26x2x7/main/ZclCallbacks.cpp | 5 ++-- .../cc13x2x7_26x2x7/main/include/AppTask.h | 2 ++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/examples/pump-app/cc13x2x7_26x2x7/main/AppTask.cpp b/examples/pump-app/cc13x2x7_26x2x7/main/AppTask.cpp index 745949c9f30b56..0ce27d5fea05d5 100644 --- a/examples/pump-app/cc13x2x7_26x2x7/main/AppTask.cpp +++ b/examples/pump-app/cc13x2x7_26x2x7/main/AppTask.cpp @@ -20,6 +20,7 @@ #include "AppTask.h" #include "AppConfig.h" #include "AppEvent.h" +#include #include #include @@ -52,6 +53,7 @@ #define PCC_CLUSTER_ENDPOINT 1 #define ONOFF_CLUSTER_ENDPOINT 1 +#define EXTENDED_DISCOVERY_TIMEOUT_SEC 20 using namespace ::chip::Credentials; using namespace ::chip::DeviceLayer; @@ -140,6 +142,10 @@ int AppTask::Init() ; } +#if CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY + chip::app::DnssdServer::Instance().SetExtendedDiscoveryTimeoutSecs(EXTENDED_DISCOVERY_TIMEOUT_SEC); +#endif + // Init ZCL Data Model and start server PLAT_LOG("Initialize Server"); chip::Server::GetInstance().Init(); @@ -357,6 +363,23 @@ void AppTask::DispatchEvent(AppEvent * aEvent) } } +void AppTask::InitOnOffClusterState() +{ + + EmberStatus status; + + ChipLogProgress(NotSpecified, "Init On/Off clusterstate"); + + // Write false as pump always boots in stopped mode + status = OnOff::Attributes::OnOff::Set(ONOFF_CLUSTER_ENDPOINT, false); + if (status != EMBER_ZCL_STATUS_SUCCESS) + { + ChipLogError(NotSpecified, "ERR: Init On/Off state %" PRIx8, status); + } +} + +void AppTask::InitPCCClusterState() {} + void AppTask::UpdateClusterState() { EmberStatus status; @@ -364,10 +387,8 @@ void AppTask::UpdateClusterState() ChipLogProgress(NotSpecified, "UpdateClusterState"); // Write the new values - bool onOffState = !PumpMgr().IsStopped(); - - status = OnOff::Attributes::OnOff::Set(ONOFF_CLUSTER_ENDPOINT, onOffState); + status = OnOff::Attributes::OnOff::Set(ONOFF_CLUSTER_ENDPOINT, onOffState); if (status != EMBER_ZCL_STATUS_SUCCESS) { ChipLogError(NotSpecified, "ERR: Updating On/Off state %" PRIx8, status); diff --git a/examples/pump-app/cc13x2x7_26x2x7/main/ZclCallbacks.cpp b/examples/pump-app/cc13x2x7_26x2x7/main/ZclCallbacks.cpp index 4d97751ad0a190..f8dbde9662b73c 100644 --- a/examples/pump-app/cc13x2x7_26x2x7/main/ZclCallbacks.cpp +++ b/examples/pump-app/cc13x2x7_26x2x7/main/ZclCallbacks.cpp @@ -65,11 +65,10 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & */ void emberAfOnOffClusterInitCallback(EndpointId endpoint) { - GetAppTask().UpdateClusterState(); + GetAppTask().InitOnOffClusterState(); } void emberAfPumpConfigurationAndControlClusterInitCallback(chip::EndpointId endpoint) { - // TODO: Setup the default values in the cluster for this specific application - GetAppTask().UpdateClusterState(); + GetAppTask().InitPCCClusterState(); } diff --git a/examples/pump-app/cc13x2x7_26x2x7/main/include/AppTask.h b/examples/pump-app/cc13x2x7_26x2x7/main/include/AppTask.h index 11e402ebe3bcb9..a681197a13c961 100644 --- a/examples/pump-app/cc13x2x7_26x2x7/main/include/AppTask.h +++ b/examples/pump-app/cc13x2x7_26x2x7/main/include/AppTask.h @@ -40,6 +40,8 @@ class AppTask void PostStartActionRequest(int32_t aActor, PumpManager::Action_t aAction); void PostEvent(const AppEvent * event); void UpdateClusterState(); + void InitOnOffClusterState(); + void InitPCCClusterState(); private: friend AppTask & GetAppTask(void);