From e10e57959334f797df45ac83f31a27e6bdc1dbbb Mon Sep 17 00:00:00 2001 From: Ken Bannister <kb2ma@runbox.com> Date: Thu, 17 Nov 2016 00:03:08 -0500 Subject: [PATCH] gcoap: Update CLI example for rebase on sock --- examples/gcoap/Makefile | 5 ++--- examples/gcoap/Makefile.slip | 5 ++--- examples/gcoap/README.md | 2 +- examples/gcoap/gcoap_cli.c | 13 +++++++++---- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/examples/gcoap/Makefile b/examples/gcoap/Makefile index e59ed27b13..8897ddeaaa 100644 --- a/examples/gcoap/Makefile +++ b/examples/gcoap/Makefile @@ -1,4 +1,4 @@ -# Default Makefile, for host native networking +# Default Makefile, for host native GNRC-based networking # name of your application APPLICATION = gcoap @@ -29,8 +29,6 @@ BOARD_BLACKLIST := nrf52dk USEPKG += nanocoap # Required by nanocoap, but only due to issue #5959. USEMODULE += posix -# Required by nanocoap to compile nanocoap_sock. -USEMODULE += gnrc_sock_udp # Include packages that pull up and auto-init the link layer. # NOTE: 6LoWPAN will be included if IEEE802.15.4 devices are present @@ -38,6 +36,7 @@ USEMODULE += gnrc_netdev_default USEMODULE += auto_init_gnrc_netif # Specify the mandatory networking modules USEMODULE += gnrc_ipv6_default +USEMODULE += gnrc_sock_udp USEMODULE += gcoap # Additional networking modules that can be dropped if not needed USEMODULE += gnrc_icmpv6_echo diff --git a/examples/gcoap/Makefile.slip b/examples/gcoap/Makefile.slip index abd5771863..8cb8a5fec1 100644 --- a/examples/gcoap/Makefile.slip +++ b/examples/gcoap/Makefile.slip @@ -1,4 +1,4 @@ -# Border router Makefile for SLIP based networking +# Border router Makefile for GNRC and SLIP based networking # Assumes use of SAMR21 board # name of your application @@ -45,14 +45,13 @@ CFLAGS += -DSLIP_BAUDRATE=$(SLIP_BAUDRATE) USEPKG += nanocoap # Required by nanocoap, but only due to issue #5959. USEMODULE += posix -# Required by nanocoap to compile nanocoap_sock. -USEMODULE += gnrc_sock_udp # Include packages that pull up and auto-init the link layer. # NOTE: 6LoWPAN will be included if IEEE802.15.4 devices are present USEMODULE += gnrc_netdev_default USEMODULE += auto_init_gnrc_netif # Specify the mandatory networking modules +USEMODULE += gnrc_sock_udp USEMODULE += gcoap # Add a routing protocol USEMODULE += gnrc_rpl diff --git a/examples/gcoap/README.md b/examples/gcoap/README.md index 46ccdcabb4..a795838534 100644 --- a/examples/gcoap/README.md +++ b/examples/gcoap/README.md @@ -1,6 +1,6 @@ # gcoap Example -This application provides command line access to gcoap, a GNRC implementation of CoAP. See the [CoAP spec][1] for background, and the Modules>Networking>GNRC>CoAP topic in the source documentation for the structure of the implementation. +This application provides command line access to gcoap, a high-level API for CoAP messaging. See the [CoAP spec][1] for background, and the Modules>Networking>CoAP topic in the source documentation for detailed usage instructions and implementation notes. We support two setup options for this example: diff --git a/examples/gcoap/gcoap_cli.c b/examples/gcoap/gcoap_cli.c index 75de7dceee..69e774de71 100644 --- a/examples/gcoap/gcoap_cli.c +++ b/examples/gcoap/gcoap_cli.c @@ -96,22 +96,27 @@ static ssize_t _stats_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len) static size_t _send(uint8_t *buf, size_t len, char *addr_str, char *port_str) { ipv6_addr_t addr; - uint16_t port; size_t bytes_sent; + sock_udp_ep_t remote; + + remote.family = AF_INET6; + remote.netif = SOCK_ADDR_ANY_NETIF; /* parse destination address */ if (ipv6_addr_from_str(&addr, addr_str) == NULL) { puts("gcoap_cli: unable to parse destination address"); return 0; } + memcpy(&remote.addr.ipv6[0], &addr.u8[0], sizeof(addr.u8)); + /* parse port */ - port = (uint16_t)atoi(port_str); - if (port == 0) { + remote.port = (uint16_t)atoi(port_str); + if (remote.port == 0) { puts("gcoap_cli: unable to parse destination port"); return 0; } - bytes_sent = gcoap_req_send(buf, len, &addr, port, _resp_handler); + bytes_sent = gcoap_req_send2(buf, len, &remote, _resp_handler); if (bytes_sent > 0) { req_count++; } -- GitLab