-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ESP32] Fix few attributes with fixed quality in DeviceInfoProvider (#…
…32893) (#33138) * [ESP32] Fix few attributes with fixed quality in DeviceInfoProvider Fixed labels, supported locales, supported calendar types were being read from the nvs(flash) and during OTA its a hassle if one wants to upgrade these values. Added few APIs to set the data for these attributes in ESP32DeviceInfoProvider. * Restyled by clang-format * Restyled by prettier-markdown * fix the lint errors * Add back the original Device info provider which reads from the nvs Add StaticESP32DeviceInfoProvider along with APIs to set data Remove changes from example and add a guide along with usage --------- Co-authored-by: Restyled.io <[email protected]>
- Loading branch information
1 parent
29ed2f9
commit 5b0afc7
Showing
7 changed files
with
345 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
## Providers Implemented for ESP32 Platform | ||
|
||
The ESP32 platform has implemented several providers that can be used with data | ||
stored in the factory or by setting fixed data. | ||
|
||
Below are the providers that have been implemented: | ||
|
||
- [Commissionable Data Provider](https://github.com/project-chip/connectedhomeip/blob/master/src/platform/ESP32/ESP32FactoryDataProvider.h#L47) | ||
This provider reads the discriminator and setup pincode related parameters | ||
from the factory partition. | ||
- [Device Attestation Credentials Provider](https://github.com/project-chip/connectedhomeip/blob/master/src/platform/ESP32/ESP32FactoryDataProvider.h#L56) | ||
This provider manages the attestation data. | ||
- [Device Instance Info Provider](https://github.com/project-chip/connectedhomeip/blob/master/src/platform/ESP32/ESP32FactoryDataProvider.h#L86) | ||
This provider reads basic device information from the factory partition. | ||
- [Device Info Provider](https://github.com/project-chip/connectedhomeip/blob/master/src/platform/ESP32/ESP32DeviceInfoProvider.h#L31) | ||
This provider provides fixed labels, supported calendar types, and supported | ||
locales from the factory partition. | ||
- [Supported Modes](https://github.com/project-chip/connectedhomeip/blob/master/examples/platform/esp32/mode-support/static-supported-modes-manager.h#L28) | ||
This provider offers the supported modes for the mode-select cluster. | ||
|
||
More information can be found in the [factory data guide](factory_data.md). | ||
|
||
### Device Info Provider | ||
|
||
Currently, there are two implementations for this provider: | ||
|
||
1. [Reads data stored in the factory partition](https://github.com/project-chip/connectedhomeip/blob/master/src/platform/ESP32/ESP32FactoryDataProvider.h#L56) | ||
_(This will be deprecated in the future)_ | ||
2. [Provides APIs to set fixed data that gets read later](https://github.com/project-chip/connectedhomeip/blob/master/src/platform/ESP32/StaticESP32DeviceInfoProvider.h) | ||
|
||
- New products should use the `StaticESP32DeviceInfoProvider`. Utilize the | ||
`Set...()` APIs to set the fixed data. | ||
- Existing products using the first implementation can continue to use it if | ||
they do not wish to change the data. | ||
- For products using the first implementation and wanting to change the fixed | ||
data via OTA, they should switch to the second implementation in the OTA | ||
image and use the `Set...()` APIs to set the fixed data. | ||
|
||
#### Example: | ||
|
||
```cpp | ||
#include <platform/ESP32/StaticESP32FactoryDataProvider.h> | ||
|
||
DeviceLayer::StaticESP32DeviceInfoProvider deviceInfoProvider; | ||
|
||
// Define array for Supported Calendar Types | ||
using namespace chip::app::Clusters::TimeFormatLocalization::CalendarTypeEnum; | ||
CalendarTypeEnum supportedCalendarTypes[] = { | ||
CalendarTypeEnum::kGregorian, CalendarTypeEnum::kCoptic, | ||
CalendarTypeEnum::kEthiopian, CalendarTypeEnum::kChinese, | ||
}; | ||
|
||
// Define array for Supported Locales | ||
const char* supportedLocales[] = { | ||
"en-US", | ||
"en-EU", | ||
}; | ||
|
||
// Define array for Fixed labels { EndpointId, Label, Value } | ||
struct StaticESP32DeviceInfoProvider::FixedLabelEntry fixedLabels[] = { | ||
{ 0, "Room", "Bedroom 2" }, | ||
{ 0, "Orientation", "North" }, | ||
{ 0, "Direction", "Up" }, | ||
}; | ||
|
||
Span<CalendarTypeEnum> sSupportedCalendarTypes(supportedCalendarTypes); | ||
Span<const char*> sSupportedLocales(supportedLocales); | ||
Span<StaticESP32DeviceInfoProvider::FixedLabelEntry> sFixedLabels(fixedLabels); | ||
|
||
{ | ||
deviceInfoProvider.SetSupportedLocales(sSupportedLocales); | ||
deviceInfoProvider.SetSupportedCalendarTypes(sSupportedCalendarTypes); | ||
deviceInfoProvider.SetFixedLabels(sFixedLabels); | ||
DeviceLayer::SetDeviceInfoProvider(&deviceInfoProvider); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* 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. | ||
*/ | ||
#include <lib/support/CodeUtils.h> | ||
#include <platform/ESP32/StaticESP32DeviceInfoProvider.h> | ||
|
||
namespace chip { | ||
namespace DeviceLayer { | ||
|
||
StaticESP32DeviceInfoProvider & StaticESP32DeviceInfoProvider::GetDefaultInstance(void) | ||
{ | ||
static StaticESP32DeviceInfoProvider sInstance; | ||
return sInstance; | ||
} | ||
|
||
DeviceInfoProvider::FixedLabelIterator * StaticESP32DeviceInfoProvider::IterateFixedLabel(EndpointId endpoint) | ||
{ | ||
return chip::Platform::New<StaticFixedLabelIteratorImpl>(endpoint, mFixedLabels); | ||
} | ||
|
||
StaticESP32DeviceInfoProvider::StaticFixedLabelIteratorImpl::StaticFixedLabelIteratorImpl(EndpointId endpoint, | ||
const Span<FixedLabelEntry> & labels) | ||
{ | ||
mEndpoint = endpoint; | ||
mLabels = labels; | ||
mIndex = 0; | ||
} | ||
|
||
size_t StaticESP32DeviceInfoProvider::StaticFixedLabelIteratorImpl::Count() | ||
{ | ||
size_t count = 0; | ||
for (size_t i = 0; i < mLabels.size(); i++) | ||
{ | ||
const FixedLabelEntry & entry = mLabels.data()[i]; | ||
|
||
if (entry.endpointId == mEndpoint) | ||
{ | ||
count++; | ||
} | ||
} | ||
return count; | ||
} | ||
|
||
bool StaticESP32DeviceInfoProvider::StaticFixedLabelIteratorImpl::Next(FixedLabelType & output) | ||
{ | ||
ChipLogDetail(DeviceLayer, "Get the fixed label with index:%u at endpoint:%d", static_cast<unsigned>(mIndex), mEndpoint); | ||
|
||
while (mIndex < mLabels.size()) | ||
{ | ||
const FixedLabelEntry & entry = mLabels.data()[mIndex++]; | ||
if (entry.endpointId == mEndpoint) | ||
{ | ||
output.label = entry.label; | ||
output.value = entry.value; | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
DeviceInfoProvider::SupportedLocalesIterator * StaticESP32DeviceInfoProvider::IterateSupportedLocales() | ||
{ | ||
return chip::Platform::New<StaticSupportedLocalesIteratorImpl>(mSupportedLocales); | ||
} | ||
|
||
StaticESP32DeviceInfoProvider::StaticSupportedLocalesIteratorImpl::StaticSupportedLocalesIteratorImpl( | ||
const Span<CharSpan> & locales) | ||
{ | ||
mLocales = locales; | ||
} | ||
|
||
size_t StaticESP32DeviceInfoProvider::StaticSupportedLocalesIteratorImpl::Count() | ||
{ | ||
return mLocales.empty() ? 0 : mLocales.size(); | ||
} | ||
|
||
bool StaticESP32DeviceInfoProvider::StaticSupportedLocalesIteratorImpl::Next(CharSpan & output) | ||
{ | ||
VerifyOrReturnValue(mIndex < mLocales.size(), false); | ||
output = mLocales.data()[mIndex++]; | ||
return true; | ||
} | ||
|
||
DeviceInfoProvider::SupportedCalendarTypesIterator * StaticESP32DeviceInfoProvider::IterateSupportedCalendarTypes() | ||
{ | ||
return chip::Platform::New<StaticSupportedCalendarTypesIteratorImpl>(mSupportedCalendarTypes); | ||
} | ||
|
||
StaticESP32DeviceInfoProvider::StaticSupportedCalendarTypesIteratorImpl::StaticSupportedCalendarTypesIteratorImpl( | ||
const Span<CalendarType> & calendarTypes) | ||
{ | ||
mCalendarTypes = calendarTypes; | ||
} | ||
|
||
size_t StaticESP32DeviceInfoProvider::StaticSupportedCalendarTypesIteratorImpl::Count() | ||
{ | ||
return mCalendarTypes.empty() ? 0 : mCalendarTypes.size(); | ||
} | ||
|
||
bool StaticESP32DeviceInfoProvider::StaticSupportedCalendarTypesIteratorImpl::Next(CalendarType & output) | ||
{ | ||
VerifyOrReturnValue(mIndex < mCalendarTypes.size(), false); | ||
output = mCalendarTypes.data()[mIndex++]; | ||
return true; | ||
} | ||
|
||
} // namespace DeviceLayer | ||
} // namespace chip |
Oops, something went wrong.