Bluetooth: Mesh: shell: Add basic skeleton
Add a basic shell skeleton for Mesh, containing basic command for initialization, provisioning and reset. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
parent
e04a5412a1
commit
e2e74f705b
4 changed files with 244 additions and 0 deletions
|
@ -22,3 +22,5 @@ zephyr_library_sources_ifdef(CONFIG_BT_MESH_PROV prov.c)
|
|||
zephyr_library_sources_ifdef(CONFIG_BT_MESH_PROXY proxy.c)
|
||||
|
||||
zephyr_library_sources_ifdef(CONFIG_BT_MESH_SELF_TEST test.c)
|
||||
|
||||
zephyr_library_sources_ifdef(CONFIG_BT_MESH_SHELL shell.c)
|
||||
|
|
|
@ -336,6 +336,13 @@ config BT_MESH_FRIEND_SEG_RX
|
|||
|
||||
endif # BT_MESH_FRIEND
|
||||
|
||||
config BT_MESH_SHELL
|
||||
bool "Enable Bluetooth Mesh shell"
|
||||
select CONSOLE_SHELL
|
||||
help
|
||||
Activate shell module that provides Bluetooth Mesh commands to
|
||||
the console.
|
||||
|
||||
config BT_MESH_DEBUG
|
||||
bool "Enable debug logs"
|
||||
depends on BT_DEBUG
|
||||
|
|
206
subsys/bluetooth/host/mesh/shell.c
Normal file
206
subsys/bluetooth/host/mesh/shell.c
Normal file
|
@ -0,0 +1,206 @@
|
|||
/** @file
|
||||
* @brief Bluetooth Mesh shell
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <zephyr.h>
|
||||
#include <shell/shell.h>
|
||||
#include <misc/printk.h>
|
||||
|
||||
#include <bluetooth/bluetooth.h>
|
||||
#include <bluetooth/mesh.h>
|
||||
|
||||
static struct bt_mesh_cfg cfg_srv = {
|
||||
.relay = BT_MESH_RELAY_DISABLED,
|
||||
.beacon = BT_MESH_BEACON_DISABLED,
|
||||
#if defined(CONFIG_BT_MESH_FRIEND)
|
||||
.frnd = BT_MESH_FRIEND_DISABLED,
|
||||
#else
|
||||
.frnd = BT_MESH_FRIEND_NOT_SUPPORTED,
|
||||
#endif
|
||||
#if defined(CONFIG_BT_MESH_GATT_PROXY)
|
||||
.gatt_proxy = BT_MESH_GATT_PROXY_DISABLED,
|
||||
#else
|
||||
.gatt_proxy = BT_MESH_GATT_PROXY_NOT_SUPPORTED,
|
||||
#endif
|
||||
|
||||
.default_ttl = 7,
|
||||
|
||||
/* 3 transmissions with 20ms interval */
|
||||
.net_transmit = BT_MESH_TRANSMIT(2, 20),
|
||||
.relay_retransmit = BT_MESH_TRANSMIT(2, 20),
|
||||
};
|
||||
|
||||
static struct bt_mesh_health health_srv = {
|
||||
};
|
||||
|
||||
static const u8_t dev_uuid[16] = { 0xdd, 0xdd };
|
||||
|
||||
static struct bt_mesh_model root_models[] = {
|
||||
BT_MESH_MODEL_CFG_SRV(&cfg_srv),
|
||||
BT_MESH_MODEL_HEALTH_SRV(&health_srv),
|
||||
};
|
||||
|
||||
static struct bt_mesh_elem elements[] = {
|
||||
BT_MESH_ELEM(0, root_models, BT_MESH_MODEL_NONE),
|
||||
};
|
||||
|
||||
static const struct bt_mesh_comp comp = {
|
||||
.cid = 0xffff,
|
||||
.elem = elements,
|
||||
.elem_count = ARRAY_SIZE(elements),
|
||||
};
|
||||
|
||||
static void prov_complete(void)
|
||||
{
|
||||
printk("Local node provisioned\n");
|
||||
}
|
||||
|
||||
static int output_number(bt_mesh_output_action action, uint32_t number)
|
||||
{
|
||||
printk("OOB Number: %u\n", number);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int output_string(const char *str)
|
||||
{
|
||||
printk("OOB String: %s\n", str);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bt_mesh_input_action input_act;
|
||||
static u8_t input_size;
|
||||
|
||||
static int cmd_input_num(int argc, char *argv[])
|
||||
{
|
||||
int err;
|
||||
|
||||
if (argc < 2) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (input_act != BT_MESH_ENTER_NUMBER) {
|
||||
printk("A number hasn't been requested!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strlen(argv[1]) < input_size) {
|
||||
printk("Too short input (%u digits required)\n",
|
||||
input_size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
err = bt_mesh_input_number(strtoul(argv[1], NULL, 10));
|
||||
if (err) {
|
||||
printk("Numeric input failed (err %d)\n", err);
|
||||
return 0;
|
||||
}
|
||||
|
||||
input_act = BT_MESH_NO_INPUT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_input_str(int argc, char *argv[])
|
||||
{
|
||||
int err;
|
||||
|
||||
if (argc < 2) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (input_act != BT_MESH_ENTER_STRING) {
|
||||
printk("A string hasn't been requested!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (strlen(argv[1]) < input_size) {
|
||||
printk("Too short input (%u characters required)\n",
|
||||
input_size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
err = bt_mesh_input_string(argv[1]);
|
||||
if (err) {
|
||||
printk("String input failed (err %d)\n", err);
|
||||
return 0;
|
||||
}
|
||||
|
||||
input_act = BT_MESH_NO_INPUT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int input(bt_mesh_input_action act, u8_t size)
|
||||
{
|
||||
switch (act) {
|
||||
case BT_MESH_ENTER_NUMBER:
|
||||
printk("Enter a number (max %u digits) with: input-num <num>\n",
|
||||
size);
|
||||
break;
|
||||
case BT_MESH_ENTER_STRING:
|
||||
printk("Enter a string (max %u chars) with: input-str <str>\n",
|
||||
size);
|
||||
break;
|
||||
default:
|
||||
printk("Unknown input action %u (size %u) requested!\n",
|
||||
act, size);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
input_act = act;
|
||||
input_size = size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const u8_t static_val[] = {
|
||||
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef
|
||||
};
|
||||
|
||||
static const struct bt_mesh_prov prov = {
|
||||
.uuid = dev_uuid,
|
||||
.complete = prov_complete,
|
||||
.static_val = static_val,
|
||||
.static_val_len = sizeof(static_val),
|
||||
.output_size = 6,
|
||||
.output_actions = (BT_MESH_DISPLAY_NUMBER | BT_MESH_DISPLAY_STRING),
|
||||
.output_number = output_number,
|
||||
.output_string = output_string,
|
||||
.input_size = 6,
|
||||
.input_actions = (BT_MESH_ENTER_NUMBER | BT_MESH_ENTER_STRING),
|
||||
.input = input,
|
||||
};
|
||||
|
||||
static int cmd_init(int argc, char *argv[])
|
||||
{
|
||||
int err;
|
||||
|
||||
err = bt_mesh_init(&prov, &comp);
|
||||
if (err) {
|
||||
printk("Mesh initialization failed (err %d)\n", err);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_reset(int argc, char *argv[])
|
||||
{
|
||||
bt_mesh_reset();
|
||||
printk("Local node reset complete\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct shell_cmd mesh_commands[] = {
|
||||
{ "init", cmd_init, NULL },
|
||||
{ "reset", cmd_reset, NULL },
|
||||
{ "input-num", cmd_input_num, "<number>" },
|
||||
{ "input-str", cmd_input_str, "<string>" },
|
||||
{ NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
SHELL_REGISTER("mesh", mesh_commands);
|
|
@ -1,3 +1,7 @@
|
|||
CONFIG_USERSPACE=n
|
||||
#CONFIG_INIT_STACKS=y
|
||||
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
|
||||
|
||||
CONFIG_BT=y
|
||||
CONFIG_CONSOLE_HANDLER=y
|
||||
CONFIG_BT_DEBUG_LOG=y
|
||||
|
@ -14,3 +18,28 @@ CONFIG_CONSOLE_SHELL=y
|
|||
CONFIG_BT_SHELL=y
|
||||
CONFIG_BT_DEVICE_NAME="test shell"
|
||||
CONFIG_BT_L2CAP_TX_BUF_COUNT=6
|
||||
|
||||
CONFIG_BT_RX_BUF_COUNT=30
|
||||
CONFIG_BT_L2CAP_RX_MTU=69
|
||||
CONFIG_BT_L2CAP_TX_MTU=69
|
||||
|
||||
CONFIG_BT_MESH=y
|
||||
CONFIG_BT_MESH_SHELL=y
|
||||
CONFIG_BT_MESH_RELAY=y
|
||||
CONFIG_BT_MESH_LOW_POWER=y
|
||||
CONFIG_BT_MESH_LPN_AUTO=n
|
||||
CONFIG_BT_MESH_FRIEND=y
|
||||
CONFIG_BT_MESH_FRIEND_QUEUE_SIZE=16
|
||||
CONFIG_BT_MESH_ADV_BUF_COUNT=20
|
||||
|
||||
CONFIG_BT_MESH_PB_GATT=y
|
||||
CONFIG_BT_MESH_PB_ADV=y
|
||||
CONFIG_BT_MESH_GATT_PROXY=y
|
||||
|
||||
CONFIG_BT_MESH_SUBNET_COUNT=2
|
||||
CONFIG_BT_MESH_APP_KEY_COUNT=2
|
||||
CONFIG_BT_MESH_MODEL_KEY_COUNT=2
|
||||
CONFIG_BT_MESH_MODEL_GROUP_COUNT=2
|
||||
|
||||
CONFIG_BT_MESH_IV_UPDATE_TEST=y
|
||||
CONFIG_BT_MESH_DEBUG=y
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue