Bluetooth: Mesh: Add support for Health Attention messages
Add support for sending Health Attention messages, as well as commands to use these new APIs from the shell. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
parent
30d6761396
commit
d588850c0c
3 changed files with 166 additions and 0 deletions
|
@ -56,6 +56,12 @@ int bt_mesh_health_period_get(u16_t net_idx, u16_t addr, u16_t app_idx,
|
|||
int bt_mesh_health_period_set(u16_t net_idx, u16_t addr, u16_t app_idx,
|
||||
u8_t divisor, u8_t *updated_divisor);
|
||||
|
||||
int bt_mesh_health_attention_get(u16_t net_idx, u16_t addr, u16_t app_idx,
|
||||
u8_t *attention);
|
||||
|
||||
int bt_mesh_health_attention_set(u16_t net_idx, u16_t addr, u16_t app_idx,
|
||||
u8_t attention, u8_t *updated_attention);
|
||||
|
||||
s32_t bt_mesh_health_cli_timeout_get(void);
|
||||
void bt_mesh_health_cli_timeout_set(s32_t timeout);
|
||||
|
||||
|
|
|
@ -133,10 +133,37 @@ static void health_period_status(struct bt_mesh_model *model,
|
|||
k_sem_give(&health_cli->op_sync);
|
||||
}
|
||||
|
||||
struct health_attention_param {
|
||||
u8_t *attention;
|
||||
};
|
||||
|
||||
static void health_attention_status(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
struct health_attention_param *param;
|
||||
|
||||
BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s",
|
||||
ctx->net_idx, ctx->app_idx, ctx->addr, buf->len,
|
||||
bt_hex(buf->data, buf->len));
|
||||
|
||||
if (health_cli->op_pending != OP_ATTENTION_STATUS) {
|
||||
BT_WARN("Unexpected Health Attention Status message");
|
||||
return;
|
||||
}
|
||||
|
||||
param = health_cli->op_param;
|
||||
|
||||
*param->attention = net_buf_simple_pull_u8(buf);
|
||||
|
||||
k_sem_give(&health_cli->op_sync);
|
||||
}
|
||||
|
||||
const struct bt_mesh_model_op bt_mesh_health_cli_op[] = {
|
||||
{ OP_HEALTH_FAULT_STATUS, 3, health_fault_status },
|
||||
{ OP_HEALTH_CURRENT_STATUS, 3, health_current_status },
|
||||
{ OP_HEALTH_PERIOD_STATUS, 1, health_period_status },
|
||||
{ OP_ATTENTION_STATUS, 1, health_attention_status },
|
||||
BT_MESH_MODEL_OP_END,
|
||||
};
|
||||
|
||||
|
@ -170,6 +197,78 @@ static int cli_wait(void *param, u32_t op)
|
|||
return err;
|
||||
}
|
||||
|
||||
int bt_mesh_health_attention_get(u16_t net_idx, u16_t addr, u16_t app_idx,
|
||||
u8_t *attention)
|
||||
{
|
||||
struct net_buf_simple *msg = NET_BUF_SIMPLE(2 + 0 + 4);
|
||||
struct bt_mesh_msg_ctx ctx = {
|
||||
.net_idx = net_idx,
|
||||
.app_idx = app_idx,
|
||||
.addr = addr,
|
||||
.send_ttl = BT_MESH_TTL_DEFAULT,
|
||||
};
|
||||
struct health_attention_param param = {
|
||||
.attention = attention,
|
||||
};
|
||||
int err;
|
||||
|
||||
err = check_cli();
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
bt_mesh_model_msg_init(msg, OP_ATTENTION_GET);
|
||||
|
||||
err = bt_mesh_model_send(health_cli->model, &ctx, msg, NULL, NULL);
|
||||
if (err) {
|
||||
BT_ERR("model_send() failed (err %d)", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
return cli_wait(¶m, OP_ATTENTION_STATUS);
|
||||
}
|
||||
|
||||
int bt_mesh_health_attention_set(u16_t net_idx, u16_t addr, u16_t app_idx,
|
||||
u8_t attention, u8_t *updated_attention)
|
||||
{
|
||||
struct net_buf_simple *msg = NET_BUF_SIMPLE(2 + 1 + 4);
|
||||
struct bt_mesh_msg_ctx ctx = {
|
||||
.net_idx = net_idx,
|
||||
.app_idx = app_idx,
|
||||
.addr = addr,
|
||||
.send_ttl = BT_MESH_TTL_DEFAULT,
|
||||
};
|
||||
struct health_attention_param param = {
|
||||
.attention = updated_attention,
|
||||
};
|
||||
int err;
|
||||
|
||||
err = check_cli();
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (updated_attention) {
|
||||
bt_mesh_model_msg_init(msg, OP_ATTENTION_SET);
|
||||
} else {
|
||||
bt_mesh_model_msg_init(msg, OP_ATTENTION_SET_UNREL);
|
||||
}
|
||||
|
||||
net_buf_simple_add_u8(msg, attention);
|
||||
|
||||
err = bt_mesh_model_send(health_cli->model, &ctx, msg, NULL, NULL);
|
||||
if (err) {
|
||||
BT_ERR("model_send() failed (err %d)", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
if (!updated_attention) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return cli_wait(¶m, OP_ATTENTION_STATUS);
|
||||
}
|
||||
|
||||
int bt_mesh_health_period_get(u16_t net_idx, u16_t addr, u16_t app_idx,
|
||||
u8_t *divisor)
|
||||
{
|
||||
|
|
|
@ -1397,6 +1397,64 @@ static int cmd_period_set_unack(int argc, char *argv[])
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_attention_get(int argc, char *argv[])
|
||||
{
|
||||
u8_t attention;
|
||||
int err;
|
||||
|
||||
err = bt_mesh_health_attention_get(net.net_idx, net.dst, net.app_idx,
|
||||
&attention);
|
||||
if (err) {
|
||||
printk("Failed to send Health Attention Get (err %d)\n", err);
|
||||
} else {
|
||||
printk("Health Attention Timer: %u\n", attention);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_attention_set(int argc, char *argv[])
|
||||
{
|
||||
u8_t attention, updated_attention;
|
||||
int err;
|
||||
|
||||
if (argc < 2) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
attention = strtoul(argv[1], NULL, 0);
|
||||
|
||||
err = bt_mesh_health_attention_set(net.net_idx, net.dst, net.app_idx,
|
||||
attention, &updated_attention);
|
||||
if (err) {
|
||||
printk("Failed to send Health Attention Set (err %d)\n", err);
|
||||
} else {
|
||||
printk("Health Attention Timer: %u\n", updated_attention);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_attention_set_unack(int argc, char *argv[])
|
||||
{
|
||||
u8_t attention;
|
||||
int err;
|
||||
|
||||
if (argc < 2) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
attention = strtoul(argv[1], NULL, 0);
|
||||
|
||||
err = bt_mesh_health_attention_set(net.net_idx, net.dst, net.app_idx,
|
||||
attention, NULL);
|
||||
if (err) {
|
||||
printk("Failed to send Health Attention Set (err %d)\n", err);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cmd_add_fault(int argc, char *argv[])
|
||||
{
|
||||
u8_t fault_id;
|
||||
|
@ -1521,6 +1579,9 @@ static const struct shell_cmd mesh_commands[] = {
|
|||
{ "period-get", cmd_period_get, "" },
|
||||
{ "period-set", cmd_period_set, "<divisor>" },
|
||||
{ "period-set-unack", cmd_period_set_unack, "<divisor>" },
|
||||
{ "attention-get", cmd_attention_get, "" },
|
||||
{ "attention-set", cmd_attention_set, "<timer>" },
|
||||
{ "attention-set-unack", cmd_attention_set_unack, "<timer>" },
|
||||
|
||||
/* Health Server Model Operations */
|
||||
{ "add-fault", cmd_add_fault, "<Fault ID>" },
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue