mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
tests/nanocoap_cli: add url command
This commit is contained in:
parent
7dc2f730d2
commit
2106ce4212
@ -29,11 +29,13 @@
|
||||
static msg_t _main_msg_queue[MAIN_QUEUE_SIZE];
|
||||
|
||||
extern int nanotest_client_cmd(int argc, char **argv);
|
||||
extern int nanotest_client_url_cmd(int argc, char **argv);
|
||||
extern int nanotest_server_cmd(int argc, char **argv);
|
||||
static int _list_all_inet6(int argc, char **argv);
|
||||
|
||||
static const shell_command_t shell_commands[] = {
|
||||
{ "client", "CoAP client", nanotest_client_cmd },
|
||||
{ "url", "CoAP client URL request", nanotest_client_url_cmd },
|
||||
{ "server", "CoAP server", nanotest_server_cmd },
|
||||
{ "inet6", "IPv6 addresses", _list_all_inet6 },
|
||||
{ NULL, NULL, NULL }
|
||||
|
@ -86,7 +86,7 @@ static ssize_t _send(coap_pkt_t *pkt, size_t len, char *addr_str, char *port_str
|
||||
int nanotest_client_cmd(int argc, char **argv)
|
||||
{
|
||||
/* Ordered like the RFC method code numbers, but off by 1. GET is code 0. */
|
||||
char *method_codes[] = {"get", "post", "put"};
|
||||
const char *method_codes[] = {"get", "post", "put"};
|
||||
unsigned buflen = 128;
|
||||
uint8_t buf[buflen];
|
||||
coap_pkt_t pkt;
|
||||
@ -167,3 +167,50 @@ int nanotest_client_cmd(int argc, char **argv)
|
||||
argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _blockwise_cb(void *arg, size_t offset, uint8_t *buf, size_t len, int more)
|
||||
{
|
||||
(void)arg;
|
||||
(void)more;
|
||||
|
||||
printf("offset %03u: ", (unsigned)offset);
|
||||
for (unsigned i = 0; i < len; ++i) {
|
||||
putchar(buf[i]);
|
||||
}
|
||||
puts("");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nanotest_client_url_cmd(int argc, char **argv)
|
||||
{
|
||||
/* Ordered like the RFC method code numbers, but off by 1. GET is code 0. */
|
||||
const char *method_codes[] = {"get", "post", "put"};
|
||||
|
||||
if (argc < 3) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
int code_pos = -1;
|
||||
for (size_t i = 0; i < ARRAY_SIZE(method_codes); i++) {
|
||||
if (strcmp(argv[1], method_codes[i]) == 0) {
|
||||
code_pos = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (code_pos == -1) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (code_pos != 0) {
|
||||
printf("TODO: implement %s request\n", method_codes[code_pos]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint8_t buffer[NANOCOAP_BLOCKWISE_BUF(COAP_BLOCKSIZE_32)];
|
||||
return nanocoap_get_blockwise_url(argv[2], COAP_BLOCKSIZE_32, buffer,
|
||||
_blockwise_cb, NULL);
|
||||
error:
|
||||
printf("usage: %s <get|post|put> <url> [data]\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user