1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

tests/net/nanocoap_cli: add get_non command

This commit is contained in:
Fabian Hüßler 2024-09-05 15:54:04 +02:00
parent 95b46ee2a5
commit d3417dad65
2 changed files with 28 additions and 0 deletions

View File

@ -53,6 +53,7 @@ extern int nanotest_client_url_cmd(int argc, char **argv);
extern int nanotest_server_cmd(int argc, char **argv);
extern int nanotest_client_put_cmd(int argc, char **argv);
extern int nanotest_client_put_non_cmd(int argc, char **argv);
extern int nanotest_client_get_non_cmd(int argc, char **argv);
static int _list_all_inet6(int argc, char **argv);
static const shell_command_t shell_commands[] = {
@ -60,6 +61,7 @@ static const shell_command_t shell_commands[] = {
{ "url", "CoAP client URL request", nanotest_client_url_cmd },
{ "put", "experimental put", nanotest_client_put_cmd },
{ "put_non", "non-confirmable put", nanotest_client_put_non_cmd },
{ "get_non", "non-confirmable get", nanotest_client_get_non_cmd },
{ "server", "CoAP server", nanotest_server_cmd },
{ "inet6", "IPv6 addresses", _list_all_inet6 },
{ NULL, NULL, NULL }

View File

@ -322,3 +322,29 @@ int nanotest_client_put_non_cmd(int argc, char **argv)
return res;
}
int nanotest_client_get_non_cmd(int argc, char **argv)
{
int res;
uint8_t response[CONFIG_NANOCOAP_BLOCKSIZE_DEFAULT];
if (argc < 2) {
printf("usage: %s <url>\n", argv[0]);
return 1;
}
nanocoap_sock_t sock;
nanocoap_sock_url_connect(argv[1], &sock);
res = nanocoap_sock_get_non(&sock, sock_urlpath(argv[1]), response, sizeof(response));
nanocoap_sock_close(&sock);
if (res >= 0) {
od_hex_dump(response, res, OD_WIDTH_DEFAULT);
}
else {
printf("error: %d\n", res);
}
return res;
}