Commit e87eb5fb32f3a09f667e4c9a2974b9daa04c9ce5
1 parent
59fd08c7
RPL + serveur ntp ok
Showing
8 changed files
with
672 additions
and
4 deletions
Show diff stats
... | ... | @@ -0,0 +1,67 @@ |
1 | +# name of your application | |
2 | +APPLICATION = real_time_app | |
3 | + | |
4 | +# If no BOARD is found in the environment, use this default: | |
5 | +BOARD ?= native | |
6 | + | |
7 | +# This has to be the absolute path to the RIOT base directory: | |
8 | +RIOTBASE ?= $(CURDIR)/../.. | |
9 | + | |
10 | +BOARD_INSUFFICIENT_MEMORY := airfy-beacon chronos msb-430 msb-430h nrf51dongle \ | |
11 | + nrf6310 nucleo-f103 nucleo-f334 pca10000 pca10005 spark-core \ | |
12 | + stm32f0discovery telosb weio wsn430-v1_3b wsn430-v1_4 \ | |
13 | + yunjia-nrf51822 z1 nucleo-f072 nucleo-f030 nucleo-f070 \ | |
14 | + microbit calliope-mini | |
15 | + | |
16 | +# Include packages that pull up and auto-init the link layer. | |
17 | +USEMODULE += gnrc_sock_udp | |
18 | +USEMODULE += sntp | |
19 | +# NOTE: 6LoWPAN will be included if IEEE802.15.4 devices are present | |
20 | +USEMODULE += gnrc_netdev_default | |
21 | +USEMODULE += auto_init_gnrc_netif | |
22 | +# Specify the mandatory networking modules for IPv6 and UDP | |
23 | +USEMODULE += gnrc_ipv6_router_default | |
24 | +USEMODULE += gnrc_udp | |
25 | +# Add a routing protocol | |
26 | +USEMODULE += gnrc_rpl | |
27 | +USEMODULE += auto_init_gnrc_rpl | |
28 | +# This application dumps received packets to STDIO using the pktdump module | |
29 | +#USEMODULE += gnrc_pktdump | |
30 | +# Additional networking modules that can be dropped if not needed | |
31 | +USEMODULE += gnrc_icmpv6_echo | |
32 | +# Add also the shell, some shell commands | |
33 | +USEMODULE += shell | |
34 | +USEMODULE += shell_commands | |
35 | +USEMODULE += ps | |
36 | +USEMODULE += netstats_l2 | |
37 | +USEMODULE += netstats_ipv6 | |
38 | +USEMODULE += netstats_rpl | |
39 | +#include our RF module | |
40 | +USEMODULE += at86rf231 | |
41 | +# Comment this out to disable code in RIOT that does safety checking | |
42 | +# which is not needed in a production environment but helps in the | |
43 | +# development process: | |
44 | +CFLAGS += -DDEVELHELP | |
45 | + | |
46 | +# Comment this out to join RPL DODAGs even if DIOs do not contain | |
47 | +# DODAG Configuration Options (see the doc for more info) | |
48 | +# CFLAGS += -DGNRC_RPL_DODAG_CONF_OPTIONAL_ON_JOIN | |
49 | + | |
50 | +# Change this to 0 show compiler invocation lines by default: | |
51 | +QUIET ?= 1 | |
52 | + | |
53 | +include $(RIOTBASE)/Makefile.include | |
54 | + | |
55 | +# Set a custom channel if needed | |
56 | +ifneq (,$(filter cc110x,$(USEMODULE))) # radio is cc110x sub-GHz | |
57 | + DEFAULT_CHANNEL ?= 0 | |
58 | + CFLAGS += -DCC110X_DEFAULT_CHANNEL=$(DEFAULT_CHANNEL) | |
59 | +else | |
60 | + ifneq (,$(filter at86rf212b,$(USEMODULE))) # radio is IEEE 802.15.4 sub-GHz | |
61 | + DEFAULT_CHANNEL ?= 5 | |
62 | + FLAGS += -DIEEE802154_DEFAULT_SUBGHZ_CHANNEL=$(DEFAULT_CHANNEL) | |
63 | + else # radio is IEEE 802.15.4 2.4 GHz | |
64 | + DEFAULT_CHANNEL ?= 26 | |
65 | + CFLAGS += -DIEEE802154_DEFAULT_CHANNEL=$(DEFAULT_CHANNEL) | |
66 | + endif | |
67 | +endif | ... | ... |
... | ... | @@ -0,0 +1,428 @@ |
1 | +/* | |
2 | + * Copyright (C) 2015 Freie Universität Berlin | |
3 | + * | |
4 | + * This file is subject to the terms and conditions of the GNU Lesser | |
5 | + * General Public License v2.1. See the file LICENSE in the top level | |
6 | + * directory for more details. | |
7 | + */ | |
8 | + | |
9 | +/** | |
10 | + * @ingroup examples | |
11 | + * @{ | |
12 | + * | |
13 | + * @file | |
14 | + * @brief Example application for demonstrating the RIOT network stack | |
15 | + * | |
16 | + * @author Hauke Petersen <hauke.petersen@fu-berlin.de> | |
17 | + * | |
18 | + * @} | |
19 | + */ | |
20 | +#include <stdbool.h> | |
21 | +#include <stdint.h> | |
22 | +#include <stdio.h> | |
23 | +#include <stdlib.h> | |
24 | +#include <string.h> | |
25 | +#include <inttypes.h> | |
26 | + | |
27 | +#include <arpa/inet.h> | |
28 | +#include "../../boards/stm32f4discovery/include/board.h" | |
29 | +#include "../../boards/stm32f4discovery/include/periph_conf.h" | |
30 | +#include "net/sock/udp.h" | |
31 | +#include "net/gnrc/ipv6.h" | |
32 | +#include "net/af.h" | |
33 | +#include "net/sixlowpan.h" | |
34 | +#include "net/gnrc/pktdump.h" | |
35 | +#include "shell.h" | |
36 | +#include "shell_commands.h" | |
37 | +#include "msg.h" | |
38 | +#include "thread.h" | |
39 | +#include "sched.h" | |
40 | +#include "thread.h" | |
41 | +#include "kernel_types.h" | |
42 | +#include "net/netstats.h" | |
43 | +#include "net/ipv6/addr.h" | |
44 | +#include "periph/timer.h" | |
45 | +#include "net/gnrc/ipv6/netif.h" | |
46 | +#include "net/gnrc/netif.h" | |
47 | +#include "net/gnrc/netapi.h" | |
48 | +#include "net/netopt.h" | |
49 | +#include "net/gnrc/pkt.h" | |
50 | +#include "net/gnrc/pktbuf.h" | |
51 | +#include "net/gnrc/netif/hdr.h" | |
52 | +#include "net/gnrc/sixlowpan/netif.h" | |
53 | +#include "net/fib.h" | |
54 | +#include "net/gnrc/udp.h" | |
55 | +#include "periph/pwm.h" | |
56 | +#include "od.h" | |
57 | +#include "net/sntp.h" | |
58 | +#include "net/ntp_packet.h" | |
59 | +#include "net/gnrc/rpl.h" | |
60 | +#include "net/gnrc/rpl/structs.h" | |
61 | +#include "net/gnrc/rpl/dodag.h" | |
62 | +#include "utlist.h" | |
63 | +#include "trickle.h" | |
64 | +#ifdef MODULE_SCHEDSTATISTICS | |
65 | +#include "xtimer.h" | |
66 | +#endif | |
67 | + | |
68 | +#ifdef MODULE_TLSF | |
69 | +#include "tlsf.h" | |
70 | +#endif | |
71 | + | |
72 | +#define MAIN_QUEUE_SIZE (8) | |
73 | +/** | |
74 | + * @brief The maximal expected link layer address length in byte | |
75 | + */ | |
76 | +#define MAX_ADDR_LEN (8U) | |
77 | + | |
78 | +/** | |
79 | + * @brief The default IPv6 prefix length if not specified. | |
80 | + */ | |
81 | +#define SC_NETIF_IPV6_DEFAULT_PREFIX_LEN (64) | |
82 | + | |
83 | +#define _STACKSIZE (THREAD_STACKSIZE_DEFAULT + THREAD_EXTRA_STACKSIZE_PRINTF) | |
84 | +#define MSG_TYPE_ISR (0x3456) | |
85 | + | |
86 | +#define PWM_FREQ 100 | |
87 | +#define PWM_RES 100 | |
88 | +#define DEADLINE 24000 | |
89 | + | |
90 | +static msg_t _main_msg_queue[MAIN_QUEUE_SIZE]; | |
91 | + | |
92 | +extern int udp_cmd(int argc, char **argv); | |
93 | + | |
94 | +static const shell_command_t shell_commands[] = { | |
95 | + { "udp", "send data over UDP and listen on UDP ports", udp_cmd }, | |
96 | + { NULL, NULL, NULL } | |
97 | +}; | |
98 | + | |
99 | +// addr ipv6 link local node 1: fe80::3734:510e:3317:3402 | |
100 | +uint8_t node1[16]={0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x37,0x34,0x51,0x0e,0x33,0x17,0x34,0x02}; | |
101 | +// addr ipv6 link local node 2: fe80::3634:5110:3473:3762 | |
102 | +uint8_t node2[16]={0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x36,0x34,0x51,0x10,0x34,0x73,0x37,0x62}; | |
103 | +// addr ipv6 link local node 3: fe80::3734:510e:330b:342a | |
104 | +uint8_t node3[16]={0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x37,0x34,0x51,0x0e,0x33,0x0b,0x34,0x2a}; | |
105 | +// addr ipv6 link local node 4: fe80::3734:510b:330b:340a | |
106 | +uint8_t node4[16]={0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x37,0x34,0x51,0x0b,0x33,0x0b,0x34,0x0a}; | |
107 | +// addr ipv6 link local node 5: fe80::3734:510b:330a:341e | |
108 | +uint8_t node5[16]={0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x37,0x34,0x51,0x0b,0x33,0x0a,0x34,0x1e}; | |
109 | +//static char _stack_server[GNRC_PKTDUMP_STACKSIZE]; | |
110 | +char pwm_stack[THREAD_STACKSIZE_MAIN]; | |
111 | +char sock_server_stack[THREAD_STACKSIZE_MAIN]; | |
112 | +char sock_client_stack[THREAD_STACKSIZE_MAIN]; | |
113 | +char sock_time_server_stack[THREAD_STACKSIZE_MAIN]; | |
114 | +// static gnrc_netreg_entry_t server = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, | |
115 | +// KERNEL_PID_UNDEF); | |
116 | +// | |
117 | +// kernel_pid_t gnrc_server_pid = KERNEL_PID_UNDEF; | |
118 | +// | |
119 | +kernel_pid_t server, client, time_server; | |
120 | +int ordre = 0; | |
121 | +int64_t offset = 0; | |
122 | +int timer_run = 0; | |
123 | +int tourne = 0; | |
124 | +sock_udp_ep_t local = SOCK_IPV6_EP_ANY; | |
125 | +sock_udp_t sock; | |
126 | +sock_udp_ep_t local_ntp = SOCK_IPV6_EP_ANY; | |
127 | +sock_udp_t sock_ntp; | |
128 | +static ntp_packet_t sntp_packet; | |
129 | + | |
130 | +typedef struct tableau { | |
131 | + uint32_t heure_actuelle; | |
132 | + char donnees[2]; | |
133 | +}Data; | |
134 | + | |
135 | +/***************** RPL functions *****************/ | |
136 | + | |
137 | +int crea_rpl_dodag_root(char *arg1, char *arg2) | |
138 | +{ | |
139 | + uint8_t instance_id = (uint8_t) atoi(arg1); | |
140 | + ipv6_addr_t dodag_id; | |
141 | + | |
142 | + if (ipv6_addr_from_str(&dodag_id, arg2) == NULL) { | |
143 | + puts("error: <dodag_id> must be a valid IPv6 address"); | |
144 | + return 1; | |
145 | + } | |
146 | + | |
147 | + gnrc_rpl_instance_t *inst = NULL; | |
148 | + inst = gnrc_rpl_root_init(instance_id, &dodag_id, false, false); | |
149 | + if (inst == NULL) { | |
150 | + char addr_str[IPV6_ADDR_MAX_STR_LEN]; | |
151 | + printf("error: could not add DODAG (%s) to instance (%d)\n", | |
152 | + ipv6_addr_to_str(addr_str, &dodag_id, sizeof(addr_str)), instance_id); | |
153 | + return 1; | |
154 | + } | |
155 | + | |
156 | + printf("successfully added a new RPL DODAG\n"); | |
157 | + return 0; | |
158 | +} | |
159 | +/***************** /RPL functions ****************/ | |
160 | + | |
161 | +void *sock_time_server_thread(void *arg) | |
162 | +{ | |
163 | + (void) arg; | |
164 | + local_ntp.port = NTP_PORT; | |
165 | + | |
166 | + if (sock_udp_create(&sock_ntp, &local_ntp, NULL, 0) < 0) { | |
167 | + puts("Error creating UDP sock"); | |
168 | + return NULL; | |
169 | + } | |
170 | + | |
171 | + while (1) { | |
172 | + sock_udp_ep_t remote; | |
173 | + ssize_t res; | |
174 | + | |
175 | + if ((res = sock_udp_recv(&sock_ntp,&sntp_packet, sizeof(sntp_packet), SOCK_NO_TIMEOUT, | |
176 | + &remote)) >= 0) { | |
177 | + puts("Received a message"); | |
178 | + //printf("TT: %lu\n", byteorder_ntohl(sntp_packet.transmit.seconds)); | |
179 | + | |
180 | + // printf("%c\n",remote.addr.ipv6[15]); | |
181 | + //xtimer_ticks64_t now = xtimer_now64(); | |
182 | + // heure actuelle du serveur | |
183 | + sntp_packet.receive.seconds=byteorder_htonl( xtimer_now_usec()); | |
184 | + sntp_packet.origin.seconds=sntp_packet.transmit.seconds; | |
185 | + sntp_packet.transmit.seconds=byteorder_htonl( xtimer_now_usec()); | |
186 | + //printf("heure actuelle : %lu\n",xtimer_now_usec()); | |
187 | + //printf("TT2: %lu\n", byteorder_ntohl(sntp_packet.transmit.seconds)); | |
188 | + //memset(&sntp_packet, 0, sizeof(sntp_packet)); | |
189 | + //ntp_packet_set_vn(&sntp_packet); | |
190 | + //ntp_packet_set_mode(&sntp_packet, NTP_MODE_SERVER); | |
191 | + if (sock_udp_send(&sock_ntp, &sntp_packet, sizeof(sntp_packet), &remote) < 0) { | |
192 | + puts("Error sending reply"); | |
193 | + } | |
194 | + } | |
195 | + } | |
196 | + return NULL; | |
197 | +} | |
198 | +/*void *pwm_thread(void *arg) | |
199 | +{ | |
200 | + (void) arg; | |
201 | + int tourne = 0; | |
202 | + while(1) | |
203 | + { | |
204 | + | |
205 | + if(ordre==1) | |
206 | + { | |
207 | + pwm_set(PWM_DEV(0),1,45); | |
208 | + tourne = 1; | |
209 | + } | |
210 | + else if(ordre==0) | |
211 | + { | |
212 | + pwm_set(PWM_DEV(0),1,0); | |
213 | + tourne = 0; | |
214 | + } | |
215 | + else if(ordre==2 && tourne == 1) | |
216 | + pwm_set(PWM_DEV(0),1,31); | |
217 | + | |
218 | + } | |
219 | + return NULL; | |
220 | +}*/ | |
221 | + | |
222 | +void *sock_server_thread(void *arg) | |
223 | +{ | |
224 | + (void) arg; | |
225 | + Data buf; | |
226 | + int compteur = 5; | |
227 | + int deadline; | |
228 | + local.port = 1234; | |
229 | + sock_udp_ep_t server = { .port = NTP_PORT, .family = AF_INET6 }; | |
230 | + ipv6_addr_from_str((ipv6_addr_t *)&server.addr, "dead:beef::3402"); | |
231 | + | |
232 | + if (sock_udp_create(&sock, &local, NULL, 0) < 0) { | |
233 | + puts("Error creating UDP sock"); | |
234 | + return NULL; | |
235 | + } | |
236 | + if (sntp_sync(&server, SOCK_NO_TIMEOUT) < 0) { | |
237 | + puts("Error in synchronization"); | |
238 | + return NULL; | |
239 | + } | |
240 | + offset = sntp_get_offset(); | |
241 | + printf("offset : %i\n",(int)offset); | |
242 | + | |
243 | + while (1) { | |
244 | + sock_udp_ep_t remote; | |
245 | + ssize_t res; | |
246 | + | |
247 | + if ((res = sock_udp_recv(&sock, &buf, sizeof(buf), SOCK_NO_TIMEOUT, | |
248 | + &remote)) >= 0) { | |
249 | + // puts("Received a message"); | |
250 | + //printf("%s\n",buf); | |
251 | + /*if (sock_udp_send(&sock, buf, res, &remote) < 0) { | |
252 | + puts("Error sending reply"); | |
253 | + }*/ | |
254 | + | |
255 | + deadline = xtimer_now_usec() + offset - buf.heure_actuelle; | |
256 | + printf("tps de transmission : %i\n",deadline); | |
257 | + | |
258 | + if(deadline >= DEADLINE && compteur >=5) | |
259 | + { | |
260 | + //ordre = 2; | |
261 | + compteur = 0; | |
262 | + if(tourne == 1) | |
263 | + pwm_set(PWM_DEV(0),1,31); | |
264 | + if(timer_run == 0) | |
265 | + { | |
266 | + timer_set(TIMER_DEV(1),0,25200); | |
267 | + printf("relance timer\n"); | |
268 | + timer_run = 1; | |
269 | + } | |
270 | + } | |
271 | + if(deadline >= DEADLINE && compteur < 5) | |
272 | + { | |
273 | + compteur = 0; | |
274 | + } | |
275 | + if(deadline<=DEADLINE && compteur >=5) | |
276 | + { | |
277 | + //ordre = 1; | |
278 | + pwm_set(PWM_DEV(0),1,45); | |
279 | + tourne = 1; | |
280 | + timer_run=0; | |
281 | + timer_clear(TIMER_DEV(1),0); | |
282 | + printf("clear timer\n"); | |
283 | + } | |
284 | + if(deadline<=DEADLINE && compteur <5) | |
285 | + { | |
286 | + compteur++; | |
287 | + } | |
288 | + | |
289 | + printf("compteur : %d\n",compteur); | |
290 | + memset(&buf,0,sizeof(buf)); | |
291 | + } | |
292 | + } | |
293 | + return NULL; | |
294 | +} | |
295 | + | |
296 | + | |
297 | +/*void *sock_client_thread(void *arg) | |
298 | +{ | |
299 | + (void) arg; | |
300 | + Data data; | |
301 | + data.donnees[0] = 'g'; | |
302 | + data.donnees[1] = 'o'; | |
303 | + //uint8_t paquet[]; | |
304 | + sock_udp_ep_t remote = { .family = AF_INET6 }; | |
305 | + | |
306 | + remote.port = 1234; | |
307 | + remote.addr.ipv6[0] = 0xde; | |
308 | + remote.addr.ipv6[1] = 0xad; | |
309 | + remote.addr.ipv6[2] = 0xbe; | |
310 | + remote.addr.ipv6[3] = 0xef; | |
311 | + remote.addr.ipv6[14] = 0x34; | |
312 | + remote.addr.ipv6[15] = 0x2a; | |
313 | +// memcpy(remote.addr.ipv6,addr.u8,IPV6_ADDR_BIT_LEN); | |
314 | + while (1) { | |
315 | +// //ipv6_addr_set_all_nodes_multicast((ipv6_addr_t *)&remote.addr.ipv6, | |
316 | +// // IPV6_ADDR_MCAST_SCP_LINK_LOCAL); | |
317 | + data.heure_actuelle = xtimer_now_usec(); | |
318 | + | |
319 | + if (sock_udp_send(NULL, &data, sizeof(data), &remote) < 0) { | |
320 | + puts("Error sending message"); | |
321 | + } | |
322 | + xtimer_sleep(2); | |
323 | + } | |
324 | + return NULL; | |
325 | +}*/ | |
326 | + | |
327 | +/*static void arret_urgence(void *arg,int channel) | |
328 | +{ | |
329 | + pwm_set(PWM_DEV(0),1,0); | |
330 | + tourne = 0; | |
331 | + //ordre=0; | |
332 | + timer_run = 0; | |
333 | + printf("Arret d'urgence\n"); | |
334 | +}*/ | |
335 | + | |
336 | +/*static void degradation(void *arg,int channel) | |
337 | +{ | |
338 | + ordre=2; | |
339 | + //pwm_set(PWM_DEV(0),1,0); | |
340 | + printf("Ralentissement\n"); | |
341 | + timer_set(TIMER_DEV(1),0,25200); | |
342 | +}*/ | |
343 | + | |
344 | +/*static void _init_timer(void) | |
345 | +{ | |
346 | + printf("ok timer\n"); | |
347 | + //timer_init(XTIMER_DEV, CLOCK_CORECLOCK/2 ,°radation,NULL); | |
348 | + //timer_set(XTIMER_DEV, 0, 8400); | |
349 | + //timer_irq_enable(XTIMER_DEV); | |
350 | + timer_init(TIMER_DEV(1), CLOCK_CORECLOCK/2 ,&arret_urgence,NULL); | |
351 | + timer_irq_enable(TIMER_DEV(1)); | |
352 | +} | |
353 | + | |
354 | +static void _init_pwm(void) | |
355 | +{ | |
356 | + pwm_init(PWM_DEV(0), PWM_LEFT, PWM_FREQ, PWM_RES); | |
357 | + pwm_set(PWM_DEV(0),1,0); | |
358 | + | |
359 | +// thread_create(pwm_stack,sizeof(pwm_stack),7,THREAD_CREATE_STACKTEST,pwm_thread,NULL,"pwm_thread"); | |
360 | +} | |
361 | +*/ | |
362 | + | |
363 | + | |
364 | + | |
365 | +static void _init_interface(void) | |
366 | +{ | |
367 | + kernel_pid_t ifs[GNRC_NETIF_NUMOF]; | |
368 | + ipv6_addr_t addr = IPV6_ADDR_UNSPECIFIED; | |
369 | + ipv6_addr_t tmp_addr= IPV6_ADDR_UNSPECIFIED; | |
370 | + uint8_t hwaddr[MAX_ADDR_LEN]; | |
371 | + int res; | |
372 | + | |
373 | + gnrc_netif_get(ifs); | |
374 | + | |
375 | + //addresses gobales | |
376 | + addr.u8[0] = 0xde; | |
377 | + addr.u8[1] = 0xad; | |
378 | + addr.u8[2] = 0xbe; | |
379 | + addr.u8[3] = 0xef; | |
380 | + | |
381 | + res = gnrc_netapi_get(ifs[0], NETOPT_ADDRESS, 0, hwaddr, sizeof(hwaddr)); | |
382 | + | |
383 | + if (res >= 0) { | |
384 | + addr.u8[14] = *hwaddr; | |
385 | + addr.u8[15] = *(hwaddr+1); | |
386 | + } | |
387 | + //init RPL | |
388 | + //init_RPL(ifs[0]); | |
389 | + memcpy(tmp_addr.u8,addr.u8,IPV6_ADDR_BIT_LEN); | |
390 | + | |
391 | + gnrc_ipv6_netif_add_addr(ifs[0], &addr, 64, GNRC_IPV6_NETIF_ADDR_FLAGS_UNICAST); | |
392 | + /* model ipv6 addr: dead:beef::Hwaddr */ | |
393 | + if((addr.u8[14]==0x34)&&(addr.u8[15]==0x02)){ | |
394 | + crea_rpl_dodag_root("1", "dead:beef::3402"); | |
395 | + /*client=thread_create(sock_client_stack,sizeof(sock_client_stack),8,THREAD_CREATE_STACKTEST,sock_client_thread,NULL,"sock_client_thread"); | |
396 | + xtimer_usleep(200);*/ | |
397 | + time_server=thread_create(sock_time_server_stack,sizeof(sock_time_server_stack),6,THREAD_CREATE_STACKTEST,sock_time_server_thread,NULL,"sock_time_server_thread"); | |
398 | + xtimer_usleep(200); | |
399 | + }else if((addr.u8[14]==0x37)&&(addr.u8[15]==0x62)){ | |
400 | + | |
401 | + }else if((addr.u8[14]==0x34)&&(addr.u8[15]==0x2a)){ | |
402 | + //_init_timer(); | |
403 | + //_init_pwm(); | |
404 | + /*server=thread_create(sock_server_stack,sizeof(sock_server_stack),6,THREAD_CREATE_STACKTEST,sock_server_thread,NULL,"sock_server_thread");*/ | |
405 | + | |
406 | + }else if((addr.u8[14]==0x34)&&(addr.u8[15]==0x0a)){ | |
407 | + }else if((addr.u8[14]==0x34)&&(addr.u8[15]==0x1e)){ | |
408 | + }else{ | |
409 | + puts("new node ?"); | |
410 | + } | |
411 | +} | |
412 | + | |
413 | + | |
414 | +int main(void) | |
415 | +{ | |
416 | + | |
417 | + msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE); | |
418 | + puts("RIOT network stack example application"); | |
419 | + _init_interface(); | |
420 | + | |
421 | + /* start shell */ | |
422 | + puts("All up, running the shell now"); | |
423 | + char line_buf[SHELL_DEFAULT_BUFSIZE]; | |
424 | + shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE); | |
425 | + | |
426 | + /* should be never reached */ | |
427 | + return 0; | |
428 | +} | ... | ... |
... | ... | @@ -0,0 +1,174 @@ |
1 | +/* | |
2 | + * Copyright (C) 2015 Freie Universität Berlin | |
3 | + * | |
4 | + * This file is subject to the terms and conditions of the GNU Lesser | |
5 | + * General Public License v2.1. See the file LICENSE in the top level | |
6 | + * directory for more details. | |
7 | + */ | |
8 | + | |
9 | +/** | |
10 | + * @ingroup examples | |
11 | + * @{ | |
12 | + * | |
13 | + * @file | |
14 | + * @brief Demonstrating the sending and receiving of UDP data | |
15 | + * | |
16 | + * @author Hauke Petersen <hauke.petersen@fu-berlin.de> | |
17 | + * | |
18 | + * @} | |
19 | + */ | |
20 | + | |
21 | +#include <stdio.h> | |
22 | +#include <inttypes.h> | |
23 | + | |
24 | +#include "net/gnrc.h" | |
25 | +#include "net/gnrc/ipv6.h" | |
26 | +#include "net/gnrc/udp.h" | |
27 | +#include "net/gnrc/pktdump.h" | |
28 | +#include "timex.h" | |
29 | +#include "xtimer.h" | |
30 | + | |
31 | +//static gnrc_netreg_entry_t server = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, | |
32 | + // KERNEL_PID_UNDEF); | |
33 | + | |
34 | + | |
35 | +static void send(char *addr_str, char *port_str, char *data, unsigned int num, | |
36 | + unsigned int delay) | |
37 | +{ | |
38 | + uint16_t port; | |
39 | + ipv6_addr_t addr; | |
40 | + | |
41 | + /* parse destination address */ | |
42 | + if (ipv6_addr_from_str(&addr, addr_str) == NULL) { | |
43 | + puts("Error: unable to parse destination address"); | |
44 | + return; | |
45 | + } | |
46 | + /* parse port */ | |
47 | + port = (uint16_t)atoi(port_str); | |
48 | + if (port == 0) { | |
49 | + puts("Error: unable to parse destination port"); | |
50 | + return; | |
51 | + } | |
52 | + | |
53 | + for (unsigned int i = 0; i < num; i++) { | |
54 | + gnrc_pktsnip_t *payload, *udp, *ip; | |
55 | + unsigned payload_size; | |
56 | + /* allocate payload */ | |
57 | + payload = gnrc_pktbuf_add(NULL, data, strlen(data), GNRC_NETTYPE_UNDEF); | |
58 | + if (payload == NULL) { | |
59 | + puts("Error: unable to copy data to packet buffer"); | |
60 | + return; | |
61 | + } | |
62 | + /* store size for output */ | |
63 | + payload_size = (unsigned)payload->size; | |
64 | + /* allocate UDP header, set source port := destination port */ | |
65 | + udp = gnrc_udp_hdr_build(payload, port, port); | |
66 | + if (udp == NULL) { | |
67 | + puts("Error: unable to allocate UDP header"); | |
68 | + gnrc_pktbuf_release(payload); | |
69 | + return; | |
70 | + } | |
71 | + /* allocate IPv6 header */ | |
72 | + ip = gnrc_ipv6_hdr_build(udp, NULL, &addr); | |
73 | + if (ip == NULL) { | |
74 | + puts("Error: unable to allocate IPv6 header"); | |
75 | + gnrc_pktbuf_release(udp); | |
76 | + return; | |
77 | + } | |
78 | + /* send packet */ | |
79 | + if (!gnrc_netapi_dispatch_send(GNRC_NETTYPE_UDP, GNRC_NETREG_DEMUX_CTX_ALL, ip)) { | |
80 | + puts("Error: unable to locate UDP thread"); | |
81 | + gnrc_pktbuf_release(ip); | |
82 | + return; | |
83 | + } | |
84 | + /* access to `payload` was implicitly given up with the send operation above | |
85 | + * => use temporary variable for output */ | |
86 | + printf("Success: send %u byte to [%s]:%u\n", payload_size, addr_str, | |
87 | + port); | |
88 | + xtimer_usleep(delay); | |
89 | + } | |
90 | +} | |
91 | + | |
92 | +static void start_server(char *port_str) | |
93 | +{ | |
94 | +// uint16_t port; | |
95 | +// | |
96 | +// /* check if server is already running */ | |
97 | +// if (server.target.pid != KERNEL_PID_UNDEF) { | |
98 | +// printf("Error: server already running on port %" PRIu32 "\n", | |
99 | +// server.demux_ctx); | |
100 | +// return; | |
101 | +// } | |
102 | +// /* parse port */ | |
103 | +// port = (uint16_t)atoi(port_str); | |
104 | +// if (port == 0) { | |
105 | +// puts("Error: invalid port specified"); | |
106 | +// return; | |
107 | +// } | |
108 | +// /* start server (which means registering pktdump for the chosen port) */ | |
109 | +// server.target.pid = gnrc_pktdump_pid; | |
110 | +// server.demux_ctx = (uint32_t)port; | |
111 | +// gnrc_netreg_register(GNRC_NETTYPE_UDP, &server); | |
112 | +// printf("Success: started UDP server on port %" PRIu16 "\n", port); | |
113 | +} | |
114 | + | |
115 | +static void stop_server(void) | |
116 | +{ | |
117 | +// /* check if server is running at all */ | |
118 | +// if (server.target.pid == KERNEL_PID_UNDEF) { | |
119 | +// printf("Error: server was not running\n"); | |
120 | +// return; | |
121 | +// } | |
122 | +// /* stop server */ | |
123 | +// gnrc_netreg_unregister(GNRC_NETTYPE_UDP, &server); | |
124 | +// server.target.pid = KERNEL_PID_UNDEF; | |
125 | +// puts("Success: stopped UDP server"); | |
126 | +} | |
127 | + | |
128 | +int udp_cmd(int argc, char **argv) | |
129 | +{ | |
130 | + if (argc < 2) { | |
131 | + printf("usage: %s [send|server]\n", argv[0]); | |
132 | + return 1; | |
133 | + } | |
134 | + | |
135 | + if (strcmp(argv[1], "send") == 0) { | |
136 | + uint32_t num = 1; | |
137 | + uint32_t delay = 1000000; | |
138 | + if (argc < 5) { | |
139 | + printf("usage: %s send <addr> <port> <data> [<num> [<delay in us>]]\n", | |
140 | + argv[0]); | |
141 | + return 1; | |
142 | + } | |
143 | + if (argc > 5) { | |
144 | + num = (uint32_t)atoi(argv[5]); | |
145 | + } | |
146 | + if (argc > 6) { | |
147 | + delay = (uint32_t)atoi(argv[6]); | |
148 | + } | |
149 | + send(argv[2], argv[3], argv[4], num, delay); | |
150 | + } | |
151 | + else if (strcmp(argv[1], "server") == 0) { | |
152 | + if (argc < 3) { | |
153 | + printf("usage: %s server [start|stop]\n", argv[0]); | |
154 | + return 1; | |
155 | + } | |
156 | + if (strcmp(argv[2], "start") == 0) { | |
157 | + if (argc < 4) { | |
158 | + printf("usage %s server start <port>\n", argv[0]); | |
159 | + return 1; | |
160 | + } | |
161 | + start_server(argv[3]); | |
162 | + } | |
163 | + else if (strcmp(argv[2], "stop") == 0) { | |
164 | + stop_server(); | |
165 | + } | |
166 | + else { | |
167 | + puts("error: invalid command"); | |
168 | + } | |
169 | + } | |
170 | + else { | |
171 | + puts("error: invalid command"); | |
172 | + } | |
173 | + return 0; | |
174 | +} | ... | ... |
RIOT/sys/net/gnrc/pktdump/gnrc_pktdump.c
RIOT/sys/net/gnrc/routing/rpl/gnrc_rpl.c
... | ... | @@ -58,7 +58,7 @@ kernel_pid_t gnrc_rpl_init(kernel_pid_t if_pid) |
58 | 58 | if (gnrc_rpl_pid == KERNEL_PID_UNDEF) { |
59 | 59 | _instance_id = 0; |
60 | 60 | /* start the event loop */ |
61 | - gnrc_rpl_pid = thread_create(_stack, sizeof(_stack), GNRC_RPL_PRIO, | |
61 | + gnrc_rpl_pid = thread_create(_stack, sizeof(_stack),GNRC_RPL_PRIO, | |
62 | 62 | THREAD_CREATE_STACKTEST, |
63 | 63 | _event_loop, NULL, "RPL"); |
64 | 64 | ... | ... |
RIOT/sys/net/gnrc/routing/rpl/gnrc_rpl_auto_init.c
RIOT/tests/gnrc_sixlowpan/Makefile
... | ... | @@ -22,7 +22,7 @@ USEMODULE += gnrc_sixlowpan_default |
22 | 22 | USEMODULE += gnrc_udp |
23 | 23 | # Dumps packets |
24 | 24 | USEMODULE += gnrc_pktdump |
25 | - | |
25 | +USEMODULE += at86rf231 | |
26 | 26 | # Comment this out to disable code in RIOT that does safety checking |
27 | 27 | # which is not needed in a production environment but helps in the |
28 | 28 | # development process: | ... | ... |