apps/wireless/bluetooth/btsak: Add commands to get the result of GATT read and write operations.
This commit is contained in:
parent
8a0e690483
commit
141abff299
@ -258,15 +258,19 @@ void btsak_cmd_discover(FAR struct btsak_s *btsak, int argc,
|
|||||||
FAR char *argv[]);
|
FAR char *argv[]);
|
||||||
void btsak_cmd_gatt_discover_characteristic(FAR struct btsak_s *btsak,
|
void btsak_cmd_gatt_discover_characteristic(FAR struct btsak_s *btsak,
|
||||||
int argc, FAR char *argv[]);
|
int argc, FAR char *argv[]);
|
||||||
void btsak_cmd_gat_discover_descriptor(FAR struct btsak_s *btsak,
|
void btsak_cmd_gatt_discover_descriptor(FAR struct btsak_s *btsak,
|
||||||
int argc, FAR char *argv[]);
|
int argc, FAR char *argv[]);
|
||||||
void btsak_cmd_gat_discover_get(FAR struct btsak_s *btsak,
|
void btsak_cmd_gatt_discover_get(FAR struct btsak_s *btsak,
|
||||||
int argc, FAR char *argv[]);
|
int argc, FAR char *argv[]);
|
||||||
void btsak_cmd_gatt_read(FAR struct btsak_s *btsak, int argc,
|
void btsak_cmd_gatt_read(FAR struct btsak_s *btsak, int argc,
|
||||||
FAR char *argv[]);
|
FAR char *argv[]);
|
||||||
void btsak_cmd_gatt_read_multiple(FAR struct btsak_s *btsak, int argc,
|
void btsak_cmd_gatt_read_multiple(FAR struct btsak_s *btsak, int argc,
|
||||||
FAR char *argv[]);
|
FAR char *argv[]);
|
||||||
|
void btsak_cmd_gatt_read_get(FAR struct btsak_s *btsak, int argc,
|
||||||
|
FAR char *argv[]);
|
||||||
void btsak_cmd_gatt_write(FAR struct btsak_s *btsak, int argc,
|
void btsak_cmd_gatt_write(FAR struct btsak_s *btsak, int argc,
|
||||||
FAR char *argv[]);
|
FAR char *argv[]);
|
||||||
|
void btsak_cmd_gatt_write_get(FAR struct btsak_s *btsak, int argc,
|
||||||
|
FAR char *argv[]);
|
||||||
|
|
||||||
#endif /* __APPS_EXAMPLES_WIRELESS_BLUETOOTH_BTSAK_BTSAK_H */
|
#endif /* __APPS_EXAMPLES_WIRELESS_BLUETOOTH_BTSAK_BTSAK_H */
|
||||||
|
@ -152,10 +152,14 @@ static void btsak_cmd_discover_common(FAR struct btsak_s *btsak,
|
|||||||
fprintf(stderr, "ERROR: ioctl(SIOCBTDISCOVER) failed: %d\n",
|
fprintf(stderr, "ERROR: ioctl(SIOCBTDISCOVER) failed: %d\n",
|
||||||
errno);
|
errno);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Discovery in progress..\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
close(sockfd);
|
close(sockfd);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public functions
|
* Public functions
|
||||||
@ -219,10 +223,10 @@ void btsak_cmd_gatt_exchange_mtu(FAR struct btsak_s *btsak, int argc,
|
|||||||
{
|
{
|
||||||
printf("MTU exchange pending...\n");
|
printf("MTU exchange pending...\n");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
close(sockfd);
|
close(sockfd);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: btsak_cmd_gatt_exchange_mtu_result
|
* Name: btsak_cmd_gatt_exchange_mtu_result
|
||||||
@ -266,6 +270,8 @@ void btsak_cmd_gatt_exchange_mtu_result(FAR struct btsak_s *btsak, int argc,
|
|||||||
printf("\tResult: %u\n", btreq.btr_exresult);
|
printf("\tResult: %u\n", btreq.btr_exresult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
close(sockfd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,28 +303,28 @@ void btsak_cmd_gatt_discover_characteristic(FAR struct btsak_s *btsak,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: btsak_cmd_gat_discover_descriptor
|
* Name: btsak_cmd_gatt_discover_descriptor
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* gatt [-h] descriptor [-h] <addr> public|private command
|
* gatt [-h] descriptor [-h] <addr> public|private command
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
void btsak_cmd_gat_discover_descriptor(FAR struct btsak_s *btsak,
|
void btsak_cmd_gatt_discover_descriptor(FAR struct btsak_s *btsak,
|
||||||
int argc, FAR char *argv[])
|
int argc, FAR char *argv[])
|
||||||
{
|
{
|
||||||
btsak_cmd_discover_common(btsak, argc, argv, GATT_DISCOVER_DESC);
|
btsak_cmd_discover_common(btsak, argc, argv, GATT_DISCOVER_DESC);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: btsak_cmd_gat_discover_get
|
* Name: btsak_cmd_gatt_discover_get
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* gatt [-h] dget [-h]
|
* gatt [-h] dget [-h]
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
void btsak_cmd_gat_discover_get(FAR struct btsak_s *btsak,
|
void btsak_cmd_gatt_discover_get(FAR struct btsak_s *btsak,
|
||||||
int argc, FAR char *argv[])
|
int argc, FAR char *argv[])
|
||||||
{
|
{
|
||||||
FAR struct bt_discresonse_s *rsp;
|
FAR struct bt_discresonse_s *rsp;
|
||||||
@ -341,7 +347,7 @@ void btsak_cmd_gat_discover_get(FAR struct btsak_s *btsak,
|
|||||||
btsak_gatt_showusage(btsak->progname, argv[0], EXIT_FAILURE);
|
btsak_gatt_showusage(btsak->progname, argv[0], EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Perform the IOCTL to start the discovery */
|
/* Perform the IOCTL to get the result of the discovery */
|
||||||
|
|
||||||
strncpy(btreq.btr_name, btsak->ifname, IFNAMSIZ);
|
strncpy(btreq.btr_name, btsak->ifname, IFNAMSIZ);
|
||||||
btreq.btr_gnrsp = 8;
|
btreq.btr_gnrsp = 8;
|
||||||
@ -439,10 +445,10 @@ void btsak_cmd_gatt_read(FAR struct btsak_s *btsak, int argc,
|
|||||||
{
|
{
|
||||||
printf("Read pending...\n");
|
printf("Read pending...\n");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
close(sockfd);
|
close(sockfd);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: btsak_cmd_gatt_read_multiple
|
* Name: btsak_cmd_gatt_read_multiple
|
||||||
@ -511,10 +517,88 @@ void btsak_cmd_gatt_read_multiple(FAR struct btsak_s *btsak, int argc,
|
|||||||
{
|
{
|
||||||
printf("Read pending...\n");
|
printf("Read pending...\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
close(sockfd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: btsak_cmd_gatt_read_get
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* gatt [-h] rget [-h]
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void btsak_cmd_gatt_read_get(FAR struct btsak_s *btsak, int argc,
|
||||||
|
FAR char *argv[])
|
||||||
|
{
|
||||||
|
struct btreq_s btreq;
|
||||||
|
uint8_t data[HCI_GATTRD_DATA];
|
||||||
|
int sockfd;
|
||||||
|
int ret;
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
/* Check for help command */
|
||||||
|
|
||||||
|
if (argc == 2 && strcmp(argv[1], "-h") == 0)
|
||||||
|
{
|
||||||
|
btsak_gatt_showusage(btsak->progname, argv[0], EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc != 1)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: No arguments expected\n");
|
||||||
|
btsak_gatt_showusage(btsak->progname, argv[0], EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Perform the IOCTL to start the discovery */
|
||||||
|
|
||||||
|
memset(&btreq, 0, sizeof(struct btreq_s));
|
||||||
|
strncpy(btreq.btr_name, btsak->ifname, IFNAMSIZ);
|
||||||
|
btreq.btr_rdsize = HCI_GATTRD_DATA;
|
||||||
|
btreq.btr_rddata = data;
|
||||||
|
|
||||||
|
sockfd = btsak_socket(btsak);
|
||||||
|
if (sockfd >= 0)
|
||||||
|
{
|
||||||
|
ret = ioctl(sockfd, SIOCBTGATTRDGET, (unsigned long)((uintptr_t)&btreq));
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: ioctl(SIOCBTGATTRDGET) failed: %d\n", errno);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Has the read completed? */
|
||||||
|
|
||||||
|
else if (btreq.btr_rdpending)
|
||||||
|
{
|
||||||
|
printf("Read pending. Data not yet available.\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Show the results that we obtained */
|
||||||
|
|
||||||
|
printf("Read:\n");
|
||||||
|
for (i = 0; i < btreq.btr_rdsize; i += 16)
|
||||||
|
{
|
||||||
|
for (j = 0; j < 16 && (i + j) < btreq.btr_rdsize; j++)
|
||||||
|
{
|
||||||
|
if (j == 8)
|
||||||
|
{
|
||||||
|
putchar(' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
printf(" %02x", data[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
putchar('\n');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
close(sockfd);
|
close(sockfd);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: btsak_cmd_gatt_write
|
* Name: btsak_cmd_gatt_write
|
||||||
@ -590,7 +674,54 @@ void btsak_cmd_gatt_write(FAR struct btsak_s *btsak, int argc,
|
|||||||
{
|
{
|
||||||
printf("Write pending...\n");
|
printf("Write pending...\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
close(sockfd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: btsak_cmd_gatt_write_get
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* gatt [-h] dget [-h]
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void btsak_cmd_gatt_write_get(FAR struct btsak_s *btsak, int argc,
|
||||||
|
FAR char *argv[])
|
||||||
|
{
|
||||||
|
struct btreq_s btreq;
|
||||||
|
int sockfd;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/* Perform the IOCTL to recover the result of the write operation */
|
||||||
|
|
||||||
|
strncpy(btreq.btr_name, btsak->ifname, IFNAMSIZ);
|
||||||
|
|
||||||
|
sockfd = btsak_socket(btsak);
|
||||||
|
if (sockfd >= 0)
|
||||||
|
{
|
||||||
|
ret = ioctl(sockfd, SIOCBTGATTWRGET, (unsigned long)((uintptr_t)&btreq));
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: ioctl(SIOCBTGATTWRGET) failed: %d\n",
|
||||||
|
errno);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Write Result:\n");
|
||||||
|
if (btreq.btr_wrpending)
|
||||||
|
{
|
||||||
|
printf("\tState: Pending\n");
|
||||||
|
printf("\tResult: Not yet available\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("\tState: Complete\n");
|
||||||
|
printf("\tResult: %u\n", btreq.btr_wrresult);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
close(sockfd);
|
close(sockfd);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -139,12 +139,12 @@ static const struct btsak_command_s g_btsak_gatt_commands[] =
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"descriptor",
|
"descriptor",
|
||||||
(CODE void *)btsak_cmd_gat_discover_descriptor,
|
(CODE void *)btsak_cmd_gatt_discover_descriptor,
|
||||||
"[-h] <addr> public|private [<start> [<end>]]"
|
"[-h] <addr> public|private [<start> [<end>]]"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"dget",
|
"dget",
|
||||||
(CODE void *)btsak_cmd_gat_discover_get,
|
(CODE void *)btsak_cmd_gatt_discover_get,
|
||||||
"[-h]"
|
"[-h]"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -157,10 +157,20 @@ static const struct btsak_command_s g_btsak_gatt_commands[] =
|
|||||||
(CODE void *)btsak_cmd_gatt_read_multiple,
|
(CODE void *)btsak_cmd_gatt_read_multiple,
|
||||||
"[-h] <addr> public|private <handle> [<handle> [<handle>]..]"
|
"[-h] <addr> public|private <handle> [<handle> [<handle>]..]"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"rget",
|
||||||
|
(CODE void *)btsak_cmd_gatt_read_get,
|
||||||
|
"[-h]"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"write",
|
"write",
|
||||||
(CODE void *)btsak_cmd_gatt_write,
|
(CODE void *)btsak_cmd_gatt_write,
|
||||||
"[-h] <addr> public|private <handle> <byte> [<byte> [<byte>]..]"
|
"[-h] <addr> public|private <handle> <byte> [<byte> [<byte>]..]"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"wget",
|
||||||
|
(CODE void *)btsak_cmd_gatt_write_get,
|
||||||
|
"[-h]"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user