Commit 0ce5a8d8309523bff5fc8b55b915a8c2dccdea96
1 parent
93480153
correctif mode dégradé
Showing
2 changed files
with
180 additions
and
186 deletions
Show diff stats
RIOT/examples/real_time_app/Makefile
... | ... | @@ -22,13 +22,12 @@ USEMODULE += auto_init_gnrc_netif |
22 | 22 | # Specify the mandatory networking modules for IPv6 and UDP |
23 | 23 | USEMODULE += gnrc_ipv6_router_default |
24 | 24 | USEMODULE += gnrc_udp |
25 | -# Add a routing protocol | |
26 | -USEMODULE += gnrc_rpl | |
27 | -#USEMODULE += auto_init_gnrc_rpl | |
28 | 25 | # This application dumps received packets to STDIO using the pktdump module |
29 | 26 | #USEMODULE += gnrc_pktdump |
30 | 27 | # Additional networking modules that can be dropped if not needed |
31 | 28 | USEMODULE += gnrc_icmpv6_echo |
29 | +# Add a routing protocol | |
30 | +USEMODULE += gnrc_rpl | |
32 | 31 | # Add also the shell, some shell commands |
33 | 32 | USEMODULE += shell |
34 | 33 | USEMODULE += shell_commands | ... | ... |
RIOT/examples/real_time_app/main.c
... | ... | @@ -23,8 +23,8 @@ |
23 | 23 | #include <stdlib.h> |
24 | 24 | #include <string.h> |
25 | 25 | #include <inttypes.h> |
26 | - | |
27 | 26 | #include <arpa/inet.h> |
27 | + | |
28 | 28 | #include "../../boards/stm32f4discovery/include/board.h" |
29 | 29 | #include "../../boards/stm32f4discovery/include/periph_conf.h" |
30 | 30 | #include "periph/gpio.h" |
... | ... | @@ -38,7 +38,6 @@ |
38 | 38 | #include "msg.h" |
39 | 39 | #include "thread.h" |
40 | 40 | #include "sched.h" |
41 | -#include "thread.h" | |
42 | 41 | #include "kernel_types.h" |
43 | 42 | #include "net/netstats.h" |
44 | 43 | #include "net/ipv6/addr.h" |
... | ... | @@ -79,9 +78,9 @@ |
79 | 78 | #define _STACKSIZE (THREAD_STACKSIZE_DEFAULT + THREAD_EXTRA_STACKSIZE_PRINTF) |
80 | 79 | #define MSG_TYPE_ISR (0x3456) |
81 | 80 | |
82 | -#define PWM_FREQ 100 | |
83 | -#define PWM_RES 100 | |
84 | -#define DEADLINE 15000 | |
81 | +#define PWM_FREQ 1000 | |
82 | +#define PWM_RES 1000 | |
83 | +#define DEADLINE 40000 | |
85 | 84 | |
86 | 85 | // addr ipv6 link local node 1: fe80::3734:510e:3317:3402 |
87 | 86 | uint8_t node1[16]={0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x37,0x34,0x51,0x0e,0x33,0x17,0x34,0x02}; |
... | ... | @@ -119,64 +118,42 @@ typedef struct tableau { |
119 | 118 | |
120 | 119 | void *sock_time_server_thread(void *arg) |
121 | 120 | { |
122 | - (void) arg; | |
123 | - local_ntp.port = NTP_PORT; | |
124 | - | |
125 | - if (sock_udp_create(&sock_ntp, &local_ntp, NULL, 0) < 0) { | |
126 | - puts("Error creating UDP sock"); | |
127 | - return NULL; | |
128 | - } | |
129 | - | |
130 | - while (1) { | |
131 | - sock_udp_ep_t remote; | |
132 | - ssize_t res; | |
133 | - | |
134 | - if ((res = sock_udp_recv(&sock_ntp,&sntp_packet, sizeof(sntp_packet), SOCK_NO_TIMEOUT, | |
135 | - &remote)) >= 0) { | |
136 | - puts("Received a message"); | |
137 | - //printf("TT: %lu\n", byteorder_ntohl(sntp_packet.transmit.seconds)); | |
138 | - | |
139 | - // printf("%c\n",remote.addr.ipv6[15]); | |
140 | - //xtimer_ticks64_t now = xtimer_now64(); | |
141 | - // heure actuelle du serveur | |
142 | - sntp_packet.receive.seconds=byteorder_htonl( xtimer_now_usec()); | |
143 | - sntp_packet.origin.seconds=sntp_packet.transmit.seconds; | |
144 | - sntp_packet.transmit.seconds=byteorder_htonl( xtimer_now_usec()); | |
145 | - //printf("heure actuelle : %lu\n",xtimer_now_usec()); | |
146 | - //printf("TT2: %lu\n", byteorder_ntohl(sntp_packet.transmit.seconds)); | |
147 | - //memset(&sntp_packet, 0, sizeof(sntp_packet)); | |
148 | - //ntp_packet_set_vn(&sntp_packet); | |
149 | - //ntp_packet_set_mode(&sntp_packet, NTP_MODE_SERVER); | |
150 | - if (sock_udp_send(&sock_ntp, &sntp_packet, sizeof(sntp_packet), &remote) < 0) { | |
151 | - puts("Error sending reply"); | |
152 | - } | |
153 | - } | |
154 | - } | |
121 | + (void) arg; | |
122 | + local_ntp.port = NTP_PORT; | |
123 | + | |
124 | + if (sock_udp_create(&sock_ntp, &local_ntp, NULL, 0) < 0) { | |
125 | + puts("Error creating UDP sock"); | |
155 | 126 | return NULL; |
156 | -} | |
157 | -/*void *pwm_thread(void *arg) | |
158 | -{ | |
159 | - (void) arg; | |
160 | - int tourne = 0; | |
161 | - while(1) | |
162 | - { | |
163 | - | |
164 | - if(ordre==1) | |
165 | - { | |
166 | - pwm_set(PWM_DEV(0),1,45); | |
167 | - tourne = 1; | |
168 | - } | |
169 | - else if(ordre==0) | |
170 | - { | |
171 | - pwm_set(PWM_DEV(0),1,0); | |
172 | - tourne = 0; | |
173 | - } | |
174 | - else if(ordre==2 && tourne == 1) | |
175 | - pwm_set(PWM_DEV(0),1,31); | |
127 | + } | |
128 | + | |
129 | + while (1) { | |
130 | + sock_udp_ep_t remote; | |
131 | + ssize_t res; | |
132 | + | |
133 | + if ((res = sock_udp_recv(&sock_ntp,&sntp_packet, sizeof(sntp_packet), SOCK_NO_TIMEOUT, | |
134 | + &remote)) >= 0) { | |
135 | + // puts("Received a message"); | |
136 | + //printf("TT: %lu\n", byteorder_ntohl(sntp_packet.transmit.seconds)); | |
176 | 137 | |
138 | + // printf("%c\n",remote.addr.ipv6[15]); | |
139 | + //xtimer_ticks64_t now = xtimer_now64(); | |
140 | + // heure actuelle du serveur | |
141 | + sntp_packet.receive.seconds=byteorder_htonl( xtimer_now_usec()); | |
142 | + sntp_packet.origin.seconds=sntp_packet.transmit.seconds; | |
143 | + sntp_packet.transmit.seconds=byteorder_htonl( xtimer_now_usec()); | |
144 | + //printf("heure actuelle : %lu\n",xtimer_now_usec()); | |
145 | + //printf("TT2: %lu\n", byteorder_ntohl(sntp_packet.transmit.seconds)); | |
146 | + //memset(&sntp_packet, 0, sizeof(sntp_packet)); | |
147 | + //ntp_packet_set_vn(&sntp_packet); | |
148 | + //ntp_packet_set_mode(&sntp_packet, NTP_MODE_SERVER); | |
149 | + if (sock_udp_send(&sock_ntp, &sntp_packet, sizeof(sntp_packet), &remote) < 0) { | |
150 | + puts("Error sending reply"); | |
177 | 151 | } |
178 | - return NULL; | |
179 | -}*/ | |
152 | + } | |
153 | + } | |
154 | + return NULL; | |
155 | +} | |
156 | + | |
180 | 157 | |
181 | 158 | void *sock_server_thread(void *arg) |
182 | 159 | { |
... | ... | @@ -184,10 +161,11 @@ void *sock_server_thread(void *arg) |
184 | 161 | Data buf; |
185 | 162 | int compteur = 5; |
186 | 163 | int deadline; |
164 | + int interruption_msg = 0; | |
187 | 165 | local.port = 1234; |
188 | 166 | sock_udp_ep_t server = { .port = NTP_PORT, .family = AF_INET6 }; |
189 | 167 | ipv6_addr_from_str((ipv6_addr_t *)&server.addr, "dead:beef::3402"); |
190 | - | |
168 | + | |
191 | 169 | if (sock_udp_create(&sock, &local, NULL, 0) < 0) { |
192 | 170 | puts("Error creating UDP sock"); |
193 | 171 | return NULL; |
... | ... | @@ -202,48 +180,62 @@ void *sock_server_thread(void *arg) |
202 | 180 | while (1) { |
203 | 181 | sock_udp_ep_t remote; |
204 | 182 | ssize_t res; |
205 | - if ((res = sock_udp_recv(&sock, &buf, sizeof(buf), SOCK_NO_TIMEOUT,&remote)) >= 0) { | |
183 | + if ((res = sock_udp_recv(&sock, &buf, sizeof(buf), 5 * SEC_IN_USEC ,&remote)) >= 0) { | |
206 | 184 | deadline = xtimer_now_usec() + offset - buf.heure_actuelle; |
207 | 185 | printf("tps de transmission : %i\n",deadline); |
208 | 186 | |
209 | 187 | if(buf.donnees[0] == 'g' && buf.donnees[1] == 'o') { |
188 | + if(interruption_msg == 1) { | |
189 | + if (sntp_sync(&server, SOCK_NO_TIMEOUT) < 0) { | |
190 | + puts("Error in synchronization"); | |
191 | + return NULL; | |
192 | + } | |
193 | + offset = sntp_get_offset(); | |
194 | + printf("offset : %i\n",(int)offset); | |
195 | + interruption_msg = 0; | |
196 | + } | |
210 | 197 | if(deadline >= DEADLINE && compteur >=5) { |
211 | 198 | compteur = 0; |
212 | - if(tourne == 1) | |
213 | - pwm_set(PWM_DEV(0),1,31); | |
199 | + if (sock_udp_send(&sock, "d", sizeof("d"), &remote) < 0) { | |
200 | + puts("Error sending reply"); | |
201 | + } | |
202 | + if(tourne == 1) | |
203 | + { | |
204 | + pwm_set(PWM_DEV(0),1,987); | |
205 | + pwm_set(PWM_DEV(1),1,960); | |
206 | + } | |
214 | 207 | if(timer_run == 0) { |
215 | - if (sock_udp_send(&sock, "d", sizeof("d"), &remote) < 0) { | |
216 | - puts("Error sending reply"); | |
217 | - } | |
218 | 208 | gpio_clear(LED1_PIN); |
219 | 209 | gpio_clear(LED2_PIN); |
220 | 210 | gpio_set(LED0_PIN); |
221 | 211 | timer_set(TIMER_DEV(1),0,25200); |
222 | - printf("relance timer\n"); | |
223 | - if (sntp_sync(&server, SOCK_NO_TIMEOUT) < 0) { | |
212 | + /* if (sntp_sync(&server, SOCK_NO_TIMEOUT) < 0) { | |
224 | 213 | puts("Error in synchronization"); |
225 | 214 | return NULL; |
226 | 215 | } |
227 | 216 | offset = sntp_get_offset(); |
228 | - printf("offset : %i\n",(int)offset); | |
217 | + printf("offset : %i\n",(int)offset);*/ | |
229 | 218 | timer_run = 1; |
230 | 219 | } |
231 | 220 | } |
232 | 221 | if(deadline >= DEADLINE && compteur < 5) { |
233 | 222 | compteur = 0; |
223 | + if (sock_udp_send(&sock, "d", sizeof("d"), &remote) < 0) { | |
224 | + puts("Error sending reply"); | |
225 | + } | |
234 | 226 | } |
235 | 227 | if(deadline<=DEADLINE && compteur >=5) { |
236 | - pwm_set(PWM_DEV(0),1,45); | |
228 | + pwm_set(PWM_DEV(0),1,992); | |
229 | + pwm_set(PWM_DEV(1),1,658); | |
237 | 230 | tourne = 1; |
238 | 231 | timer_run=0; |
239 | 232 | timer_clear(TIMER_DEV(1),0); |
240 | - printf("clear timer\n"); | |
241 | - if (sock_udp_send(&sock, "n", sizeof("n"), &remote) < 0) { | |
242 | - puts("Error sending reply"); | |
243 | - } | |
244 | - gpio_clear(LED2_PIN); | |
245 | - gpio_clear(LED0_PIN); | |
246 | - gpio_set(LED1_PIN); | |
233 | + if (sock_udp_send(&sock, "n", sizeof("n"), &remote) < 0) { | |
234 | + puts("Error sending reply"); | |
235 | + } | |
236 | + gpio_clear(LED2_PIN); | |
237 | + gpio_clear(LED0_PIN); | |
238 | + gpio_set(LED1_PIN); | |
247 | 239 | } |
248 | 240 | if(deadline<=DEADLINE && compteur <5) { |
249 | 241 | compteur++; |
... | ... | @@ -252,8 +244,24 @@ void *sock_server_thread(void *arg) |
252 | 244 | memset(&buf,0,sizeof(buf)); |
253 | 245 | } |
254 | 246 | } |
247 | + else { | |
248 | + puts("msg non recu"); | |
249 | + if(timer_run == 0 && interruption_msg == 0) { | |
250 | + timer_run = 1; | |
251 | + timer_set(TIMER_DEV(1),0,25200); | |
252 | + } | |
253 | + interruption_msg = 1; | |
254 | + if(tourne == 1) | |
255 | + { | |
256 | + pwm_set(PWM_DEV(0),1,987); | |
257 | + pwm_set(PWM_DEV(1),1,960); | |
258 | + gpio_clear(LED1_PIN); | |
259 | + gpio_clear(LED2_PIN); | |
260 | + gpio_set(LED0_PIN); | |
261 | + } | |
262 | + } | |
255 | 263 | } |
256 | - return NULL; | |
264 | + return NULL; | |
257 | 265 | } |
258 | 266 | |
259 | 267 | void *sock_client_thread(void *arg) |
... | ... | @@ -261,7 +269,7 @@ void *sock_client_thread(void *arg) |
261 | 269 | (void) arg; |
262 | 270 | Data data; |
263 | 271 | int vitesse=2; |
264 | - uint8_t buf[3]; | |
272 | + uint8_t buf[3];pwm_set(PWM_DEV(0),1,0); | |
265 | 273 | data.donnees[0] = 'g'; |
266 | 274 | data.donnees[1] = 'o'; |
267 | 275 | //uint8_t paquet[]; |
... | ... | @@ -275,14 +283,8 @@ void *sock_client_thread(void *arg) |
275 | 283 | remote.addr.ipv6[3] = 0xef; |
276 | 284 | remote.addr.ipv6[14] = 0x34; |
277 | 285 | remote.addr.ipv6[15] = 0x1e; |
278 | - | |
286 | + | |
279 | 287 | while (1) { |
280 | - data.heure_actuelle = xtimer_now_usec(); | |
281 | - | |
282 | - if (sock_udp_send(&sock, &data, sizeof(data), &remote) < 0) { | |
283 | - puts("Error sending message"); | |
284 | - } | |
285 | - puts("Send a message"); | |
286 | 288 | if(vitesse==2) { |
287 | 289 | gpio_clear(LED0_PIN); |
288 | 290 | gpio_toggle(LED1_PIN); |
... | ... | @@ -291,9 +293,14 @@ void *sock_client_thread(void *arg) |
291 | 293 | gpio_clear(LED1_PIN); |
292 | 294 | gpio_toggle(LED0_PIN); |
293 | 295 | } |
296 | + | |
297 | + data.heure_actuelle = xtimer_now_usec(); | |
298 | + if (sock_udp_send(&sock, &data, sizeof(data), &remote) < 0) { | |
299 | + puts("Error sending message"); | |
300 | + } | |
294 | 301 | if ((res = sock_udp_recv(&sock, buf, sizeof(buf), 0.05 * SEC_IN_USEC,NULL)) < 0) { |
295 | 302 | if (res == -ETIMEDOUT) { |
296 | - puts("Timed out"); | |
303 | + vitesse = 1; | |
297 | 304 | } |
298 | 305 | else { |
299 | 306 | puts("Error receiving message"); |
... | ... | @@ -317,6 +324,7 @@ void *sock_client_thread(void *arg) |
317 | 324 | static void arret_urgence(void *arg,int channel) |
318 | 325 | { |
319 | 326 | pwm_set(PWM_DEV(0),1,0); |
327 | + pwm_set(PWM_DEV(1),1,0); | |
320 | 328 | tourne = 0; |
321 | 329 | timer_run = 0; |
322 | 330 | gpio_clear(LED0_PIN); |
... | ... | @@ -325,20 +333,8 @@ static void arret_urgence(void *arg,int channel) |
325 | 333 | printf("Arret d'urgence\n"); |
326 | 334 | } |
327 | 335 | |
328 | -/*static void degradation(void *arg,int channel) | |
329 | -{ | |
330 | - ordre=2; | |
331 | - //pwm_set(PWM_DEV(0),1,0); | |
332 | - printf("Ralentissement\n"); | |
333 | - timer_set(TIMER_DEV(1),0,25200); | |
334 | -}*/ | |
335 | - | |
336 | 336 | static void _init_timer(void) |
337 | 337 | { |
338 | - printf("ok timer\n"); | |
339 | - //timer_init(XTIMER_DEV, CLOCK_CORECLOCK/2 ,°radation,NULL); | |
340 | - //timer_set(XTIMER_DEV, 0, 8400); | |
341 | - //timer_irq_enable(XTIMER_DEV); | |
342 | 338 | timer_init(TIMER_DEV(1), CLOCK_CORECLOCK/2 ,&arret_urgence,NULL); |
343 | 339 | timer_irq_enable(TIMER_DEV(1)); |
344 | 340 | } |
... | ... | @@ -347,100 +343,99 @@ static void _init_pwm(void) |
347 | 343 | { |
348 | 344 | pwm_init(PWM_DEV(0), PWM_LEFT, PWM_FREQ, PWM_RES); |
349 | 345 | pwm_set(PWM_DEV(0),1,0); |
346 | + pwm_init(PWM_DEV(1), PWM_LEFT, PWM_FREQ, PWM_RES); | |
347 | + pwm_set(PWM_DEV(1),1,0); | |
350 | 348 | } |
351 | 349 | |
352 | - | |
353 | - static void _init_interface(void) | |
354 | - { | |
355 | - kernel_pid_t ifs[GNRC_NETIF_NUMOF]; | |
356 | - ipv6_addr_t addr = IPV6_ADDR_UNSPECIFIED; | |
357 | - ipv6_addr_t tmp_addr= IPV6_ADDR_UNSPECIFIED; | |
358 | - uint8_t hwaddr[MAX_ADDR_LEN]; | |
359 | - int res; | |
360 | - | |
361 | - gnrc_netif_get(ifs); | |
362 | - | |
363 | - //addresses gobales | |
364 | - addr.u8[0] = 0xde; | |
365 | - addr.u8[1] = 0xad; | |
366 | - addr.u8[2] = 0xbe; | |
367 | - addr.u8[3] = 0xef; | |
368 | - | |
369 | - res = gnrc_netapi_get(ifs[0], NETOPT_ADDRESS, 0, hwaddr, sizeof(hwaddr)); | |
370 | - | |
371 | - if (res >= 0) { | |
372 | - addr.u8[14] = *hwaddr; | |
373 | - addr.u8[15] = *(hwaddr+1); | |
374 | - } | |
375 | - memcpy(tmp_addr.u8,addr.u8,IPV6_ADDR_BIT_LEN); | |
376 | - | |
377 | - gnrc_ipv6_netif_add_addr(ifs[0], &addr, 64, GNRC_IPV6_NETIF_ADDR_FLAGS_UNICAST); | |
378 | - /* model ipv6 addr: dead:beef::Hwaddr */ | |
379 | - if((addr.u8[14]==0x34)&&(addr.u8[15]==0x02)){ | |
380 | - | |
381 | - tmp_addr.u8[14] = 0x34; | |
382 | - tmp_addr.u8[15] = 0x1e; | |
383 | - //fibroute dest: dead:beef::3766 via fe80::3634:5110:3473:3762 | |
384 | - fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node2, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); | |
385 | - tmp_addr.u8[14] = 0x37; | |
386 | - tmp_addr.u8[15] = 0x62; | |
387 | - //fibroute dest: dead:beef::3762 via fe80::3634:5110:3473:3762 | |
388 | - fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node2, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); | |
389 | - client=thread_create(sock_client_stack,sizeof(sock_client_stack),8,THREAD_CREATE_STACKTEST,sock_client_thread,NULL,"sock_client_thread"); | |
390 | - //xtimer_usleep(10000); | |
391 | - 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"); | |
392 | - // xtimer_usleep(200); | |
393 | - }else if((addr.u8[14]==0x37)&&(addr.u8[15]==0x62)){ | |
394 | - tmp_addr.u8[14] = 0x34; | |
395 | - tmp_addr.u8[15] = 0x1e; | |
396 | - //fibroute dest: dead:beef::3766 via fe80::3634:5110:3471:3766 | |
397 | - fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node3, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); | |
398 | - tmp_addr.u8[14] = 0x34; | |
399 | - tmp_addr.u8[15] = 0x02; | |
400 | - //fibroute dest: dead:beef::3402 via fe80::3734:510e:3317:3402 | |
401 | - fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node1, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); | |
402 | - }else if((addr.u8[14]==0x34)&&(addr.u8[15]==0x1e)){ | |
403 | - tmp_addr.u8[14] = 0x34; | |
404 | - tmp_addr.u8[15] = 0x02; | |
405 | - //fibroute dest: dead:beef::3402 via fe80::3634:5110:3473:3762 | |
406 | - fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node2, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); tmp_addr.u8[14] = 0x37; | |
407 | - tmp_addr.u8[14] = 0x37; | |
408 | - tmp_addr.u8[15] = 0x62; | |
409 | - //fibroute dest: dead:beef::3762 via fe80::3634:5110:3473:3762 | |
410 | - fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node2, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); | |
411 | - //start_server("1234"); | |
412 | - _init_timer(); | |
413 | - _init_pwm(); | |
414 | - server=thread_create(sock_server_stack,sizeof(sock_server_stack),6,THREAD_CREATE_STACKTEST,sock_server_thread,NULL,"sock_server_thread"); | |
415 | - | |
416 | - | |
417 | - }else{ | |
418 | - puts("new node ?"); | |
419 | - } | |
420 | - } | |
350 | + | |
351 | +static void _init_interface(void) | |
352 | +{ | |
353 | + kernel_pid_t ifs[GNRC_NETIF_NUMOF]; | |
354 | + ipv6_addr_t addr = IPV6_ADDR_UNSPECIFIED; | |
355 | + ipv6_addr_t tmp_addr= IPV6_ADDR_UNSPECIFIED; | |
356 | + uint8_t hwaddr[MAX_ADDR_LEN]; | |
357 | + int res; | |
358 | + | |
359 | + gnrc_netif_get(ifs); | |
360 | + | |
361 | + //addresses gobales | |
362 | + addr.u8[0] = 0xde; | |
363 | + addr.u8[1] = 0xad; | |
364 | + addr.u8[2] = 0xbe; | |
365 | + addr.u8[3] = 0xef; | |
366 | + | |
367 | + res = gnrc_netapi_get(ifs[0], NETOPT_ADDRESS, 0, hwaddr, sizeof(hwaddr)); | |
368 | + | |
369 | + if (res >= 0) { | |
370 | + addr.u8[14] = *hwaddr; | |
371 | + addr.u8[15] = *(hwaddr+1); | |
372 | + } | |
373 | + memcpy(tmp_addr.u8,addr.u8,IPV6_ADDR_BIT_LEN); | |
374 | + | |
375 | + gnrc_ipv6_netif_add_addr(ifs[0], &addr, 64, GNRC_IPV6_NETIF_ADDR_FLAGS_UNICAST); | |
376 | + /* model ipv6 addr: dead:beef::Hwaddr */ | |
377 | + if((addr.u8[14]==0x34)&&(addr.u8[15]==0x02)){ | |
378 | + | |
379 | + tmp_addr.u8[14] = 0x34; | |
380 | + tmp_addr.u8[15] = 0x1e; | |
381 | + //fibroute dest: dead:beef::3766 via fe80::3634:5110:3473:3762 | |
382 | + fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node2, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); | |
383 | + tmp_addr.u8[14] = 0x37; | |
384 | + tmp_addr.u8[15] = 0x62; | |
385 | + //fibroute dest: dead:beef::3762 via fe80::3634:5110:3473:3762 | |
386 | + fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node2, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); | |
387 | + client=thread_create(sock_client_stack,sizeof(sock_client_stack),8,THREAD_CREATE_STACKTEST,sock_client_thread,NULL,"sock_client_thread"); | |
388 | + 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"); | |
389 | + }else if((addr.u8[14]==0x37)&&(addr.u8[15]==0x62)){ | |
390 | + tmp_addr.u8[14] = 0x34; | |
391 | + tmp_addr.u8[15] = 0x1e; | |
392 | + //fibroute dest: dead:beef::3766 via fe80::3634:5110:3471:3766 | |
393 | + fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node3, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); | |
394 | + tmp_addr.u8[14] = 0x34; | |
395 | + tmp_addr.u8[15] = 0x02; | |
396 | + //fibroute dest: dead:beef::3402 via fe80::3734:510e:3317:3402 | |
397 | + fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node1, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); | |
398 | + }else if((addr.u8[14]==0x34)&&(addr.u8[15]==0x1e)){ | |
399 | + tmp_addr.u8[14] = 0x34; | |
400 | + tmp_addr.u8[15] = 0x02; | |
401 | + //fibroute dest: dead:beef::3402 via fe80::3634:5110:3473:3762 | |
402 | + fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node2, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); tmp_addr.u8[14] = 0x37; | |
403 | + tmp_addr.u8[14] = 0x37; | |
404 | + tmp_addr.u8[15] = 0x62; | |
405 | + //fibroute dest: dead:beef::3762 via fe80::3634:5110:3473:3762 | |
406 | + fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node2, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); | |
407 | + _init_timer(); | |
408 | + _init_pwm(); | |
409 | + server=thread_create(sock_server_stack,sizeof(sock_server_stack),6,THREAD_CREATE_STACKTEST,sock_server_thread,NULL,"sock_server_thread"); | |
410 | + | |
411 | + | |
412 | + }else{ | |
413 | + puts("new node ?"); | |
414 | + } | |
415 | +} | |
421 | 416 | |
422 | 417 | static msg_t _main_msg_queue[MAIN_QUEUE_SIZE]; |
423 | 418 | |
424 | 419 | extern int udp_cmd(int argc, char **argv); |
425 | 420 | |
426 | 421 | static const shell_command_t shell_commands[] = { |
427 | - { "udp", "send data over UDP and listen on UDP ports", udp_cmd }, | |
428 | - { NULL, NULL, NULL } | |
422 | + { "udp", "send data over UDP and listen on UDP ports", udp_cmd }, | |
423 | + { NULL, NULL, NULL } | |
429 | 424 | }; |
430 | 425 | |
431 | 426 | |
432 | 427 | int main(void) |
433 | 428 | { |
434 | - | |
435 | - msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE); | |
436 | - puts("RIOT network stack example application"); | |
437 | - _init_interface(); | |
438 | - | |
439 | - /* start shell */ | |
440 | - puts("All up, running the shell now"); | |
441 | - char line_buf[SHELL_DEFAULT_BUFSIZE]; | |
442 | - shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE); | |
443 | - | |
444 | - /* should be never reached */ | |
445 | - return 0; | |
429 | + | |
430 | + msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE); | |
431 | + puts("RIOT network stack example application"); | |
432 | + _init_interface(); | |
433 | + | |
434 | + /* start shell */ | |
435 | + puts("All up, running the shell now"); | |
436 | + char line_buf[SHELL_DEFAULT_BUFSIZE]; | |
437 | + shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE); | |
438 | + | |
439 | + /* should be never reached */ | |
440 | + return 0; | |
446 | 441 | } | ... | ... |