Commit d4c7bb1655100216177ba943c05df62aef7fcee9

Authored by root
1 parent 3accef26

resolution pb de synchro, nettoyage du code

RIOT/examples/dynamic_app/main.c
... ... @@ -26,8 +26,8 @@
26 26  
27 27 #include <arpa/inet.h>
28 28 #include "periph/gpio.h"
29   -#include "../../boards/stm32f4discovery/include/board.h"
30   -#include "../../boards/stm32f4discovery/include/periph_conf.h"
  29 +#include "board.h"
  30 +#include "periph_conf.h"
31 31 #include "net/sock/udp.h"
32 32 #include "net/gnrc/ipv6.h"
33 33 #include "net/af.h"
... ... @@ -86,29 +86,10 @@
86 86  
87 87 #define PWM_FREQ 1000
88 88 #define PWM_RES 1000
89   -#define DEADLINE 40000
  89 +#define DEADLINE 30000
90 90  
91 91 static msg_t _main_msg_queue[MAIN_QUEUE_SIZE];
92 92  
93   -extern int udp_cmd(int argc, char **argv);
94   -
95   -static const shell_command_t shell_commands[] = {
96   - { "udp", "send data over UDP and listen on UDP ports", udp_cmd },
97   - { NULL, NULL, NULL }
98   -};
99   -
100   -// addr ipv6 link local node 1: fe80::3734:510e:3317:3402
101   -uint8_t node1[16]={0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x37,0x34,0x51,0x0e,0x33,0x17,0x34,0x02};
102   -// addr ipv6 link local node 2: fe80::3634:5110:3473:3762
103   -uint8_t node2[16]={0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x36,0x34,0x51,0x10,0x34,0x73,0x37,0x62};
104   -// addr ipv6 link local node 3: fe80::3734:510e:330b:342a
105   -uint8_t node3[16]={0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x31,0x33,0x47,0x11,0x37,0x2c,0x34,0x12};
106   -// addr ipv6 link local node 4: fe80::3734:510b:330b:340a
107   -uint8_t node4[16]={0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x37,0x34,0x51,0x0b,0x33,0x0b,0x34,0x0a};
108   -// addr ipv6 link local node 5: fe80::3734:510b:330a:341e
109   -uint8_t node5[16]={0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x37,0x34,0x51,0x0b,0x33,0x0a,0x34,0x1e};
110   -//static char _stack_server[GNRC_PKTDUMP_STACKSIZE];
111   -char pwm_stack[THREAD_STACKSIZE_MAIN];
112 93 char sock_server_stack[THREAD_STACKSIZE_MAIN];
113 94 char sock_client_stack[THREAD_STACKSIZE_MAIN];
114 95 char sock_time_server_stack[THREAD_STACKSIZE_MAIN];
... ... @@ -133,16 +114,8 @@ typedef struct tableau {
133 114  
134 115 /***************** RPL functions *****************/
135 116  
136   -int crea_rpl_dodag_root(char *arg1, char *arg2)
  117 +int crea_rpl_dodag_root(uint8_t instance_id, ipv6_addr_t dodag_id)
137 118 {
138   - uint8_t instance_id = (uint8_t) atoi(arg1);
139   - ipv6_addr_t dodag_id;
140   -
141   - if (ipv6_addr_from_str(&dodag_id, arg2) == NULL) {
142   - puts("error: <dodag_id> must be a valid IPv6 address");
143   - return 1;
144   - }
145   -
146 119 gnrc_rpl_instance_t *inst = NULL;
147 120 inst = gnrc_rpl_root_init(instance_id, &dodag_id, false, false);
148 121 if (inst == NULL) {
... ... @@ -173,20 +146,10 @@ void *sock_time_server_thread(void *arg)
173 146  
174 147 if ((res = sock_udp_recv(&sock_ntp,&sntp_packet, sizeof(sntp_packet), SOCK_NO_TIMEOUT,
175 148 &remote)) >= 0) {
176   - puts("Received a message");
177   - //printf("TT: %lu\n", byteorder_ntohl(sntp_packet.transmit.seconds));
178   -
179   - // printf("%c\n",remote.addr.ipv6[15]);
180   - //xtimer_ticks64_t now = xtimer_now64();
181   - // heure actuelle du serveur
182   - sntp_packet.receive.seconds=byteorder_htonl( xtimer_now_usec());
  149 + sntp_packet.receive.seconds=byteorder_htonl( xtimer_now_usec());
183 150 sntp_packet.origin.seconds=sntp_packet.transmit.seconds;
184 151 sntp_packet.transmit.seconds=byteorder_htonl( xtimer_now_usec());
185   - //printf("heure actuelle : %lu\n",xtimer_now_usec());
186   - //printf("TT2: %lu\n", byteorder_ntohl(sntp_packet.transmit.seconds));
187   - //memset(&sntp_packet, 0, sizeof(sntp_packet));
188   - //ntp_packet_set_vn(&sntp_packet);
189   - //ntp_packet_set_mode(&sntp_packet, NTP_MODE_SERVER);
  152 +
190 153 if (sock_udp_send(&sock_ntp, &sntp_packet, sizeof(sntp_packet), &remote) < 0) {
191 154 puts("Error sending reply");
192 155 }
... ... @@ -204,6 +167,7 @@ void *sock_server_thread(void *arg)
204 167 int deadline;
205 168 local.port = 1234;
206 169 int interruption_msg = 0;
  170 + int sync = 0;
207 171 sock_udp_ep_t server = { .port = NTP_PORT, .family = AF_INET6 };
208 172 ipv6_addr_from_str((ipv6_addr_t *)&server.addr, "dead:beef::3402");
209 173  
... ... @@ -211,11 +175,6 @@ void *sock_server_thread(void *arg)
211 175 puts("Error creating UDP sock");
212 176 return NULL;
213 177 }
214   - if (sntp_sync(&server, SOCK_NO_TIMEOUT) < 0) {
215   - puts("Error in synchronization");
216   - }
217   - offset = sntp_get_offset();
218   - printf("offset : %i\n",(int)offset);
219 178  
220 179 while (1) {
221 180 sock_udp_ep_t remote;
... ... @@ -225,10 +184,19 @@ void *sock_server_thread(void *arg)
225 184 printf("tps de transmission : %i\n",deadline);
226 185  
227 186 if(buf.donnees[0] == 'g' && buf.donnees[1] == 'o') {
  187 + if(sync == 0)
  188 + {
  189 + while(sntp_sync(&server, 5000000) < 0) {
  190 + puts("Erreur dans la synchronisation - Nouvelle tentative :");
  191 + }
  192 + offset = sntp_get_offset();
  193 + sync = 1;
  194 + printf("offset : %i\n",(int)offset);
  195 + }
228 196 if(interruption_msg == 1) {
229   - if (sntp_sync(&server, SOCK_NO_TIMEOUT) < 0) {
230   - puts("Error in synchronization");
231   - return NULL;
  197 + puts("reprise de la communication - tentative de synchronisation :");
  198 + while(sntp_sync(&server, 5000000) < 0) {
  199 + puts("Erreur dans la synchronisation - Nouvelle tentative :");
232 200 }
233 201 offset = sntp_get_offset();
234 202 printf("offset : %i\n",(int)offset);
... ... @@ -252,12 +220,6 @@ void *sock_server_thread(void *arg)
252 220 gpio_clear(LED2_PIN);
253 221 gpio_set(LED0_PIN);
254 222 timer_set(TIMER_DEV(1),0,25200);
255   - /* if (sntp_sync(&server, SOCK_NO_TIMEOUT) < 0) {
256   - * puts("Error in synchronization");
257   - * return NULL;
258   - }
259   - offset = sntp_get_offset();
260   - printf("offset : %i\n",(int)offset);*/
261 223 timer_run = 1;
262 224 }
263 225 }
... ... @@ -323,7 +285,7 @@ void *sock_client_thread(void *arg)
323 285 ssize_t res;
324 286 data.donnees[0] = 'g';
325 287 data.donnees[1] = 'o';
326   - //uint8_t paquet[];
  288 +
327 289 sock_udp_ep_t remote = { .family = AF_INET6 };
328 290  
329 291 remote.port = 1234;
... ... @@ -333,7 +295,7 @@ void *sock_client_thread(void *arg)
333 295 remote.addr.ipv6[3] = 0xef;
334 296 remote.addr.ipv6[14] = 0x34;
335 297 remote.addr.ipv6[15] = 0x1e;
336   - // memcpy(remote.addr.ipv6,addr.u8,IPV6_ADDR_BIT_LEN);
  298 +
337 299 while (1) {
338 300 data.heure_actuelle = xtimer_now_usec();
339 301 if (sock_udp_send(&sock, &data, sizeof(data), &remote) < 0) {
... ... @@ -428,7 +390,7 @@ static void _init_interface(void)
428 390 gnrc_ipv6_netif_add_addr(ifs[0], &addr, 64, GNRC_IPV6_NETIF_ADDR_FLAGS_UNICAST);
429 391 /* model ipv6 addr: dead:beef::Hwaddr */
430 392 if((addr.u8[14]==0x34)&&(addr.u8[15]==0x02)){
431   - crea_rpl_dodag_root("1", "dead:beef::3402");
  393 + crea_rpl_dodag_root(1, addr);
432 394 client=thread_create(sock_client_stack,sizeof(sock_client_stack),8,THREAD_CREATE_STACKTEST | THREAD_CREATE_WOUT_YIELD,sock_client_thread,NULL,"sock_client_thread");
433 395 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");
434 396 }else if((addr.u8[14]==0x37)&&(addr.u8[15]==0x62)){
... ... @@ -439,13 +401,17 @@ static void _init_interface(void)
439 401 }else if((addr.u8[14]==0x34)&&(addr.u8[15]==0x1e)){
440 402 _init_timer();
441 403 _init_pwm();
442   - xtimer_sleep(10);
  404 + xtimer_sleep(2);
443 405 server=thread_create(sock_server_stack,sizeof(sock_server_stack),6,THREAD_CREATE_STACKTEST,sock_server_thread,NULL,"sock_server_thread");
444 406 }else{
445 407 puts("new node ?");
446 408 }
447 409 }
448 410  
  411 +static const shell_command_t shell_commands[] = {
  412 + { NULL, NULL, NULL }
  413 +};
  414 +
449 415  
450 416 int main(void)
451 417 {
... ... @@ -457,8 +423,8 @@ int main(void)
457 423 /* start shell */
458 424 puts("All up, running the shell now");
459 425 char line_buf[SHELL_DEFAULT_BUFSIZE];
460   - shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
461 426  
  427 + shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
462 428 /* should be never reached */
463 429 return 0;
464 430 }
... ...
RIOT/examples/real_time_app/main.c
... ... @@ -25,8 +25,8 @@
25 25 #include <inttypes.h>
26 26 #include <arpa/inet.h>
27 27  
28   -#include "../../boards/stm32f4discovery/include/board.h"
29   -#include "../../boards/stm32f4discovery/include/periph_conf.h"
  28 +#include "board.h"
  29 +#include "periph_conf.h"
30 30 #include "periph/gpio.h"
31 31 #include "net/sock/udp.h"
32 32 #include "net/gnrc/ipv6.h"
... ... @@ -89,16 +89,10 @@ uint8_t node2[16]={0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x36,0x34,0x51,0x10,0
89 89 //addr ipv6 link local node 3: fe80::3634:5110:3471:3766
90 90 uint8_t node3[16]={0xfe,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x37,0x34,0x51,0x0b,0x33,0x0a,0x34,0x1e};
91 91  
92   -//static char _stack_server[GNRC_PKTDUMP_STACKSIZE];
93   -char pwm_stack[THREAD_STACKSIZE_MAIN];
94 92 char sock_server_stack[THREAD_STACKSIZE_MAIN];
95 93 char sock_client_stack[THREAD_STACKSIZE_MAIN];
96 94 char sock_time_server_stack[THREAD_STACKSIZE_MAIN];
97   -// static gnrc_netreg_entry_t server = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL,
98   -// KERNEL_PID_UNDEF);
99   -//
100   -// kernel_pid_t gnrc_server_pid = KERNEL_PID_UNDEF;
101   -//
  95 +
102 96 kernel_pid_t server, client, time_server;
103 97 int ordre = 0;
104 98 int64_t offset = 0;
... ... @@ -133,20 +127,10 @@ void *sock_time_server_thread(void *arg)
133 127  
134 128 if ((res = sock_udp_recv(&sock_ntp,&sntp_packet, sizeof(sntp_packet), SOCK_NO_TIMEOUT,
135 129 &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 130 sntp_packet.receive.seconds=byteorder_htonl( xtimer_now_usec());
143 131 sntp_packet.origin.seconds=sntp_packet.transmit.seconds;
144 132 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);
  133 +
150 134 if (sock_udp_send(&sock_ntp, &sntp_packet, sizeof(sntp_packet), &remote) < 0) {
151 135 puts("Error sending reply");
152 136 }
... ... @@ -213,12 +197,6 @@ void *sock_server_thread(void *arg)
213 197 gpio_clear(LED2_PIN);
214 198 gpio_set(LED0_PIN);
215 199 timer_set(TIMER_DEV(1),0,25200);
216   - /* if (sntp_sync(&server, SOCK_NO_TIMEOUT) < 0) {
217   - * puts("Error in synchronization");
218   - * return NULL;
219   - }
220   - offset = sntp_get_offset();
221   - printf("offset : %i\n",(int)offset);*/
222 200 timer_run = 1;
223 201 }
224 202 }
... ... @@ -426,10 +404,7 @@ static void _init_interface(void)
426 404  
427 405 static msg_t _main_msg_queue[MAIN_QUEUE_SIZE];
428 406  
429   -extern int udp_cmd(int argc, char **argv);
430   -
431 407 static const shell_command_t shell_commands[] = {
432   - { "udp", "send data over UDP and listen on UDP ports", udp_cmd },
433 408 { NULL, NULL, NULL }
434 409 };
435 410  
... ...
RIOT/sys/net/application_layer/sntp/sntp.c
... ... @@ -63,7 +63,7 @@ int sntp_sync(sock_udp_ep_t *server, uint32_t timeout)
63 63 if ((result = (int)sock_udp_recv(&_sntp_sock,
64 64 &_sntp_packet,
65 65 sizeof(_sntp_packet),
66   - SOCK_NO_TIMEOUT,
  66 + timeout,
67 67 NULL)) < 0) {
68 68 DEBUG("Error receiving message\n");
69 69 sock_udp_close(&_sntp_sock);
... ...
RIOT/sys/net/gnrc/network_layer/ipv6/gnrc_ipv6.c
... ... @@ -16,6 +16,8 @@
16 16 #include <inttypes.h>
17 17 #include <stdbool.h>
18 18  
  19 +#include "board.h"
  20 +#include "periph_conf.h"
19 21 #include "byteorder.h"
20 22 #include "cpu_conf.h"
21 23 #include "kernel_types.h"
... ... @@ -923,7 +925,7 @@ static void _receive(gnrc_pktsnip_t *pkt)
923 925 gnrc_pktsnip_t *reversed_pkt = NULL, *ptr = pkt;
924 926  
925 927 DEBUG("ipv6: forward packet to next hop\n");
926   - // printf ("transmission\n");
  928 + LED1_TOGGLE;
927 929 /* pkt might not be writable yet, if header was given above */
928 930 ipv6 = gnrc_pktbuf_start_write(ipv6);
929 931 if (ipv6 == NULL) {
... ...
RIOT/sys/net/gnrc/routing/rpl/gnrc_rpl_dodag.c
... ... @@ -309,7 +309,6 @@ static gnrc_rpl_parent_t *_gnrc_rpl_find_preferred_parent(gnrc_rpl_dodag_t *doda
309 309 gnrc_rpl_parent_t *elt, *tmp;
310 310  
311 311 if (dodag->parents == NULL) {
312   - puts("NULL 1");
313 312 return NULL;
314 313 }
315 314  
... ... @@ -318,7 +317,6 @@ static gnrc_rpl_parent_t *_gnrc_rpl_find_preferred_parent(gnrc_rpl_dodag_t *doda
318 317 }
319 318  
320 319 if (new_best->rank == GNRC_RPL_INFINITE_RANK) {
321   - puts("NULL 2");
322 320 return NULL;
323 321 }
324 322  
... ...
RIOT/sys/net/gnrc/routing/rpl/of0.c
... ... @@ -54,10 +54,8 @@ uint16_t calc_rank(gnrc_rpl_parent_t *parent, uint16_t base_rank)
54 54 {
55 55 if (base_rank == 0) {
56 56 if (parent == NULL) {
57   - puts("pas parent");
58 57 return GNRC_RPL_INFINITE_RANK;
59 58 }
60   - //puts("if1");
61 59 base_rank = parent->rank;
62 60  
63 61 }
... ... @@ -65,26 +63,21 @@ uint16_t calc_rank(gnrc_rpl_parent_t *parent, uint16_t base_rank)
65 63 uint16_t add;
66 64  
67 65 if (parent != NULL) {
68   - //puts("if2");
69   - //add = parent->dodag->instance->min_hop_rank_inc;
70 66 /*******************************************************************/
71 67 //ADDED BY PFE7 2017
72 68  
73 69 add = 256 - (parent->mc.rssi + parent->mc.lqi)/10;
74 70 parent->dodag->instance->min_hop_rank_inc=add;
75   - //printf("add= %u\n",add);
76 71  
77 72 //\ADDED BY PFE7 2017
78 73 /*******************************************************************/
79 74 }
80 75 else {
81   - puts("else1");
82 76 add = GNRC_RPL_DEFAULT_MIN_HOP_RANK_INCREASE;
83 77  
84 78 }
85 79  
86 80 if ((base_rank + add) < base_rank) {
87   - puts("b_r + add < br");
88 81 return GNRC_RPL_INFINITE_RANK;
89 82 }
90 83 return base_rank + add;
... ...