Example/test ng_udp

Hi,

Could you add an example/test for the new ng_udp? It will be easier to use it then. @haukepetersen @authmillenon

Cheers,

Hi Baptiste, as discussed in #2720 [1] an example will follow in a short amount of time.

Cheers, Martine

[1] https://github.com/RIOT-OS/RIOT/pull/2720#issuecomment-96582422

Hi Baptiste,

there is one small thing missing, namely a concept for initializing radio drivers and MAC layers in an automated fashion (as in auto_init). But I have already a concept in mind, hopefully I will get it done tomorrow - and with that I will update the example for UDP. So stay tuned :slight_smile:

Cheers, Hauke

Great Hauke! I’m looking forward to using the all new network stack from UDP to the transceiver :slight_smile:

Hey Baptiste, though there is no example yet you can use the new network stack never the less. Just take one of the test applications for the device you want to use and compile them with the modules ng_ipv6 and ng_udp. If you use an IEEE 802.15.4 device (which are currently the only ones in master) you need to add ng_sixlowpan_frag, too. The threads will be started properly by auto_init (which should have been initialized automatically).

If you want to listen on a port just call

ng_netreg_t entry = { thread_getpid(), port }; ng_netreg_register(NG_NETTYPE_UDP, &entry);

while (1) { msg_receive(&msg);

switch (msg.type) { NG_NETAPI_MSG_TYPE_RCV: /* do something with the ng_pktsnip_t* at msg.content.ptr */ break; } }

If you want to send a pktsnip payload via UDP use:

ng_netreg_t *sendto = ng_netreg_lookup(NG_NETTYPE_UDP, NG_NETREG_DEMUX_CTX_ALL); udp = ng_udp_hdr_build(payload, sport, 2, dport, 2); ipv6 = ng_ipv6_hdr_build(udp, NULL, 0, (uint8_t *)dst_addr, 16);

ng_pktbuf_hold(ipv6, ng_netreg_num(NG_NETTYPE_UDP, NG_NETREG_DEMUX_CTX_ALL) - 1); while (sendto) { ng_netapi_send(sendto->pid, ipv6); sendto = sendto->next; }

Be adviced that it is always a good idea to check if the returned values are not NULL (in case of a full packet buffer). Also: I did not compile this, so be warned of syntax errors :wink:

Cheers, Martine

Thanks Martine! Will try this tomorrow!