Bluetooth: Mesh: shell: Convert hb-pub-set command to hb-pub
Convert the hb-pub-set command to a more generic hb-pub that can be
used both for getting and setting the Heartrate Publication State.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
diff --git a/subsys/bluetooth/host/mesh/shell.c b/subsys/bluetooth/host/mesh/shell.c
index 6c1f576..93972aa 100644
--- a/subsys/bluetooth/host/mesh/shell.c
+++ b/subsys/bluetooth/host/mesh/shell.c
@@ -705,16 +705,41 @@
return 0;
}
-static int cmd_hb_pub_set(int argc, char *argv[])
+static int hb_pub_get(int argc, char *argv[])
{
u8_t status, count, period, ttl;
u16_t pub_dst, feat, pub_net_idx;
int err;
- if (argc < 7) {
- return -EINVAL;
+ err = bt_mesh_cfg_hb_pub_get(net.net_idx, net.dst, &pub_dst, &count,
+ &period, &ttl, &feat, &pub_net_idx,
+ &status);
+ if (err) {
+ printk("Heartbeat Publication Get failed (err %d)\n", err);
+ return 0;
}
+ if (status) {
+ printk("Heartbeat Publication Get failed (status 0x%02x)\n",
+ status);
+ return 0;
+ }
+
+ printk("Heartbeat publication:\n");
+ printk("\tdst 0x%04x count 0x%02x period 0x%02x\n",
+ pub_dst, count, period);
+ printk("\tttl 0x%02x feat 0x%04x net_idx 0x%04x\n",
+ ttl, feat, pub_net_idx);
+
+ return 0;
+}
+
+static int hb_pub_set(int argc, char *argv[])
+{
+ u8_t status, count, period, ttl;
+ u16_t pub_dst, feat, pub_net_idx;
+ int err;
+
pub_dst = strtoul(argv[1], NULL, 0);
count = strtoul(argv[2], NULL, 0);
period = strtoul(argv[3], NULL, 0);
@@ -739,6 +764,19 @@
return 0;
}
+static int cmd_hb_pub(int argc, char *argv[])
+{
+ if (argc > 1) {
+ if (argc < 7) {
+ return -EINVAL;
+ }
+
+ return hb_pub_set(argc, argv);
+ } else {
+ return hb_pub_get(argc, argv);
+ }
+}
+
#if defined(CONFIG_BT_MESH_PROV)
static int cmd_pb(bt_mesh_prov_bearer_t bearer, int argc, char *argv[])
{
@@ -844,8 +882,8 @@
{ "mod-sub-add", cmd_mod_sub_add,
"<elem addr> <sub addr> <Model ID> [Company ID]" },
{ "hb-sub-set", cmd_hb_sub_set, "<src> <dst> <period>" },
- { "hb-pub-set", cmd_hb_pub_set,
- "<dst> <count> <period> <ttl> <features> <NetKeyIndex>" },
+ { "hb-pub", cmd_hb_pub,
+ "[<dst> <count> <period> <ttl> <features> <NetKeyIndex>]" },
{ NULL, NULL, NULL}
};