From 743f40d4f526e1fcbf16c5688141e327921084af Mon Sep 17 00:00:00 2001 From: Hieu Vo Date: Mon, 20 Jan 2025 03:56:52 +0100 Subject: [PATCH 1/6] Remove unused models Signed-off-by: Hieu Vo --- src/main.c | 96 ++---------------------------------------------------- 1 file changed, 2 insertions(+), 94 deletions(-) diff --git a/src/main.c b/src/main.c index 1c9dcb0..71a62ad 100644 --- a/src/main.c +++ b/src/main.c @@ -1,7 +1,7 @@ /* - * Copyright (c) 2017 Intel Corporation + * Copyright (c) 2025 Nordic Semiconductor ASA * - * SPDX-License-Identifier: Apache-2.0 + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause */ #include @@ -16,35 +16,6 @@ static struct bt_mesh_cfg_cli cfg_cli; -#if defined(CONFIG_BT_MESH_DFD_SRV) -static struct bt_mesh_dfd_srv dfd_srv; -#endif - -#if defined(CONFIG_BT_MESH_SAR_CFG_CLI) -static struct bt_mesh_sar_cfg_cli sar_cfg_cli; -#endif - -#if defined(CONFIG_BT_MESH_PRIV_BEACON_CLI) -static struct bt_mesh_priv_beacon_cli priv_beacon_cli; -#endif - -#if defined(CONFIG_BT_MESH_SOL_PDU_RPL_CLI) -static struct bt_mesh_sol_pdu_rpl_cli srpl_cli; -#endif - - -#if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_CLI) -static struct bt_mesh_od_priv_proxy_cli od_priv_proxy_cli; -#endif - -#if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_CLI) -struct bt_mesh_large_comp_data_cli large_comp_data_cli; -#endif - -#if defined(CONFIG_BT_MESH_BRG_CFG_CLI) -static struct bt_mesh_brg_cfg_cli brg_cfg_cli; -#endif - BT_MESH_SHELL_HEALTH_PUB_DEFINE(health_pub); static const struct bt_mesh_model root_models[] = { @@ -52,69 +23,6 @@ static const struct bt_mesh_model root_models[] = { BT_MESH_MODEL_CFG_CLI(&cfg_cli), BT_MESH_MODEL_HEALTH_SRV(&bt_mesh_shell_health_srv, &health_pub, health_srv_meta), BT_MESH_MODEL_HEALTH_CLI(&bt_mesh_shell_health_cli), -#if defined(CONFIG_BT_MESH_DFD_SRV) - BT_MESH_MODEL_DFD_SRV(&dfd_srv), -#else -#if defined(CONFIG_BT_MESH_SHELL_DFU_SRV) - BT_MESH_MODEL_DFU_SRV(&bt_mesh_shell_dfu_srv), -#elif defined(CONFIG_BT_MESH_SHELL_BLOB_SRV) - BT_MESH_MODEL_BLOB_SRV(&bt_mesh_shell_blob_srv), -#endif -#if defined(CONFIG_BT_MESH_SHELL_DFU_CLI) - BT_MESH_MODEL_DFU_CLI(&bt_mesh_shell_dfu_cli), -#elif defined(CONFIG_BT_MESH_SHELL_BLOB_CLI) - BT_MESH_MODEL_BLOB_CLI(&bt_mesh_shell_blob_cli), -#endif -#endif /* CONFIG_BT_MESH_DFD_SRV */ -#if defined(CONFIG_BT_MESH_SHELL_RPR_CLI) - BT_MESH_MODEL_RPR_CLI(&bt_mesh_shell_rpr_cli), -#endif -#if defined(CONFIG_BT_MESH_RPR_SRV) - BT_MESH_MODEL_RPR_SRV, -#endif - -#if defined(CONFIG_BT_MESH_SAR_CFG_SRV) - BT_MESH_MODEL_SAR_CFG_SRV, -#endif -#if defined(CONFIG_BT_MESH_SAR_CFG_CLI) - BT_MESH_MODEL_SAR_CFG_CLI(&sar_cfg_cli), -#endif - -#if defined(CONFIG_BT_MESH_OP_AGG_SRV) - BT_MESH_MODEL_OP_AGG_SRV, -#endif -#if defined(CONFIG_BT_MESH_OP_AGG_CLI) - BT_MESH_MODEL_OP_AGG_CLI, -#endif - -#if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_SRV) - BT_MESH_MODEL_LARGE_COMP_DATA_SRV, -#endif -#if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_CLI) - BT_MESH_MODEL_LARGE_COMP_DATA_CLI(&large_comp_data_cli), -#endif - -#if defined(CONFIG_BT_MESH_PRIV_BEACON_SRV) - BT_MESH_MODEL_PRIV_BEACON_SRV, -#endif -#if defined(CONFIG_BT_MESH_PRIV_BEACON_CLI) - BT_MESH_MODEL_PRIV_BEACON_CLI(&priv_beacon_cli), -#endif -#if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_CLI) - BT_MESH_MODEL_OD_PRIV_PROXY_CLI(&od_priv_proxy_cli), -#endif -#if defined(CONFIG_BT_MESH_SOL_PDU_RPL_CLI) - BT_MESH_MODEL_SOL_PDU_RPL_CLI(&srpl_cli), -#endif -#if defined(CONFIG_BT_MESH_OD_PRIV_PROXY_SRV) - BT_MESH_MODEL_OD_PRIV_PROXY_SRV, -#endif -#if defined(CONFIG_BT_MESH_BRG_CFG_SRV) - BT_MESH_MODEL_BRG_CFG_SRV, -#endif -#if defined(CONFIG_BT_MESH_BRG_CFG_CLI) - BT_MESH_MODEL_BRG_CFG_CLI(&brg_cfg_cli), -#endif }; static const struct bt_mesh_elem elements[] = { From cd1eb631a127b5dade2d7ab68f1cf6150fdb4114 Mon Sep 17 00:00:00 2001 From: Hieu Vo Date: Mon, 20 Jan 2025 03:56:52 +0100 Subject: [PATCH 2/6] Add Time Models Signed-off-by: Hieu Vo --- prj.conf | 6 ++++++ src/main.c | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/prj.conf b/prj.conf index bb4c878..b9fd56d 100644 --- a/prj.conf +++ b/prj.conf @@ -77,3 +77,9 @@ CONFIG_BT_MESH_LOG_LEVEL_DBG=y CONFIG_BT_MESH_CDB=y CONFIG_BT_MESH_PROVISIONER=y CONFIG_BT_MESH_STATISTIC=y + +CONFIG_BT_MESH_TIME_SRV=y +CONFIG_BT_MESH_TIME_CLI=y +CONFIG_BT_MESH_SHELL_TIME_CLI=y + +CONFIG_LOG_BUFFER_SIZE=4096 diff --git a/src/main.c b/src/main.c index 71a62ad..f9c2686 100644 --- a/src/main.c +++ b/src/main.c @@ -14,8 +14,18 @@ #include #include +#include + static struct bt_mesh_cfg_cli cfg_cli; +void dtt_update_handler(struct bt_mesh_dtt_srv *srv, + struct bt_mesh_msg_ctx *ctx, + uint32_t old_transition_time, + uint32_t new_transition_time) {} + +static struct bt_mesh_time_srv time_srv = BT_MESH_TIME_SRV_INIT(NULL); +static struct bt_mesh_time_cli time_cli = BT_MESH_TIME_CLI_INIT(NULL); + BT_MESH_SHELL_HEALTH_PUB_DEFINE(health_pub); static const struct bt_mesh_model root_models[] = { @@ -25,8 +35,18 @@ static const struct bt_mesh_model root_models[] = { BT_MESH_MODEL_HEALTH_CLI(&bt_mesh_shell_health_cli), }; +static const struct bt_mesh_model client_models[] = { + BT_MESH_MODEL_TIME_CLI(&time_cli), +}; + +static const struct bt_mesh_model server_models[] = { + BT_MESH_MODEL_TIME_SRV(&time_srv), +}; + static const struct bt_mesh_elem elements[] = { BT_MESH_ELEM(0, root_models, BT_MESH_MODEL_NONE), + BT_MESH_ELEM(1, client_models, BT_MESH_MODEL_NONE), + BT_MESH_ELEM(2, server_models, BT_MESH_MODEL_NONE), }; static const struct bt_mesh_comp comp = { From 9c1a514691062088e40be894a51b71848b8a010d Mon Sep 17 00:00:00 2001 From: Hieu Vo Date: Mon, 20 Jan 2025 03:56:52 +0100 Subject: [PATCH 3/6] Add custom commands to get and set time to/from the Time Server for demo purposes. Signed-off-by: Hieu Vo --- src/main.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/src/main.c b/src/main.c index f9c2686..8dd71fd 100644 --- a/src/main.c +++ b/src/main.c @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -100,3 +101,66 @@ int main(void) printk("Before any Mesh commands you must run \"mesh init\"\n"); return 0; } + +int demo_time_authority_time_set_cmd(const struct shell *sh, size_t argc, char **argv) +{ + int err; + + struct bt_mesh_time_status time_status = { + .tai = { // For demo purpose, set TAI time to 100000:0 + .sec = 100000, + .subsec = 0, + }, + .uncertainty = 0, + .tai_utc_delta = 292, // Current TAI-UTC Delta (leap seconds) in spec representation + .time_zone_offset = 0x44, // +1:00 for Norway (with Daylight Saving Time) + .is_authority = true // Reliable TAI source flag + }; + + int64_t uptime = k_uptime_get(); + + bt_mesh_time_srv_time_set(&time_srv, uptime, &time_status); + + printk("TAI time set to 100000:0\n"); + printk("Uptime: %lldms\n", uptime); + + return 0; +} + +int demo_time_get_cmd(const struct shell *sh, size_t argc, char **argv) +{ + int err; + int64_t uptime; + uint64_t tai_sec; + uint8_t tai_subsec; + struct bt_mesh_time_status time_status; + + uptime = k_uptime_get(); + + err = bt_mesh_time_srv_status(&time_srv, uptime, &time_status); + + if (err) { + if (err == -EAGAIN) printk("bt_mesh_time_srv_status() error -EAGAIN. Has time been set yet?\n"); + else printk("bt_mesh_time_srv_status() error %d\n", err); + } + else { + printk("TAI time extracted directly from Time Server: "); + tai_sec = time_status.tai.sec; + tai_subsec = time_status.tai.subsec; + printk("%lld:%d\n", tai_sec, tai_subsec); + printk("Uptime: %lldms\n", uptime); + } + return 0; +} + +SHELL_STATIC_SUBCMD_SET_CREATE( + demo_subcmds, + SHELL_CMD_ARG(time_authority_time_set, NULL, + "Set time on the Time Server, meant to be used on node with Time Authority Role only\n", + demo_time_authority_time_set_cmd, 1, 0), + SHELL_CMD_ARG(time_get, NULL, + "Get time from the local Time Server\n", + demo_time_get_cmd, 1, 0), + SHELL_SUBCMD_SET_END + ); +SHELL_CMD_REGISTER(demo, &demo_subcmds, "Demo commands\n", NULL); From e71ac80cc6dcab1f356a7c10b6be963955c1c800 Mon Sep 17 00:00:00 2001 From: Hieu Vo Date: Mon, 20 Jan 2025 03:56:52 +0100 Subject: [PATCH 4/6] Add .gitignore Signed-off-by: Hieu Vo --- .gitignore | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eab21d3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +*.bak +*.bin +*.hex +*.lnk +*.log +*.png +*.ppk2 +*.zip + +temp*.* + +build/* +build-*/* +build_*/* + +*/test_record/* + +.vscode From 5010bf2a1fa4ea01910ed04805772d086dcd775d Mon Sep 17 00:00:00 2001 From: Hieu Vo Date: Mon, 20 Jan 2025 14:05:04 +0100 Subject: [PATCH 5/6] Format code, change subcommand name, no feature change. Signed-off-by: Hieu Vo --- src/main.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main.c b/src/main.c index 8dd71fd..a009d1e 100644 --- a/src/main.c +++ b/src/main.c @@ -140,8 +140,12 @@ int demo_time_get_cmd(const struct shell *sh, size_t argc, char **argv) err = bt_mesh_time_srv_status(&time_srv, uptime, &time_status); if (err) { - if (err == -EAGAIN) printk("bt_mesh_time_srv_status() error -EAGAIN. Has time been set yet?\n"); - else printk("bt_mesh_time_srv_status() error %d\n", err); + if (err == -EAGAIN) { + printk("bt_mesh_time_srv_status() error -EAGAIN. Has time been set yet?\n"); + } + else { + printk("bt_mesh_time_srv_status() error %d\n", err); + } } else { printk("TAI time extracted directly from Time Server: "); @@ -155,10 +159,14 @@ int demo_time_get_cmd(const struct shell *sh, size_t argc, char **argv) SHELL_STATIC_SUBCMD_SET_CREATE( demo_subcmds, - SHELL_CMD_ARG(time_authority_time_set, NULL, - "Set time on the Time Server, meant to be used on node with Time Authority Role only\n", + SHELL_CMD_ARG(time_authority_set_time, + NULL, + "Set time on the Time Server, \ + meant to be used on node with Time Authority Role only\n", demo_time_authority_time_set_cmd, 1, 0), - SHELL_CMD_ARG(time_get, NULL, + + SHELL_CMD_ARG(local_time_server_get_time, + NULL, "Get time from the local Time Server\n", demo_time_get_cmd, 1, 0), SHELL_SUBCMD_SET_END From 605e0aa2b35b8dbdf758fc7201e926126746a67f Mon Sep 17 00:00:00 2001 From: Hieu Vo Date: Wed, 22 Jan 2025 11:10:12 +0100 Subject: [PATCH 6/6] Add README. Remove unused config file. Signed-off-by: Hieu Vo --- README.rst | 1 + proxy_solicitation.conf | 7 ------- 2 files changed, 1 insertion(+), 7 deletions(-) create mode 100644 README.rst delete mode 100644 proxy_solicitation.conf diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..da8d886 --- /dev/null +++ b/README.rst @@ -0,0 +1 @@ +A modification of the Zephyr Mesh Shell to evaluate the Bluetooth Mesh Time solution. diff --git a/proxy_solicitation.conf b/proxy_solicitation.conf deleted file mode 100644 index 51e50c0..0000000 --- a/proxy_solicitation.conf +++ /dev/null @@ -1,7 +0,0 @@ -CONFIG_BT_CENTRAL=y -CONFIG_BT_MESH_PROXY_CLIENT=y -CONFIG_BT_MESH_PROXY_SOLICITATION=y -CONFIG_BT_MESH_PRIV_BEACON_SRV=y -CONFIG_BT_MESH_OD_PRIV_PROXY_CLI=y -CONFIG_BT_MESH_OD_PRIV_PROXY_SRV=y -CONFIG_BT_MESH_SOL_PDU_RPL_CLI=y