client: Add support for optional gatt read offset parameter 74/204974/1
authorGrzegorz Kolodziejczyk <grzegorz.kolodziejczyk@codecoup.pl>
Thu, 26 Apr 2018 12:31:59 +0000 (14:31 +0200)
committerAmit Purwar <amit.purwar@samsung.com>
Mon, 29 Apr 2019 04:02:58 +0000 (09:32 +0530)
This patch extends missing optional gatt read offset parameter.

Change-Id: I74c8bf0ed060310a9d1c87f4d13e81e1f348c510
Signed-off-by: Amit Purwar <amit.purwar@samsung.com>
client/gatt.c
client/gatt.h
client/main.c

index 7d63c02..1766651 100755 (executable)
@@ -518,6 +518,7 @@ static void read_reply(DBusMessage *message, void *user_data)
 static void read_setup(DBusMessageIter *iter, void *user_data)
 {
        DBusMessageIter dict;
+       uint16_t *offset = user_data;
 
        dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
                                        DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
@@ -525,14 +526,16 @@ static void read_setup(DBusMessageIter *iter, void *user_data)
                                        DBUS_TYPE_VARIANT_AS_STRING
                                        DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
                                        &dict);
-       /* TODO: Add offset support */
+
+       g_dbus_dict_append_entry(&dict, "offset", DBUS_TYPE_UINT16, offset);
+
        dbus_message_iter_close_container(iter, &dict);
 }
 
-static void read_attribute(GDBusProxy *proxy)
+static void read_attribute(GDBusProxy *proxy, uint16_t offset)
 {
        if (g_dbus_proxy_method_call(proxy, "ReadValue", read_setup, read_reply,
-                                                       NULL, NULL) == FALSE) {
+                                               &offset, NULL) == FALSE) {
                bt_shell_printf("Failed to read\n");
                return bt_shell_noninteractive_quit(EXIT_FAILURE);
        }
@@ -540,14 +543,19 @@ static void read_attribute(GDBusProxy *proxy)
        bt_shell_printf("Attempting to read %s\n", g_dbus_proxy_get_path(proxy));
 }
 
-void gatt_read_attribute(GDBusProxy *proxy)
+void gatt_read_attribute(GDBusProxy *proxy, int argc, char *argv[])
 {
        const char *iface;
+       uint16_t offset = 0;
 
        iface = g_dbus_proxy_get_interface(proxy);
        if (!strcmp(iface, "org.bluez.GattCharacteristic1") ||
                                !strcmp(iface, "org.bluez.GattDescriptor1")) {
-               read_attribute(proxy);
+
+               if (argc == 2)
+                       offset = atoi(argv[1]);
+
+               read_attribute(proxy, offset);
                return;
        }
 
index f4c36b8..274c76b 100755 (executable)
@@ -34,7 +34,7 @@ void gatt_list_attributes(const char *device);
 GDBusProxy *gatt_select_attribute(GDBusProxy *parent, const char *path);
 char *gatt_attribute_generator(const char *text, int state);
 
-void gatt_read_attribute(GDBusProxy *proxy);
+void gatt_read_attribute(GDBusProxy *proxy, int argc, char *argv[]);
 void gatt_write_attribute(GDBusProxy *proxy, const char *arg);
 void gatt_notify_attribute(GDBusProxy *proxy, bool enable);
 
index 53ff4c5..a895bcf 100644 (file)
@@ -1914,7 +1914,7 @@ static void cmd_read(int argc, char *argv[])
                return bt_shell_noninteractive_quit(EXIT_FAILURE);
        }
 
-       gatt_read_attribute(default_attr);
+       gatt_read_attribute(default_attr, argc, argv);
 }
 
 static void cmd_write(int argc, char *argv[])
@@ -2421,7 +2421,7 @@ static const struct bt_shell_menu gatt_menu = {
                                "Select attribute", attribute_generator },
        { "attribute-info", "[attribute/UUID]",  cmd_attribute_info,
                                "Select attribute", attribute_generator },
-       { "read",         NULL,       cmd_read, "Read attribute value" },
+       { "read", "[offset]", cmd_read, "Read attribute value" },
        { "write",        "<data=xx xx ...>", cmd_write,
                                                "Write attribute value" },
        { "acquire-write", NULL, cmd_acquire_write,