Commit 3accef2640d0d3b51f2f27d5cdd7c99598aeccd4

Authored by root
1 parent d3acc3ce

integration application avec rpl

Showing 1 changed file with 287 additions and 268 deletions   Show diff stats
RIOT/examples/dynamic_app/main.c
... ... @@ -86,15 +86,15 @@
86 86  
87 87 #define PWM_FREQ 1000
88 88 #define PWM_RES 1000
89   -#define DEADLINE 15000
  89 +#define DEADLINE 40000
90 90  
91 91 static msg_t _main_msg_queue[MAIN_QUEUE_SIZE];
92 92  
93 93 extern int udp_cmd(int argc, char **argv);
94 94  
95 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 }
  96 + { "udp", "send data over UDP and listen on UDP ports", udp_cmd },
  97 + { NULL, NULL, NULL }
98 98 };
99 99  
100 100 // addr ipv6 link local node 1: fe80::3734:510e:3317:3402
... ... @@ -112,16 +112,14 @@ char pwm_stack[THREAD_STACKSIZE_MAIN];
112 112 char sock_server_stack[THREAD_STACKSIZE_MAIN];
113 113 char sock_client_stack[THREAD_STACKSIZE_MAIN];
114 114 char sock_time_server_stack[THREAD_STACKSIZE_MAIN];
115   -// static gnrc_netreg_entry_t server = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL,
116   -// KERNEL_PID_UNDEF);
117   -//
118   -// kernel_pid_t gnrc_server_pid = KERNEL_PID_UNDEF;
119   -//
  115 +
  116 +
120 117 kernel_pid_t server, client, time_server;
121 118 int ordre = 0;
122 119 int64_t offset = 0;
123 120 int timer_run = 0;
124 121 int tourne = 0;
  122 +int arret = 0;
125 123 sock_udp_ep_t local = SOCK_IPV6_EP_ANY;
126 124 sock_udp_t sock;
127 125 sock_udp_ep_t local_ntp = SOCK_IPV6_EP_ANY;
... ... @@ -129,317 +127,338 @@ sock_udp_t sock_ntp;
129 127 static ntp_packet_t sntp_packet;
130 128  
131 129 typedef struct tableau {
132   - uint32_t heure_actuelle;
133   - char donnees[2];
  130 + uint32_t heure_actuelle;
  131 + char donnees[2];
134 132 }Data;
135 133  
136 134 /***************** RPL functions *****************/
137 135  
138 136 int crea_rpl_dodag_root(char *arg1, char *arg2)
139 137 {
140   - uint8_t instance_id = (uint8_t) atoi(arg1);
141   - ipv6_addr_t dodag_id;
142   -
143   - if (ipv6_addr_from_str(&dodag_id, arg2) == NULL) {
144   - puts("error: <dodag_id> must be a valid IPv6 address");
145   - return 1;
146   - }
147   -
148   - gnrc_rpl_instance_t *inst = NULL;
149   - inst = gnrc_rpl_root_init(instance_id, &dodag_id, false, false);
150   - if (inst == NULL) {
151   - char addr_str[IPV6_ADDR_MAX_STR_LEN];
152   - printf("error: could not add DODAG (%s) to instance (%d)\n",
153   - ipv6_addr_to_str(addr_str, &dodag_id, sizeof(addr_str)), instance_id);
154   - return 1;
155   - }
156   -
157   - printf("successfully added a new RPL DODAG\n");
158   - return 0;
  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 + gnrc_rpl_instance_t *inst = NULL;
  147 + inst = gnrc_rpl_root_init(instance_id, &dodag_id, false, false);
  148 + if (inst == NULL) {
  149 + char addr_str[IPV6_ADDR_MAX_STR_LEN];
  150 + printf("error: could not add DODAG (%s) to instance (%d)\n",
  151 + ipv6_addr_to_str(addr_str, &dodag_id, sizeof(addr_str)), instance_id);
  152 + return 1;
  153 + }
  154 +
  155 + printf("successfully added a new RPL DODAG\n");
  156 + return 0;
159 157 }
160 158 /***************** /RPL functions ****************/
161 159  
162 160 void *sock_time_server_thread(void *arg)
163 161 {
164   - (void) arg;
165   - local_ntp.port = NTP_PORT;
  162 + (void) arg;
  163 + local_ntp.port = NTP_PORT;
  164 +
  165 + if (sock_udp_create(&sock_ntp, &local_ntp, NULL, 0) < 0) {
  166 + puts("Error creating UDP sock");
  167 + return NULL;
  168 + }
  169 +
  170 + while (1) {
  171 + sock_udp_ep_t remote;
  172 + ssize_t res;
166 173  
167   - if (sock_udp_create(&sock_ntp, &local_ntp, NULL, 0) < 0) {
168   - puts("Error creating UDP sock");
169   - return NULL;
170   - }
  174 + if ((res = sock_udp_recv(&sock_ntp,&sntp_packet, sizeof(sntp_packet), SOCK_NO_TIMEOUT,
  175 + &remote)) >= 0) {
  176 + puts("Received a message");
  177 + //printf("TT: %lu\n", byteorder_ntohl(sntp_packet.transmit.seconds));
171 178  
172   - while (1) {
173   - sock_udp_ep_t remote;
174   - ssize_t res;
175   -
176   - if ((res = sock_udp_recv(&sock_ntp,&sntp_packet, sizeof(sntp_packet), SOCK_NO_TIMEOUT,
177   - &remote)) >= 0) {
178   - puts("Received a message");
179   - //printf("TT: %lu\n", byteorder_ntohl(sntp_packet.transmit.seconds));
180   -
181   - // printf("%c\n",remote.addr.ipv6[15]);
182   - //xtimer_ticks64_t now = xtimer_now64();
183   - // heure actuelle du serveur
184   - sntp_packet.receive.seconds=byteorder_htonl( xtimer_now_usec());
185   - sntp_packet.origin.seconds=sntp_packet.transmit.seconds;
186   - sntp_packet.transmit.seconds=byteorder_htonl( xtimer_now_usec());
187   - //printf("heure actuelle : %lu\n",xtimer_now_usec());
188   - //printf("TT2: %lu\n", byteorder_ntohl(sntp_packet.transmit.seconds));
189   - //memset(&sntp_packet, 0, sizeof(sntp_packet));
190   - //ntp_packet_set_vn(&sntp_packet);
191   - //ntp_packet_set_mode(&sntp_packet, NTP_MODE_SERVER);
192   - if (sock_udp_send(&sock_ntp, &sntp_packet, sizeof(sntp_packet), &remote) < 0) {
193   - puts("Error sending reply");
194   - }
195   - }
  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());
  183 + sntp_packet.origin.seconds=sntp_packet.transmit.seconds;
  184 + 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);
  190 + if (sock_udp_send(&sock_ntp, &sntp_packet, sizeof(sntp_packet), &remote) < 0) {
  191 + puts("Error sending reply");
196 192 }
197   - return NULL;
  193 + }
  194 + }
  195 + return NULL;
198 196 }
199 197  
200 198  
201 199 void *sock_server_thread(void *arg)
202 200 {
203   - (void) arg;
204   - Data buf;
205   - int compteur = 5;
206   - int deadline;
207   - local.port = 1234;
208   - sock_udp_ep_t server = { .port = NTP_PORT, .family = AF_INET6 };
209   - ipv6_addr_from_str((ipv6_addr_t *)&server.addr, "dead:beef::3402");
210   -
211   - if (sock_udp_create(&sock, &local, NULL, 0) < 0) {
212   - puts("Error creating UDP sock");
213   - return NULL;
214   - }
215   - if (sntp_sync(&server, SOCK_NO_TIMEOUT) < 0) {
216   - puts("Error in synchronization");
  201 + (void) arg;
  202 + Data buf;
  203 + int compteur = 5;
  204 + int deadline;
  205 + local.port = 1234;
  206 + int interruption_msg = 0;
  207 + sock_udp_ep_t server = { .port = NTP_PORT, .family = AF_INET6 };
  208 + ipv6_addr_from_str((ipv6_addr_t *)&server.addr, "dead:beef::3402");
  209 +
  210 + if (sock_udp_create(&sock, &local, NULL, 0) < 0) {
  211 + puts("Error creating UDP sock");
  212 + return NULL;
  213 + }
  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 +
  220 + while (1) {
  221 + sock_udp_ep_t remote;
  222 + ssize_t res;
  223 + if ((res = sock_udp_recv(&sock, &buf, sizeof(buf), 5 * SEC_IN_USEC ,&remote)) >= 0) {
  224 + deadline = xtimer_now_usec() + offset - buf.heure_actuelle;
  225 + printf("tps de transmission : %i\n",deadline);
  226 +
  227 + if(buf.donnees[0] == 'g' && buf.donnees[1] == 'o') {
  228 + if(interruption_msg == 1) {
  229 + if (sntp_sync(&server, SOCK_NO_TIMEOUT) < 0) {
  230 + puts("Error in synchronization");
  231 + return NULL;
  232 + }
  233 + offset = sntp_get_offset();
  234 + printf("offset : %i\n",(int)offset);
  235 + interruption_msg = 0;
  236 + }
  237 + if(deadline >= DEADLINE && compteur >=5) {
  238 + compteur = 0;
  239 + if(arret == 0) {
  240 + if (sock_udp_send(&sock, "d", sizeof("d"), &remote) < 0) {
  241 + puts("Error sending reply");
  242 + }
  243 + }
  244 + if(tourne == 1)
  245 + {
  246 + pwm_set(PWM_DEV(0),1,987);
  247 + pwm_set(PWM_DEV(1),1,960);
  248 + }
  249 + if(timer_run == 0) {
  250 + puts("Degradation");
  251 + gpio_clear(LED1_PIN);
  252 + gpio_clear(LED2_PIN);
  253 + gpio_set(LED0_PIN);
  254 + 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 + timer_run = 1;
  262 + }
  263 + }
  264 + if(deadline >= DEADLINE && compteur < 5) {
  265 + compteur = 0;
  266 + if (sock_udp_send(&sock, "d", sizeof("d"), &remote) < 0) {
  267 + puts("Error sending reply");
  268 + }
  269 + }
  270 + if(deadline<=DEADLINE && compteur >=5) {
  271 + pwm_set(PWM_DEV(0),1,992);
  272 + pwm_set(PWM_DEV(1),1,658);
  273 + tourne = 1;
  274 + timer_run=0;
  275 + timer_clear(TIMER_DEV(1),0);
  276 + if (sock_udp_send(&sock, "n", sizeof("n"), &remote) < 0) {
  277 + puts("Error sending reply");
  278 + }
  279 + arret = 0;
  280 + gpio_clear(LED2_PIN);
  281 + gpio_clear(LED0_PIN);
  282 + gpio_set(LED1_PIN);
  283 + }
  284 + if(deadline<=DEADLINE && compteur <5) {
  285 + compteur++;
  286 + }
  287 + printf("compteur : %d\n",compteur);
  288 + memset(&buf,0,sizeof(buf));
  289 + if(arret == 1) {
  290 + if (sock_udp_send(&sock, "a", sizeof("a"), &remote) < 0) {
  291 + puts("Error sending reply");
  292 + }
  293 + }
  294 + }
217 295 }
218   - offset = sntp_get_offset();
219   - printf("offset : %i\n",(int)offset);
220   -
221   - while (1) {
222   - sock_udp_ep_t remote;
223   - ssize_t res;
224   - if ((res = sock_udp_recv(&sock, &buf, sizeof(buf), 5 * SEC_IN_USEC,&remote)) >= 0) {
225   - deadline = xtimer_now_usec() + offset - buf.heure_actuelle;
226   - printf("tps de transmission : %i\n",deadline);
227   -
228   - if(buf.donnees[0] == 'g' && buf.donnees[1] == 'o') {
229   - if(deadline >= DEADLINE && compteur >=5) {
230   - compteur = 0;
231   - if(tourne == 1){
232   - pwm_set(PWM_DEV(0),1,987);
233   - pwm_set(PWM_DEV(1),1,960);
234   - }
235   - if(timer_run == 0) {
236   - if (sock_udp_send(&sock, "d", sizeof("d"), &remote) < 0) {
237   - puts("Error sending reply");
238   - }
239   - gpio_clear(LED1_PIN);
240   - gpio_clear(LED2_PIN);
241   - gpio_set(LED0_PIN);
242   - timer_set(TIMER_DEV(1),0,25200);
243   - printf("relance timer\n");
244   - if (sntp_sync(&server, SOCK_NO_TIMEOUT) < 0) {
245   - puts("Error in synchronization");
246   - return NULL;
247   - }
248   - offset = sntp_get_offset();
249   - printf("offset : %i\n",(int)offset);
250   - timer_run = 1;
251   - }
252   - }
253   - if(deadline >= DEADLINE && compteur < 5) {
254   - compteur = 0;
255   - }
256   - if(deadline<=DEADLINE && compteur >=5) {
257   - pwm_set(PWM_DEV(0),1,992);
258   - pwm_set(PWM_DEV(1),1,658);
259   - tourne = 1;
260   - timer_run=0;
261   - timer_clear(TIMER_DEV(1),0);
262   - printf("clear timer\n");
263   - if (sock_udp_send(&sock, "n", sizeof("n"), &remote) < 0) {
264   - puts("Error sending reply");
265   - }
266   - gpio_clear(LED2_PIN);
267   - gpio_clear(LED0_PIN);
268   - gpio_set(LED1_PIN);
269   - }
270   - if(deadline<=DEADLINE && compteur <5) {
271   - compteur++;
272   - }
273   - printf("compteur : %d\n",compteur);
274   - memset(&buf,0,sizeof(buf));
275   - }
276   - }else{
277   - puts("msg non recu");
278   - }
  296 + else {
  297 + puts("msg non recu");
  298 + if(timer_run == 0 && interruption_msg == 0) {
  299 + timer_run = 1;
  300 + timer_set(TIMER_DEV(1),0,25200);
  301 + }
  302 + interruption_msg = 1;
  303 + if(tourne == 1)
  304 + {
  305 + pwm_set(PWM_DEV(0),1,987);
  306 + pwm_set(PWM_DEV(1),1,960);
  307 + gpio_clear(LED1_PIN);
  308 + gpio_clear(LED2_PIN);
  309 + gpio_set(LED0_PIN);
  310 + }
279 311 }
280   - return NULL;
  312 + }
  313 + return NULL;
281 314 }
282 315  
283 316  
284 317 void *sock_client_thread(void *arg)
285 318 {
286   - (void) arg;
287   - Data data;
288   - int vitesse=2;
289   - uint8_t buf[3];
290   - ssize_t res;
291   - data.donnees[0] = 'g';
292   - data.donnees[1] = 'o';
293   - //uint8_t paquet[];
294   - sock_udp_ep_t remote = { .family = AF_INET6 };
295   -
296   - remote.port = 1234;
297   - remote.addr.ipv6[0] = 0xde;
298   - remote.addr.ipv6[1] = 0xad;
299   - remote.addr.ipv6[2] = 0xbe;
300   - remote.addr.ipv6[3] = 0xef;
301   - remote.addr.ipv6[14] = 0x34;
302   - remote.addr.ipv6[15] = 0x1e;
303   - // memcpy(remote.addr.ipv6,addr.u8,IPV6_ADDR_BIT_LEN);
304   - while (1) {
305   - data.heure_actuelle = xtimer_now_usec();
306   -
307   - if (sock_udp_send(&sock, &data, sizeof(data), &remote) < 0) {
308   - puts("Error sending message");
309   - }
310   - puts("Send a message");
311   - if(vitesse==2) {
312   - gpio_clear(LED0_PIN);
313   - gpio_toggle(LED1_PIN);
314   - }
315   - else {
316   - gpio_clear(LED1_PIN);
317   - gpio_toggle(LED0_PIN);
318   - }
319   - if ((res = sock_udp_recv(&sock, buf, sizeof(buf), 0.05 * SEC_IN_USEC,NULL)) < 0) {
320   - if (res == -ETIMEDOUT) {
321   - puts("Timed out");
322   - }
323   - else {
324   - puts("Error receiving message");
325   - }
326   - }
327   - else {
328   - printf("Received message: \"");
329   - for (int i = 0; i < res; i++) {
330   - printf("%c", buf[i]);
331   - }
332   - if(buf[0] == 'n')
333   - vitesse = 2;
334   - else vitesse = 1;
335   - printf("\"\n");
336   - }
337   - xtimer_sleep(vitesse);
  319 + (void) arg;
  320 + Data data;
  321 + int vitesse=2;
  322 + uint8_t buf[3];
  323 + ssize_t res;
  324 + data.donnees[0] = 'g';
  325 + data.donnees[1] = 'o';
  326 + //uint8_t paquet[];
  327 + sock_udp_ep_t remote = { .family = AF_INET6 };
  328 +
  329 + remote.port = 1234;
  330 + remote.addr.ipv6[0] = 0xde;
  331 + remote.addr.ipv6[1] = 0xad;
  332 + remote.addr.ipv6[2] = 0xbe;
  333 + remote.addr.ipv6[3] = 0xef;
  334 + remote.addr.ipv6[14] = 0x34;
  335 + remote.addr.ipv6[15] = 0x1e;
  336 + // memcpy(remote.addr.ipv6,addr.u8,IPV6_ADDR_BIT_LEN);
  337 + while (1) {
  338 + data.heure_actuelle = xtimer_now_usec();
  339 + if (sock_udp_send(&sock, &data, sizeof(data), &remote) < 0) {
  340 + puts("Error sending message");
  341 + }
  342 + if ((res = sock_udp_recv(&sock, buf, sizeof(buf), 0.05 * SEC_IN_USEC,NULL)) < 0) {
  343 + if (res == -ETIMEDOUT) {
  344 + vitesse = 1;
  345 + }
  346 + else {
  347 + puts("Error receiving message");
  348 + }
338 349 }
339   - return NULL;
  350 + else {
  351 + if(buf[0] == 'n')
  352 + vitesse = 2;
  353 + else if(buf[0] == 'a') {
  354 + vitesse = 1;
  355 + gpio_set(LED2_PIN);
  356 + }
  357 + else vitesse = 1;
  358 + }
  359 + if(vitesse==2) {
  360 + gpio_clear(LED0_PIN);
  361 + gpio_clear(LED2_PIN);
  362 + gpio_toggle(LED1_PIN);
  363 + }
  364 + else {
  365 + gpio_clear(LED1_PIN);
  366 + gpio_toggle(LED0_PIN);
  367 + }
  368 + xtimer_sleep(vitesse);
  369 + }
  370 + return NULL;
340 371 }
341 372  
342 373 static void arret_urgence(void *arg,int channel)
343 374 {
344   - pwm_set(PWM_DEV(0),1,0);
345   - pwm_set(PWM_DEV(1),1,0);
346   - tourne = 0;
347   - timer_run = 0;
348   - gpio_clear(LED0_PIN);
349   - gpio_clear(LED1_PIN);
350   - gpio_set(LED2_PIN);
351   - printf("Arret d'urgence\n");
  375 + pwm_set(PWM_DEV(0),1,0);
  376 + pwm_set(PWM_DEV(1),1,0);
  377 + tourne = 0;
  378 + timer_run = 0;
  379 + arret = 1;
  380 + gpio_clear(LED0_PIN);
  381 + gpio_clear(LED1_PIN);
  382 + gpio_set(LED2_PIN);
  383 + puts("Arret d'urgence");
352 384 }
353 385  
354   -/*static void degradation(void *arg,int channel)
355   - * {
356   - * ordre=2;
357   - * //pwm_set(PWM_DEV(0),1,0);
358   - * printf("Ralentissement\n");
359   - * timer_set(TIMER_DEV(1),0,25200);
360   - * }*/
361 386  
362 387 static void _init_timer(void)
363 388 {
364   - printf("ok timer\n");
365   - //timer_init(XTIMER_DEV, CLOCK_CORECLOCK/2 ,&degradation,NULL);
366   - //timer_set(XTIMER_DEV, 0, 8400);
367   - //timer_irq_enable(XTIMER_DEV);
368   - timer_init(TIMER_DEV(1), CLOCK_CORECLOCK/2 ,&arret_urgence,NULL);
369   - timer_irq_enable(TIMER_DEV(1));
  389 + timer_init(TIMER_DEV(1), CLOCK_CORECLOCK/2 ,&arret_urgence,NULL);
  390 + timer_irq_enable(TIMER_DEV(1));
370 391 }
371 392  
372 393 static void _init_pwm(void)
373 394 {
374   - pwm_init(PWM_DEV(0), PWM_LEFT, PWM_FREQ, PWM_RES);
375   - pwm_set(PWM_DEV(0),1,0);
376   - pwm_init(PWM_DEV(1), PWM_LEFT, PWM_FREQ, PWM_RES);
377   - pwm_set(PWM_DEV(1),1,0);
378   -
379   - // thread_create(pwm_stack,sizeof(pwm_stack),7,THREAD_CREATE_STACKTEST,pwm_thread,NULL,"pwm_thread");
  395 + pwm_init(PWM_DEV(0), PWM_LEFT, PWM_FREQ, PWM_RES);
  396 + pwm_set(PWM_DEV(0),1,0);
  397 + pwm_init(PWM_DEV(1), PWM_LEFT, PWM_FREQ, PWM_RES);
  398 + pwm_set(PWM_DEV(1),1,0);
380 399 }
381 400  
382 401  
383 402  
384 403 static void _init_interface(void)
385 404 {
386   - kernel_pid_t ifs[GNRC_NETIF_NUMOF];
387   - ipv6_addr_t addr = IPV6_ADDR_UNSPECIFIED;
388   - ipv6_addr_t tmp_addr= IPV6_ADDR_UNSPECIFIED;
389   - uint8_t hwaddr[MAX_ADDR_LEN];
390   - int res;
391   -
392   - gnrc_netif_get(ifs);
  405 + kernel_pid_t ifs[GNRC_NETIF_NUMOF];
  406 + ipv6_addr_t addr = IPV6_ADDR_UNSPECIFIED;
  407 + ipv6_addr_t tmp_addr= IPV6_ADDR_UNSPECIFIED;
  408 + uint8_t hwaddr[MAX_ADDR_LEN];
  409 + int res;
  410 +
  411 + gnrc_netif_get(ifs);
  412 +
  413 + //addresses gobales
  414 + addr.u8[0] = 0xde;
  415 + addr.u8[1] = 0xad;
  416 + addr.u8[2] = 0xbe;
  417 + addr.u8[3] = 0xef;
  418 +
  419 + res = gnrc_netapi_get(ifs[0], NETOPT_ADDRESS, 0, hwaddr, sizeof(hwaddr));
  420 +
  421 + if (res >= 0) {
  422 + addr.u8[14] = *hwaddr;
  423 + addr.u8[15] = *(hwaddr+1);
  424 + }
  425 +
  426 + memcpy(tmp_addr.u8,addr.u8,IPV6_ADDR_BIT_LEN);
  427 +
  428 + gnrc_ipv6_netif_add_addr(ifs[0], &addr, 64, GNRC_IPV6_NETIF_ADDR_FLAGS_UNICAST);
  429 + /* model ipv6 addr: dead:beef::Hwaddr */
  430 + if((addr.u8[14]==0x34)&&(addr.u8[15]==0x02)){
  431 + crea_rpl_dodag_root("1", "dead:beef::3402");
  432 + 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 + 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 + }else if((addr.u8[14]==0x37)&&(addr.u8[15]==0x62)){
393 435  
394   - //addresses gobales
395   - addr.u8[0] = 0xde;
396   - addr.u8[1] = 0xad;
397   - addr.u8[2] = 0xbe;
398   - addr.u8[3] = 0xef;
  436 + }else if((addr.u8[14]==0x34)&&(addr.u8[15]==0x12)){
399 437  
400   - res = gnrc_netapi_get(ifs[0], NETOPT_ADDRESS, 0, hwaddr, sizeof(hwaddr));
401   -
402   - if (res >= 0) {
403   - addr.u8[14] = *hwaddr;
404   - addr.u8[15] = *(hwaddr+1);
405   - }
406   -
407   - memcpy(tmp_addr.u8,addr.u8,IPV6_ADDR_BIT_LEN);
408   -
409   - gnrc_ipv6_netif_add_addr(ifs[0], &addr, 64, GNRC_IPV6_NETIF_ADDR_FLAGS_UNICAST);
410   - /* model ipv6 addr: dead:beef::Hwaddr */
411   - if((addr.u8[14]==0x34)&&(addr.u8[15]==0x02)){
412   - crea_rpl_dodag_root("1", "dead:beef::3402");
413   - client=thread_create(sock_client_stack,sizeof(sock_client_stack),8,THREAD_CREATE_STACKTEST,sock_client_thread,NULL,"sock_client_thread");
414   - 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");
415   - }else if((addr.u8[14]==0x37)&&(addr.u8[15]==0x62)){
416   -
417   - }else if((addr.u8[14]==0x34)&&(addr.u8[15]==0x12)){
418   -
419   - }else if((addr.u8[14]==0x34)&&(addr.u8[15]==0x0a)){
420   - }else if((addr.u8[14]==0x34)&&(addr.u8[15]==0x1e)){
421   - _init_timer();
422   - _init_pwm();
423   - xtimer_sleep(2);
424   - server=thread_create(sock_server_stack,sizeof(sock_server_stack),6,THREAD_CREATE_STACKTEST,sock_server_thread,NULL,"sock_server_thread");
425   - }else{
426   - puts("new node ?");
427   - }
  438 + }else if((addr.u8[14]==0x34)&&(addr.u8[15]==0x0a)){
  439 + }else if((addr.u8[14]==0x34)&&(addr.u8[15]==0x1e)){
  440 + _init_timer();
  441 + _init_pwm();
  442 + xtimer_sleep(10);
  443 + server=thread_create(sock_server_stack,sizeof(sock_server_stack),6,THREAD_CREATE_STACKTEST,sock_server_thread,NULL,"sock_server_thread");
  444 + }else{
  445 + puts("new node ?");
  446 + }
428 447 }
429 448  
430 449  
431 450 int main(void)
432 451 {
433   - msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE);
434   - puts("RIOT network stack example application");
435   -
436   - _init_interface();
437   -
438   - /* start shell */
439   - puts("All up, running the shell now");
440   - char line_buf[SHELL_DEFAULT_BUFSIZE];
441   - shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
442   -
443   - /* should be never reached */
444   - return 0;
  452 + msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE);
  453 + puts("RIOT network stack example application");
  454 +
  455 + _init_interface();
  456 +
  457 + /* start shell */
  458 + puts("All up, running the shell now");
  459 + char line_buf[SHELL_DEFAULT_BUFSIZE];
  460 + shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
  461 +
  462 + /* should be never reached */
  463 + return 0;
445 464 }
... ...