From 81aede2c39c77050c2a4b605089883fdb0a6ba31 Mon Sep 17 00:00:00 2001 From: Timothy Maes Date: Tue, 5 Jul 2022 20:41:12 +0200 Subject: [PATCH 1/4] Adding Identify effect handling to lighting-app (#20310) --- examples/lighting-app/qpg/src/AppTask.cpp | 104 ++++++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/examples/lighting-app/qpg/src/AppTask.cpp b/examples/lighting-app/qpg/src/AppTask.cpp index 96cdfc9577a04e..13e526024c1edf 100644 --- a/examples/lighting-app/qpg/src/AppTask.cpp +++ b/examples/lighting-app/qpg/src/AppTask.cpp @@ -28,6 +28,9 @@ #include #include #include +#include +#include + #include #include #include @@ -66,6 +69,107 @@ StaticQueue_t sAppEventQueueStruct; StackType_t appStack[APP_TASK_STACK_SIZE / sizeof(StackType_t)]; StaticTask_t appTaskStruct; + +EmberAfIdentifyEffectIdentifier sIdentifyEffect = EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT; + +/********************************************************** + * Identify Callbacks + *********************************************************/ + +namespace { +void OnTriggerIdentifyEffectCompleted(chip::System::Layer * systemLayer, void * appState) +{ + sIdentifyEffect = EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT; +} +} // namespace + +void OnTriggerIdentifyEffect(Identify * identify) +{ + sIdentifyEffect = identify->mCurrentEffectIdentifier; + + if (identify->mCurrentEffectIdentifier == EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_CHANNEL_CHANGE) + { + ChipLogProgress(Zcl, "IDENTIFY_EFFECT_IDENTIFIER_CHANNEL_CHANGE - Not supported, use effect variant %d", + identify->mEffectVariant); + sIdentifyEffect = static_cast(identify->mEffectVariant); + } + + switch (sIdentifyEffect) + { + case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_BLINK: + case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_BREATHE: + case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_OKAY: + (void) chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds16(5), OnTriggerIdentifyEffectCompleted, + identify); + break; + case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_FINISH_EFFECT: + (void) chip::DeviceLayer::SystemLayer().CancelTimer(OnTriggerIdentifyEffectCompleted, identify); + (void) chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds16(1), OnTriggerIdentifyEffectCompleted, + identify); + break; + case EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT: + (void) chip::DeviceLayer::SystemLayer().CancelTimer(OnTriggerIdentifyEffectCompleted, identify); + sIdentifyEffect = EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT; + break; + default: + ChipLogProgress(Zcl, "No identifier effect"); + } +} + +Identify gIdentify = { + chip::EndpointId{ 1 }, + [](Identify *) { ChipLogProgress(Zcl, "onIdentifyStart"); }, + [](Identify *) { ChipLogProgress(Zcl, "onIdentifyStop"); }, + EMBER_ZCL_IDENTIFY_IDENTIFY_TYPE_VISIBLE_LED, + OnTriggerIdentifyEffect, +}; + +/********************************************************** + * OffWithEffect Callbacks + *********************************************************/ + +void OnTriggerOffWithEffect(OnOffEffect * effect) +{ + chip::app::Clusters::OnOff::OnOffEffectIdentifier effectId = effect->mEffectIdentifier; + uint8_t effectVariant = effect->mEffectVariant; + + // Uses print outs until we can support the effects + if (effectId == EMBER_ZCL_ON_OFF_EFFECT_IDENTIFIER_DELAYED_ALL_OFF) + { + if (effectVariant == EMBER_ZCL_ON_OFF_DELAYED_ALL_OFF_EFFECT_VARIANT_FADE_TO_OFF_IN_0P8_SECONDS) + { + ChipLogProgress(Zcl, "EMBER_ZCL_ON_OFF_DELAYED_ALL_OFF_EFFECT_VARIANT_FADE_TO_OFF_IN_0P8_SECONDS"); + } + else if (effectVariant == EMBER_ZCL_ON_OFF_DELAYED_ALL_OFF_EFFECT_VARIANT_NO_FADE) + { + ChipLogProgress(Zcl, "EMBER_ZCL_ON_OFF_DELAYED_ALL_OFF_EFFECT_VARIANT_NO_FADE"); + } + else if (effectVariant == + EMBER_ZCL_ON_OFF_DELAYED_ALL_OFF_EFFECT_VARIANT_50_PERCENT_DIM_DOWN_IN_0P8_SECONDS_THEN_FADE_TO_OFF_IN_12_SECONDS) + { + ChipLogProgress(Zcl, + "EMBER_ZCL_ON_OFF_DELAYED_ALL_OFF_EFFECT_VARIANT_50_PERCENT_DIM_DOWN_IN_0P8_SECONDS_THEN_FADE_TO_OFF_" + "IN_12_SECONDS"); + } + } + else if (effectId == EMBER_ZCL_ON_OFF_EFFECT_IDENTIFIER_DYING_LIGHT) + { + if (effectVariant == + EMBER_ZCL_ON_OFF_DYING_LIGHT_EFFECT_VARIANT_20_PERCENTER_DIM_UP_IN_0P5_SECONDS_THEN_FADE_TO_OFF_IN_1_SECOND) + { + ChipLogProgress( + Zcl, "EMBER_ZCL_ON_OFF_DYING_LIGHT_EFFECT_VARIANT_20_PERCENTER_DIM_UP_IN_0P5_SECONDS_THEN_FADE_TO_OFF_IN_1_SECOND"); + } + } +} + +OnOffEffect gEffect = { + chip::EndpointId{ 1 }, + OnTriggerOffWithEffect, + EMBER_ZCL_ON_OFF_EFFECT_IDENTIFIER_DELAYED_ALL_OFF, + static_cast(EMBER_ZCL_ON_OFF_DELAYED_ALL_OFF_EFFECT_VARIANT_FADE_TO_OFF_IN_0P8_SECONDS), +}; + } // namespace AppTask AppTask::sAppTask; From 760d50e1198002e85d75df42b29fef34db358405 Mon Sep 17 00:00:00 2001 From: Michael Spang Date: Tue, 5 Jul 2022 15:06:07 -0400 Subject: [PATCH 2/4] Disable pigweed clang build on Mac M1 (#20319) This build's dependencies are not met on Mac ARM64 as there's no arm64 clang package available from pigweed yet. --- BUILD.gn | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/BUILD.gn b/BUILD.gn index f02d6fb3e6888f..e581759f25e85d 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -210,7 +210,9 @@ if (current_toolchain != "${dir_pw_toolchain}/default:default") { declare_args() { # Enable building chip with clang. - enable_host_clang_build = enable_default_builds && host_os != "win" + # Disabled on Mac arm64 but note that the "gcc" build uses Apple clang. + enable_host_clang_build = enable_default_builds && host_os != "win" && + (host_os != "mac" || host_cpu != "arm64") # Enable building chip with gcc. enable_host_gcc_build = enable_default_builds && host_os != "win" From 777ee25502dd82cb2079c871cb39671e3f340ebf Mon Sep 17 00:00:00 2001 From: tehampson Date: Tue, 5 Jul 2022 15:09:28 -0400 Subject: [PATCH 3/4] Fix python PersistentStorageDelegate to latest API description (#20287) * Fix python PersistentStorageDelegate to latest API description * Restyle * Address PR comment * Address PR comment --- .../ChipDeviceController-StorageDelegate.cpp | 7 ++++--- .../python/ChipDeviceController-StorageDelegate.h | 4 +--- src/controller/python/chip/storage/__init__.py | 15 ++++++++++----- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/controller/python/ChipDeviceController-StorageDelegate.cpp b/src/controller/python/ChipDeviceController-StorageDelegate.cpp index 7e25d71a440cd1..c9320a5eca531d 100644 --- a/src/controller/python/ChipDeviceController-StorageDelegate.cpp +++ b/src/controller/python/ChipDeviceController-StorageDelegate.cpp @@ -86,10 +86,11 @@ CHIP_ERROR StorageAdapter::SyncGetKeyValue(const char * key, void * value, uint1 } uint16_t tmpSize = size; + bool isFound = false; - mGetKeyCb(mContext, key, (char *) value, &tmpSize); + mGetKeyCb(mContext, key, (char *) value, &tmpSize, &isFound); - if (tmpSize == 0) + if (!isFound) { ChipLogDetail(Controller, "Key Not Found\n"); return CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; @@ -107,8 +108,8 @@ CHIP_ERROR StorageAdapter::SyncGetKeyValue(const char * key, void * value, uint1 CHIP_ERROR StorageAdapter::SyncSetKeyValue(const char * key, const void * value, uint16_t size) { + ReturnErrorCodeIf(((value == nullptr) && (size != 0)), CHIP_ERROR_INVALID_ARGUMENT); ChipLogDetail(Controller, "StorageAdapter::SetKeyValue: Key = %s, Value = %p (%u)", key, value, size); - mStorage[key] = std::string(static_cast(value), size); mSetKeyCb(mContext, key, value, size); return CHIP_NO_ERROR; } diff --git a/src/controller/python/ChipDeviceController-StorageDelegate.h b/src/controller/python/ChipDeviceController-StorageDelegate.h index bb00e240413182..4d1e0df7465897 100644 --- a/src/controller/python/ChipDeviceController-StorageDelegate.h +++ b/src/controller/python/ChipDeviceController-StorageDelegate.h @@ -45,7 +45,7 @@ namespace Python { using PyObject = void; using SyncSetKeyValueCb = void (*)(PyObject * appContext, const char * key, const void * value, uint16_t size); -using SetGetKeyValueCb = void (*)(PyObject * appContext, const char * key, char * value, uint16_t * size); +using SetGetKeyValueCb = void (*)(PyObject * appContext, const char * key, char * value, uint16_t * size, bool * isFound); using SyncDeleteKeyValueCb = void (*)(PyObject * appContext, const char * key); class StorageAdapter : public PersistentStorageDelegate @@ -68,8 +68,6 @@ class StorageAdapter : public PersistentStorageDelegate SetGetKeyValueCb mGetKeyCb; SyncDeleteKeyValueCb mDeleteKeyCb; PyObject * mContext; - - std::map mStorage; }; } // namespace Python diff --git a/src/controller/python/chip/storage/__init__.py b/src/controller/python/chip/storage/__init__.py index 4b3fc28ff18c37..cb5c8a1deb9c29 100644 --- a/src/controller/python/chip/storage/__init__.py +++ b/src/controller/python/chip/storage/__init__.py @@ -35,7 +35,7 @@ _SyncSetKeyValueCbFunct = CFUNCTYPE( None, py_object, c_char_p, POINTER(c_char), c_uint16) _SyncGetKeyValueCbFunct = CFUNCTYPE( - None, py_object, c_char_p, POINTER(c_char), POINTER(c_uint16)) + None, py_object, c_char_p, POINTER(c_char), POINTER(c_uint16), POINTER(c_bool)) _SyncDeleteKeyValueCbFunct = CFUNCTYPE(None, py_object, c_char_p) @@ -45,7 +45,7 @@ def _OnSyncSetKeyValueCb(storageObj, key: str, value, size): @_SyncGetKeyValueCbFunct -def _OnSyncGetKeyValueCb(storageObj, key: str, value, size): +def _OnSyncGetKeyValueCb(storageObj, key: str, value, size, is_found): ''' This does not adhere to the API requirements of PersistentStorageDelegate::SyncGetKeyValue, but that is okay since the C++ storage binding layer is capable of adapting results from @@ -57,7 +57,7 @@ def _OnSyncGetKeyValueCb(storageObj, key: str, value, size): except Exception as ex: keyValue = None - if (keyValue): + if (keyValue is not None): sizeOfValue = size[0] sizeToCopy = min(sizeOfValue, len(keyValue)) @@ -74,13 +74,15 @@ def _OnSyncGetKeyValueCb(storageObj, key: str, value, size): # will use the value in size[0] to determine if it should # return CHIP_ERROR_BUFFER_TOO_SMALL. size[0] = len(keyValue) + is_found[0] = True else: + is_found[0] = False size[0] = 0 @_SyncDeleteKeyValueCbFunct def _OnSyncDeleteKeyValueCb(storageObj, key): - storageObj.SetSdkKey(key.decode("utf-8"), None) + storageObj.DeleteSdkKey(key.decode("utf-8")) class PersistentStorage: @@ -151,7 +153,7 @@ def SetSdkKey(self, key: str, value: bytes): raise ValueError("Invalid Key") if (value is None): - del(self.jsonData['sdk-config'][key]) + raise ValueError('value is not expected to be None') else: self.jsonData['sdk-config'][key] = base64.b64encode( value).decode("utf-8") @@ -161,6 +163,9 @@ def SetSdkKey(self, key: str, value: bytes): def GetSdkKey(self, key: str): return base64.b64decode(self.jsonData['sdk-config'][key]) + def DeleteSdkKey(self, key: str): + del(self.jsonData['sdk-config'][key]) + def GetUnderlyingStorageAdapter(self): return self._storageAdapterObj From a4986739f830d9b49ceb5e9a48c7ceb0b2ec615d Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Tue, 5 Jul 2022 21:14:20 +0200 Subject: [PATCH 4/4] [chip-tool] Add read-all command to read all events and attributes from a given endpoint (could be wildcard) onto a single transaction (#20270) * [chip-tool] Add read-all command to read all events and attributes from a given endpoint (could be wildcard) onto a single transaction * Update generated code --- .../commands/clusters/ReportCommand.h | 26 ++++++++++++++ examples/chip-tool/templates/commands.zapt | 1 + .../interaction_model/InteractionModel.cpp | 34 +++++++++++++++++++ .../interaction_model/InteractionModel.h | 3 ++ .../zap-generated/cluster/Commands.h | 1 + 5 files changed, 65 insertions(+) diff --git a/examples/chip-tool/commands/clusters/ReportCommand.h b/examples/chip-tool/commands/clusters/ReportCommand.h index 5a6bb4bf20c3b3..98f8f6de772051 100644 --- a/examples/chip-tool/commands/clusters/ReportCommand.h +++ b/examples/chip-tool/commands/clusters/ReportCommand.h @@ -411,3 +411,29 @@ class SubscribeEvent : public SubscribeCommand chip::Optional mKeepSubscriptions; chip::Optional> mIsUrgents; }; + +class ReadAll : public ReadCommand +{ +public: + ReadAll(CredentialIssuerCommands * credsIssuerConfig) : ReadCommand("read-all", credsIssuerConfig) + { + AddArgument("fabric-filtered", 0, 1, &mFabricFiltered); + ReadCommand::AddArguments(); + } + + ~ReadAll() {} + + void OnDone(chip::app::ReadClient * aReadClient) override + { + InteractionModelReports::CleanupReadClient(aReadClient); + SetCommandExitStatus(mError); + } + + CHIP_ERROR SendCommand(chip::DeviceProxy * device, std::vector endpointIds) override + { + return ReadCommand::ReadAll(device, endpointIds, mFabricFiltered); + } + +private: + chip::Optional mFabricFiltered; +}; diff --git a/examples/chip-tool/templates/commands.zapt b/examples/chip-tool/templates/commands.zapt index 25c8a54859f471..2600ce10eeaa1f 100644 --- a/examples/chip-tool/templates/commands.zapt +++ b/examples/chip-tool/templates/commands.zapt @@ -137,6 +137,7 @@ void registerClusterAny(Commands & commands, CredentialIssuerCommands * credsIss make_unique(credsIssuerConfig), // make_unique(credsIssuerConfig), // make_unique(credsIssuerConfig), // + make_unique(credsIssuerConfig), // }; commands.Register(clusterName, clusterCommands); diff --git a/src/app/tests/suites/commands/interaction_model/InteractionModel.cpp b/src/app/tests/suites/commands/interaction_model/InteractionModel.cpp index 526106c56d4a07..9a3c738b45d373 100644 --- a/src/app/tests/suites/commands/interaction_model/InteractionModel.cpp +++ b/src/app/tests/suites/commands/interaction_model/InteractionModel.cpp @@ -448,3 +448,37 @@ void InteractionModelReports::CleanupReadClient(ReadClient * aReadClient) std::remove_if(mReadClients.begin(), mReadClients.end(), [aReadClient](auto & item) { return item.get() == aReadClient; }), mReadClients.end()); } + +CHIP_ERROR InteractionModelReports::ReadAll(DeviceProxy * device, std::vector endpointIds, + const Optional & fabricFiltered) +{ + AttributePathParams attributePathParams[kMaxAllowedPaths]; + EventPathParams eventPathParams[kMaxAllowedPaths]; + + auto pathsCount = endpointIds.size(); + VerifyOrReturnError(pathsCount > 0 && pathsCount <= kMaxAllowedPaths, CHIP_ERROR_INVALID_ARGUMENT); + + for (size_t i = 0; i < pathsCount; i++) + { + auto endpointId = endpointIds.at(i); + attributePathParams[i].mEndpointId = endpointId; + eventPathParams[i].mEndpointId = endpointId; + } + + ReadPrepareParams params(device->GetSecureSession().Value()); + params.mpEventPathParamsList = eventPathParams; + params.mEventPathParamsListSize = pathsCount; + params.mpAttributePathParamsList = attributePathParams; + params.mAttributePathParamsListSize = pathsCount; + + if (fabricFiltered.HasValue()) + { + params.mIsFabricFiltered = fabricFiltered.Value(); + } + + auto client = std::make_unique(InteractionModelEngine::GetInstance(), device->GetExchangeManager(), + mBufferedReadAdapter, ReadClient::InteractionType::Read); + ReturnErrorOnFailure(client->SendRequest(params)); + mReadClients.push_back(std::move(client)); + return CHIP_NO_ERROR; +} diff --git a/src/app/tests/suites/commands/interaction_model/InteractionModel.h b/src/app/tests/suites/commands/interaction_model/InteractionModel.h index a5853fdd3ac560..157195bf2a8352 100644 --- a/src/app/tests/suites/commands/interaction_model/InteractionModel.h +++ b/src/app/tests/suites/commands/interaction_model/InteractionModel.h @@ -107,6 +107,9 @@ class InteractionModelReports const chip::Optional & keepSubscriptions = chip::NullOptional, const chip::Optional> & isUrgents = chip::NullOptional); + CHIP_ERROR ReadAll(chip::DeviceProxy * device, std::vector endpointIds, + const chip::Optional & fabricFiltered = chip::Optional(true)); + void Shutdown() { mReadClients.clear(); } void CleanupReadClient(chip::app::ReadClient * aReadClient); diff --git a/zzz_generated/chip-tool/zap-generated/cluster/Commands.h b/zzz_generated/chip-tool/zap-generated/cluster/Commands.h index f9349d380f31ff..5f3218a160a64c 100644 --- a/zzz_generated/chip-tool/zap-generated/cluster/Commands.h +++ b/zzz_generated/chip-tool/zap-generated/cluster/Commands.h @@ -17356,6 +17356,7 @@ void registerClusterAny(Commands & commands, CredentialIssuerCommands * credsIss make_unique(credsIssuerConfig), // make_unique(credsIssuerConfig), // make_unique(credsIssuerConfig), // + make_unique(credsIssuerConfig), // }; commands.Register(clusterName, clusterCommands);