Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added PartNumber, ProductURL, ProductLabel and UniqueID for basic cluster on android tv server #12718

Merged
merged 5 commits into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 69 additions & 13 deletions src/app/clusters/basic/basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "basic.h"

#include <app-common/zap-generated/attributes/Accessors.h>
#include <cstddef>
#include <platform/CHIPDeviceLayer.h>
#include <platform/ConfigurationManager.h>

Expand All @@ -32,69 +33,82 @@ void emberAfBasicClusterServerInitCallback(chip::EndpointId endpoint)
{
EmberAfStatus status;

char nodeLabel[DeviceLayer::ConfigurationManager::kMaxNodeLabelLength + 1];
if (ConfigurationMgr().GetNodeLabel(nodeLabel, sizeof(nodeLabel)) == CHIP_NO_ERROR)
{
status = Attributes::NodeLabel::Set(endpoint, chip::CharSpan(nodeLabel, strlen(nodeLabel)));
VerifyOrdo(EMBER_ZCL_STATUS_SUCCESS == status, ChipLogError(Zcl, "Error setting Node Label: 0x%02x", status));
}

char location[DeviceLayer::ConfigurationManager::kMaxLocationLength + 1];
size_t codeLen = 0;
if (ConfigurationMgr().GetCountryCode(location, sizeof(location), codeLen) == CHIP_NO_ERROR)
{
status = Attributes::Location::Set(endpoint, chip::CharSpan(location, strlen(location)));
VerifyOrdo(EMBER_ZCL_STATUS_SUCCESS == status, ChipLogError(Zcl, "Error setting Location: 0x%02x", status));
}

char vendorName[DeviceLayer::ConfigurationManager::kMaxVendorNameLength + 1];
if (ConfigurationMgr().GetVendorName(vendorName, sizeof(vendorName)) == CHIP_NO_ERROR)
{
status = Attributes::VendorName::Set(endpoint, chip::CharSpan(vendorName, strlen(vendorName)));
VerifyOrReturn(EMBER_ZCL_STATUS_SUCCESS == status, ChipLogError(Zcl, "Error setting Vendor Name: 0x%02x", status));
VerifyOrdo(EMBER_ZCL_STATUS_SUCCESS == status, ChipLogError(Zcl, "Error setting Vendor Name: 0x%02x", status));
}

uint16_t vendorId;
if (ConfigurationMgr().GetVendorId(vendorId) == CHIP_NO_ERROR)
{
status = Attributes::VendorID::Set(endpoint, vendorId);
VerifyOrReturn(EMBER_ZCL_STATUS_SUCCESS == status, ChipLogError(Zcl, "Error setting Vendor Id: 0x%02x", status));
VerifyOrdo(EMBER_ZCL_STATUS_SUCCESS == status, ChipLogError(Zcl, "Error setting Vendor Id: 0x%02x", status));
}

char productName[DeviceLayer::ConfigurationManager::kMaxProductNameLength + 1];
if (ConfigurationMgr().GetProductName(productName, sizeof(productName)) == CHIP_NO_ERROR)
{
status = Attributes::ProductName::Set(endpoint, chip::CharSpan(productName, strlen(productName)));
VerifyOrReturn(EMBER_ZCL_STATUS_SUCCESS == status, ChipLogError(Zcl, "Error setting Product Name: 0x%02x", status));
VerifyOrdo(EMBER_ZCL_STATUS_SUCCESS == status, ChipLogError(Zcl, "Error setting Product Name: 0x%02x", status));
}

uint16_t productId;
if (ConfigurationMgr().GetProductId(productId) == CHIP_NO_ERROR)
{
status = Attributes::ProductID::Set(endpoint, productId);
VerifyOrReturn(EMBER_ZCL_STATUS_SUCCESS == status, ChipLogError(Zcl, "Error setting Product Id: 0x%02x", status));
VerifyOrdo(EMBER_ZCL_STATUS_SUCCESS == status, ChipLogError(Zcl, "Error setting Product Id: 0x%02x", status));
}

char hardwareVersionString[DeviceLayer::ConfigurationManager::kMaxHardwareVersionStringLength + 1];
if (ConfigurationMgr().GetHardwareVersionString(hardwareVersionString, sizeof(hardwareVersionString)) == CHIP_NO_ERROR)
{
status = Attributes::HardwareVersionString::Set(endpoint, CharSpan(hardwareVersionString, strlen(hardwareVersionString)));
VerifyOrReturn(EMBER_ZCL_STATUS_SUCCESS == status,
ChipLogError(Zcl, "Error setting Hardware Version String: 0x%02x", status));
VerifyOrdo(EMBER_ZCL_STATUS_SUCCESS == status, ChipLogError(Zcl, "Error setting Hardware Version String: 0x%02x", status));
}

uint16_t hardwareVersion;
if (ConfigurationMgr().GetHardwareVersion(hardwareVersion) == CHIP_NO_ERROR)
{
status = Attributes::HardwareVersion::Set(endpoint, hardwareVersion);
VerifyOrReturn(EMBER_ZCL_STATUS_SUCCESS == status, ChipLogError(Zcl, "Error setting Hardware Version: 0x%02x", status));
VerifyOrdo(EMBER_ZCL_STATUS_SUCCESS == status, ChipLogError(Zcl, "Error setting Hardware Version: 0x%02x", status));
}

char softwareVersionString[DeviceLayer::ConfigurationManager::kMaxSoftwareVersionLength + 1];
if (ConfigurationMgr().GetSoftwareVersionString(softwareVersionString, sizeof(softwareVersionString)) == CHIP_NO_ERROR)
{
status = Attributes::SoftwareVersionString::Set(endpoint, CharSpan(softwareVersionString, strlen(softwareVersionString)));
VerifyOrReturn(EMBER_ZCL_STATUS_SUCCESS == status,
ChipLogError(Zcl, "Error setting Software Version String: 0x%02x", status));
VerifyOrdo(EMBER_ZCL_STATUS_SUCCESS == status, ChipLogError(Zcl, "Error setting Software Version String: 0x%02x", status));
}

uint16_t softwareVersion;
if (ConfigurationMgr().GetSoftwareVersion(softwareVersion) == CHIP_NO_ERROR)
{
status = Attributes::SoftwareVersion::Set(endpoint, softwareVersion);
VerifyOrReturn(EMBER_ZCL_STATUS_SUCCESS == status, ChipLogError(Zcl, "Error setting Software Version: 0x%02x", status));
VerifyOrdo(EMBER_ZCL_STATUS_SUCCESS == status, ChipLogError(Zcl, "Error setting Software Version: 0x%02x", status));
}

char serialNumberString[DeviceLayer::ConfigurationManager::kMaxSerialNumberLength + 1];
if (ConfigurationMgr().GetSerialNumber(serialNumberString, sizeof(serialNumberString)) == CHIP_NO_ERROR)
{
status = Attributes::SerialNumber::Set(endpoint, CharSpan(serialNumberString, strlen(serialNumberString)));
VerifyOrReturn(EMBER_ZCL_STATUS_SUCCESS == status, ChipLogError(Zcl, "Error setting Serial Number String: 0x%02x", status));
VerifyOrdo(EMBER_ZCL_STATUS_SUCCESS == status, ChipLogError(Zcl, "Error setting Serial Number String: 0x%02x", status));
}

char manufacturingDateString[DeviceLayer::ConfigurationManager::kMaxManufacturingDateLength + 1];
Expand All @@ -106,8 +120,50 @@ void emberAfBasicClusterServerInitCallback(chip::EndpointId endpoint)
snprintf(manufacturingDateString, sizeof(manufacturingDateString), "%04" PRIu16 "-%02" PRIu16 "-%02" PRIu16,
manufacturingYear, manufacturingMonth, manufacturingDayOfMonth);
status = Attributes::ManufacturingDate::Set(endpoint, CharSpan(manufacturingDateString, strlen(manufacturingDateString)));
VerifyOrReturn(EMBER_ZCL_STATUS_SUCCESS == status,
ChipLogError(Zcl, "Error setting Manufacturing Date String: 0x%02x", status));
VerifyOrdo(EMBER_ZCL_STATUS_SUCCESS == status,
ChipLogError(Zcl, "Error setting Manufacturing Date String: 0x%02x", status));
}

char partNumber[DeviceLayer::ConfigurationManager::kMaxPartNumberLength + 1];
if (ConfigurationMgr().GetPartNumber(partNumber, sizeof(partNumber)) == CHIP_NO_ERROR)
{
status = Attributes::PartNumber::Set(endpoint, CharSpan(partNumber, strlen(partNumber)));
VerifyOrdo(EMBER_ZCL_STATUS_SUCCESS == status, ChipLogError(Zcl, "Error setting Part Number: 0x%02x", status));
}

char productURL[DeviceLayer::ConfigurationManager::kMaxProductURLLength + 1];
if (ConfigurationMgr().GetProductURL(productURL, sizeof(productURL)) == CHIP_NO_ERROR)
{
status = Attributes::ProductURL::Set(endpoint, CharSpan(productURL, strlen(productURL)));
VerifyOrdo(EMBER_ZCL_STATUS_SUCCESS == status, ChipLogError(Zcl, "Error setting Product URL: 0x%02x", status));
}

char productLabel[DeviceLayer::ConfigurationManager::kMaxProductURLLength + 1];
if (ConfigurationMgr().GetProductLabel(productLabel, sizeof(productLabel)) == CHIP_NO_ERROR)
{
status = Attributes::ProductLabel::Set(endpoint, CharSpan(productLabel, strlen(productLabel)));
VerifyOrdo(EMBER_ZCL_STATUS_SUCCESS == status, ChipLogError(Zcl, "Error setting Product Label: 0x%02x", status));
}

bool localConfigDisabled;
if (ConfigurationMgr().GetLocalConfigDisabled(localConfigDisabled) == CHIP_NO_ERROR)
{
status = Attributes::LocalConfigDisabled::Set(endpoint, localConfigDisabled);
VerifyOrdo(EMBER_ZCL_STATUS_SUCCESS == status, ChipLogError(Zcl, "Error setting Local Config Disabled: 0x%02x", status));
}

bool reachable;
if (ConfigurationMgr().GetReachable(reachable) == CHIP_NO_ERROR)
{
status = Attributes::Reachable::Set(endpoint, reachable);
VerifyOrdo(EMBER_ZCL_STATUS_SUCCESS == status, ChipLogError(Zcl, "Error setting Reachable: 0x%02x", status));
}

char uniqueId[DeviceLayer::ConfigurationManager::kMaxUniqueIDLength + 1];
if (ConfigurationMgr().GetUniqueId(uniqueId, sizeof(uniqueId)) == CHIP_NO_ERROR)
{
status = Attributes::UniqueID::Set(endpoint, CharSpan(uniqueId, strlen(uniqueId)));
VerifyOrdo(EMBER_ZCL_STATUS_SUCCESS == status, ChipLogError(Zcl, "Error setting Unique Id: 0x%02x", status));
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/include/platform/ConfigurationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ class ConfigurationManager
virtual CHIP_ERROR StoreTotalOperationalHours(uint32_t totalOperationalHours) = 0;
virtual CHIP_ERROR GetBootReason(uint32_t & bootReason) = 0;
virtual CHIP_ERROR StoreBootReason(uint32_t bootReason) = 0;
virtual CHIP_ERROR GetNodeLabel(char * buf, size_t bufSize) = 0;
virtual CHIP_ERROR StoreNodeLabel(const char * buf, size_t bufSize) = 0;
virtual CHIP_ERROR GetPartNumber(char * buf, size_t bufSize) = 0;
virtual CHIP_ERROR GetProductURL(char * buf, size_t bufSize) = 0;
virtual CHIP_ERROR GetProductLabel(char * buf, size_t bufSize) = 0;
virtual CHIP_ERROR GetLocalConfigDisabled(bool & disabled) = 0;
virtual CHIP_ERROR GetReachable(bool & reachable) = 0;
virtual CHIP_ERROR GetUniqueId(char * buf, size_t bufSize) = 0;

virtual CHIP_ERROR GetBLEDeviceIdentificationInfo(Ble::ChipBLEDeviceIdentificationInfo & deviceIdInfo) = 0;

Expand Down
48 changes: 48 additions & 0 deletions src/include/platform/internal/GenericConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,54 @@ CHIP_ERROR GenericConfigurationManagerImpl<ImplClass>::StoreBootReason(uint32_t
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}

template <class ConfigClass>
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetNodeLabel(char * buf, size_t bufSize)
{
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}

template <class ConfigClass>
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::StoreNodeLabel(const char * buf, size_t bufSize)
{
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}

template <class ConfigClass>
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetPartNumber(char * buf, size_t bufSize)
{
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}

template <class ConfigClass>
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetProductURL(char * buf, size_t bufSize)
{
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}

template <class ConfigClass>
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetProductLabel(char * buf, size_t bufSize)
{
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}

template <class ConfigClass>
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetLocalConfigDisabled(bool & disabled)
{
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}

template <class ConfigClass>
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetReachable(bool & reachable)
{
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}

template <class ConfigClass>
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetUniqueId(char * buf, size_t bufSize)
{
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
}

template <class ConfigClass>
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetLifetimeCounter(uint16_t & lifetimeCounter)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ class GenericConfigurationManagerImpl : public ConfigurationManager
CHIP_ERROR StoreTotalOperationalHours(uint32_t totalOperationalHours) override;
CHIP_ERROR GetBootReason(uint32_t & bootReason) override;
CHIP_ERROR StoreBootReason(uint32_t bootReason) override;
CHIP_ERROR GetNodeLabel(char * buf, size_t bufSize) override;
CHIP_ERROR StoreNodeLabel(const char * buf, size_t bufSize) override;
CHIP_ERROR GetPartNumber(char * buf, size_t bufSize) override;
CHIP_ERROR GetProductURL(char * buf, size_t bufSize) override;
CHIP_ERROR GetProductLabel(char * buf, size_t bufSize) override;
CHIP_ERROR GetLocalConfigDisabled(bool & disabled) override;
CHIP_ERROR GetReachable(bool & reachable) override;
CHIP_ERROR GetUniqueId(char * buf, size_t bufSize) override;
CHIP_ERROR RunUnitTests(void) override;
bool IsFullyProvisioned() override;
void InitiateFactoryReset() override;
Expand Down
23 changes: 23 additions & 0 deletions src/lib/support/CodeUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,29 @@ inline void chipDie(void)
} \
} while (false)

/**
* @def VerifyOrdo(expr, ...)
*
* @brief
* do something if expression evaluates to false
*
* Example usage:
*
* @code
* VerifyOrdo(param != nullptr, LogError("param is nullptr"));
* @endcode
*
* @param[in] expr A Boolean expression to be evaluated.
*/
#define VerifyOrdo(expr, ...) \
do \
{ \
if (!(expr)) \
{ \
__VA_ARGS__; \
} \
} while (false)

#if (__cplusplus >= 201103L)

#ifndef __FINAL
Expand Down
7 changes: 7 additions & 0 deletions src/platform/android/AndroidConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ const AndroidConfig::Key AndroidConfig::kConfigKey_ProductId = { kCo
const AndroidConfig::Key AndroidConfig::kConfigKey_ProductName = { kConfigNamespace_ChipFactory, "product-name" };
const AndroidConfig::Key AndroidConfig::kConfigKey_SoftwareVersion = { kConfigNamespace_ChipFactory, "software-version" };
const AndroidConfig::Key AndroidConfig::kConfigKey_SoftwareVersionString = { kConfigNamespace_ChipFactory, "software-version-str" };
const AndroidConfig::Key AndroidConfig::kConfigKey_NodeLabel = { kConfigNamespace_ChipFactory, "node-label" };
const AndroidConfig::Key AndroidConfig::kConfigKey_PartNumber = { kConfigNamespace_ChipFactory, "part-number" };
const AndroidConfig::Key AndroidConfig::kConfigKey_ProductURL = { kConfigNamespace_ChipFactory, "product-url" };
const AndroidConfig::Key AndroidConfig::kConfigKey_ProductLabel = { kConfigNamespace_ChipFactory, "product-label" };
const AndroidConfig::Key AndroidConfig::kConfigKey_LocalConfigDisabled = { kConfigNamespace_ChipFactory, "local-config-disabled" };
const AndroidConfig::Key AndroidConfig::kConfigKey_Reachable = { kConfigNamespace_ChipFactory, "reachable" };
const AndroidConfig::Key AndroidConfig::kConfigKey_UniqueId = { kConfigNamespace_ChipFactory, "uniqueId" };

// Keys stored in the Chip-config namespace
const AndroidConfig::Key AndroidConfig::kConfigKey_FabricId = { kConfigNamespace_ChipConfig, "fabric-id" };
Expand Down
7 changes: 7 additions & 0 deletions src/platform/android/AndroidConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ class AndroidConfig
static const Key kConfigKey_ProductName;
static const Key kConfigKey_SoftwareVersion;
static const Key kConfigKey_SoftwareVersionString;
static const Key kConfigKey_NodeLabel;
static const Key kConfigKey_PartNumber;
static const Key kConfigKey_ProductURL;
static const Key kConfigKey_ProductLabel;
static const Key kConfigKey_LocalConfigDisabled;
static const Key kConfigKey_Reachable;
static const Key kConfigKey_UniqueId;

static const char kGroupKeyNamePrefix[];

Expand Down
45 changes: 45 additions & 0 deletions src/platform/android/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,5 +242,50 @@ CHIP_ERROR ConfigurationManagerImpl::GetHardwareVersionString(char * buf, size_t
return CHIP_NO_ERROR;
}

CHIP_ERROR ConfigurationManagerImpl::GetNodeLabel(char * buf, size_t bufSize)
{
size_t dateLen;
return ReadConfigValueStr(AndroidConfig::kConfigKey_NodeLabel, buf, bufSize, dateLen);
}

CHIP_ERROR ConfigurationManagerImpl::StoreNodeLabel(const char * buf, size_t bufSize)
{
return WriteConfigValueStr(AndroidConfig::kConfigKey_NodeLabel, buf, bufSize);
}

CHIP_ERROR ConfigurationManagerImpl::GetPartNumber(char * buf, size_t bufSize)
{
size_t dateLen;
return ReadConfigValueStr(AndroidConfig::kConfigKey_PartNumber, buf, bufSize, dateLen);
}

CHIP_ERROR ConfigurationManagerImpl::GetProductURL(char * buf, size_t bufSize)
{
size_t dateLen;
return ReadConfigValueStr(AndroidConfig::kConfigKey_ProductURL, buf, bufSize, dateLen);
}

CHIP_ERROR ConfigurationManagerImpl::GetProductLabel(char * buf, size_t bufSize)
{
size_t dateLen;
return ReadConfigValueStr(AndroidConfig::kConfigKey_ProductLabel, buf, bufSize, dateLen);
}

CHIP_ERROR ConfigurationManagerImpl::GetLocalConfigDisabled(bool & disabled)
{
return ReadConfigValue(AndroidConfig::kConfigKey_LocalConfigDisabled, disabled);
}

CHIP_ERROR ConfigurationManagerImpl::GetReachable(bool & reachable)
{
return ReadConfigValue(AndroidConfig::kConfigKey_Reachable, reachable);
}

CHIP_ERROR ConfigurationManagerImpl::GetUniqueId(char * buf, size_t bufSize)
{
size_t dateLen;
return ReadConfigValueStr(AndroidConfig::kConfigKey_UniqueId, buf, bufSize, dateLen);
}

} // namespace DeviceLayer
} // namespace chip
8 changes: 8 additions & 0 deletions src/platform/android/ConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp
CHIP_ERROR GetHardwareVersionString(char * buf, size_t bufSize) override;
CHIP_ERROR GetSoftwareVersionString(char * buf, size_t bufSize) override;
CHIP_ERROR GetSoftwareVersion(uint16_t & softwareVer) override;
CHIP_ERROR GetNodeLabel(char * buf, size_t bufSize) override;
CHIP_ERROR StoreNodeLabel(const char * buf, size_t bufSize) override;
CHIP_ERROR GetPartNumber(char * buf, size_t bufSize) override;
CHIP_ERROR GetProductURL(char * buf, size_t bufSize) override;
CHIP_ERROR GetProductLabel(char * buf, size_t bufSize) override;
CHIP_ERROR GetLocalConfigDisabled(bool & disabled) override;
CHIP_ERROR GetReachable(bool & reachable) override;
CHIP_ERROR GetUniqueId(char * buf, size_t bufSize) override;

private:
// ===== Members that implement the ConfigurationManager public interface.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ public interface ConfigurationManager {
String kConfigKey_ProductName = "product-name";
String kConfigKey_SoftwareVersion = "software-version";
String kConfigKey_SoftwareVersionString = "software-version-str";
String kConfigKey_NodeLabel = "node-label";
String kConfigKey_PartNumber = "part-number";
String kConfigKey_ProductURL = "product-url";
String kConfigKey_ProductLabel = "product-label";
String kConfigKey_LocalConfigDisabled = "local-config-disabled";
String kConfigKey_Reachable = "reachable";
String kConfigKey_UniqueId = "uniqueId";

// Keys stored in the Chip-config namespace
String kConfigKey_FabricId = "fabric-id";
Expand Down
Loading