Skip to content

Commit

Permalink
[Chef] Support assigning product name when compiling Chef applications (
Browse files Browse the repository at this point in the history
#24731)

* Chef support assigning product name

Support assigning product name for chef applications.
Now only linux, esp32, nrfconnect are supported

* Show verbose err text when get product name failed

* Restyled by clang-format

* Print "err.Format()" when get product name failed

* [Chef] Fix type when printing error message

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Jul 10, 2023
1 parent ca3c6ef commit d42dbf7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
6 changes: 5 additions & 1 deletion examples/chef/chef.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ def main() -> int:
help="specifies the Vendor ID. Default is 0xFFF1", metavar="VID", default=0xFFF1)
parser.add_option("-p", "--pid", dest="pid", type=int,
help="specifies the Product ID. Default is 0x8000", metavar="PID", default=0x8000)
parser.add_option("-P", "--pname", dest="pname", type=str, metavar="PRODUCT_NAME",
help="specifies the Product Name. Default is TEST_PRODUCT", default="TEST_PRODUCT")
parser.add_option("", "--rpc_console", help="Opens PW RPC Console",
action="store_true", dest="do_rpc_console")
parser.add_option("-y", "--tty", help="Enumerated USB tty/serial interface enumerated for your physical device. E.g.: /dev/ACM0",
Expand Down Expand Up @@ -626,6 +628,7 @@ def main() -> int:
f.write(textwrap.dedent(f"""\
set(CONFIG_DEVICE_VENDOR_ID {options.vid})
set(CONFIG_DEVICE_PRODUCT_ID {options.pid})
set(CONFIG_DEVICE_PRODUCT_NAME \"{options.pname}\")
set(CONFIG_ENABLE_PW_RPC {"1" if options.do_rpc else "0"})
set(SAMPLE_NAME {options.sample_device_type_name})
set(CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING \"{sw_ver_string}\")"""))
Expand Down Expand Up @@ -716,7 +719,7 @@ def main() -> int:
'chip_shell_cmd_server = false',
'chip_build_libshell = true',
'chip_config_network_layer_ble = false',
f'target_defines = ["CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID={options.vid}", "CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID={options.pid}", "CONFIG_ENABLE_PW_RPC={int(options.do_rpc)}"]',
f'target_defines = ["CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID={options.vid}", "CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID={options.pid}", "CONFIG_ENABLE_PW_RPC={int(options.do_rpc)}", "CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME=\\"{str(options.pname)}\\""]',
])

uname_resp = shell.run_cmd("uname -m", return_cmd_output=True)
Expand Down Expand Up @@ -763,6 +766,7 @@ def main() -> int:
if sw_ver_string:
linux_args.append(
f'chip_device_config_device_software_version_string = "{sw_ver_string}"')

with open(f"{_CHEF_SCRIPT_PATH}/linux/args.gni", "w") as f:
f.write("\n".join(linux_args))
with open(f"{_CHEF_SCRIPT_PATH}/linux/sample.gni", "w") as f:
Expand Down
8 changes: 6 additions & 2 deletions examples/chef/esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ endif()

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
include(${CMAKE_CURRENT_LIST_DIR}/../project_include.cmake)
message(STATUS "Product ID " ${CONFIG_DEVICE_PRODUCT_ID})
message(STATUS "Vendor ID " ${CONFIG_DEVICE_VENDOR_ID})
message(STATUS "Product ID " ${CONFIG_DEVICE_PRODUCT_ID})
message(STATUS "Product Name " ${CONFIG_DEVICE_PRODUCT_NAME})
message(STATUS "SW Version String" ${CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING})
idf_build_set_property(COMPILE_OPTIONS "-DCHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID=${CONFIG_DEVICE_PRODUCT_ID}" APPEND)
idf_build_set_property(COMPILE_OPTIONS "-DCHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID=${CONFIG_DEVICE_VENDOR_ID}" APPEND)
idf_build_set_property(COMPILE_OPTIONS "-DCHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID=${CONFIG_DEVICE_PRODUCT_ID}" APPEND)
if(NOT ${CONFIG_DEVICE_PRODUCT_NAME} STREQUAL "")
idf_build_set_property(COMPILE_OPTIONS "-DCHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME=\"${CONFIG_DEVICE_PRODUCT_NAME}\"" APPEND)
endif()
if(NOT ${CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING} STREQUAL "")
idf_build_set_property(COMPILE_OPTIONS "-DCHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING=\"${CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING}\"" APPEND)
endif()
Expand Down
9 changes: 7 additions & 2 deletions examples/chef/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@ get_filename_component(GEN_DIR ${CHEF}/out/${SAMPLE_NAME}/zap-generated REALPATH
set(CONF_FILE prj.conf)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CHIP_CFLAGS "${CHIP_CFLAGS} -DCHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID=${CONFIG_DEVICE_PRODUCT_ID}")
set(CHIP_CFLAGS "${CHIP_CFLAGS} -DCHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID=${CONFIG_DEVICE_VENDOR_ID}")
set(CHIP_CFLAGS "${CHIP_CFLAGS} -DCHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID=${CONFIG_DEVICE_PRODUCT_ID}")
if(NOT ${CONFIG_DEVICE_PRODUCT_NAME} STREQUAL "")
set(CHIP_CFLAGS "${CHIP_CFLAGS} -DCHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME=\"${CONFIG_DEVICE_PRODUCT_NAME}\"")
endif()
set(CHIP_CFLAGS "${CHIP_CFLAGS} -DCHIP_PLATFORM_NRFCONNECT=1")
if(NOT ${CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING} STREQUAL "")
set(CHIP_CFLAGS "${CHIP_CFLAGS} -DCHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING=\"${CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING}\"")
endif()
message(STATUS "Product ID " ${CONFIG_DEVICE_PRODUCT_ID})
message(STATUS "Vendor ID " ${CONFIG_DEVICE_VENDOR_ID})
message(STATUS "Product ID " ${CONFIG_DEVICE_PRODUCT_ID})
message(STATUS "Product Name " ${CONFIG_DEVICE_PRODUCT_NAME})
message(STATUS "SW Version String" ${CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING})

# Set Kconfig root files that will be processed as a first Kconfig for used child images.
Expand Down Expand Up @@ -67,6 +71,7 @@ target_include_directories(app PRIVATE
${CHEF}
${GEN_DIR}/../
${CHIP_ROOT}/src
${CHIP_ROOT}/examples/shell/shell_common/include
${NRFCONNECT_COMMON}/util/include
${NRFCONNECT_COMMON}/app/include
)
Expand Down
13 changes: 13 additions & 0 deletions src/include/platform/internal/GenericConfigurationManagerImpl.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,19 @@ void GenericConfigurationManagerImpl<ConfigClass>::LogDeviceConfig()
ChipLogProgress(DeviceLayer, " Product Id: %u (0x%X)", productId, productId);
}

{
char productName[ConfigurationManager::kMaxProductNameLength + 1];
err = deviceInstanceInfoProvider->GetProductName(productName, sizeof(productName));
if (CHIP_NO_ERROR == err)
{
ChipLogProgress(DeviceLayer, " Product Name: %s", productName);
}
else
{
ChipLogError(DeviceLayer, " Product Name: n/a (%" CHIP_ERROR_FORMAT ")", err.Format());
}
}

{
uint16_t hardwareVer;
if (deviceInstanceInfoProvider->GetHardwareVersion(hardwareVer) != CHIP_NO_ERROR)
Expand Down

0 comments on commit d42dbf7

Please sign in to comment.