diff --git a/samples/boards/nrf52/mesh/onoff_level_lighting_vnd_app/CMakeLists.txt b/samples/boards/nrf52/mesh/onoff_level_lighting_vnd_app/CMakeLists.txt index 777e56d30c5..9fa73e8d761 100644 --- a/samples/boards/nrf52/mesh/onoff_level_lighting_vnd_app/CMakeLists.txt +++ b/samples/boards/nrf52/mesh/onoff_level_lighting_vnd_app/CMakeLists.txt @@ -18,6 +18,8 @@ target_sources(app PRIVATE src/mesh/transition.c ) +target_sources_ifdef(CONFIG_MCUMGR app PRIVATE src/smp_svr.c) + zephyr_include_directories( src/ src/mesh diff --git a/samples/boards/nrf52/mesh/onoff_level_lighting_vnd_app/prj_smp_svr.conf b/samples/boards/nrf52/mesh/onoff_level_lighting_vnd_app/prj_smp_svr.conf new file mode 100644 index 00000000000..c76f69b720c --- /dev/null +++ b/samples/boards/nrf52/mesh/onoff_level_lighting_vnd_app/prj_smp_svr.conf @@ -0,0 +1,33 @@ +# Enable mcumgr. +CONFIG_MCUMGR=y + +# Ensure an MCUboot-compatible binary is generated. +CONFIG_BOOTLOADER_MCUBOOT=y + +# Allow for large Bluetooth data packets. +CONFIG_BT_L2CAP_TX_MTU=260 +CONFIG_BT_RX_BUF_LEN=260 + +# Enable the Bluetooth and shell mcumgr transports. +CONFIG_MCUMGR_SMP_BT=y +#CONFIG_MCUMGR_SMP_SHELL=y +#CONFIG_MCUMGR_SMP_UART=y + +# Bluetooth support requires a net_buf user_data size >= 7. +CONFIG_NET_BUF_USER_DATA_SIZE=7 + +# Enable flash operations. +CONFIG_FLASH=y + +# Required by the `taskstat` command. +CONFIG_THREAD_MONITOR=y + +# Enable statistics and statistic names. +CONFIG_STATS=y +CONFIG_STATS_NAMES=y + +# Enable all core commands. +CONFIG_MCUMGR_CMD_FS_MGMT=y +CONFIG_MCUMGR_CMD_IMG_MGMT=y +CONFIG_MCUMGR_CMD_OS_MGMT=y +CONFIG_MCUMGR_CMD_STAT_MGMT=y diff --git a/samples/boards/nrf52/mesh/onoff_level_lighting_vnd_app/src/main.c b/samples/boards/nrf52/mesh/onoff_level_lighting_vnd_app/src/main.c index aa258014a85..104b987de9e 100644 --- a/samples/boards/nrf52/mesh/onoff_level_lighting_vnd_app/src/main.c +++ b/samples/boards/nrf52/mesh/onoff_level_lighting_vnd_app/src/main.c @@ -8,15 +8,19 @@ #include #include "app_gpio.h" -#include "storage.h" - #include "ble_mesh.h" #include "device_composition.h" #include "no_transition_work_handler.h" #include "publisher.h" #include "state_binding.h" +#include "storage.h" #include "transition.h" +#if defined(CONFIG_MCUMGR) +#include +#include "smp_svr.h" +#endif + static bool reset; static void light_default_var_init(void) @@ -185,6 +189,10 @@ void main(void) app_gpio_init(); +#if defined(CONFIG_MCUMGR) + smp_svr_init(); +#endif + printk("Initializing...\n"); ps_settings_init(); @@ -203,4 +211,11 @@ void main(void) short_time_multireset_bt_mesh_unprovisioning(); k_timer_start(&reset_counter_timer, K_MSEC(7000), 0); + +#if defined(CONFIG_MCUMGR) + /* Initialize the Bluetooth mcumgr transport. */ + smp_bt_register(); + + k_timer_start(&smp_svr_timer, 0, K_MSEC(1000)); +#endif } diff --git a/samples/boards/nrf52/mesh/onoff_level_lighting_vnd_app/src/smp_svr.c b/samples/boards/nrf52/mesh/onoff_level_lighting_vnd_app/src/smp_svr.c new file mode 100644 index 00000000000..eaa1eb22253 --- /dev/null +++ b/samples/boards/nrf52/mesh/onoff_level_lighting_vnd_app/src/smp_svr.c @@ -0,0 +1,69 @@ +/* Bluetooth: Mesh Generic OnOff, Generic Level, Lighting & Vendor Models + * + * Copyright (c) 2018 Vikrant More + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef CONFIG_MCUMGR_CMD_IMG_MGMT +#include "img_mgmt/img_mgmt.h" +#endif +#ifdef CONFIG_MCUMGR_CMD_OS_MGMT +#include "os_mgmt/os_mgmt.h" +#endif +#ifdef CONFIG_MCUMGR_CMD_STAT_MGMT +#include "stat_mgmt/stat_mgmt.h" +#endif + +/* Define an example stats group; approximates seconds since boot. */ +STATS_SECT_START(smp_svr_stats) +STATS_SECT_ENTRY(ticks) +STATS_SECT_END; + +/* Assign a name to the `ticks` stat. */ +STATS_NAME_START(smp_svr_stats) +STATS_NAME(smp_svr_stats, ticks) +STATS_NAME_END(smp_svr_stats); + +/* Define an instance of the stats group. */ +STATS_SECT_DECL(smp_svr_stats) smp_svr_stats; + +void smp_svr_init(void) +{ + int rc; + + rc = STATS_INIT_AND_REG(smp_svr_stats, STATS_SIZE_32, "smp_svr_stats"); + assert(rc == 0); + + /* Register the built-in mcumgr command handlers. */ +#ifdef CONFIG_MCUMGR_CMD_FS_MGMT + fs_mgmt_register_group(); +#endif +#ifdef CONFIG_MCUMGR_CMD_OS_MGMT + os_mgmt_register_group(); +#endif +#ifdef CONFIG_MCUMGR_CMD_IMG_MGMT + img_mgmt_register_group(); +#endif +#ifdef CONFIG_MCUMGR_CMD_STAT_MGMT + stat_mgmt_register_group(); +#endif +} + +static void smp_svr_timer_handler(struct k_timer *dummy) +{ + STATS_INC(smp_svr_stats, ticks); +} + +K_TIMER_DEFINE(smp_svr_timer, smp_svr_timer_handler, NULL); diff --git a/samples/boards/nrf52/mesh/onoff_level_lighting_vnd_app/src/smp_svr.h b/samples/boards/nrf52/mesh/onoff_level_lighting_vnd_app/src/smp_svr.h new file mode 100644 index 00000000000..b0c64391a81 --- /dev/null +++ b/samples/boards/nrf52/mesh/onoff_level_lighting_vnd_app/src/smp_svr.h @@ -0,0 +1,16 @@ +/* Bluetooth: Mesh Generic OnOff, Generic Level, Lighting & Vendor Models + * + * Copyright (c) 2018 Vikrant More + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef _SMP_SVR_H +#define _SMP_SVR_H + +extern struct k_timer smp_svr_timer; + +void smp_svr_init(void); +void smp_svr(void); + +#endif