Skip to content

Commit

Permalink
[ESP32] Changes to support product-appearance attribute in ESP32. (#3…
Browse files Browse the repository at this point in the history
…4363)

* Changes to support product-appearance attribute on ESP32.

- Added the support for product-appearance attribute of BasicInformationCluster in factory script.
- Added DeviceInstanceInfoProvider implementation for the attribute.

* Addressed review comments

* Changes to support few more missing attributes
  • Loading branch information
shripad621git authored Jul 24, 2024
1 parent 8ebace8 commit 6768739
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 2 deletions.
85 changes: 84 additions & 1 deletion scripts/tools/generate_esp32_chip_factory_bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import logging
import os
import sys
from enum import Enum
from types import SimpleNamespace

import cryptography.x509
Expand All @@ -45,6 +46,40 @@
INVALID_PASSCODES = [00000000, 11111111, 22222222, 33333333, 44444444, 55555555,
66666666, 77777777, 88888888, 99999999, 12345678, 87654321]


class Product_Finish_Enum(Enum):
other = 0
matte = 1
satin = 2
polished = 3
rugged = 4
fabric = 5


class Product_Color_Enum(Enum):
black = 0
navy = 1
green = 2
teal = 3
maroon = 4
purple = 5
olive = 6
gray = 7
blue = 8
lime = 9
aqua = 10
red = 11
fuchsia = 12
yellow = 13
white = 14
nickel = 15
chrome = 16
brass = 17
copper = 18
silver = 19
gold = 20


TOOLS = {}

FACTORY_PARTITION_CSV = 'nvs_partition.csv'
Expand Down Expand Up @@ -149,6 +184,31 @@
'encoding': 'hex2bin',
'value': None,
},
'product-finish': {
'type': 'data',
'encoding': 'u32',
'value': None,
},
'product-color': {
'type': 'data',
'encoding': 'u32',
'value': None,
},
'part-number': {
'type': 'data',
'encoding': 'string',
'value': None,
},
'product-label': {
'type': 'data',
'encoding': 'string',
'value': None,
},
'product-url': {
'type': 'data',
'encoding': 'string',
'value': None,
},
}


Expand Down Expand Up @@ -301,6 +361,16 @@ def populate_factory_data(args, spake2p_params):
FACTORY_DATA['hardware-ver']['value'] = args.hw_ver
if args.hw_ver_str:
FACTORY_DATA['hw-ver-str']['value'] = args.hw_ver_str
if args.product_finish:
FACTORY_DATA['product-finish']['value'] = Product_Finish_Enum[args.product_finish].value
if args.product_color:
FACTORY_DATA['product-color']['value'] = Product_Color_Enum[args.product_color].value
if args.part_number:
FACTORY_DATA['part-number']['value'] = args.part_number
if args.product_url:
FACTORY_DATA['product-url']['value'] = args.product_url
if args.product_label:
FACTORY_DATA['product-label']['value'] = args.product_label

# SupportedModes are stored as multiple entries
# - sm-sz/<ep> : number of supported modes for the endpoint
Expand Down Expand Up @@ -471,6 +541,18 @@ def any_base_int(s): return int(s, 0)
parser.add_argument('--supported-modes', type=str, nargs='+', required=False,
help='List of supported modes, eg: mode1/label1/ep/"tagValue1\\mfgCode, tagValue2\\mfgCode" mode2/label2/ep/"tagValue1\\mfgCode, tagValue2\\mfgCode" mode3/label3/ep/"tagValue1\\mfgCode, tagValue2\\mfgCode"')

product_finish_choices = [finish.name for finish in Product_Finish_Enum]
parser.add_argument("--product-finish", type=str, choices=product_finish_choices,
help='Product finishes choices for product appearance')

product_color_choices = [color.name for color in Product_Color_Enum]
parser.add_argument("--product-color", type=str, choices=product_color_choices,
help='Product colors choices for product appearance')

parser.add_argument("--part-number", type=str, help='human readable product number')
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('-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 Expand Up @@ -509,7 +591,8 @@ def set_up_factory_data(args):
def generate_factory_partiton_binary(args):
generate_nvs_csv(args.output_dir, FACTORY_PARTITION_CSV)
if args.generate_bin:
generate_nvs_bin(args.encrypt, args.size, FACTORY_PARTITION_CSV, FACTORY_PARTITION_BIN, args.output_dir)
csv_file = os.path.join(args.output_dir, FACTORY_PARTITION_CSV)
generate_nvs_bin(args.encrypt, args.size, csv_file, FACTORY_PARTITION_BIN, args.output_dir)
print_flashing_help(args.encrypt, args.output_dir, FACTORY_PARTITION_BIN)
clean_up()

Expand Down
3 changes: 3 additions & 0 deletions src/platform/ESP32/ESP32Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ const ESP32Config::Key ESP32Config::kConfigKey_ProductURL = { kConfig
const ESP32Config::Key ESP32Config::kConfigKey_SupportedCalTypes = { kConfigNamespace_ChipFactory, "cal-types" };
const ESP32Config::Key ESP32Config::kConfigKey_SupportedLocaleSize = { kConfigNamespace_ChipFactory, "locale-sz" };
const ESP32Config::Key ESP32Config::kConfigKey_RotatingDevIdUniqueId = { kConfigNamespace_ChipFactory, "rd-id-uid" };
const ESP32Config::Key ESP32Config::kConfigKey_ProductFinish = { kConfigNamespace_ChipFactory, "product-finish" };
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" };

// Keys stored in the chip-config namespace
Expand Down
3 changes: 3 additions & 0 deletions src/platform/ESP32/ESP32Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,13 @@ class ESP32Config
static const Key kConfigKey_ProductId;
static const Key kConfigKey_ProductName;
static const Key kConfigKey_ProductLabel;
static const Key kConfigKey_PartNumber;
static const Key kConfigKey_ProductURL;
static const Key kConfigKey_SupportedCalTypes;
static const Key kConfigKey_SupportedLocaleSize;
static const Key kConfigKey_RotatingDevIdUniqueId;
static const Key kConfigKey_ProductFinish;
static const Key kConfigKey_ProductColor;
static const Key kConfigKey_LocationCapability;

// CHIP Config keys
Expand Down
33 changes: 32 additions & 1 deletion src/platform/ESP32/ESP32FactoryDataProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,45 @@ CHIP_ERROR ESP32FactoryDataProvider::GetManufacturingDate(uint16_t & year, uint8
return GenericDeviceInstanceInfoProvider<ESP32Config>::GetManufacturingDate(year, month, day);
}

CHIP_ERROR ESP32FactoryDataProvider::GetProductFinish(app::Clusters::BasicInformation::ProductFinishEnum * finish)
{
CHIP_ERROR err = CHIP_NO_ERROR;
uint32_t productFinish = 0;

err = ESP32Config::ReadConfigValue(ESP32Config::kConfigKey_ProductFinish, productFinish);
ReturnErrorCodeIf(err != CHIP_NO_ERROR, CHIP_ERROR_NOT_IMPLEMENTED);

*finish = static_cast<app::Clusters::BasicInformation::ProductFinishEnum>(productFinish);

return err;
}

CHIP_ERROR ESP32FactoryDataProvider::GetProductPrimaryColor(app::Clusters::BasicInformation::ColorEnum * primaryColor)
{
CHIP_ERROR err = CHIP_NO_ERROR;
uint32_t color = 0;

err = ESP32Config::ReadConfigValue(ESP32Config::kConfigKey_ProductColor, color);
ReturnErrorCodeIf(err != CHIP_NO_ERROR, CHIP_ERROR_NOT_IMPLEMENTED);

*primaryColor = static_cast<app::Clusters::BasicInformation::ColorEnum>(color);

return err;
}

CHIP_ERROR ESP32FactoryDataProvider::GetHardwareVersion(uint16_t & hardwareVersion)
{
return GenericDeviceInstanceInfoProvider<ESP32Config>::GetHardwareVersion(hardwareVersion);
}

CHIP_ERROR ESP32FactoryDataProvider::GetPartNumber(char * buf, size_t bufSize)
{
return GenericDeviceInstanceInfoProvider<ESP32Config>::GetPartNumber(buf, bufSize);
CHIP_ERROR err = ESP32Config::ReadConfigValueStr(ESP32Config::kConfigKey_PartNumber, buf, bufSize, bufSize);
if (err == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND)
{
return CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;
}
return err;
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_DEVICE_INSTANCE_INFO_PROVIDER

Expand Down
2 changes: 2 additions & 0 deletions src/platform/ESP32/ESP32FactoryDataProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ class ESP32FactoryDataProvider : public CommissionableDataProvider,
CHIP_ERROR GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & day) override;
CHIP_ERROR GetPartNumber(char * buf, size_t bufSize) override;
CHIP_ERROR GetHardwareVersion(uint16_t & hardwareVersion) override;
CHIP_ERROR GetProductFinish(app::Clusters::BasicInformation::ProductFinishEnum * finish) override;
CHIP_ERROR GetProductPrimaryColor(app::Clusters::BasicInformation::ColorEnum * primaryColor) override;
#endif // CHIP_DEVICE_CONFIG_ENABLE_DEVICE_INSTANCE_INFO_PROVIDER

private:
Expand Down

0 comments on commit 6768739

Please sign in to comment.