Skip to content

Commit

Permalink
Merge pull request #1 from hieuv/dev
Browse files Browse the repository at this point in the history
v0.5
  • Loading branch information
hieuv authored Jan 22, 2025
2 parents 013f0da + 605e0aa commit b8c6d99
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 99 deletions.
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
*.bak
*.bin
*.hex
*.lnk
*.log
*.png
*.ppk2
*.zip

temp*.*

build/*
build-*/*
build_*/*

*/test_record/*

.vscode
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A modification of the Zephyr Mesh Shell to evaluate the Bluetooth Mesh Time solution.
6 changes: 6 additions & 0 deletions prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 0 additions & 7 deletions proxy_solicitation.conf

This file was deleted.

184 changes: 92 additions & 92 deletions src/main.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/*
* 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 <zephyr/sys/printk.h>
#include <stdlib.h>
#include <stdint.h>
#include <zephyr/kernel.h>

#include <zephyr/shell/shell.h>
Expand All @@ -14,36 +15,17 @@
#include <zephyr/bluetooth/mesh.h>
#include <zephyr/bluetooth/mesh/shell.h>

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
#include <bluetooth/mesh/models.h>

static struct bt_mesh_cfg_cli cfg_cli;

#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
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) {}

#if defined(CONFIG_BT_MESH_BRG_CFG_CLI)
static struct bt_mesh_brg_cfg_cli brg_cfg_cli;
#endif
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);

Expand All @@ -52,73 +34,20 @@ 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_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 = {
Expand Down Expand Up @@ -172,3 +101,74 @@ 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_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(local_time_server_get_time,
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);

0 comments on commit b8c6d99

Please sign in to comment.