mirror of
https://git.kernel.org/pub/scm/bluetooth/bluez.git
synced 2024-11-15 16:24:28 +08:00
Move attr_data_from_string() to utils.c
The attr_data_from_string() function will be used in interactive and usual gatttool so this function was moved to common file utils.c.
This commit is contained in:
parent
607c54cbd9
commit
d3a5c56882
@ -313,25 +313,6 @@ static gboolean characteristics_read(gpointer user_data)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static size_t attr_data_from_string(const char *str, uint8_t **data)
|
||||
{
|
||||
char tmp[3];
|
||||
size_t size, i;
|
||||
|
||||
size = strlen(str) / 2;
|
||||
*data = g_try_malloc0(size);
|
||||
if (*data == NULL)
|
||||
return 0;
|
||||
|
||||
tmp[2] = '\0';
|
||||
for (i = 0; i < size; i++) {
|
||||
memcpy(tmp, str + (i * 2), 2);
|
||||
(*data)[i] = (uint8_t) strtol(tmp, NULL, 16);
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
static void mainloop_quit(gpointer user_data)
|
||||
{
|
||||
uint8_t *value = user_data;
|
||||
@ -356,7 +337,7 @@ static gboolean characteristics_write(gpointer user_data)
|
||||
goto error;
|
||||
}
|
||||
|
||||
len = attr_data_from_string(opt_value, &value);
|
||||
len = gatt_attr_data_from_string(opt_value, &value);
|
||||
if (len == 0) {
|
||||
g_printerr("Invalid value\n");
|
||||
goto error;
|
||||
@ -408,7 +389,7 @@ static gboolean characteristics_write_req(gpointer user_data)
|
||||
goto error;
|
||||
}
|
||||
|
||||
len = attr_data_from_string(opt_value, &value);
|
||||
len = gatt_attr_data_from_string(opt_value, &value);
|
||||
if (len == 0) {
|
||||
g_printerr("Invalid value\n");
|
||||
goto error;
|
||||
|
@ -25,3 +25,4 @@ int interactive(gchar *dst, gboolean le);
|
||||
GIOChannel *gatt_connect(const gchar *src, const gchar *dst,
|
||||
const gchar *sec_level, int psm, int mtu,
|
||||
BtIOConnect connect_cb);
|
||||
size_t gatt_attr_data_from_string(const char *str, uint8_t **data);
|
||||
|
@ -104,3 +104,22 @@ GIOChannel *gatt_connect(const gchar *src, const gchar *dst,
|
||||
|
||||
return chan;
|
||||
}
|
||||
|
||||
size_t gatt_attr_data_from_string(const char *str, uint8_t **data)
|
||||
{
|
||||
char tmp[3];
|
||||
size_t size, i;
|
||||
|
||||
size = strlen(str) / 2;
|
||||
*data = g_try_malloc0(size);
|
||||
if (*data == NULL)
|
||||
return 0;
|
||||
|
||||
tmp[2] = '\0';
|
||||
for (i = 0; i < size; i++) {
|
||||
memcpy(tmp, str + (i * 2), 2);
|
||||
(*data)[i] = (uint8_t) strtol(tmp, NULL, 16);
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user