Bluetooth: Mesh: shell: Convert hb-sub-set command to hb-sub
Convert the hb-ub-set command to a more generic hb-sub that can be
used both for getting and setting the Heartrate Subscription 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 93972aa..9cb2e3b 100644
--- a/subsys/bluetooth/host/mesh/shell.c
+++ b/subsys/bluetooth/host/mesh/shell.c
@@ -674,16 +674,38 @@
return 0;
}
-static int cmd_hb_sub_set(int argc, char *argv[])
+static int hb_sub_get(int argc, char *argv[])
+{
+ u8_t status, period, count, min, max;
+ u16_t src, dst;
+ int err;
+
+ err = bt_mesh_cfg_hb_sub_get(net.net_idx, net.dst, &src, &dst, &period,
+ &count, &min, &max, &status);
+ if (err) {
+ printk("Heartbeat Subscription Get failed (err %d)\n", err);
+ return 0;
+ }
+
+ if (status) {
+ printk("Heartbeat Subscription Get failed (status 0x%02x)\n",
+ status);
+ return 0;
+ }
+
+ printk("Heartbeat subscription:\n");
+ printk("\tsrc 0x%04x dst 0x%04x period 0x%02x\n", src, dst, period);
+ printk("\tcount 0x%02x min 0x%02x max 0x%02x\n", count, min, max);
+
+ return 0;
+}
+
+static int hb_sub_set(int argc, char *argv[])
{
u8_t status, period;
u16_t sub_src, sub_dst;
int err;
- if (argc < 4) {
- return -EINVAL;
- }
-
sub_src = strtoul(argv[1], NULL, 0);
sub_dst = strtoul(argv[2], NULL, 0);
period = strtoul(argv[3], NULL, 0);
@@ -705,6 +727,19 @@
return 0;
}
+static int cmd_hb_sub(int argc, char *argv[])
+{
+ if (argc > 1) {
+ if (argc < 4) {
+ return -EINVAL;
+ }
+
+ return hb_sub_set(argc, argv);
+ } else {
+ return hb_sub_get(argc, argv);
+ }
+}
+
static int hb_pub_get(int argc, char *argv[])
{
u8_t status, count, period, ttl;
@@ -881,7 +916,7 @@
"<addr> <AppIndex> <Model ID> [Company ID]" },
{ "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-sub", cmd_hb_sub, "[<src> <dst> <period>]" },
{ "hb-pub", cmd_hb_pub,
"[<dst> <count> <period> <ttl> <features> <NetKeyIndex>]" },
{ NULL, NULL, NULL}