@@ -41,46 +41,58 @@ ESP32DeviceInfoProvider & ESP32DeviceInfoProvider::GetDefaultInstance(void)
41
41
42
42
DeviceInfoProvider::FixedLabelIterator * ESP32DeviceInfoProvider::IterateFixedLabel (EndpointId endpoint)
43
43
{
44
- return chip::Platform::New<FixedLabelIteratorImpl>(endpoint, mFixedLabels );
44
+ return chip::Platform::New<FixedLabelIteratorImpl>(endpoint);
45
45
}
46
46
47
- ESP32DeviceInfoProvider::FixedLabelIteratorImpl::FixedLabelIteratorImpl (EndpointId endpoint, const Span<FixedLabelEntry> & labels) :
48
- mEndpoint(endpoint), mLabels(labels)
47
+ ESP32DeviceInfoProvider::FixedLabelIteratorImpl::FixedLabelIteratorImpl (EndpointId endpoint) : mEndpoint(endpoint)
49
48
{
50
49
mIndex = 0 ;
51
50
}
52
51
53
52
size_t ESP32DeviceInfoProvider::FixedLabelIteratorImpl::Count ()
54
53
{
55
- size_t count = 0 ;
56
- for (size_t i = 0 ; i < mLabels .size (); i++)
57
- {
58
- const FixedLabelEntry & entry = mLabels .data ()[i];
54
+ char keyBuf[ESP32Config::kMaxConfigKeyNameLength ];
55
+ uint32_t count = 0 ;
59
56
60
- if (entry.endpointId == mEndpoint )
61
- {
62
- count++;
63
- }
64
- }
57
+ VerifyOrReturnValue (ESP32Config::KeyAllocator::FixedLabelCount (keyBuf, sizeof (keyBuf), mEndpoint ) == CHIP_NO_ERROR, 0 );
58
+ ESP32Config::Key key (ESP32Config::kConfigNamespace_ChipFactory , keyBuf);
59
+ VerifyOrReturnValue (ESP32Config::ReadConfigValue (key, count) == CHIP_NO_ERROR, 0 );
65
60
return count;
66
61
}
67
62
68
63
bool ESP32DeviceInfoProvider::FixedLabelIteratorImpl::Next (FixedLabelType & output)
69
64
{
70
65
ChipLogDetail (DeviceLayer, " Get the fixed label with index:%u at endpoint:%d" , static_cast <unsigned >(mIndex ), mEndpoint );
71
66
72
- while (mIndex < mLabels .size ())
73
- {
74
- const FixedLabelEntry & entry = mLabels .data ()[mIndex ++];
75
- if (entry.endpointId == mEndpoint )
76
- {
77
- output.label = entry.label ;
78
- output.value = entry.value ;
79
- return true ;
80
- }
81
- }
67
+ char keyBuf[ESP32Config::kMaxConfigKeyNameLength ];
68
+ size_t keyOutLen = 0 ;
69
+ size_t valueOutLen = 0 ;
70
+
71
+ memset (mFixedLabelNameBuf , 0 , sizeof (mFixedLabelNameBuf ));
72
+ memset (mFixedLabelValueBuf , 0 , sizeof (mFixedLabelValueBuf ));
73
+
74
+ VerifyOrReturnValue (
75
+ ESP32Config::KeyAllocator::FixedLabelKey (keyBuf, sizeof (keyBuf), mEndpoint , static_cast <uint16_t >(mIndex )) == CHIP_NO_ERROR,
76
+ false );
77
+ ESP32Config::Key keyKey (ESP32Config::kConfigNamespace_ChipFactory , keyBuf);
78
+ VerifyOrReturnValue (
79
+ ESP32Config::ReadConfigValueStr (keyKey, mFixedLabelNameBuf , sizeof (mFixedLabelNameBuf ), keyOutLen) == CHIP_NO_ERROR, false );
80
+
81
+ VerifyOrReturnValue (ESP32Config::KeyAllocator::FixedLabelValue (keyBuf, sizeof (keyBuf), mEndpoint ,
82
+ static_cast <uint16_t >(mIndex )) == CHIP_NO_ERROR,
83
+ false );
84
+ ESP32Config::Key valueKey (ESP32Config::kConfigNamespace_ChipFactory , keyBuf);
85
+ VerifyOrReturnValue (ESP32Config::ReadConfigValueStr (valueKey, mFixedLabelValueBuf , sizeof (mFixedLabelValueBuf ), valueOutLen) ==
86
+ CHIP_NO_ERROR,
87
+ false );
88
+
89
+ output.label = CharSpan::fromCharString (mFixedLabelNameBuf );
90
+ output.value = CharSpan::fromCharString (mFixedLabelValueBuf );
91
+ ChipLogDetail (DeviceLayer, " Fixed label with index:%u at endpoint:%d, %s:%s" , static_cast <unsigned >(mIndex ), mEndpoint ,
92
+ mFixedLabelNameBuf , mFixedLabelValueBuf );
82
93
83
- return false ;
94
+ mIndex ++;
95
+ return true ;
84
96
}
85
97
86
98
CHIP_ERROR ESP32DeviceInfoProvider::SetUserLabelLength (EndpointId endpoint, size_t val)
@@ -180,47 +192,82 @@ bool ESP32DeviceInfoProvider::UserLabelIteratorImpl::Next(UserLabelType & output
180
192
181
193
DeviceInfoProvider::SupportedLocalesIterator * ESP32DeviceInfoProvider::IterateSupportedLocales ()
182
194
{
183
- return chip::Platform::New<SupportedLocalesIteratorImpl>(mSupportedLocales );
184
- }
185
-
186
- ESP32DeviceInfoProvider::SupportedLocalesIteratorImpl::SupportedLocalesIteratorImpl (const Span<CharSpan> & locales)
187
- {
188
- mLocales = locales;
195
+ return chip::Platform::New<SupportedLocalesIteratorImpl>();
189
196
}
190
197
191
198
size_t ESP32DeviceInfoProvider::SupportedLocalesIteratorImpl::Count ()
192
199
{
193
- return mLocales .empty () ? 0 : mLocales .size ();
200
+ uint32_t count = 0 ;
201
+ CHIP_ERROR err = ESP32Config::ReadConfigValue (ESP32Config::kConfigKey_SupportedLocaleSize , count);
202
+ if (err != CHIP_NO_ERROR)
203
+ {
204
+ return 0 ;
205
+ }
206
+ return count;
194
207
}
195
208
196
209
bool ESP32DeviceInfoProvider::SupportedLocalesIteratorImpl::Next (CharSpan & output)
197
210
{
198
- VerifyOrReturnValue (mIndex < mLocales .size (), false );
199
- output = mLocales .data ()[mIndex ++];
211
+ char keyBuf[ESP32Config::kMaxConfigKeyNameLength ];
212
+ size_t keyOutLen = 0 ;
213
+ memset (mLocaleBuf , 0 , sizeof (mLocaleBuf ));
214
+
215
+ VerifyOrReturnValue (ESP32Config::KeyAllocator::Locale (keyBuf, sizeof (keyBuf), static_cast <uint16_t >(mIndex )) == CHIP_NO_ERROR,
216
+ false );
217
+ ESP32Config::Key keyKey (ESP32Config::kConfigNamespace_ChipFactory , keyBuf);
218
+ VerifyOrReturnValue (ESP32Config::ReadConfigValueStr (keyKey, mLocaleBuf , sizeof (mLocaleBuf ), keyOutLen) == CHIP_NO_ERROR, false );
219
+
220
+ output = CharSpan::fromCharString (mLocaleBuf );
221
+ mIndex ++;
200
222
return true ;
201
223
}
202
224
225
+ void ESP32DeviceInfoProvider::SupportedLocalesIteratorImpl::Release ()
226
+ {
227
+ chip::Platform::Delete (this );
228
+ }
229
+
203
230
DeviceInfoProvider::SupportedCalendarTypesIterator * ESP32DeviceInfoProvider::IterateSupportedCalendarTypes ()
204
231
{
205
- return chip::Platform::New<SupportedCalendarTypesIteratorImpl>(mSupportedCalendarTypes );
232
+ return chip::Platform::New<SupportedCalendarTypesIteratorImpl>();
206
233
}
207
234
208
- ESP32DeviceInfoProvider::SupportedCalendarTypesIteratorImpl::SupportedCalendarTypesIteratorImpl (
209
- const Span<CalendarType> & calendarTypes)
235
+ ESP32DeviceInfoProvider::SupportedCalendarTypesIteratorImpl::SupportedCalendarTypesIteratorImpl ()
210
236
{
211
- mCalendarTypes = calendarTypes;
237
+ CHIP_ERROR err = ESP32Config::ReadConfigValue (ESP32Config::kConfigKey_SupportedCalTypes , mSupportedCalendarTypes );
238
+ if (err != CHIP_NO_ERROR)
239
+ {
240
+ ChipLogError (DeviceLayer, " Failed to read supported calendar types: %" CHIP_ERROR_FORMAT, err.Format ());
241
+ }
212
242
}
213
243
214
244
size_t ESP32DeviceInfoProvider::SupportedCalendarTypesIteratorImpl::Count ()
215
245
{
216
- return mCalendarTypes .empty () ? 0 : mCalendarTypes .size ();
246
+ size_t count = 0 ;
247
+ for (uint8_t i = 0 ; i < to_underlying (app::Clusters::TimeFormatLocalization::CalendarTypeEnum::kUnknownEnumValue ); i++)
248
+ {
249
+ if (mSupportedCalendarTypes & (1 << i))
250
+ {
251
+ count++;
252
+ }
253
+ }
254
+ ChipLogDetail (DeviceLayer, " Supported calendar types count:%u" , count);
255
+ return count;
217
256
}
218
257
219
258
bool ESP32DeviceInfoProvider::SupportedCalendarTypesIteratorImpl::Next (CalendarType & output)
220
259
{
221
- VerifyOrReturnValue (mIndex < mCalendarTypes .size (), false );
222
- output = mCalendarTypes .data ()[mIndex ++];
223
- return true ;
260
+ while (mIndex < to_underlying (app::Clusters::TimeFormatLocalization::CalendarTypeEnum::kUnknownEnumValue ))
261
+ {
262
+ if (mSupportedCalendarTypes & (1 << mIndex ))
263
+ {
264
+ output = static_cast <CalendarType>(mIndex );
265
+ mIndex ++;
266
+ return true ;
267
+ }
268
+ mIndex ++;
269
+ }
270
+ return false ;
224
271
}
225
272
226
273
} // namespace DeviceLayer
0 commit comments