Bluetooth: Mesh: Add support for Health Fault Clear messages

Add support for sending Clear and Clear Unacknowledged messages.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2017-11-22 13:25:35 +02:00 committed by Johan Hedberg
commit 987c68b7aa
3 changed files with 106 additions and 0 deletions

View file

@ -42,6 +42,10 @@ int bt_mesh_health_fault_get(u16_t net_idx, u16_t addr, u16_t app_idx,
u16_t cid, u8_t *test_id, u8_t *faults,
size_t *fault_count);
int bt_mesh_health_fault_clear(u16_t net_idx, u16_t addr, u16_t app_idx,
u16_t cid, u8_t *test_id, u8_t *faults,
size_t *fault_count);
s32_t bt_mesh_health_cli_timeout_get(void);
void bt_mesh_health_cli_timeout_set(s32_t timeout);

View file

@ -121,6 +121,59 @@ static int check_cli(void)
return 0;
}
int bt_mesh_health_fault_clear(u16_t net_idx, u16_t addr, u16_t app_idx,
u16_t cid, u8_t *test_id, u8_t *faults,
size_t *fault_count)
{
struct net_buf_simple *msg = NET_BUF_SIMPLE(2 + 2 + 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_fault_param param = {
.cid = cid,
.test_id = test_id,
.faults = faults,
.fault_count = fault_count,
};
int err;
err = check_cli();
if (err) {
return err;
}
if (test_id) {
bt_mesh_model_msg_init(msg, OP_HEALTH_FAULT_CLEAR);
} else {
bt_mesh_model_msg_init(msg, OP_HEALTH_FAULT_CLEAR_UNREL);
}
net_buf_simple_add_le16(msg, cid);
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 (!test_id) {
return 0;
}
health_cli->op_param = &param;
health_cli->op_pending = OP_HEALTH_FAULT_STATUS;
err = k_sem_take(&health_cli->op_sync, msg_timeout);
health_cli->op_pending = 0;
health_cli->op_param = NULL;
return err;
}
int bt_mesh_health_fault_get(u16_t net_idx, u16_t addr, u16_t app_idx,
u16_t cid, u8_t *test_id, u8_t *faults,
size_t *fault_count)

View file

@ -1242,6 +1242,53 @@ static int cmd_fault_get(int argc, char *argv[])
return 0;
}
static int cmd_fault_clear(int argc, char *argv[])
{
u8_t faults[32];
size_t fault_count;
u8_t test_id;
u16_t cid;
int err;
if (argc < 2) {
return -EINVAL;
}
cid = strtoul(argv[1], NULL, 0);
fault_count = sizeof(faults);
err = bt_mesh_health_fault_clear(net.net_idx, net.dst, net.app_idx,
cid, &test_id, faults, &fault_count);
if (err) {
printk("Failed to send Health Fault Clear (err %d)\n", err);
} else {
show_faults(test_id, cid, faults, fault_count);
}
return 0;
}
static int cmd_fault_clear_unack(int argc, char *argv[])
{
u16_t cid;
int err;
if (argc < 2) {
return -EINVAL;
}
cid = strtoul(argv[1], NULL, 0);
err = bt_mesh_health_fault_clear(net.net_idx, net.dst, net.app_idx,
cid, NULL, NULL, NULL);
if (err) {
printk("Health Fault Clear Unacknowledged failed (err %d)\n",
err);
}
return 0;
}
static int cmd_add_fault(int argc, char *argv[])
{
u8_t fault_id;
@ -1359,6 +1406,8 @@ static const struct shell_cmd mesh_commands[] = {
/* Health Client Model Operations */
{ "fault-get", cmd_fault_get, "<Company ID>" },
{ "fault-clear", cmd_fault_clear, "<Company ID>" },
{ "fault-clear-unack", cmd_fault_clear_unack, "Company ID>" },
/* Health Server Model Operations */
{ "add-fault", cmd_add_fault, "<Fault ID>" },