sys/shell/sc_nimble_netif: add ping subcommand

This commit is contained in:
Hauke Petersen 2021-06-08 12:08:53 +02:00
parent 3878096cce
commit b985ad2330

View File

@ -398,6 +398,13 @@ static void _cmd_update(int handle, int itvl, int timeout)
}
}
static void _on_echo_rsp(uint16_t gap_handle, uint32_t rtt, struct os_mbuf *om)
{
int handle = nimble_netif_conn_get_by_gaphandle(gap_handle);
printf("ECHO_RSP handle:%i rtt:%u size:%u\n",
handle, (unsigned)rtt, (unsigned)OS_MBUF_PKTLEN(om));
}
static int _ishelp(char *argv)
{
return memcmp(argv, "help", 4) == 0;
@ -418,9 +425,9 @@ int _nimble_netif_handler(int argc, char **argv)
{
if ((argc == 1) || _ishelp(argv[1])) {
#if !IS_USED(MODULE_NIMBLE_AUTOCONN) && !IS_USED(MODULE_NIMBLE_STATCONN)
printf("usage: %s [help|info|adv|scan|connect|close|update|chanmap]\n", argv[0]);
printf("usage: %s [help|info|adv|scan|connect|close|update|chanmap|ping]\n", argv[0]);
#else
printf("usage: %s [help|info|close|update|chanmap]\n", argv[0]);
printf("usage: %s [help|info|close|update|chanmap|ping]\n", argv[0]);
#endif
return 0;
}
@ -543,7 +550,21 @@ int _nimble_netif_handler(int argc, char **argv)
}
return 0;
}
else if ((memcmp(argv[1], "ping", 4) == 0)) {
if ((argc < 3) || _ishelp(argv[2])) {
printf("usage: %s %s <handle>\n", argv[0], argv[1]);
return 0;
}
int handle = atoi(argv[2]);
char *data = (argc > 3) ? argv[3] : NULL;
uint16_t data_len = (data != NULL) ? (uint16_t)strlen(data) : 0;
int res = nimble_netif_l2cap_ping(handle, _on_echo_rsp, data, data_len);
if (res != 0) {
printf("err: unable to send ping (%i)\n", res);
}
}
else {
printf("unable to parse the command. Use '%s help' for more help\n",
argv[0]);