summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruna Moreira <bruna.moreira@gmail.com>2013-12-18 15:46:00 -0400
committerJefferson Delfes <jefferson.delfes@gmail.com>2013-12-23 11:08:03 -0400
commit39232306910e88a6d545d64b1443dda867c686b4 (patch)
treeaf282915842843afa32799afc9c71fabd56478e4
parentfa5cf480647343b4b1e332ab73ad0ddfb3d6386a (diff)
Update read-char command for multiple connections
The connection ID was added in read-char command to add support for multiple connections.
-rw-r--r--btctl.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/btctl.c b/btctl.c
index 091d2e7..e2c64df 100644
--- a/btctl.c
+++ b/btctl.c
@@ -1293,36 +1293,40 @@ static void cmd_read_char(char *args) {
bt_status_t status;
service_info_t *svc_info;
char_info_t *char_info;
- int svc_id, char_id, auth;
+ connection_t *conn;
+ int svc_id, char_id, auth, conn_id;
- if (u.conn_id <= 0) {
- rl_printf("Not connected\n");
+ if (u.gattiface == NULL) {
+ rl_printf("Unable to BLE read-char: GATT interface not avaiable\n");
return;
}
- if (u.gattiface == NULL) {
- rl_printf("Unable to BLE read-char: GATT interface not avaiable\n");
+ if (sscanf(args, " %i %i %i %i ", &conn_id, &svc_id, &char_id, &auth)
+ != 4) {
+ rl_printf("Usage: read-char <connection ID> <serviceID> "
+ "<characteristicID> <auth>\n");
+ rl_printf(" auth - enable authentication (1) or not (0)\n");
return;
}
- if (u.svcs_size <= 0) {
- rl_printf("Run search-svc first to get all services list\n");
+ conn = get_connection(conn_id);
+ if (conn == NULL) {
+ rl_printf("Invalid connection ID\n");
return;
}
- if (sscanf(args, " %i %i %i ", &svc_id, &char_id, &auth) != 3) {
- rl_printf("Usage: read-char serviceID characteristicID auth\n");
- rl_printf(" auth - enable authentication (1) or not (0)\n");
+ if (conn->svcs_size <= 0) {
+ rl_printf("Run search-svc first to get all services list\n");
return;
}
- if (svc_id < 0 || svc_id >= u.svcs_size) {
+ if (svc_id < 0 || svc_id >= conn->svcs_size) {
rl_printf("Invalid serviceID: %i need to be between 0 and %i\n", svc_id,
- u.svcs_size - 1);
+ conn->svcs_size - 1);
return;
}
- svc_info = &u.svcs[svc_id];
+ svc_info = &conn->svcs[svc_id];
if (char_id < 0 || char_id >= svc_info->char_count) {
rl_printf("Invalid characteristicID, try to run characteristics "
"command.\n");
@@ -1330,7 +1334,7 @@ static void cmd_read_char(char *args) {
}
char_info = &svc_info->chars_buf[char_id];
- status = u.gattiface->client->read_characteristic(u.conn_id,
+ status = u.gattiface->client->read_characteristic(conn->conn_id,
&svc_info->svc_id,
&char_info->char_id,
auth);