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[]);
|
||||
void btsak_cmd_gatt_discover_characteristic(FAR struct btsak_s *btsak,
|
||||
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[]);
|
||||
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[]);
|
||||
void btsak_cmd_gatt_read(FAR struct btsak_s *btsak, int argc,
|
||||
FAR char *argv[]);
|
||||
void btsak_cmd_gatt_read_multiple(FAR struct btsak_s *btsak, int argc,
|
||||
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,
|
||||
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 */
|
||||
|
@ -152,10 +152,14 @@ static void btsak_cmd_discover_common(FAR struct btsak_s *btsak,
|
||||
fprintf(stderr, "ERROR: ioctl(SIOCBTDISCOVER) failed: %d\n",
|
||||
errno);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Discovery in progress..\n");
|
||||
}
|
||||
|
||||
close(sockfd);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public functions
|
||||
@ -219,10 +223,10 @@ void btsak_cmd_gatt_exchange_mtu(FAR struct btsak_s *btsak, int argc,
|
||||
{
|
||||
printf("MTU exchange pending...\n");
|
||||
}
|
||||
}
|
||||
|
||||
close(sockfd);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
||||
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:
|
||||
* 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[])
|
||||
{
|
||||
btsak_cmd_discover_common(btsak, argc, argv, GATT_DISCOVER_DESC);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: btsak_cmd_gat_discover_get
|
||||
* Name: btsak_cmd_gatt_discover_get
|
||||
*
|
||||
* Description:
|
||||
* 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[])
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/* Perform the IOCTL to start the discovery */
|
||||
/* Perform the IOCTL to get the result of the discovery */
|
||||
|
||||
strncpy(btreq.btr_name, btsak->ifname, IFNAMSIZ);
|
||||
btreq.btr_gnrsp = 8;
|
||||
@ -439,10 +445,10 @@ void btsak_cmd_gatt_read(FAR struct btsak_s *btsak, int argc,
|
||||
{
|
||||
printf("Read pending...\n");
|
||||
}
|
||||
}
|
||||
|
||||
close(sockfd);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* 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");
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* 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");
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -139,12 +139,12 @@ static const struct btsak_command_s g_btsak_gatt_commands[] =
|
||||
},
|
||||
{
|
||||
"descriptor",
|
||||
(CODE void *)btsak_cmd_gat_discover_descriptor,
|
||||
(CODE void *)btsak_cmd_gatt_discover_descriptor,
|
||||
"[-h] <addr> public|private [<start> [<end>]]"
|
||||
},
|
||||
{
|
||||
"dget",
|
||||
(CODE void *)btsak_cmd_gat_discover_get,
|
||||
(CODE void *)btsak_cmd_gatt_discover_get,
|
||||
"[-h]"
|
||||
},
|
||||
{
|
||||
@ -157,10 +157,20 @@ static const struct btsak_command_s g_btsak_gatt_commands[] =
|
||||
(CODE void *)btsak_cmd_gatt_read_multiple,
|
||||
"[-h] <addr> public|private <handle> [<handle> [<handle>]..]"
|
||||
},
|
||||
{
|
||||
"rget",
|
||||
(CODE void *)btsak_cmd_gatt_read_get,
|
||||
"[-h]"
|
||||
},
|
||||
{
|
||||
"write",
|
||||
(CODE void *)btsak_cmd_gatt_write,
|
||||
"[-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