Skip to content

Commit 6768739

Browse files
[ESP32] Changes to support product-appearance attribute in ESP32. (project-chip#34363)
* 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
1 parent 8ebace8 commit 6768739

5 files changed

+124
-2
lines changed

scripts/tools/generate_esp32_chip_factory_bin.py

+84-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import logging
2222
import os
2323
import sys
24+
from enum import Enum
2425
from types import SimpleNamespace
2526

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

49+
50+
class Product_Finish_Enum(Enum):
51+
other = 0
52+
matte = 1
53+
satin = 2
54+
polished = 3
55+
rugged = 4
56+
fabric = 5
57+
58+
59+
class Product_Color_Enum(Enum):
60+
black = 0
61+
navy = 1
62+
green = 2
63+
teal = 3
64+
maroon = 4
65+
purple = 5
66+
olive = 6
67+
gray = 7
68+
blue = 8
69+
lime = 9
70+
aqua = 10
71+
red = 11
72+
fuchsia = 12
73+
yellow = 13
74+
white = 14
75+
nickel = 15
76+
chrome = 16
77+
brass = 17
78+
copper = 18
79+
silver = 19
80+
gold = 20
81+
82+
4883
TOOLS = {}
4984

5085
FACTORY_PARTITION_CSV = 'nvs_partition.csv'
@@ -149,6 +184,31 @@
149184
'encoding': 'hex2bin',
150185
'value': None,
151186
},
187+
'product-finish': {
188+
'type': 'data',
189+
'encoding': 'u32',
190+
'value': None,
191+
},
192+
'product-color': {
193+
'type': 'data',
194+
'encoding': 'u32',
195+
'value': None,
196+
},
197+
'part-number': {
198+
'type': 'data',
199+
'encoding': 'string',
200+
'value': None,
201+
},
202+
'product-label': {
203+
'type': 'data',
204+
'encoding': 'string',
205+
'value': None,
206+
},
207+
'product-url': {
208+
'type': 'data',
209+
'encoding': 'string',
210+
'value': None,
211+
},
152212
}
153213

154214

@@ -301,6 +361,16 @@ def populate_factory_data(args, spake2p_params):
301361
FACTORY_DATA['hardware-ver']['value'] = args.hw_ver
302362
if args.hw_ver_str:
303363
FACTORY_DATA['hw-ver-str']['value'] = args.hw_ver_str
364+
if args.product_finish:
365+
FACTORY_DATA['product-finish']['value'] = Product_Finish_Enum[args.product_finish].value
366+
if args.product_color:
367+
FACTORY_DATA['product-color']['value'] = Product_Color_Enum[args.product_color].value
368+
if args.part_number:
369+
FACTORY_DATA['part-number']['value'] = args.part_number
370+
if args.product_url:
371+
FACTORY_DATA['product-url']['value'] = args.product_url
372+
if args.product_label:
373+
FACTORY_DATA['product-label']['value'] = args.product_label
304374

305375
# SupportedModes are stored as multiple entries
306376
# - sm-sz/<ep> : number of supported modes for the endpoint
@@ -471,6 +541,18 @@ def any_base_int(s): return int(s, 0)
471541
parser.add_argument('--supported-modes', type=str, nargs='+', required=False,
472542
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"')
473543

544+
product_finish_choices = [finish.name for finish in Product_Finish_Enum]
545+
parser.add_argument("--product-finish", type=str, choices=product_finish_choices,
546+
help='Product finishes choices for product appearance')
547+
548+
product_color_choices = [color.name for color in Product_Color_Enum]
549+
parser.add_argument("--product-color", type=str, choices=product_color_choices,
550+
help='Product colors choices for product appearance')
551+
552+
parser.add_argument("--part-number", type=str, help='human readable product number')
553+
parser.add_argument("--product-label", type=str, help='human readable product label')
554+
parser.add_argument("--product-url", type=str, help='link to product specific web page')
555+
474556
parser.add_argument('-s', '--size', type=any_base_int, default=0x6000,
475557
help='The size of the partition.bin, default: 0x6000')
476558
parser.add_argument('--target', default='esp32',
@@ -509,7 +591,8 @@ def set_up_factory_data(args):
509591
def generate_factory_partiton_binary(args):
510592
generate_nvs_csv(args.output_dir, FACTORY_PARTITION_CSV)
511593
if args.generate_bin:
512-
generate_nvs_bin(args.encrypt, args.size, FACTORY_PARTITION_CSV, FACTORY_PARTITION_BIN, args.output_dir)
594+
csv_file = os.path.join(args.output_dir, FACTORY_PARTITION_CSV)
595+
generate_nvs_bin(args.encrypt, args.size, csv_file, FACTORY_PARTITION_BIN, args.output_dir)
513596
print_flashing_help(args.encrypt, args.output_dir, FACTORY_PARTITION_BIN)
514597
clean_up()
515598

src/platform/ESP32/ESP32Config.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ const ESP32Config::Key ESP32Config::kConfigKey_ProductURL = { kConfig
7777
const ESP32Config::Key ESP32Config::kConfigKey_SupportedCalTypes = { kConfigNamespace_ChipFactory, "cal-types" };
7878
const ESP32Config::Key ESP32Config::kConfigKey_SupportedLocaleSize = { kConfigNamespace_ChipFactory, "locale-sz" };
7979
const ESP32Config::Key ESP32Config::kConfigKey_RotatingDevIdUniqueId = { kConfigNamespace_ChipFactory, "rd-id-uid" };
80+
const ESP32Config::Key ESP32Config::kConfigKey_ProductFinish = { kConfigNamespace_ChipFactory, "product-finish" };
81+
const ESP32Config::Key ESP32Config::kConfigKey_ProductColor = { kConfigNamespace_ChipFactory, "product-color" };
82+
const ESP32Config::Key ESP32Config::kConfigKey_PartNumber = { kConfigNamespace_ChipFactory, "part-number" };
8083
const ESP32Config::Key ESP32Config::kConfigKey_LocationCapability = { kConfigNamespace_ChipFactory, "loc-capability" };
8184

8285
// Keys stored in the chip-config namespace

src/platform/ESP32/ESP32Config.h

+3
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,13 @@ class ESP32Config
7575
static const Key kConfigKey_ProductId;
7676
static const Key kConfigKey_ProductName;
7777
static const Key kConfigKey_ProductLabel;
78+
static const Key kConfigKey_PartNumber;
7879
static const Key kConfigKey_ProductURL;
7980
static const Key kConfigKey_SupportedCalTypes;
8081
static const Key kConfigKey_SupportedLocaleSize;
8182
static const Key kConfigKey_RotatingDevIdUniqueId;
83+
static const Key kConfigKey_ProductFinish;
84+
static const Key kConfigKey_ProductColor;
8285
static const Key kConfigKey_LocationCapability;
8386

8487
// CHIP Config keys

src/platform/ESP32/ESP32FactoryDataProvider.cpp

+32-1
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,45 @@ CHIP_ERROR ESP32FactoryDataProvider::GetManufacturingDate(uint16_t & year, uint8
245245
return GenericDeviceInstanceInfoProvider<ESP32Config>::GetManufacturingDate(year, month, day);
246246
}
247247

248+
CHIP_ERROR ESP32FactoryDataProvider::GetProductFinish(app::Clusters::BasicInformation::ProductFinishEnum * finish)
249+
{
250+
CHIP_ERROR err = CHIP_NO_ERROR;
251+
uint32_t productFinish = 0;
252+
253+
err = ESP32Config::ReadConfigValue(ESP32Config::kConfigKey_ProductFinish, productFinish);
254+
ReturnErrorCodeIf(err != CHIP_NO_ERROR, CHIP_ERROR_NOT_IMPLEMENTED);
255+
256+
*finish = static_cast<app::Clusters::BasicInformation::ProductFinishEnum>(productFinish);
257+
258+
return err;
259+
}
260+
261+
CHIP_ERROR ESP32FactoryDataProvider::GetProductPrimaryColor(app::Clusters::BasicInformation::ColorEnum * primaryColor)
262+
{
263+
CHIP_ERROR err = CHIP_NO_ERROR;
264+
uint32_t color = 0;
265+
266+
err = ESP32Config::ReadConfigValue(ESP32Config::kConfigKey_ProductColor, color);
267+
ReturnErrorCodeIf(err != CHIP_NO_ERROR, CHIP_ERROR_NOT_IMPLEMENTED);
268+
269+
*primaryColor = static_cast<app::Clusters::BasicInformation::ColorEnum>(color);
270+
271+
return err;
272+
}
273+
248274
CHIP_ERROR ESP32FactoryDataProvider::GetHardwareVersion(uint16_t & hardwareVersion)
249275
{
250276
return GenericDeviceInstanceInfoProvider<ESP32Config>::GetHardwareVersion(hardwareVersion);
251277
}
252278

253279
CHIP_ERROR ESP32FactoryDataProvider::GetPartNumber(char * buf, size_t bufSize)
254280
{
255-
return GenericDeviceInstanceInfoProvider<ESP32Config>::GetPartNumber(buf, bufSize);
281+
CHIP_ERROR err = ESP32Config::ReadConfigValueStr(ESP32Config::kConfigKey_PartNumber, buf, bufSize, bufSize);
282+
if (err == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND)
283+
{
284+
return CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;
285+
}
286+
return err;
256287
}
257288
#endif // CHIP_DEVICE_CONFIG_ENABLE_DEVICE_INSTANCE_INFO_PROVIDER
258289

src/platform/ESP32/ESP32FactoryDataProvider.h

+2
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ class ESP32FactoryDataProvider : public CommissionableDataProvider,
9696
CHIP_ERROR GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & day) override;
9797
CHIP_ERROR GetPartNumber(char * buf, size_t bufSize) override;
9898
CHIP_ERROR GetHardwareVersion(uint16_t & hardwareVersion) override;
99+
CHIP_ERROR GetProductFinish(app::Clusters::BasicInformation::ProductFinishEnum * finish) override;
100+
CHIP_ERROR GetProductPrimaryColor(app::Clusters::BasicInformation::ColorEnum * primaryColor) override;
99101
#endif // CHIP_DEVICE_CONFIG_ENABLE_DEVICE_INSTANCE_INFO_PROVIDER
100102

101103
private:

0 commit comments

Comments
 (0)