diff --git a/examples/all-clusters-app/esp32/main/AppTask.cpp b/examples/all-clusters-app/esp32/main/AppTask.cpp index 6db8c63b3c14ec..04604ba419bd17 100644 --- a/examples/all-clusters-app/esp32/main/AppTask.cpp +++ b/examples/all-clusters-app/esp32/main/AppTask.cpp @@ -26,6 +26,7 @@ #include "esp_log.h" #include "esp_spi_flash.h" #include "freertos/FreeRTOS.h" +#include #include #define APP_TASK_NAME "APP" @@ -39,6 +40,8 @@ namespace { QueueHandle_t sAppEventQueue; TaskHandle_t sAppTaskHandle; +chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; + } // namespace AppTask AppTask::sAppTask; @@ -84,6 +87,9 @@ CHIP_ERROR AppTask::Init() #if CONFIG_HAVE_DISPLAY InitDeviceDisplay(); #endif + + chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); + return err; } diff --git a/examples/all-clusters-app/esp32/main/CMakeLists.txt b/examples/all-clusters-app/esp32/main/CMakeLists.txt index 4f8db9d121402d..40697450af516b 100644 --- a/examples/all-clusters-app/esp32/main/CMakeLists.txt +++ b/examples/all-clusters-app/esp32/main/CMakeLists.txt @@ -21,6 +21,7 @@ set(PRIV_INCLUDE_DIRS_LIST "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/all-clusters-app" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/all-clusters-app/all-clusters-common/include" "${CMAKE_CURRENT_LIST_DIR}/include" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/providers" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32" ) set(SRC_DIRS_LIST @@ -28,6 +29,7 @@ set(SRC_DIRS_LIST "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/all-clusters-app/zap-generated" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/app-common/app-common/zap-generated/attributes" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/app-common/app-common/zap-generated" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/providers" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/route_hook" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/ota" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/common" diff --git a/examples/light-switch-app/esp32/main/AppTask.cpp b/examples/light-switch-app/esp32/main/AppTask.cpp index f29b4a0927f783..6a1531940a1197 100644 --- a/examples/light-switch-app/esp32/main/AppTask.cpp +++ b/examples/light-switch-app/esp32/main/AppTask.cpp @@ -20,6 +20,7 @@ #include "BindingHandler.h" #include "esp_log.h" #include "freertos/FreeRTOS.h" +#include #define APP_TASK_NAME "APP" #define APP_EVENT_QUEUE_SIZE 10 @@ -37,6 +38,7 @@ namespace { QueueHandle_t sAppEventQueue; TaskHandle_t sAppTaskHandle; +chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; } // namespace @@ -62,8 +64,8 @@ CHIP_ERROR AppTask::Init() CHIP_ERROR err = CHIP_NO_ERROR; AppButton.Init(); - AppButton.SetButtonPressCallback(ButtonPressCallback); + chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); return err; } diff --git a/examples/light-switch-app/esp32/main/CMakeLists.txt b/examples/light-switch-app/esp32/main/CMakeLists.txt index 959a9bdb37f123..3abe09f4040e8b 100644 --- a/examples/light-switch-app/esp32/main/CMakeLists.txt +++ b/examples/light-switch-app/esp32/main/CMakeLists.txt @@ -19,12 +19,14 @@ idf_component_register(PRIV_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/light-switch-app" "${CMAKE_CURRENT_LIST_DIR}/include" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/providers" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32" SRC_DIRS "${CMAKE_CURRENT_LIST_DIR}" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/app-common/app-common/zap-generated/attributes" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/app-common/app-common/zap-generated" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/light-switch-app/zap-generated" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/providers" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/route_hook" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/ota" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/common" diff --git a/examples/lighting-app/esp32/main/AppTask.cpp b/examples/lighting-app/esp32/main/AppTask.cpp index bfa8a8d1401973..f175af3a3c5eeb 100644 --- a/examples/lighting-app/esp32/main/AppTask.cpp +++ b/examples/lighting-app/esp32/main/AppTask.cpp @@ -20,6 +20,7 @@ #include "esp_log.h" #include "freertos/FreeRTOS.h" +#include #include #include #include @@ -46,6 +47,8 @@ constexpr EndpointId kLightEndpointId = 1; QueueHandle_t sAppEventQueue; TaskHandle_t sAppTaskHandle; +chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; + } // namespace AppTask AppTask::sAppTask; @@ -74,6 +77,8 @@ CHIP_ERROR AppTask::Init() AppButton.SetButtonPressCallback(ButtonPressCallback); + chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); + return err; } diff --git a/examples/lighting-app/esp32/main/CMakeLists.txt b/examples/lighting-app/esp32/main/CMakeLists.txt index 93ff9dc67217bd..c30c6995c44e8f 100644 --- a/examples/lighting-app/esp32/main/CMakeLists.txt +++ b/examples/lighting-app/esp32/main/CMakeLists.txt @@ -18,6 +18,7 @@ idf_component_register(PRIV_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/lighting-app" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/providers" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/lighting-app/lighting-common/include" "${CMAKE_CURRENT_LIST_DIR}/include" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32" @@ -26,11 +27,12 @@ idf_component_register(PRIV_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/app-common/app-common/zap-generated/attributes" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/app-common/app-common/zap-generated" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/lighting-app/zap-generated" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/providers" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/lighting-app/lighting-common/src" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/route_hook" - "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/ota" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/ota" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/common" - "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/shell_extension" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/shell_extension" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/server" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/util" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/reporting" diff --git a/examples/lock-app/esp32/main/AppTask.cpp b/examples/lock-app/esp32/main/AppTask.cpp index bedaf75b6946e2..b78de7f2cd30a4 100644 --- a/examples/lock-app/esp32/main/AppTask.cpp +++ b/examples/lock-app/esp32/main/AppTask.cpp @@ -21,6 +21,7 @@ #include "Button.h" #include "LEDWidget.h" #include "esp_log.h" +#include #include #include #include @@ -56,6 +57,8 @@ QueueHandle_t sAppEventQueue; bool sHaveBLEConnections = false; StackType_t appStack[APP_TASK_STACK_SIZE / sizeof(StackType_t)]; + +chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; } // namespace using namespace ::chip::DeviceLayer; @@ -103,6 +106,8 @@ CHIP_ERROR AppTask::Init() sLockLED.Set(!BoltLockMgr().IsUnlocked()); + chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); + chip::DeviceLayer::SystemLayer().ScheduleWork(UpdateClusterState, nullptr); ConfigurationMgr().LogDeviceConfig(); diff --git a/examples/lock-app/esp32/main/CMakeLists.txt b/examples/lock-app/esp32/main/CMakeLists.txt index 24fa3cc6ed70c7..0c5816f69eb5fd 100644 --- a/examples/lock-app/esp32/main/CMakeLists.txt +++ b/examples/lock-app/esp32/main/CMakeLists.txt @@ -21,6 +21,7 @@ idf_component_register(INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/pw_sys_io/public" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/providers" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/common" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/common/pigweed" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/common/pigweed/esp32" @@ -30,9 +31,10 @@ idf_component_register(INCLUDE_DIRS "${IDF_PATH}/components/freertos/include/freertos" SRC_DIRS "${CMAKE_CURRENT_LIST_DIR}" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/providers" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/common" - "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/common/pigweed" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/common/pigweed" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/common/pigweed/esp32" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/app-common/app-common/zap-generated/attributes" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/app-common/app-common/zap-generated" @@ -141,15 +143,17 @@ target_compile_options(${COMPONENT_LIB} PRIVATE else (CONFIG_ENABLE_PW_RPC) idf_component_register(PRIV_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/lock-app/" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/providers" "${CMAKE_CURRENT_LIST_DIR}/include" SRC_DIRS "${CMAKE_CURRENT_LIST_DIR}" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/app-common/app-common/zap-generated/attributes" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/app-common/app-common/zap-generated" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/zzz_generated/lock-app/zap-generated" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/providers" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/route_hook" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/shell_extension" - "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/common" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/examples/platform/esp32/common" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/server" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/util" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/reporting" diff --git a/src/platform/ESP32/BUILD.gn b/src/platform/ESP32/BUILD.gn index 822ffa58efcd5c..9f38280a1dfae9 100644 --- a/src/platform/ESP32/BUILD.gn +++ b/src/platform/ESP32/BUILD.gn @@ -34,8 +34,6 @@ static_library("ESP32") { "ConfigurationManagerImpl.h", "ConnectivityManagerImpl.cpp", "ConnectivityManagerImpl.h", - "DeviceInfoProviderImpl.cpp", - "DeviceInfoProviderImpl.h", "DeviceNetworkProvisioningDelegateImpl.cpp", "DeviceNetworkProvisioningDelegateImpl.h", "DiagnosticDataProviderImpl.cpp", diff --git a/src/platform/ESP32/DeviceInfoProviderImpl.cpp b/src/platform/ESP32/DeviceInfoProviderImpl.cpp deleted file mode 100644 index ff28ee8c585002..00000000000000 --- a/src/platform/ESP32/DeviceInfoProviderImpl.cpp +++ /dev/null @@ -1,376 +0,0 @@ -/* - * - * Copyright (c) 2022 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. - */ - -#include -#include -#include -#include -#include -#include - -#include -#include - -namespace chip { -namespace DeviceLayer { - -namespace { -constexpr TLV::Tag kLabelNameTag = TLV::ContextTag(0); -constexpr TLV::Tag kLabelValueTag = TLV::ContextTag(1); -} // anonymous namespace - -DeviceInfoProviderImpl & DeviceInfoProviderImpl::GetDefaultInstance() -{ - static DeviceInfoProviderImpl sInstance; - return sInstance; -} - -DeviceInfoProvider::FixedLabelIterator * DeviceInfoProviderImpl::IterateFixedLabel(EndpointId endpoint) -{ - return new FixedLabelIteratorImpl(endpoint); -} - -DeviceInfoProviderImpl::FixedLabelIteratorImpl::FixedLabelIteratorImpl(EndpointId endpoint) : mEndpoint(endpoint) -{ - mIndex = 0; -} - -size_t DeviceInfoProviderImpl::FixedLabelIteratorImpl::Count() -{ - // TODO: Need to provide a script which can generate a binary file which contains device information and - // update the DeviceInfoProvider which can read the information from it. - // Now we use the hardcoded labellist. - return 4; -} - -bool DeviceInfoProviderImpl::FixedLabelIteratorImpl::Next(FixedLabelType & output) -{ - bool retval = true; - - // TODO: Need to provide a script which can generate a binary file which contains device information and - // update the DeviceInfoProvider which can read the information from it. - // Now we use the hardcoded labellist. - CHIP_ERROR err = CHIP_NO_ERROR; - - const char * labelPtr = nullptr; - const char * valuePtr = nullptr; - - VerifyOrReturnError(mIndex < 4, false); - - ChipLogProgress(DeviceLayer, "Get the fixed label with index:%d at endpoint:%d", mIndex, mEndpoint); - - switch (mIndex) - { - case 0: - labelPtr = "room"; - valuePtr = "bedroom 2"; - break; - case 1: - labelPtr = "orientation"; - valuePtr = "North"; - break; - case 2: - labelPtr = "floor"; - valuePtr = "2"; - break; - case 3: - labelPtr = "direction"; - valuePtr = "up"; - break; - default: - err = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; - break; - } - - if (err == CHIP_NO_ERROR) - { - VerifyOrReturnError(strlen(labelPtr) <= kMaxLabelNameLength, false); - VerifyOrReturnError(strlen(valuePtr) <= kMaxLabelValueLength, false); - - Platform::CopyString(mFixedLabelNameBuf, kMaxLabelNameLength + 1, labelPtr); - Platform::CopyString(mFixedLabelValueBuf, kMaxLabelValueLength + 1, valuePtr); - - output.label = CharSpan::fromCharString(mFixedLabelNameBuf); - output.value = CharSpan::fromCharString(mFixedLabelValueBuf); - - mIndex++; - - retval = true; - } - else - { - retval = false; - } - - return retval; -} - -CHIP_ERROR DeviceInfoProviderImpl::SetUserLabelLength(EndpointId endpoint, size_t val) -{ - DefaultStorageKeyAllocator keyAlloc; - - return mStorage->SyncSetKeyValue(keyAlloc.UserLabelLengthKey(endpoint), &val, static_cast(sizeof(val))); -} - -CHIP_ERROR DeviceInfoProviderImpl::GetUserLabelLength(EndpointId endpoint, size_t & val) -{ - DefaultStorageKeyAllocator keyAlloc; - uint16_t len = static_cast(sizeof(val)); - - return mStorage->SyncGetKeyValue(keyAlloc.UserLabelLengthKey(endpoint), &val, len); -} - -CHIP_ERROR DeviceInfoProviderImpl::SetUserLabelAt(EndpointId endpoint, size_t index, const UserLabelType & userLabel) -{ - DefaultStorageKeyAllocator keyAlloc; - uint8_t buf[UserLabelTLVMaxSize()]; - TLV::TLVWriter writer; - writer.Init(buf); - - TLV::TLVType outerType; - ReturnErrorOnFailure(writer.StartContainer(TLV::AnonymousTag(), TLV::kTLVType_Structure, outerType)); - ReturnErrorOnFailure(writer.PutString(kLabelNameTag, userLabel.label)); - ReturnErrorOnFailure(writer.PutString(kLabelValueTag, userLabel.value)); - ReturnErrorOnFailure(writer.EndContainer(outerType)); - - return mStorage->SyncSetKeyValue(keyAlloc.UserLabelIndexKey(endpoint, index), buf, - static_cast(writer.GetLengthWritten())); -} - -DeviceInfoProvider::UserLabelIterator * DeviceInfoProviderImpl::IterateUserLabel(EndpointId endpoint) -{ - return new UserLabelIteratorImpl(*this, endpoint); -} - -DeviceInfoProviderImpl::UserLabelIteratorImpl::UserLabelIteratorImpl(DeviceInfoProviderImpl & provider, EndpointId endpoint) : - mProvider(provider), mEndpoint(endpoint) -{ - size_t total = 0; - - ReturnOnFailure(mProvider.GetUserLabelLength(mEndpoint, total)); - mTotal = total; - mIndex = 0; -} - -bool DeviceInfoProviderImpl::UserLabelIteratorImpl::Next(UserLabelType & output) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - - VerifyOrReturnError(mIndex < mTotal, false); - - DefaultStorageKeyAllocator keyAlloc; - uint8_t buf[UserLabelTLVMaxSize()]; - uint16_t len = static_cast(sizeof(buf)); - - err = mProvider.mStorage->SyncGetKeyValue(keyAlloc.UserLabelIndexKey(mEndpoint, mIndex), buf, len); - VerifyOrReturnError(err == CHIP_NO_ERROR, false); - - TLV::ContiguousBufferTLVReader reader; - reader.Init(buf); - err = reader.Next(TLV::kTLVType_Structure, TLV::AnonymousTag()); - VerifyOrReturnError(err == CHIP_NO_ERROR, false); - - TLV::TLVType containerType; - VerifyOrReturnError(reader.EnterContainer(containerType) == CHIP_NO_ERROR, false); - - chip::CharSpan label; - chip::CharSpan value; - - VerifyOrReturnError(reader.Next(kLabelNameTag) == CHIP_NO_ERROR, false); - VerifyOrReturnError(reader.Get(label) == CHIP_NO_ERROR, false); - - VerifyOrReturnError(reader.Next(kLabelValueTag) == CHIP_NO_ERROR, false); - VerifyOrReturnError(reader.Get(value) == CHIP_NO_ERROR, false); - - VerifyOrReturnError(reader.VerifyEndOfContainer() == CHIP_NO_ERROR, false); - VerifyOrReturnError(reader.ExitContainer(containerType) == CHIP_NO_ERROR, false); - - Platform::CopyString(mUserLabelNameBuf, label); - Platform::CopyString(mUserLabelValueBuf, value); - - output.label = CharSpan::fromCharString(mUserLabelNameBuf); - output.value = CharSpan::fromCharString(mUserLabelValueBuf); - - mIndex++; - - return true; -} - -DeviceInfoProvider::SupportedLocalesIterator * DeviceInfoProviderImpl::IterateSupportedLocales() -{ - return new SupportedLocalesIteratorImpl(); -} - -size_t DeviceInfoProviderImpl::SupportedLocalesIteratorImpl::Count() -{ - // TODO: Need to provide a script which can generate a binary file which contains device information and - // update the DeviceInfoProvider which can read the information from it. - // Now we use the hardcoded SupportedLocales. - // {("en-US"), ("de-DE"), ("fr-FR"), ("en-GB"), ("es-ES"), ("zh-CN"), ("it-IT"), ("ja-JP")} - - return 8; -} - -bool DeviceInfoProviderImpl::SupportedLocalesIteratorImpl::Next(CharSpan & output) -{ - bool retval = true; - - // TODO: Need to provide a script which can generate a binary file which contains device information and - // update the DeviceInfoProvider which can read the information from it. - // Now we use the hardcoded SupportedLocales. - CHIP_ERROR err = CHIP_NO_ERROR; - - const char * activeLocalePtr = nullptr; - - VerifyOrReturnError(mIndex < 8, false); - - switch (mIndex) - { - case 0: - activeLocalePtr = "en-US"; - break; - case 1: - activeLocalePtr = "de-DE"; - break; - case 2: - activeLocalePtr = "fr-FR"; - break; - case 3: - activeLocalePtr = "en-GB"; - break; - case 4: - activeLocalePtr = "es-ES"; - break; - case 5: - activeLocalePtr = "zh-CN"; - break; - case 6: - activeLocalePtr = "it-IT"; - break; - case 7: - activeLocalePtr = "ja-JP"; - break; - default: - err = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; - break; - } - - if (err == CHIP_NO_ERROR) - { - VerifyOrReturnError(strlen(activeLocalePtr) <= kMaxActiveLocaleLength, false); - - Platform::CopyString(mActiveLocaleBuf, kMaxActiveLocaleLength + 1, activeLocalePtr); - - output = CharSpan::fromCharString(mActiveLocaleBuf); - - mIndex++; - - retval = true; - } - else - { - retval = false; - } - - return retval; -} - -DeviceInfoProvider::SupportedCalendarTypesIterator * DeviceInfoProviderImpl::IterateSupportedCalendarTypes() -{ - return new SupportedCalendarTypesIteratorImpl(); -} - -size_t DeviceInfoProviderImpl::SupportedCalendarTypesIteratorImpl::Count() -{ - // TODO: Need to provide a script which can generate a binary file which contains device information and - // update the DeviceInfoProvider which can read the information from it. - // Now we use the hardcoded SupportedCalendarTypes. - // {("kBuddhist"), ("kChinese"), ("kCoptic"), ("kEthiopian"), ("kGregorian"), ("kHebrew"), ("kIndian"), ("kJapanese"), - // ("kKorean"), ("kPersian"), ("kTaiwanese"), ("kIslamic")} - - return 12; -} - -bool DeviceInfoProviderImpl::SupportedCalendarTypesIteratorImpl::Next(CalendarType & output) -{ - bool retval = true; - - // TODO: Need to provide a script which can generate a binary file which contains device information and - // update the DeviceInfoProvider which can read the information from it. - // Now we use the hardcoded SupportedCalendarTypes. - CHIP_ERROR err = CHIP_NO_ERROR; - - VerifyOrReturnError(mIndex < 12, false); - - switch (mIndex) - { - case 0: - output = app::Clusters::TimeFormatLocalization::CalendarType::kBuddhist; - break; - case 1: - output = app::Clusters::TimeFormatLocalization::CalendarType::kChinese; - break; - case 2: - output = app::Clusters::TimeFormatLocalization::CalendarType::kCoptic; - break; - case 3: - output = app::Clusters::TimeFormatLocalization::CalendarType::kEthiopian; - break; - case 4: - output = app::Clusters::TimeFormatLocalization::CalendarType::kGregorian; - break; - case 5: - output = app::Clusters::TimeFormatLocalization::CalendarType::kHebrew; - break; - case 6: - output = app::Clusters::TimeFormatLocalization::CalendarType::kIndian; - break; - case 7: - output = app::Clusters::TimeFormatLocalization::CalendarType::kJapanese; - break; - case 8: - output = app::Clusters::TimeFormatLocalization::CalendarType::kKorean; - break; - case 9: - output = app::Clusters::TimeFormatLocalization::CalendarType::kPersian; - break; - case 10: - output = app::Clusters::TimeFormatLocalization::CalendarType::kTaiwanese; - break; - case 11: - output = app::Clusters::TimeFormatLocalization::CalendarType::kIslamic; - break; - default: - err = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; - break; - } - - if (err == CHIP_NO_ERROR) - { - mIndex++; - retval = true; - } - else - { - retval = false; - } - - return retval; -} - -} // namespace DeviceLayer -} // namespace chip diff --git a/src/platform/ESP32/DeviceInfoProviderImpl.h b/src/platform/ESP32/DeviceInfoProviderImpl.h deleted file mode 100644 index 856e15498ab46f..00000000000000 --- a/src/platform/ESP32/DeviceInfoProviderImpl.h +++ /dev/null @@ -1,107 +0,0 @@ -/* - * - * Copyright (c) 2022 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. - */ -#pragma once - -#include -#include -#include - -namespace chip { -namespace DeviceLayer { - -class DeviceInfoProviderImpl : public DeviceInfoProvider -{ -public: - DeviceInfoProviderImpl() = default; - ~DeviceInfoProviderImpl() override {} - - // Iterators - FixedLabelIterator * IterateFixedLabel(EndpointId endpoint) override; - UserLabelIterator * IterateUserLabel(EndpointId endpoint) override; - SupportedLocalesIterator * IterateSupportedLocales() override; - SupportedCalendarTypesIterator * IterateSupportedCalendarTypes() override; - - static DeviceInfoProviderImpl & GetDefaultInstance(); - -protected: - class FixedLabelIteratorImpl : public FixedLabelIterator - { - public: - FixedLabelIteratorImpl(EndpointId endpoint); - size_t Count() override; - bool Next(FixedLabelType & output) override; - void Release() override { delete this; } - - private: - EndpointId mEndpoint = 0; - size_t mIndex = 0; - char mFixedLabelNameBuf[kMaxLabelNameLength + 1]; - char mFixedLabelValueBuf[kMaxLabelValueLength + 1]; - }; - - class UserLabelIteratorImpl : public UserLabelIterator - { - public: - UserLabelIteratorImpl(DeviceInfoProviderImpl & provider, EndpointId endpoint); - size_t Count() override { return mTotal; } - bool Next(UserLabelType & output) override; - void Release() override { delete this; } - - private: - DeviceInfoProviderImpl & mProvider; - EndpointId mEndpoint = 0; - size_t mIndex = 0; - size_t mTotal = 0; - char mUserLabelNameBuf[kMaxLabelNameLength + 1]; - char mUserLabelValueBuf[kMaxLabelValueLength + 1]; - }; - - class SupportedLocalesIteratorImpl : public SupportedLocalesIterator - { - public: - SupportedLocalesIteratorImpl() = default; - size_t Count() override; - bool Next(CharSpan & output) override; - void Release() override { delete this; } - - private: - size_t mIndex = 0; - char mActiveLocaleBuf[kMaxActiveLocaleLength + 1]; - }; - - class SupportedCalendarTypesIteratorImpl : public SupportedCalendarTypesIterator - { - public: - SupportedCalendarTypesIteratorImpl() = default; - size_t Count() override; - bool Next(CalendarType & output) override; - void Release() override { delete this; } - - private: - size_t mIndex = 0; - }; - - CHIP_ERROR SetUserLabelLength(EndpointId endpoint, size_t val) override; - CHIP_ERROR GetUserLabelLength(EndpointId endpoint, size_t & val) override; - CHIP_ERROR SetUserLabelAt(EndpointId endpoint, size_t index, const UserLabelType & userLabel) override; - -private: - static constexpr size_t UserLabelTLVMaxSize() { return TLV::EstimateStructOverhead(kMaxLabelNameLength, kMaxLabelValueLength); } -}; - -} // namespace DeviceLayer -} // namespace chip diff --git a/src/platform/ESP32/PlatformManagerImpl.cpp b/src/platform/ESP32/PlatformManagerImpl.cpp index 535674b8c2782a..d387814f3241f2 100644 --- a/src/platform/ESP32/PlatformManagerImpl.cpp +++ b/src/platform/ESP32/PlatformManagerImpl.cpp @@ -27,7 +27,6 @@ #include #include -#include #include #include #include @@ -61,7 +60,6 @@ static int app_entropy_source(void * data, unsigned char * output, size_t len, s CHIP_ERROR PlatformManagerImpl::_InitChipStack(void) { SetConfigurationMgr(&ConfigurationManagerImpl::GetDefaultInstance()); - SetDeviceInfoProvider(&DeviceInfoProviderImpl::GetDefaultInstance()); esp_err_t err; // Arrange for CHIP-encapsulated ESP32 errors to be translated to text