Skip to content

Commit

Permalink
add commissionable device type config
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerry-ESP committed Sep 2, 2024
1 parent 7085588 commit 1487b12
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
9 changes: 9 additions & 0 deletions scripts/tools/generate_esp32_chip_factory_bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ class Product_Color_Enum(Enum):
'encoding': 'string',
'value': None,
},
'device-type': {
'type': 'data',
'encoding': 'u32',
'value': None,
},
}


Expand Down Expand Up @@ -372,6 +377,8 @@ def populate_factory_data(args, spake2p_params):
FACTORY_DATA['product-url']['value'] = args.product_url
if args.product_label:
FACTORY_DATA['product-label']['value'] = args.product_label
if args.device_type is not None:
FACTORY_DATA['device-type']['value'] = args.device_type

# SupportedModes are stored as multiple entries
# - sm-sz/<ep> : number of supported modes for the endpoint
Expand Down Expand Up @@ -554,6 +561,8 @@ def any_base_int(s): return int(s, 0)
parser.add_argument("--product-label", type=str, help='human readable product label')
parser.add_argument("--product-url", type=str, help='link to product specific web page')

parser.add_argument("--device-type", type=any_base_int, help='commissionable device type')

parser.add_argument('-s', '--size', type=any_base_int, default=0x6000,
help='The size of the partition.bin, default: 0x6000')
parser.add_argument('--target', default='esp32',
Expand Down
22 changes: 22 additions & 0 deletions src/platform/ESP32/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,28 @@ CHIP_ERROR ConfigurationManagerImpl::GetLocationCapability(uint8_t & location)
#endif // CONFIG_ENABLE_ESP32_LOCATIONCAPABILITY
}

CHIP_ERROR ConfigurationManagerImpl::GetDeviceTypeId(uint32_t & deviceType)
{
#if CHIP_DEVICE_CONFIG_ENABLE_COMMISSIONABLE_DEVICE_TYPE
uint32_t value = 0;
CHIP_ERROR err = ReadConfigValue(ESP32Config::kConfigKey_PrimaryDeviceType, value);

if (err == CHIP_NO_ERROR)
{
deviceType = value;
}
else
{
deviceType = CHIP_DEVICE_CONFIG_DEVICE_TYPE;
}

return err;
#else
deviceType = 0;
return CHIP_NO_ERROR;
#endif // CONFIG_ENABLE_ESP32_LOCATIONCAPABILITY
}

CHIP_ERROR ConfigurationManagerImpl::StoreCountryCode(const char * code, size_t codeLen)
{
// As per spec, codeLen has to be 2
Expand Down
1 change: 1 addition & 0 deletions src/platform/ESP32/ConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp
CHIP_ERROR GetSoftwareVersionString(char * buf, size_t bufSize);
CHIP_ERROR GetSoftwareVersion(uint32_t & softwareVer) override;
CHIP_ERROR GetLocationCapability(uint8_t & location) override;
CHIP_ERROR GetDeviceTypeId(uint32_t & deviceType) override;
static ConfigurationManagerImpl & GetDefaultInstance();

// Set the country code to esp_phy layer and also store it to NVS
Expand Down
1 change: 1 addition & 0 deletions src/platform/ESP32/ESP32Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const ESP32Config::Key ESP32Config::kConfigKey_ProductFinish = { kConfig
const ESP32Config::Key ESP32Config::kConfigKey_ProductColor = { kConfigNamespace_ChipFactory, "product-color" };
const ESP32Config::Key ESP32Config::kConfigKey_PartNumber = { kConfigNamespace_ChipFactory, "part-number" };
const ESP32Config::Key ESP32Config::kConfigKey_LocationCapability = { kConfigNamespace_ChipFactory, "loc-capability" };
const ESP32Config::Key ESP32Config::kConfigKey_PrimaryDeviceType = { kConfigNamespace_ChipFactory, "device-type" };

// Keys stored in the chip-config namespace
const ESP32Config::Key ESP32Config::kConfigKey_ServiceConfig = { kConfigNamespace_ChipConfig, "service-config" };
Expand Down
1 change: 1 addition & 0 deletions src/platform/ESP32/ESP32Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class ESP32Config
static const Key kConfigKey_ProductFinish;
static const Key kConfigKey_ProductColor;
static const Key kConfigKey_LocationCapability;
static const Key kConfigKey_PrimaryDeviceType;

// CHIP Config keys
static const Key kConfigKey_ServiceConfig;
Expand Down

0 comments on commit 1487b12

Please sign in to comment.