diff --git a/RIOT/examples/test_lqi_rssi/Makefile b/RIOT/examples/test_lqi_rssi/Makefile new file mode 100755 index 0000000..38c273e --- /dev/null +++ b/RIOT/examples/test_lqi_rssi/Makefile @@ -0,0 +1,64 @@ +# name of your application +APPLICATION = test_lqi_rssi + +# If no BOARD is found in the environment, use this default: +BOARD ?= native + +# This has to be the absolute path to the RIOT base directory: +RIOTBASE ?= $(CURDIR)/../.. + +BOARD_INSUFFICIENT_MEMORY := airfy-beacon chronos msb-430 msb-430h nrf51dongle \ + nrf6310 nucleo-f103 nucleo-f334 pca10000 pca10005 spark-core \ + stm32f0discovery telosb weio wsn430-v1_3b wsn430-v1_4 \ + yunjia-nrf51822 z1 nucleo-f072 nucleo-f030 nucleo-f070 \ + microbit calliope-mini + +# 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 for IPv6 and UDP +USEMODULE += gnrc_ipv6_router_default +USEMODULE += gnrc_udp +# Add a routing protocol +USEMODULE += gnrc_rpl +USEMODULE += auto_init_gnrc_rpl +# This application dumps received packets to STDIO using the pktdump module +#USEMODULE += gnrc_pktdump +# Additional networking modules that can be dropped if not needed +USEMODULE += gnrc_icmpv6_echo +# Add also the shell, some shell commands +USEMODULE += shell +USEMODULE += shell_commands +USEMODULE += ps +USEMODULE += netstats_l2 +USEMODULE += netstats_ipv6 +USEMODULE += netstats_rpl +USEMODULE += at86rf231 +# Comment this out to disable code in RIOT that does safety checking +# which is not needed in a production environment but helps in the +# development process: +CFLAGS += -DDEVELHELP + +# Comment this out to join RPL DODAGs even if DIOs do not contain +# DODAG Configuration Options (see the doc for more info) +# CFLAGS += -DGNRC_RPL_DODAG_CONF_OPTIONAL_ON_JOIN + +# Change this to 0 show compiler invocation lines by default: +QUIET ?= 1 + +include $(RIOTBASE)/Makefile.include + +# Set a custom channel if needed +ifneq (,$(filter cc110x,$(USEMODULE))) # radio is cc110x sub-GHz + DEFAULT_CHANNEL ?= 0 + CFLAGS += -DCC110X_DEFAULT_CHANNEL=$(DEFAULT_CHANNEL) +else + ifneq (,$(filter at86rf212b,$(USEMODULE))) # radio is IEEE 802.15.4 sub-GHz + DEFAULT_CHANNEL ?= 5 + FLAGS += -DIEEE802154_DEFAULT_SUBGHZ_CHANNEL=$(DEFAULT_CHANNEL) + else # radio is IEEE 802.15.4 2.4 GHz + DEFAULT_CHANNEL ?= 26 + CFLAGS += -DIEEE802154_DEFAULT_CHANNEL=$(DEFAULT_CHANNEL) + endif +endif diff --git a/RIOT/examples/test_lqi_rssi/README.md b/RIOT/examples/test_lqi_rssi/README.md new file mode 100755 index 0000000..fd32831 --- /dev/null +++ b/RIOT/examples/test_lqi_rssi/README.md @@ -0,0 +1,142 @@ +# gnrc_networking example + +This example shows you how to try out the code in two different ways: Either by communicating +between the RIOT machine and its Linux host, or by communicating between two RIOT instances. +Note that the former only works with native, i.e. if you run RIOT on your Linux machine. + +## Connecting RIOT native and the Linux host + +> **Note:** RIOT does not support IPv4, so you need to stick to IPv6 anytime. To +establish a connection between RIOT and the Linux host, you will need `netcat` +(with IPv6 support). Ubuntu 14.04 comes with netcat IPv6 support pre-installed. +On Debian it's available in the package `netcat-openbsd`. Be aware that many +programs require you to add an option such as -6 to tell them to use IPv6, otherwise they +will fail. If you're using a _Raspberry Pi_, run `sudo modprobe ipv6` before trying +this example, because raspbian does not load the IPv6 module automatically. +On some systems (openSUSE for example), the _firewall_ may interfere, and prevent +some packets to arrive at the application (they will however show up in Wireshark, +which can be confusing). So be sure to adjust your firewall rules, or turn it off +(who needs security anyway). + +First, create a tap interface: + + sudo ip tuntap add tap0 mode tap user ${USER} + sudo ip link set tap0 up + +Now you can start the `gnrc_networking` example by invoking `make term`. This should +automatically connect to the `tap0` interface. If this doesn't work for any reason, +run make term with the tap0 interface as the PORT environment variable: + + PORT=tap0 make term + +To verify that there is connectivity between RIOT and Linux, go to the RIOT console and run `ifconfig`: + + > ifconfig + Iface 7 HWaddr: ce:f5:e1:c5:f7:5a + inet6 addr: ff02::1/128 scope: local [multicast] + inet6 addr: fe80::ccf5:e1ff:fec5:f75a/64 scope: local + inet6 addr: ff02::1:ffc5:f75a/128 scope: local [multicast] + +Copy the [link-local address](https://en.wikipedia.org/wiki/Link-local_address) +of the RIOT node (prefixed with `fe80`) and try to ping it **from the Linux node**: + + ping6 fe80::ccf5:e1ff:fec5:f75a%tap0 + +Note that the interface on which to send the ping needs to be appended to the IPv6 +address, `%tap0` in the above example. When talking to the RIOT node, you always want +to send to/receive from the `tap0` interface. + +If the pings succeed you can go on to send UDP packets. To do that, first start a +UDP server on the RIOT node: + + > udp server start 8808 + Success: started UDP server on port 8808 + +Now, on the Linux host, you can run netcat to connect with RIOT's UDP server: + + nc -6uv fe80::ccf5:e1ff:fec5:f75a%tap0 8808 + +The `-6` option is necessary to tell netcat to use IPv6 only, the `-u` option tells +it to use UDP only, and the `-v` option makes it give more verbose output (this one is optional). + +You should now see that UDP messages are received on the RIOT side. Opening a UDP +server on the Linux side is also possible. To do that, write down the IP address +of the host (run on Linux): + + ifconfig tap0 + tap0 Link encap:Ethernet HWaddr ce:f5:e1:c5:f7:59 + inet6 addr: fe80::4049:5fff:fe17:b3ae/64 Scope:Link + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:6 errors:0 dropped:0 overruns:0 frame:0 + TX packets:36 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:0 + RX bytes:488 (488.0 B) TX bytes:3517 (3.5 KB) + +Then open a UDP server on Linux (the `-l` option makes netcat listen for incoming connections): + + nc -6ul 8808 + +Now, on the RIOT side, send a UDP packet using: + + udp send fe80::4049:5fff:fe17:b3ae 8808 testmessage + +You should see `testmessage` appear in netcat. Instead of using netcat, you can of +course write your own software, but you may have to bind the socket to a specific +interface (tap0 in this case). For an example that shows how to do so, see +[here](https://gist.github.com/backenklee/dad5e80b764b3b3d0d3e). + +## Connecting two RIOT instances + +When using native (i.e. when you're trying this on your Linux machine), you first +need to set up two tap devices and a bridge that connects them. This constitutes a +virtual network that the RIOT instances can use to communicate. + + ./../../dist/tools/tapsetup/tapsetup --create 2 + +Then, make sure you've compiled the application by calling `make` and start the +first RIOT instance by invoking `make term`. In the RIOT shell, get to know the +IP address of this node: + + > ifconfig + Iface 7 HWaddr: ce:f5:e1:c5:f7:5a + inet6 addr: ff02::1/128 scope: local [multicast] + inet6 addr: fe80::ccf5:e1ff:fec5:f75a/64 scope: local + inet6 addr: ff02::1:ffc5:f75a/128 scope: local [multicast] + +and start a UDP server. + + > udp server start 8808 + +This node is now ready to receive data on port `8808`. + +In a second terminal, start a second RIOT instance, this time listening on `tap1`: + + PORT=tap1 make term + +In the RIOT shell, you can now send a message to the first RIOT instance: + + > udp send fe80::ccf5:e1ff:fec5:f75 8808 testmessage + +*(Make sure to copy the actual +[link-local address](https://en.wikipedia.org/wiki/Link-local_address) of your first +RIOT instance into the above command)* + +In your first terminal, you should now see output that looks like this. + + > PKTDUMP: data received: + ~~ SNIP 0 - size: 11 byte, type: NETTYPE_UNDEF (0) + 000000 74 65 73 74 6d 65 73 73 61 67 65 + ~~ SNIP 1 - size: 8 byte, type: NETTYPE_UDP (3) + src-port: 8808 dst-port: 8808 + length: 19 cksum: 0x4d95f + ~~ SNIP 2 - size: 40 byte, type: NETTYPE_IPV6 (1) + traffic class: 0x00 (ECN: 0x0, DSCP: 0x00) + flow label: 0x00000 + length: 19 next header: 17 hop limit: 64 + source address: fe80::a08a:84ff:fe68:544f + destination address: fe80::60fc:3cff:fe5e:40df + ~~ SNIP 3 - size: 20 byte, type: NETTYPE_NETIF (-1) + if_pid: 6 rssi: 0 lqi: 0 + src_l2addr: a2:8a:84:68:54:4f + dst_l2addr: 62:fc:3c:5e:40:df + ~~ PKT - 4 snips, total size: 79 byte diff --git a/RIOT/examples/test_lqi_rssi/main.c b/RIOT/examples/test_lqi_rssi/main.c new file mode 100755 index 0000000..3c428cf --- /dev/null +++ b/RIOT/examples/test_lqi_rssi/main.c @@ -0,0 +1,344 @@ +/* + * Copyright (C) 2015 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup examples + * @{ + * + * @file + * @brief Example application for demonstrating the RIOT network stack + * + * @author Hauke Petersen + * + * @} + */ + +#include +#include +#include +#include "kernel_types.h" +#include "byteorder.h" +#include "thread.h" +#include "net/gnrc/ipv6.h" +#include "net/gnrc/udp.h" +#include "net/gnrc.h" +#include "net/ipv6/addr.h" +#include "net/ipv6/hdr.h" +#include "net/udp.h" +#include "net/sixlowpan.h" +#include "od.h" +#include "periph/timer.h" +#include "../../boards/stm32f4discovery/include/board.h" +#include "../../boards/stm32f4discovery/include/periph_conf.h" +#include "periph/pwm.h" +#include "shell.h" +#include "msg.h" + +#ifndef GNRC_PKTDUMP_MSG_QUEUE_SIZE +#define GNRC_PKTDUMP_MSG_QUEUE_SIZE (8U) +#endif + +/** + * @brief Priority of the pktdump thread + */ +#ifndef GNRC_PKTDUMP_PRIO +#define GNRC_PKTDUMP_PRIO (THREAD_PRIORITY_MAIN - 1) +#endif + +/** + * @brief Stack size used for the pktdump thread + */ +#ifndef GNRC_PKTDUMP_STACKSIZE +#define GNRC_PKTDUMP_STACKSIZE (THREAD_STACKSIZE_MAIN) +#endif +//#define DST +#define MAIN_QUEUE_SIZE (8) +static msg_t _main_msg_queue[MAIN_QUEUE_SIZE]; + +extern int udp_cmd(int argc, char **argv); +static gnrc_netreg_entry_t server = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, + KERNEL_PID_UNDEF); +unsigned rssi_dest, lqi_dest; +typedef struct mon_attribute { + uint8_t rssi; + uint8_t lqi; +} Data_quality; + +#ifdef DST + ipv6_hdr_t* ipv6_HDR; + Data_quality data_quality; +#endif + +//uint8_t node[16]={0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x37,0x34,0x51,0x0b,0x33,0x0b,0x34,0x0a}; +#ifdef DST +static void reply_quality(ipv6_addr_t addr, char *port_str, Data_quality* data) + +{ + uint16_t port; + port = (uint16_t)atoi(port_str); + if (port == 0) { + puts("Error: unable to parse destination port"); + return; + } + + + gnrc_pktsnip_t *payload, *udp, *ip; + // unsigned payload_size; + payload=gnrc_pktbuf_add(NULL, data, sizeof(data), GNRC_NETTYPE_UNDEF); + if (payload == NULL) { + puts("Error: unable to copy data to packet buffer"); + return; + } + // store size for output + //payload_size = (unsigned)payload->size; + // allocate UDP header, set source port := destination port + udp = gnrc_udp_hdr_build(payload, port, port); + if (udp == NULL) { + puts("Error: unable to allocate UDP header"); + gnrc_pktbuf_release(payload); + return; + } + // allocate IPv6 header + ip = gnrc_ipv6_hdr_build(udp, NULL, &addr); + if (ip == NULL) { + puts("Error: unable to allocate IPv6 header"); + gnrc_pktbuf_release(udp); + return; + } + // send packet + printf("RSSI %u LQI %u \n",data->rssi,data->lqi); + printf("%d\n",port); + if (!gnrc_netapi_dispatch_send(GNRC_NETTYPE_UDP, GNRC_NETREG_DEMUX_CTX_ALL, ip)) { + puts("Error: unable to locate UDP thread"); + gnrc_pktbuf_release(ip); + return; + } + + //printf("Success: send %u byte to [%s]:%u\n", payload_size, addr_str,port); + +} +#endif +/***************************************************************************************/ +//copy pktdump + + +/** + * @brief PID of the pktdump thread + */ +static kernel_pid_t copy_pktd_pid = KERNEL_PID_UNDEF; + + + +/** + * @brief Stack for the pktdump thread + */ +static char _stack[GNRC_PKTDUMP_STACKSIZE]; + +static void _dump_snip(gnrc_pktsnip_t *pkt) +{ + + switch (pkt->type) { + case GNRC_NETTYPE_UNDEF: + printf("NETTYPE_UNDEF (%i)\n", pkt->type); + //od_hex_dump(pkt->data, pkt->size, OD_WIDTH_DEFAULT); + Data_quality* pkt_rcv=pkt->data; + printf("MON_RSSI %d MON_LQI %d \n",pkt_rcv->rssi,pkt_rcv->lqi); + /*if(strcmp((char *)pkt->data,"go")==0) + { + //pwm_set(PWM_DEV(0),1,25); + ordre = 1; + timer_set(XTIMER_DEV,0,8400); + timer_clear(TIMER_DEV(1),0); + } + else + { + //pwm_set(PWM_DEV(0),1,0); + ordre = 0; + }*/ + + break; +#ifdef MODULE_GNRC_NETIF + case GNRC_NETTYPE_NETIF: + printf("NETTYPE_NETIF (%i)\n", pkt->type); + gnrc_netif_hdr_print(pkt->data); +#ifdef DST + gnrc_netif_hdr_t* header=(gnrc_netif_hdr_t*)pkt->data; + data_quality.rssi=(uint8_t)header->rssi; + data_quality.lqi=(uint8_t)header->lqi; + printf("MES DATA:%u ---- %u\n",data_quality.rssi,data_quality.lqi); +#endif + break; +#endif +#ifdef MODULE_GNRC_SIXLOWPAN + case GNRC_NETTYPE_SIXLOWPAN: + printf("NETTYPE_SIXLOWPAN (%i)\n", pkt->type); + //sixlowpan_print(pkt->data, pkt->size); + break; +#endif +#ifdef MODULE_GNRC_IPV6 + case GNRC_NETTYPE_IPV6: + printf("NETTYPE_IPV6 (%i)\n", pkt->type); +#ifdef DST + ipv6_hdr_print(pkt->data); + //ipv6_HDR= (ipv6_hdr_t*)pkt->data; + //char addr_str[IPV6_ADDR_MAX_STR_LEN]; + ipv6_HDR = (ipv6_hdr_t*)pkt->data; + // ipv6_addr_to_str(addr_str, &ipv6_HDR->src,sizeof(addr_str)); + //printf("mon-test : %s\n",addr_str); + //ipv6_HDR =(ipv6_addr_t)pkt->data; +#endif + break; +#endif +#ifdef MODULE_GNRC_ICMPV6 + case GNRC_NETTYPE_ICMPV6: + printf("NETTYPE_ICMPV6 (%i)\n", pkt->type); + break; +#endif +#ifdef MODULE_GNRC_TCP + case GNRC_NETTYPE_TCP: + printf("NETTYPE_TCP (%i)\n", pkt->type); + break; +#endif +#ifdef MODULE_GNRC_UDP + case GNRC_NETTYPE_UDP: + printf("NETTYPE_UDP (%i)\n", pkt->type); + udp_hdr_print(pkt->data); + + break; +#endif +#ifdef TEST_SUITES + case GNRC_NETTYPE_TEST: + printf("NETTYPE_TEST (%i)\n", pkt->type); + //od_hex_dump(pkt->data, pkt->size, OD_WIDTH_DEFAULT); + break; +#endif + default: + printf("NETTYPE_UNKNOWN (%i)\n", pkt->type); + //od_hex_dump(pkt->data, pkt->size, OD_WIDTH_DEFAULT); + break; + } +} + +static void _dump(gnrc_pktsnip_t *pkt) +{ + int snips = 0; + int size = 0; + gnrc_pktsnip_t *snip = pkt; + + while (snip != NULL) { + printf("~~ SNIP %2i - size: %3u byte, type: ", snips, + (unsigned int)snip->size); + _dump_snip(snip); + ++snips; + size += snip->size; + snip = snip->next; + } + + printf("~~ PKT - %2i snips, total size: %3i byte\n", snips, size); + gnrc_pktbuf_release(pkt); + #ifdef DST + reply_quality(ipv6_HDR->src,"8888",&data_quality); +#endif +} + +static void *_eventloop(void *arg) +{ + (void)arg; + msg_t msg, reply; + msg_t msg_queue[GNRC_PKTDUMP_MSG_QUEUE_SIZE]; + + /* setup the message queue */ + msg_init_queue(msg_queue, GNRC_PKTDUMP_MSG_QUEUE_SIZE); + + reply.content.value = (uint32_t)(-ENOTSUP); + reply.type = GNRC_NETAPI_MSG_TYPE_ACK; + + while (1) { + msg_receive(&msg); + + switch (msg.type) { + case GNRC_NETAPI_MSG_TYPE_RCV: + puts("PKTDUMP: data received:"); + _dump(msg.content.ptr); + break; + case GNRC_NETAPI_MSG_TYPE_SND: + puts("PKTDUMP: data to send:"); + _dump(msg.content.ptr); + break; + case GNRC_NETAPI_MSG_TYPE_GET: + case GNRC_NETAPI_MSG_TYPE_SET: + msg_reply(&msg, &reply); + break; + default: + puts("PKTDUMP: received something unexpected"); + break; + } + } + + /* never reached */ + return NULL; +} + +kernel_pid_t gnrc_pktdump_init(void) +{ + if (copy_pktd_pid == KERNEL_PID_UNDEF) { + copy_pktd_pid = thread_create(_stack, sizeof(_stack), GNRC_PKTDUMP_PRIO, + THREAD_CREATE_STACKTEST, + _eventloop, NULL, "pktdump_copy"); + } + return copy_pktd_pid; +} +//end copy pktdump +/***************************************************************************************/ + + +static void start_server(char *port_str) +{ + uint16_t port; + + /* check if server is already running */ + if (server.target.pid != KERNEL_PID_UNDEF) { + printf("Error: server already running on port %" PRIu32 "\n", + server.demux_ctx); + return; + } + /* parse port */ + port = (uint16_t)atoi(port_str); + if (port == 0) { + puts("Error: invalid port specified"); + return; + } + /* start server (which means registering pktdump for the chosen port) */ + server.target.pid = copy_pktd_pid; + server.demux_ctx = (uint32_t)port; + gnrc_netreg_register(GNRC_NETTYPE_UDP, &server); + printf("Success: started UDP server on port %" PRIu16 "\n", port); +} + +static const shell_command_t shell_commands[] = { + { "udp", "send data over UDP and listen on UDP ports", udp_cmd }, + { NULL, NULL, NULL } +}; + + +int main(void) +{ + /* we need a message queue for the thread running the shell in order to + * receive potentially fast incoming networking packets */ + msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE); + puts("RIOT network stack example application"); + gnrc_pktdump_init(); + start_server("8888"); + /* start shell */ + puts("All up, running the shell now"); + char line_buf[SHELL_DEFAULT_BUFSIZE]; + shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE); + + /* should be never reached */ + return 0; +} diff --git a/RIOT/examples/test_lqi_rssi/udp.c b/RIOT/examples/test_lqi_rssi/udp.c new file mode 100755 index 0000000..89b82f8 --- /dev/null +++ b/RIOT/examples/test_lqi_rssi/udp.c @@ -0,0 +1,175 @@ +/* + * Copyright (C) 2015 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup examples + * @{ + * + * @file + * @brief Demonstrating the sending and receiving of UDP data + * + * @author Hauke Petersen + * + * @} + */ + +#include +#include + +#include "net/gnrc.h" +#include "net/gnrc/ipv6.h" +#include "net/gnrc/udp.h" +#include "net/gnrc/pktdump.h" +#include "timex.h" +#include "xtimer.h" + +static gnrc_netreg_entry_t server = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, + KERNEL_PID_UNDEF); + +static kernel_pid_t copy_pktd_pid = KERNEL_PID_UNDEF; +static void send(char *addr_str, char *port_str, char *data, unsigned int num, + unsigned int delay) + +{ + uint16_t port; + ipv6_addr_t addr; + + /* parse destination address */ + if (ipv6_addr_from_str(&addr, addr_str) == NULL) { + puts("Error: unable to parse destination address"); + return; + } + /* parse port */ + port = (uint16_t)atoi(port_str); + if (port == 0) { + puts("Error: unable to parse destination port"); + return; + } + + for (unsigned int i = 0; i < num; i++) { + gnrc_pktsnip_t *payload, *udp, *ip; + unsigned payload_size; + /* allocate payload */ + payload = gnrc_pktbuf_add(NULL, data, strlen(data), GNRC_NETTYPE_UNDEF); + if (payload == NULL) { + puts("Error: unable to copy data to packet buffer"); + return; + } + /* store size for output */ + payload_size = (unsigned)payload->size; + /* allocate UDP header, set source port := destination port */ + udp = gnrc_udp_hdr_build(payload, port, port); + if (udp == NULL) { + puts("Error: unable to allocate UDP header"); + gnrc_pktbuf_release(payload); + return; + } + /* allocate IPv6 header */ + ip = gnrc_ipv6_hdr_build(udp, NULL, &addr); + if (ip == NULL) { + puts("Error: unable to allocate IPv6 header"); + gnrc_pktbuf_release(udp); + return; + } + /* send packet */ + if (!gnrc_netapi_dispatch_send(GNRC_NETTYPE_UDP, GNRC_NETREG_DEMUX_CTX_ALL, ip)) { + puts("Error: unable to locate UDP thread"); + gnrc_pktbuf_release(ip); + return; + } + /* access to `payload` was implicitly given up with the send operation above + * => use temporary variable for output */ + printf("Success: send %u byte to [%s]:%u\n", payload_size, addr_str, + port); + xtimer_usleep(delay); + } +} + +static void start_server(char *port_str) +{ + uint16_t port; + + /* check if server is already running */ + if (server.target.pid != KERNEL_PID_UNDEF) { + printf("Error: server already running on port %" PRIu32 "\n", + server.demux_ctx); + return; + } + /* parse port */ + port = (uint16_t)atoi(port_str); + if (port == 0) { + puts("Error: invalid port specified"); + return; + } + /* start server (which means registering pktdump for the chosen port) */ + server.target.pid = copy_pktd_pid; + server.demux_ctx = (uint32_t)port; + gnrc_netreg_register(GNRC_NETTYPE_UDP, &server); + printf("Success: started UDP server on port %" PRIu16 "\n", port); +} + +static void stop_server(void) +{ + /* check if server is running at all */ + if (server.target.pid == KERNEL_PID_UNDEF) { + printf("Error: server was not running\n"); + return; + } + /* stop server */ + gnrc_netreg_unregister(GNRC_NETTYPE_UDP, &server); + server.target.pid = KERNEL_PID_UNDEF; + puts("Success: stopped UDP server"); +} + +int udp_cmd(int argc, char **argv) +{ + if (argc < 2) { + printf("usage: %s [send|server]\n", argv[0]); + return 1; + } + + if (strcmp(argv[1], "send") == 0) { + uint32_t num = 1; + uint32_t delay = 1000000; + if (argc < 5) { + printf("usage: %s send [ []]\n", + argv[0]); + return 1; + } + if (argc > 5) { + num = (uint32_t)atoi(argv[5]); + } + if (argc > 6) { + delay = (uint32_t)atoi(argv[6]); + } + send(argv[2], argv[3], argv[4], num, delay); + } + else if (strcmp(argv[1], "server") == 0) { + if (argc < 3) { + printf("usage: %s server [start|stop]\n", argv[0]); + return 1; + } + if (strcmp(argv[2], "start") == 0) { + if (argc < 4) { + printf("usage %s server start \n", argv[0]); + return 1; + } + start_server(argv[3]); + } + else if (strcmp(argv[2], "stop") == 0) { + stop_server(); + } + else { + puts("error: invalid command"); + } + } + else { + puts("error: invalid command"); + } + return 0; +} diff --git a/RIOT/sys/include/net/gnrc/rpl/structs.h b/RIOT/sys/include/net/gnrc/rpl/structs.h index 06f7bd6..56a6946 100755 --- a/RIOT/sys/include/net/gnrc/rpl/structs.h +++ b/RIOT/sys/include/net/gnrc/rpl/structs.h @@ -74,6 +74,9 @@ extern "C" { * RFC6550, section 6.7.1, RPL Control Message Option Generic Format * */ + + + typedef struct __attribute__((packed)) { uint8_t type; /**< Option Type */ uint8_t length; /**< Option Length, does not include the first two byte */ diff --git a/RIOT/tests/sched_testing/main.c b/RIOT/tests/sched_testing/main.c index 3e8a575..3b81722 100755 --- a/RIOT/tests/sched_testing/main.c +++ b/RIOT/tests/sched_testing/main.c @@ -24,8 +24,8 @@ char snd_thread_stack[THREAD_STACKSIZE_MAIN]; void *snd_thread(void *unused) { (void) unused; - puts("snd_thread running"); - return NULL; + puts("snd_thread running"); + return NULL; } int main(void) diff --git a/RIOT/tests/thread_flags/Makefile b/RIOT/tests/thread_flags/Makefile index 5affc80..2762955 100755 --- a/RIOT/tests/thread_flags/Makefile +++ b/RIOT/tests/thread_flags/Makefile @@ -3,5 +3,4 @@ include ../Makefile.tests_common USEMODULE += xtimer USEMODULE += core_thread_flags - include $(RIOTBASE)/Makefile.include -- libgit2 0.21.2