From da86ae0cb6b0f22f975eecd99e3ba19b24359e29 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Mon, 29 May 2017 13:56:00 +0300 Subject: [PATCH] Bluetooth: Shell: Rework gatt-write-signed This makes gatt-write-signed to reuse cmd_gatt_write_without_rsp since it is quite similar and that adds the ability to send multiple octecs instead of just a single byte. Signed-off-by: Luiz Augusto von Dentz --- subsys/bluetooth/shell/bt.c | 4 ++-- subsys/bluetooth/shell/gatt.c | 29 +++-------------------------- subsys/bluetooth/shell/gatt.h | 1 - 3 files changed, 5 insertions(+), 29 deletions(-) diff --git a/subsys/bluetooth/shell/bt.c b/subsys/bluetooth/shell/bt.c index ef1979ab220..b1503453f60 100644 --- a/subsys/bluetooth/shell/bt.c +++ b/subsys/bluetooth/shell/bt.c @@ -2007,8 +2007,8 @@ static const struct shell_cmd bt_commands[] = { { "gatt-write", cmd_gatt_write, " [length]" }, { "gatt-write-without-response", cmd_gatt_write_without_rsp, " [length]" }, - { "gatt-write-signed", cmd_gatt_write_signed, - " " }, + { "gatt-write-signed", cmd_gatt_write_without_rsp, + " [length]" }, { "gatt-subscribe", cmd_gatt_subscribe, " [ind]" }, { "gatt-unsubscribe", cmd_gatt_unsubscribe, HELP_NONE }, diff --git a/subsys/bluetooth/shell/gatt.c b/subsys/bluetooth/shell/gatt.c index c6e09c206de..678809301ba 100644 --- a/subsys/bluetooth/shell/gatt.c +++ b/subsys/bluetooth/shell/gatt.c @@ -351,6 +351,7 @@ int cmd_gatt_write(int argc, char *argv[]) int cmd_gatt_write_without_rsp(int argc, char *argv[]) { int err; + bool sign; u16_t handle; u16_t len; @@ -363,6 +364,7 @@ int cmd_gatt_write_without_rsp(int argc, char *argv[]) return -EINVAL; } + sign = !strcmp(argv[0], "gatt-write-signed"); handle = strtoul(argv[1], NULL, 16); gatt_write_buf[0] = strtoul(argv[2], NULL, 16); len = 1; @@ -378,32 +380,7 @@ int cmd_gatt_write_without_rsp(int argc, char *argv[]) } err = bt_gatt_write_without_response(default_conn, handle, - gatt_write_buf, len, false); - printk("Write Complete (err %d)\n", err); - - return 0; -} - -int cmd_gatt_write_signed(int argc, char *argv[]) -{ - int err; - u16_t handle; - u8_t data; - - if (!default_conn) { - printk("Not connected\n"); - return 0; - } - - if (argc < 3) { - return -EINVAL; - } - - handle = strtoul(argv[1], NULL, 16); - data = strtoul(argv[2], NULL, 16); - - err = bt_gatt_write_without_response(default_conn, handle, &data, - sizeof(data), true); + gatt_write_buf, len, sign); printk("Write Complete (err %d)\n", err); return 0; diff --git a/subsys/bluetooth/shell/gatt.h b/subsys/bluetooth/shell/gatt.h index fb8e12a3d03..a12b84ef30a 100644 --- a/subsys/bluetooth/shell/gatt.h +++ b/subsys/bluetooth/shell/gatt.h @@ -19,7 +19,6 @@ int cmd_gatt_read(int argc, char *argv[]); int cmd_gatt_mread(int argc, char *argv[]); int cmd_gatt_write(int argc, char *argv[]); int cmd_gatt_write_without_rsp(int argc, char *argv[]); -int cmd_gatt_write_signed(int argc, char *argv[]); int cmd_gatt_subscribe(int argc, char *argv[]); int cmd_gatt_unsubscribe(int argc, char *argv[]); int cmd_gatt_register_test_svc(int argc, char *argv[]);