@@ -587,43 +587,45 @@ CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::SetFailSafeArmed(bool v
587
587
}
588
588
589
589
template <class ConfigClass >
590
- CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetDeviceLocation(DeviceLocatioType & location)
590
+ CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetDeviceLocation(MutableDeviceLocation & location)
591
591
{
592
- uint8_t locationData[kMaxDeviceLocationNameLength + sizeof (DeviceLocatioType)];
592
+ uint8_t locationData[app::Clusters::BasicInformation:: kMaxDeviceLocationNameLength + sizeof (DeviceLocatioType)];
593
593
MutableByteSpan locationSpan (locationData);
594
594
595
595
size_t outLen = 0 ;
596
- ReturnErrorOnFailure (
597
- ReadConfigValueBin (ConfigClass::kConfigKey_DeviceLocation , locationSpan.data (), locationSpan.size (), outLen));
596
+ auto err = ReadConfigValueBin (ConfigClass::kConfigKey_DeviceLocation , locationSpan.data (), locationSpan.size (), outLen);
597
+ if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND)
598
+ {
599
+ location.SetNull ();
600
+ return CHIP_NO_ERROR;
601
+ }
602
+ ReturnErrorOnFailure (err);
598
603
599
604
TLV::TLVReader tlvReader;
600
605
tlvReader.Init (locationSpan);
601
606
602
- char locationNameBuffer[DeviceLayer::ConfigurationManager:: kMaxDeviceLocationNameLength ] = { 0 };
607
+ char locationNameBuffer[1 ] = { 0 };
603
608
DeviceLocatioType loc ({
604
- .locationName = MutableCharSpan (locationNameBuffer),
609
+ .locationName = CharSpan (locationNameBuffer, 0 ),
605
610
});
606
611
607
612
ReturnErrorOnFailure (tlvReader.Next (TLV::AnonymousTag ()));
608
613
ReturnErrorOnFailure (loc->Decode (tlvReader));
609
614
610
- if (loc.IsNull ())
615
+ // This would not be needed if the Decode methed proprly decodes a null value.
616
+ if (loc.Value ().locationName .empty () && loc.Value ().floorNumber .IsNull () && loc.Value ().areaType .IsNull ())
611
617
{
612
- location.SetNull ();
613
- return CHIP_NO_ERROR;
618
+ loc.SetNull ();
614
619
}
615
620
616
- memcpy ((void *) location.Value ().locationName .data (), loc.Value ().locationName .data (), loc.Value ().locationName .size ());
617
- location.Value ().locationName .reduce_size (loc.Value ().locationName .size ());
618
- location.Value ().floorNumber = loc.Value ().floorNumber ;
619
- location.Value ().areaType = loc.Value ().areaType ;
621
+ location = loc;
620
622
621
623
return CHIP_NO_ERROR;
622
624
}
623
625
template <class ConfigClass >
624
626
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::SetDeviceLocation(DeviceLocatioType location)
625
627
{
626
- uint8_t locationData[kMaxDeviceLocationNameLength + sizeof (DeviceLocatioType)];
628
+ uint8_t locationData[app::Clusters::BasicInformation:: kMaxDeviceLocationNameLength + sizeof (DeviceLocatioType)];
627
629
MutableByteSpan locationSpan (locationData);
628
630
629
631
TLV::TLVWriter tlvWriter;
0 commit comments