From 0ce5a8d8309523bff5fc8b55b915a8c2dccdea96 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 17 Feb 2017 12:01:13 +0000 Subject: [PATCH] correctif mode dégradé --- RIOT/examples/real_time_app/Makefile | 5 ++--- RIOT/examples/real_time_app/main.c | 361 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 2 files changed, 180 insertions(+), 186 deletions(-) diff --git a/RIOT/examples/real_time_app/Makefile b/RIOT/examples/real_time_app/Makefile index 0214b5c..bfcb7d4 100755 --- a/RIOT/examples/real_time_app/Makefile +++ b/RIOT/examples/real_time_app/Makefile @@ -22,13 +22,12 @@ 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 a routing protocol +USEMODULE += gnrc_rpl # Add also the shell, some shell commands USEMODULE += shell USEMODULE += shell_commands diff --git a/RIOT/examples/real_time_app/main.c b/RIOT/examples/real_time_app/main.c index 87d364e..f2c6786 100755 --- a/RIOT/examples/real_time_app/main.c +++ b/RIOT/examples/real_time_app/main.c @@ -23,8 +23,8 @@ #include #include #include - #include + #include "../../boards/stm32f4discovery/include/board.h" #include "../../boards/stm32f4discovery/include/periph_conf.h" #include "periph/gpio.h" @@ -38,7 +38,6 @@ #include "msg.h" #include "thread.h" #include "sched.h" -#include "thread.h" #include "kernel_types.h" #include "net/netstats.h" #include "net/ipv6/addr.h" @@ -79,9 +78,9 @@ #define _STACKSIZE (THREAD_STACKSIZE_DEFAULT + THREAD_EXTRA_STACKSIZE_PRINTF) #define MSG_TYPE_ISR (0x3456) -#define PWM_FREQ 100 -#define PWM_RES 100 -#define DEADLINE 15000 +#define PWM_FREQ 1000 +#define PWM_RES 1000 +#define DEADLINE 40000 // addr ipv6 link local node 1: fe80::3734:510e:3317:3402 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 { void *sock_time_server_thread(void *arg) { - (void) arg; - local_ntp.port = NTP_PORT; - - if (sock_udp_create(&sock_ntp, &local_ntp, NULL, 0) < 0) { - puts("Error creating UDP sock"); - return NULL; - } - - while (1) { - sock_udp_ep_t remote; - ssize_t res; - - if ((res = sock_udp_recv(&sock_ntp,&sntp_packet, sizeof(sntp_packet), SOCK_NO_TIMEOUT, - &remote)) >= 0) { - puts("Received a message"); - //printf("TT: %lu\n", byteorder_ntohl(sntp_packet.transmit.seconds)); - - // printf("%c\n",remote.addr.ipv6[15]); - //xtimer_ticks64_t now = xtimer_now64(); - // heure actuelle du serveur - sntp_packet.receive.seconds=byteorder_htonl( xtimer_now_usec()); - sntp_packet.origin.seconds=sntp_packet.transmit.seconds; - sntp_packet.transmit.seconds=byteorder_htonl( xtimer_now_usec()); - //printf("heure actuelle : %lu\n",xtimer_now_usec()); - //printf("TT2: %lu\n", byteorder_ntohl(sntp_packet.transmit.seconds)); - //memset(&sntp_packet, 0, sizeof(sntp_packet)); - //ntp_packet_set_vn(&sntp_packet); - //ntp_packet_set_mode(&sntp_packet, NTP_MODE_SERVER); - if (sock_udp_send(&sock_ntp, &sntp_packet, sizeof(sntp_packet), &remote) < 0) { - puts("Error sending reply"); - } - } - } + (void) arg; + local_ntp.port = NTP_PORT; + + if (sock_udp_create(&sock_ntp, &local_ntp, NULL, 0) < 0) { + puts("Error creating UDP sock"); return NULL; -} -/*void *pwm_thread(void *arg) -{ - (void) arg; - int tourne = 0; - while(1) - { - - if(ordre==1) - { - pwm_set(PWM_DEV(0),1,45); - tourne = 1; - } - else if(ordre==0) - { - pwm_set(PWM_DEV(0),1,0); - tourne = 0; - } - else if(ordre==2 && tourne == 1) - pwm_set(PWM_DEV(0),1,31); + } + + while (1) { + sock_udp_ep_t remote; + ssize_t res; + + if ((res = sock_udp_recv(&sock_ntp,&sntp_packet, sizeof(sntp_packet), SOCK_NO_TIMEOUT, + &remote)) >= 0) { + // puts("Received a message"); + //printf("TT: %lu\n", byteorder_ntohl(sntp_packet.transmit.seconds)); + // printf("%c\n",remote.addr.ipv6[15]); + //xtimer_ticks64_t now = xtimer_now64(); + // heure actuelle du serveur + sntp_packet.receive.seconds=byteorder_htonl( xtimer_now_usec()); + sntp_packet.origin.seconds=sntp_packet.transmit.seconds; + sntp_packet.transmit.seconds=byteorder_htonl( xtimer_now_usec()); + //printf("heure actuelle : %lu\n",xtimer_now_usec()); + //printf("TT2: %lu\n", byteorder_ntohl(sntp_packet.transmit.seconds)); + //memset(&sntp_packet, 0, sizeof(sntp_packet)); + //ntp_packet_set_vn(&sntp_packet); + //ntp_packet_set_mode(&sntp_packet, NTP_MODE_SERVER); + if (sock_udp_send(&sock_ntp, &sntp_packet, sizeof(sntp_packet), &remote) < 0) { + puts("Error sending reply"); } - return NULL; -}*/ + } + } + return NULL; +} + void *sock_server_thread(void *arg) { @@ -184,10 +161,11 @@ void *sock_server_thread(void *arg) Data buf; int compteur = 5; int deadline; + int interruption_msg = 0; local.port = 1234; sock_udp_ep_t server = { .port = NTP_PORT, .family = AF_INET6 }; ipv6_addr_from_str((ipv6_addr_t *)&server.addr, "dead:beef::3402"); - + if (sock_udp_create(&sock, &local, NULL, 0) < 0) { puts("Error creating UDP sock"); return NULL; @@ -202,48 +180,62 @@ void *sock_server_thread(void *arg) while (1) { sock_udp_ep_t remote; ssize_t res; - if ((res = sock_udp_recv(&sock, &buf, sizeof(buf), SOCK_NO_TIMEOUT,&remote)) >= 0) { + if ((res = sock_udp_recv(&sock, &buf, sizeof(buf), 5 * SEC_IN_USEC ,&remote)) >= 0) { deadline = xtimer_now_usec() + offset - buf.heure_actuelle; printf("tps de transmission : %i\n",deadline); if(buf.donnees[0] == 'g' && buf.donnees[1] == 'o') { + if(interruption_msg == 1) { + if (sntp_sync(&server, SOCK_NO_TIMEOUT) < 0) { + puts("Error in synchronization"); + return NULL; + } + offset = sntp_get_offset(); + printf("offset : %i\n",(int)offset); + interruption_msg = 0; + } if(deadline >= DEADLINE && compteur >=5) { compteur = 0; - if(tourne == 1) - pwm_set(PWM_DEV(0),1,31); + if (sock_udp_send(&sock, "d", sizeof("d"), &remote) < 0) { + puts("Error sending reply"); + } + if(tourne == 1) + { + pwm_set(PWM_DEV(0),1,987); + pwm_set(PWM_DEV(1),1,960); + } if(timer_run == 0) { - if (sock_udp_send(&sock, "d", sizeof("d"), &remote) < 0) { - puts("Error sending reply"); - } gpio_clear(LED1_PIN); gpio_clear(LED2_PIN); gpio_set(LED0_PIN); timer_set(TIMER_DEV(1),0,25200); - printf("relance timer\n"); - if (sntp_sync(&server, SOCK_NO_TIMEOUT) < 0) { + /* if (sntp_sync(&server, SOCK_NO_TIMEOUT) < 0) { puts("Error in synchronization"); return NULL; } offset = sntp_get_offset(); - printf("offset : %i\n",(int)offset); + printf("offset : %i\n",(int)offset);*/ timer_run = 1; } } if(deadline >= DEADLINE && compteur < 5) { compteur = 0; + if (sock_udp_send(&sock, "d", sizeof("d"), &remote) < 0) { + puts("Error sending reply"); + } } if(deadline<=DEADLINE && compteur >=5) { - pwm_set(PWM_DEV(0),1,45); + pwm_set(PWM_DEV(0),1,992); + pwm_set(PWM_DEV(1),1,658); tourne = 1; timer_run=0; timer_clear(TIMER_DEV(1),0); - printf("clear timer\n"); - if (sock_udp_send(&sock, "n", sizeof("n"), &remote) < 0) { - puts("Error sending reply"); - } - gpio_clear(LED2_PIN); - gpio_clear(LED0_PIN); - gpio_set(LED1_PIN); + if (sock_udp_send(&sock, "n", sizeof("n"), &remote) < 0) { + puts("Error sending reply"); + } + gpio_clear(LED2_PIN); + gpio_clear(LED0_PIN); + gpio_set(LED1_PIN); } if(deadline<=DEADLINE && compteur <5) { compteur++; @@ -252,8 +244,24 @@ void *sock_server_thread(void *arg) memset(&buf,0,sizeof(buf)); } } + else { + puts("msg non recu"); + if(timer_run == 0 && interruption_msg == 0) { + timer_run = 1; + timer_set(TIMER_DEV(1),0,25200); + } + interruption_msg = 1; + if(tourne == 1) + { + pwm_set(PWM_DEV(0),1,987); + pwm_set(PWM_DEV(1),1,960); + gpio_clear(LED1_PIN); + gpio_clear(LED2_PIN); + gpio_set(LED0_PIN); + } + } } - return NULL; + return NULL; } void *sock_client_thread(void *arg) @@ -261,7 +269,7 @@ void *sock_client_thread(void *arg) (void) arg; Data data; int vitesse=2; - uint8_t buf[3]; + uint8_t buf[3];pwm_set(PWM_DEV(0),1,0); data.donnees[0] = 'g'; data.donnees[1] = 'o'; //uint8_t paquet[]; @@ -275,14 +283,8 @@ void *sock_client_thread(void *arg) remote.addr.ipv6[3] = 0xef; remote.addr.ipv6[14] = 0x34; remote.addr.ipv6[15] = 0x1e; - + while (1) { - data.heure_actuelle = xtimer_now_usec(); - - if (sock_udp_send(&sock, &data, sizeof(data), &remote) < 0) { - puts("Error sending message"); - } - puts("Send a message"); if(vitesse==2) { gpio_clear(LED0_PIN); gpio_toggle(LED1_PIN); @@ -291,9 +293,14 @@ void *sock_client_thread(void *arg) gpio_clear(LED1_PIN); gpio_toggle(LED0_PIN); } + + data.heure_actuelle = xtimer_now_usec(); + if (sock_udp_send(&sock, &data, sizeof(data), &remote) < 0) { + puts("Error sending message"); + } if ((res = sock_udp_recv(&sock, buf, sizeof(buf), 0.05 * SEC_IN_USEC,NULL)) < 0) { if (res == -ETIMEDOUT) { - puts("Timed out"); + vitesse = 1; } else { puts("Error receiving message"); @@ -317,6 +324,7 @@ void *sock_client_thread(void *arg) static void arret_urgence(void *arg,int channel) { pwm_set(PWM_DEV(0),1,0); + pwm_set(PWM_DEV(1),1,0); tourne = 0; timer_run = 0; gpio_clear(LED0_PIN); @@ -325,20 +333,8 @@ static void arret_urgence(void *arg,int channel) printf("Arret d'urgence\n"); } -/*static void degradation(void *arg,int channel) -{ - ordre=2; - //pwm_set(PWM_DEV(0),1,0); - printf("Ralentissement\n"); - timer_set(TIMER_DEV(1),0,25200); -}*/ - static void _init_timer(void) { - printf("ok timer\n"); - //timer_init(XTIMER_DEV, CLOCK_CORECLOCK/2 ,°radation,NULL); - //timer_set(XTIMER_DEV, 0, 8400); - //timer_irq_enable(XTIMER_DEV); timer_init(TIMER_DEV(1), CLOCK_CORECLOCK/2 ,&arret_urgence,NULL); timer_irq_enable(TIMER_DEV(1)); } @@ -347,100 +343,99 @@ static void _init_pwm(void) { pwm_init(PWM_DEV(0), PWM_LEFT, PWM_FREQ, PWM_RES); pwm_set(PWM_DEV(0),1,0); + pwm_init(PWM_DEV(1), PWM_LEFT, PWM_FREQ, PWM_RES); + pwm_set(PWM_DEV(1),1,0); } - - static void _init_interface(void) - { - kernel_pid_t ifs[GNRC_NETIF_NUMOF]; - ipv6_addr_t addr = IPV6_ADDR_UNSPECIFIED; - ipv6_addr_t tmp_addr= IPV6_ADDR_UNSPECIFIED; - uint8_t hwaddr[MAX_ADDR_LEN]; - int res; - - gnrc_netif_get(ifs); - - //addresses gobales - addr.u8[0] = 0xde; - addr.u8[1] = 0xad; - addr.u8[2] = 0xbe; - addr.u8[3] = 0xef; - - res = gnrc_netapi_get(ifs[0], NETOPT_ADDRESS, 0, hwaddr, sizeof(hwaddr)); - - if (res >= 0) { - addr.u8[14] = *hwaddr; - addr.u8[15] = *(hwaddr+1); - } - memcpy(tmp_addr.u8,addr.u8,IPV6_ADDR_BIT_LEN); - - gnrc_ipv6_netif_add_addr(ifs[0], &addr, 64, GNRC_IPV6_NETIF_ADDR_FLAGS_UNICAST); - /* model ipv6 addr: dead:beef::Hwaddr */ - if((addr.u8[14]==0x34)&&(addr.u8[15]==0x02)){ - - tmp_addr.u8[14] = 0x34; - tmp_addr.u8[15] = 0x1e; - //fibroute dest: dead:beef::3766 via fe80::3634:5110:3473:3762 - 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; - tmp_addr.u8[15] = 0x62; - //fibroute dest: dead:beef::3762 via fe80::3634:5110:3473:3762 - fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node2, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); - client=thread_create(sock_client_stack,sizeof(sock_client_stack),8,THREAD_CREATE_STACKTEST,sock_client_thread,NULL,"sock_client_thread"); - //xtimer_usleep(10000); - 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"); - // xtimer_usleep(200); - }else if((addr.u8[14]==0x37)&&(addr.u8[15]==0x62)){ - tmp_addr.u8[14] = 0x34; - tmp_addr.u8[15] = 0x1e; - //fibroute dest: dead:beef::3766 via fe80::3634:5110:3471:3766 - fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node3, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); - tmp_addr.u8[14] = 0x34; - tmp_addr.u8[15] = 0x02; - //fibroute dest: dead:beef::3402 via fe80::3734:510e:3317:3402 - fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node1, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); - }else if((addr.u8[14]==0x34)&&(addr.u8[15]==0x1e)){ - tmp_addr.u8[14] = 0x34; - tmp_addr.u8[15] = 0x02; - //fibroute dest: dead:beef::3402 via fe80::3634:5110:3473:3762 - 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; - tmp_addr.u8[14] = 0x37; - tmp_addr.u8[15] = 0x62; - //fibroute dest: dead:beef::3762 via fe80::3634:5110:3473:3762 - fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node2, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); - //start_server("1234"); - _init_timer(); - _init_pwm(); - server=thread_create(sock_server_stack,sizeof(sock_server_stack),6,THREAD_CREATE_STACKTEST,sock_server_thread,NULL,"sock_server_thread"); - - - }else{ - puts("new node ?"); - } - } + +static void _init_interface(void) +{ + kernel_pid_t ifs[GNRC_NETIF_NUMOF]; + ipv6_addr_t addr = IPV6_ADDR_UNSPECIFIED; + ipv6_addr_t tmp_addr= IPV6_ADDR_UNSPECIFIED; + uint8_t hwaddr[MAX_ADDR_LEN]; + int res; + + gnrc_netif_get(ifs); + + //addresses gobales + addr.u8[0] = 0xde; + addr.u8[1] = 0xad; + addr.u8[2] = 0xbe; + addr.u8[3] = 0xef; + + res = gnrc_netapi_get(ifs[0], NETOPT_ADDRESS, 0, hwaddr, sizeof(hwaddr)); + + if (res >= 0) { + addr.u8[14] = *hwaddr; + addr.u8[15] = *(hwaddr+1); + } + memcpy(tmp_addr.u8,addr.u8,IPV6_ADDR_BIT_LEN); + + gnrc_ipv6_netif_add_addr(ifs[0], &addr, 64, GNRC_IPV6_NETIF_ADDR_FLAGS_UNICAST); + /* model ipv6 addr: dead:beef::Hwaddr */ + if((addr.u8[14]==0x34)&&(addr.u8[15]==0x02)){ + + tmp_addr.u8[14] = 0x34; + tmp_addr.u8[15] = 0x1e; + //fibroute dest: dead:beef::3766 via fe80::3634:5110:3473:3762 + 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; + tmp_addr.u8[15] = 0x62; + //fibroute dest: dead:beef::3762 via fe80::3634:5110:3473:3762 + fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node2, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); + client=thread_create(sock_client_stack,sizeof(sock_client_stack),8,THREAD_CREATE_STACKTEST,sock_client_thread,NULL,"sock_client_thread"); + 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"); + }else if((addr.u8[14]==0x37)&&(addr.u8[15]==0x62)){ + tmp_addr.u8[14] = 0x34; + tmp_addr.u8[15] = 0x1e; + //fibroute dest: dead:beef::3766 via fe80::3634:5110:3471:3766 + fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node3, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); + tmp_addr.u8[14] = 0x34; + tmp_addr.u8[15] = 0x02; + //fibroute dest: dead:beef::3402 via fe80::3734:510e:3317:3402 + fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node1, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); + }else if((addr.u8[14]==0x34)&&(addr.u8[15]==0x1e)){ + tmp_addr.u8[14] = 0x34; + tmp_addr.u8[15] = 0x02; + //fibroute dest: dead:beef::3402 via fe80::3634:5110:3473:3762 + 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; + tmp_addr.u8[14] = 0x37; + tmp_addr.u8[15] = 0x62; + //fibroute dest: dead:beef::3762 via fe80::3634:5110:3473:3762 + fib_add_entry(&gnrc_ipv6_fib_table, ifs[0],tmp_addr.u8, IN6ADDRSZ, 0,node2, IN6ADDRSZ, 0, FIB_LIFETIME_NO_EXPIRE); + _init_timer(); + _init_pwm(); + server=thread_create(sock_server_stack,sizeof(sock_server_stack),6,THREAD_CREATE_STACKTEST,sock_server_thread,NULL,"sock_server_thread"); + + + }else{ + puts("new node ?"); + } +} static msg_t _main_msg_queue[MAIN_QUEUE_SIZE]; extern int udp_cmd(int argc, char **argv); static const shell_command_t shell_commands[] = { - { "udp", "send data over UDP and listen on UDP ports", udp_cmd }, - { NULL, NULL, NULL } + { "udp", "send data over UDP and listen on UDP ports", udp_cmd }, + { NULL, NULL, NULL } }; int main(void) { - - msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE); - puts("RIOT network stack example application"); - _init_interface(); - - /* 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; + + msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE); + puts("RIOT network stack example application"); + _init_interface(); + + /* 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; } -- libgit2 0.21.2