From caa117298fa13ef39c3b97513d4e775d63b6f802 Mon Sep 17 00:00:00 2001 From: thirupathi Date: Wed, 6 Sep 2023 15:53:28 +0530 Subject: [PATCH 1/7] feature/DIC feature support for thermostat app and window app --- examples/thermostat/silabs/include/AppTask.h | 9 +++ examples/thermostat/silabs/src/AppTask.cpp | 72 +++++++++++++++++++ .../thermostat/silabs/src/ZclCallbacks.cpp | 7 ++ .../window-app/silabs/src/WindowManager.cpp | 25 ++++++- 4 files changed, 110 insertions(+), 3 deletions(-) diff --git a/examples/thermostat/silabs/include/AppTask.h b/examples/thermostat/silabs/include/AppTask.h index 695b7d5b8ed751..946b936a8e2172 100644 --- a/examples/thermostat/silabs/include/AppTask.h +++ b/examples/thermostat/silabs/include/AppTask.h @@ -88,6 +88,15 @@ class AppTask : public BaseApplication */ static void ButtonEventHandler(uint8_t button, uint8_t btnAction); + /** + * @brief share the status to cloud using DIC + * + * @param attributeId attribute id for the attribute + */ +#ifdef DIC_ENABLE + void DIC_AttrubiteHandler(AttributeId attributeId); +#endif // DIC_ENABLE + private: static AppTask sAppTask; diff --git a/examples/thermostat/silabs/src/AppTask.cpp b/examples/thermostat/silabs/src/AppTask.cpp index 22d0bb3010b9ab..604baca0992f51 100644 --- a/examples/thermostat/silabs/src/AppTask.cpp +++ b/examples/thermostat/silabs/src/AppTask.cpp @@ -50,6 +50,12 @@ #include #include +#ifdef DIC_ENABLE +#define DECIMAL 10 +#define BYTE 5 +#include "dic.h" +#endif // DIC_ENABLE + /********************************************************** * Defines and Constants *********************************************************/ @@ -64,6 +70,10 @@ using namespace chip::app; using namespace chip::TLV; using namespace ::chip::DeviceLayer; +#ifdef DIC_ENABLE +namespace ThermAttr = chip::app::Clusters::Thermostat::Attributes; +#endif // DIC_ENABLE + /********************************************************** * Variable declarations *********************************************************/ @@ -173,3 +183,65 @@ void AppTask::ButtonEventHandler(uint8_t button, uint8_t btnAction) sAppTask.PostEvent(&aEvent); } } + +#ifdef DIC_ENABLE +void AppTask::DIC_AttrubiteHandler(AttributeId attributeId){ + switch (attributeId) + { + case ThermAttr::LocalTemperature::Id: { + int8_t CurrentTemp = TempMgr().GetCurrentTemp(); + char buffer[BYTE]; + itoa(CurrentTemp, buffer, DECIMAL); + dic_sendmsg("LocalTemperature/Temp",(const char *)(buffer)); + } + break; + case ThermAttr::OccupiedCoolingSetpoint::Id: { + int8_t coolingTemp = TempMgr().GetCoolingSetPoint(); + char buffer[BYTE]; + itoa(coolingTemp, buffer, DECIMAL); + dic_sendmsg("OccupiedCoolingSetpoint/coolingTemp",(const char *)(buffer)); + } + break; + case ThermAttr::OccupiedHeatingSetpoint::Id: { + int8_t heatingTemp = TempMgr().GetHeatingSetPoint(); + char buffer[BYTE]; + itoa(heatingTemp, buffer, DECIMAL); + dic_sendmsg("OccupiedHeatingSetpoint/heatingTemp", (const char *)(buffer)); + } + break; + case ThermAttr::SystemMode::Id: { + int8_t mode = TempMgr().GetMode(); + char buffer[BYTE]; + const char* Mode; + switch (mode){ + case 0: + Mode = "OFF"; + break; + case 1: + Mode = "HEAT&COOL"; + break; + case 3: + Mode ="COOL"; + break; + case 4: + Mode ="HEAT"; + break; + default: + Mode = "INVALID MODE"; + break; + } + uint16_t current_temp = TempMgr().GetCurrentTemp(); + itoa(current_temp, buffer, DECIMAL); + dic_sendmsg("thermostat/systemMode", Mode); + dic_sendmsg("thermostat/currentTemp", (const char *)(buffer)); + } + break; + + default: { + SILABS_LOG("Unhandled thermostat attribute %x", attributeId); + return; + } + break; + } +} +#endif // DIC_ENABLE \ No newline at end of file diff --git a/examples/thermostat/silabs/src/ZclCallbacks.cpp b/examples/thermostat/silabs/src/ZclCallbacks.cpp index 734637d91be401..19a4f4d7978fda 100644 --- a/examples/thermostat/silabs/src/ZclCallbacks.cpp +++ b/examples/thermostat/silabs/src/ZclCallbacks.cpp @@ -28,6 +28,10 @@ #include #include +#ifdef DIC_ENABLE +#include "AppTask.h" +#endif //DIC_ENABLE + using namespace ::chip; using namespace ::chip::app::Clusters; @@ -46,5 +50,8 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & else if (clusterId == Thermostat::Id) { TempMgr().AttributeChangeHandler(attributePath.mEndpointId, attributeId, value, size); +#ifdef DIC_ENABLE + AppTask().DIC_AttrubiteHandler(attributeId); +#endif // DIC_ENABLE } } diff --git a/examples/window-app/silabs/src/WindowManager.cpp b/examples/window-app/silabs/src/WindowManager.cpp index c6687ab2ba512e..0dbf5daf26404b 100644 --- a/examples/window-app/silabs/src/WindowManager.cpp +++ b/examples/window-app/silabs/src/WindowManager.cpp @@ -56,6 +56,12 @@ using namespace ::chip::DeviceLayer::Silabs; #define APP_STATE_LED 0 #define APP_ACTION_LED 1 +#ifdef DIC_ENABLE +#define DECIMAL 10 +#define BYTE 5 +#include "dic.h" +#endif // DIC_ENABLE + using namespace ::chip::Credentials; using namespace ::chip::DeviceLayer; using namespace chip::app::Clusters::WindowCovering; @@ -501,11 +507,24 @@ void WindowManager::Cover::CallbackPositionSet(intptr_t arg) WindowManager::Cover::CoverWorkData * data = reinterpret_cast(arg); position.SetNonNull(data->percent100ths); - if (data->isTilt) + if (data->isTilt){ TiltPositionSet(data->mEndpointId, position); - else +#ifdef DIC_ENABLE + uint16_t value = data->percent100ths; + char buffer[BYTE]; + itoa(value, buffer, DECIMAL); + dic_sendmsg("tilt/position set", (const char *)(buffer)); +#endif // DIC_ENABLE + } + else{ LiftPositionSet(data->mEndpointId, position); - +#ifdef DIC_ENABLE + uint16_t value = data->percent100ths; + char buffer[BYTE]; + itoa(value, buffer, DECIMAL); + dic_sendmsg("lift/position set",(const char *)(buffer)); +#endif // DIC_ENABLE + } chip::Platform::Delete(data); } From 28bf4f0745d94527fd2e8513f74f8378202a6cbe Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 6 Sep 2023 10:29:19 +0000 Subject: [PATCH 2/7] Restyled by whitespace --- examples/thermostat/silabs/src/AppTask.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/thermostat/silabs/src/AppTask.cpp b/examples/thermostat/silabs/src/AppTask.cpp index 604baca0992f51..8473e9bf32afd5 100644 --- a/examples/thermostat/silabs/src/AppTask.cpp +++ b/examples/thermostat/silabs/src/AppTask.cpp @@ -244,4 +244,4 @@ void AppTask::DIC_AttrubiteHandler(AttributeId attributeId){ break; } } -#endif // DIC_ENABLE \ No newline at end of file +#endif // DIC_ENABLE From 9dba71e52ac4b54e98405add5b46b8b5d4d23c54 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 6 Sep 2023 10:29:42 +0000 Subject: [PATCH 3/7] Restyled by clang-format --- examples/thermostat/silabs/src/AppTask.cpp | 48 ++++++++++--------- .../thermostat/silabs/src/ZclCallbacks.cpp | 2 +- .../window-app/silabs/src/WindowManager.cpp | 10 ++-- 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/examples/thermostat/silabs/src/AppTask.cpp b/examples/thermostat/silabs/src/AppTask.cpp index 8473e9bf32afd5..252850cf03663a 100644 --- a/examples/thermostat/silabs/src/AppTask.cpp +++ b/examples/thermostat/silabs/src/AppTask.cpp @@ -185,55 +185,57 @@ void AppTask::ButtonEventHandler(uint8_t button, uint8_t btnAction) } #ifdef DIC_ENABLE -void AppTask::DIC_AttrubiteHandler(AttributeId attributeId){ +void AppTask::DIC_AttrubiteHandler(AttributeId attributeId) +{ switch (attributeId) { case ThermAttr::LocalTemperature::Id: { int8_t CurrentTemp = TempMgr().GetCurrentTemp(); char buffer[BYTE]; itoa(CurrentTemp, buffer, DECIMAL); - dic_sendmsg("LocalTemperature/Temp",(const char *)(buffer)); + dic_sendmsg("LocalTemperature/Temp", (const char *) (buffer)); } break; case ThermAttr::OccupiedCoolingSetpoint::Id: { - int8_t coolingTemp = TempMgr().GetCoolingSetPoint(); + int8_t coolingTemp = TempMgr().GetCoolingSetPoint(); char buffer[BYTE]; itoa(coolingTemp, buffer, DECIMAL); - dic_sendmsg("OccupiedCoolingSetpoint/coolingTemp",(const char *)(buffer)); + dic_sendmsg("OccupiedCoolingSetpoint/coolingTemp", (const char *) (buffer)); } break; case ThermAttr::OccupiedHeatingSetpoint::Id: { int8_t heatingTemp = TempMgr().GetHeatingSetPoint(); char buffer[BYTE]; itoa(heatingTemp, buffer, DECIMAL); - dic_sendmsg("OccupiedHeatingSetpoint/heatingTemp", (const char *)(buffer)); + dic_sendmsg("OccupiedHeatingSetpoint/heatingTemp", (const char *) (buffer)); } break; case ThermAttr::SystemMode::Id: { int8_t mode = TempMgr().GetMode(); char buffer[BYTE]; - const char* Mode; - switch (mode){ - case 0: - Mode = "OFF"; - break; - case 1: - Mode = "HEAT&COOL"; - break; - case 3: - Mode ="COOL"; - break; - case 4: - Mode ="HEAT"; - break; - default: - Mode = "INVALID MODE"; - break; + const char * Mode; + switch (mode) + { + case 0: + Mode = "OFF"; + break; + case 1: + Mode = "HEAT&COOL"; + break; + case 3: + Mode = "COOL"; + break; + case 4: + Mode = "HEAT"; + break; + default: + Mode = "INVALID MODE"; + break; } uint16_t current_temp = TempMgr().GetCurrentTemp(); itoa(current_temp, buffer, DECIMAL); dic_sendmsg("thermostat/systemMode", Mode); - dic_sendmsg("thermostat/currentTemp", (const char *)(buffer)); + dic_sendmsg("thermostat/currentTemp", (const char *) (buffer)); } break; diff --git a/examples/thermostat/silabs/src/ZclCallbacks.cpp b/examples/thermostat/silabs/src/ZclCallbacks.cpp index 19a4f4d7978fda..06f6417cdf80a1 100644 --- a/examples/thermostat/silabs/src/ZclCallbacks.cpp +++ b/examples/thermostat/silabs/src/ZclCallbacks.cpp @@ -30,7 +30,7 @@ #ifdef DIC_ENABLE #include "AppTask.h" -#endif //DIC_ENABLE +#endif // DIC_ENABLE using namespace ::chip; using namespace ::chip::app::Clusters; diff --git a/examples/window-app/silabs/src/WindowManager.cpp b/examples/window-app/silabs/src/WindowManager.cpp index 0dbf5daf26404b..d8e010d5307418 100644 --- a/examples/window-app/silabs/src/WindowManager.cpp +++ b/examples/window-app/silabs/src/WindowManager.cpp @@ -507,22 +507,24 @@ void WindowManager::Cover::CallbackPositionSet(intptr_t arg) WindowManager::Cover::CoverWorkData * data = reinterpret_cast(arg); position.SetNonNull(data->percent100ths); - if (data->isTilt){ + if (data->isTilt) + { TiltPositionSet(data->mEndpointId, position); #ifdef DIC_ENABLE uint16_t value = data->percent100ths; char buffer[BYTE]; itoa(value, buffer, DECIMAL); - dic_sendmsg("tilt/position set", (const char *)(buffer)); + dic_sendmsg("tilt/position set", (const char *) (buffer)); #endif // DIC_ENABLE } - else{ + else + { LiftPositionSet(data->mEndpointId, position); #ifdef DIC_ENABLE uint16_t value = data->percent100ths; char buffer[BYTE]; itoa(value, buffer, DECIMAL); - dic_sendmsg("lift/position set",(const char *)(buffer)); + dic_sendmsg("lift/position set", (const char *) (buffer)); #endif // DIC_ENABLE } chip::Platform::Delete(data); From 3da7530ca3f375e78357a1293999bb815ed190e7 Mon Sep 17 00:00:00 2001 From: thirupathi Date: Wed, 6 Sep 2023 22:36:45 +0530 Subject: [PATCH 4/7] addressed review comments --- examples/thermostat/silabs/include/AppTask.h | 9 --- examples/thermostat/silabs/src/AppTask.cpp | 74 ------------------- .../thermostat/silabs/src/ZclCallbacks.cpp | 4 +- 3 files changed, 2 insertions(+), 85 deletions(-) diff --git a/examples/thermostat/silabs/include/AppTask.h b/examples/thermostat/silabs/include/AppTask.h index 946b936a8e2172..695b7d5b8ed751 100644 --- a/examples/thermostat/silabs/include/AppTask.h +++ b/examples/thermostat/silabs/include/AppTask.h @@ -88,15 +88,6 @@ class AppTask : public BaseApplication */ static void ButtonEventHandler(uint8_t button, uint8_t btnAction); - /** - * @brief share the status to cloud using DIC - * - * @param attributeId attribute id for the attribute - */ -#ifdef DIC_ENABLE - void DIC_AttrubiteHandler(AttributeId attributeId); -#endif // DIC_ENABLE - private: static AppTask sAppTask; diff --git a/examples/thermostat/silabs/src/AppTask.cpp b/examples/thermostat/silabs/src/AppTask.cpp index 252850cf03663a..22d0bb3010b9ab 100644 --- a/examples/thermostat/silabs/src/AppTask.cpp +++ b/examples/thermostat/silabs/src/AppTask.cpp @@ -50,12 +50,6 @@ #include #include -#ifdef DIC_ENABLE -#define DECIMAL 10 -#define BYTE 5 -#include "dic.h" -#endif // DIC_ENABLE - /********************************************************** * Defines and Constants *********************************************************/ @@ -70,10 +64,6 @@ using namespace chip::app; using namespace chip::TLV; using namespace ::chip::DeviceLayer; -#ifdef DIC_ENABLE -namespace ThermAttr = chip::app::Clusters::Thermostat::Attributes; -#endif // DIC_ENABLE - /********************************************************** * Variable declarations *********************************************************/ @@ -183,67 +173,3 @@ void AppTask::ButtonEventHandler(uint8_t button, uint8_t btnAction) sAppTask.PostEvent(&aEvent); } } - -#ifdef DIC_ENABLE -void AppTask::DIC_AttrubiteHandler(AttributeId attributeId) -{ - switch (attributeId) - { - case ThermAttr::LocalTemperature::Id: { - int8_t CurrentTemp = TempMgr().GetCurrentTemp(); - char buffer[BYTE]; - itoa(CurrentTemp, buffer, DECIMAL); - dic_sendmsg("LocalTemperature/Temp", (const char *) (buffer)); - } - break; - case ThermAttr::OccupiedCoolingSetpoint::Id: { - int8_t coolingTemp = TempMgr().GetCoolingSetPoint(); - char buffer[BYTE]; - itoa(coolingTemp, buffer, DECIMAL); - dic_sendmsg("OccupiedCoolingSetpoint/coolingTemp", (const char *) (buffer)); - } - break; - case ThermAttr::OccupiedHeatingSetpoint::Id: { - int8_t heatingTemp = TempMgr().GetHeatingSetPoint(); - char buffer[BYTE]; - itoa(heatingTemp, buffer, DECIMAL); - dic_sendmsg("OccupiedHeatingSetpoint/heatingTemp", (const char *) (buffer)); - } - break; - case ThermAttr::SystemMode::Id: { - int8_t mode = TempMgr().GetMode(); - char buffer[BYTE]; - const char * Mode; - switch (mode) - { - case 0: - Mode = "OFF"; - break; - case 1: - Mode = "HEAT&COOL"; - break; - case 3: - Mode = "COOL"; - break; - case 4: - Mode = "HEAT"; - break; - default: - Mode = "INVALID MODE"; - break; - } - uint16_t current_temp = TempMgr().GetCurrentTemp(); - itoa(current_temp, buffer, DECIMAL); - dic_sendmsg("thermostat/systemMode", Mode); - dic_sendmsg("thermostat/currentTemp", (const char *) (buffer)); - } - break; - - default: { - SILABS_LOG("Unhandled thermostat attribute %x", attributeId); - return; - } - break; - } -} -#endif // DIC_ENABLE diff --git a/examples/thermostat/silabs/src/ZclCallbacks.cpp b/examples/thermostat/silabs/src/ZclCallbacks.cpp index 06f6417cdf80a1..4bac6080100006 100644 --- a/examples/thermostat/silabs/src/ZclCallbacks.cpp +++ b/examples/thermostat/silabs/src/ZclCallbacks.cpp @@ -29,7 +29,7 @@ #include #ifdef DIC_ENABLE -#include "AppTask.h" +#include "dic_control.h" #endif // DIC_ENABLE using namespace ::chip; @@ -51,7 +51,7 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & { TempMgr().AttributeChangeHandler(attributePath.mEndpointId, attributeId, value, size); #ifdef DIC_ENABLE - AppTask().DIC_AttrubiteHandler(attributeId); + dic::control::AttributeHandler(attributePath.mEndpointId,attributeId); #endif // DIC_ENABLE } } From e67f042e886c12e273168e8c01002b10d3062aa8 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 6 Sep 2023 17:09:38 +0000 Subject: [PATCH 5/7] Restyled by clang-format --- examples/thermostat/silabs/src/ZclCallbacks.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/thermostat/silabs/src/ZclCallbacks.cpp b/examples/thermostat/silabs/src/ZclCallbacks.cpp index 4bac6080100006..641f4c7698c27d 100644 --- a/examples/thermostat/silabs/src/ZclCallbacks.cpp +++ b/examples/thermostat/silabs/src/ZclCallbacks.cpp @@ -51,7 +51,7 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & { TempMgr().AttributeChangeHandler(attributePath.mEndpointId, attributeId, value, size); #ifdef DIC_ENABLE - dic::control::AttributeHandler(attributePath.mEndpointId,attributeId); + dic::control::AttributeHandler(attributePath.mEndpointId, attributeId); #endif // DIC_ENABLE } } From 1c4d5fe9d0d4aea09562c3c218bb4bdae333c9c5 Mon Sep 17 00:00:00 2001 From: thirupathi Date: Thu, 7 Sep 2023 10:40:16 +0530 Subject: [PATCH 6/7] addressed review comments --- examples/window-app/silabs/src/WindowManager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/window-app/silabs/src/WindowManager.cpp b/examples/window-app/silabs/src/WindowManager.cpp index d8e010d5307418..80d641e76834dc 100644 --- a/examples/window-app/silabs/src/WindowManager.cpp +++ b/examples/window-app/silabs/src/WindowManager.cpp @@ -58,7 +58,7 @@ using namespace ::chip::DeviceLayer::Silabs; #ifdef DIC_ENABLE #define DECIMAL 10 -#define BYTE 5 +#define MSG_SIZE 5 #include "dic.h" #endif // DIC_ENABLE @@ -512,7 +512,7 @@ void WindowManager::Cover::CallbackPositionSet(intptr_t arg) TiltPositionSet(data->mEndpointId, position); #ifdef DIC_ENABLE uint16_t value = data->percent100ths; - char buffer[BYTE]; + char buffer[MSG_SIZE]; itoa(value, buffer, DECIMAL); dic_sendmsg("tilt/position set", (const char *) (buffer)); #endif // DIC_ENABLE @@ -522,7 +522,7 @@ void WindowManager::Cover::CallbackPositionSet(intptr_t arg) LiftPositionSet(data->mEndpointId, position); #ifdef DIC_ENABLE uint16_t value = data->percent100ths; - char buffer[BYTE]; + char buffer[MSG_SIZE]; itoa(value, buffer, DECIMAL); dic_sendmsg("lift/position set", (const char *) (buffer)); #endif // DIC_ENABLE From 43536d4d2176c52cf0ff56e748983a76b9da9b85 Mon Sep 17 00:00:00 2001 From: thirupathi Date: Fri, 8 Sep 2023 10:17:22 +0530 Subject: [PATCH 7/7] addressed review comments --- examples/window-app/silabs/src/WindowManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/window-app/silabs/src/WindowManager.cpp b/examples/window-app/silabs/src/WindowManager.cpp index 80d641e76834dc..851a818e9ec485 100644 --- a/examples/window-app/silabs/src/WindowManager.cpp +++ b/examples/window-app/silabs/src/WindowManager.cpp @@ -58,7 +58,7 @@ using namespace ::chip::DeviceLayer::Silabs; #ifdef DIC_ENABLE #define DECIMAL 10 -#define MSG_SIZE 5 +#define MSG_SIZE 6 #include "dic.h" #endif // DIC_ENABLE