diff --git a/RIOT/examples/real_time_app/main.c b/RIOT/examples/real_time_app/main.c index 3560b95..419d36d 100644 --- a/RIOT/examples/real_time_app/main.c +++ b/RIOT/examples/real_time_app/main.c @@ -100,13 +100,19 @@ char sock_time_server_stack[THREAD_STACKSIZE_MAIN]; // kernel_pid_t server, client, time_server; int ordre = 0; -uint8_t buf[128]; +int64_t offset = 0; +int timer_run = 0; sock_udp_ep_t local = SOCK_IPV6_EP_ANY; sock_udp_t sock; sock_udp_ep_t local_ntp = SOCK_IPV6_EP_ANY; sock_udp_t sock_ntp; static ntp_packet_t sntp_packet; +typedef struct tableau { + uint32_t heure_actuelle; + char donnees[2]; +}Data; + void *sock_time_server_thread(void *arg) { @@ -125,7 +131,7 @@ void *sock_time_server_thread(void *arg) 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("TT: %lu\n", byteorder_ntohl(sntp_packet.transmit.seconds)); // printf("%c\n",remote.addr.ipv6[15]); //xtimer_ticks64_t now = xtimer_now64(); @@ -133,8 +139,8 @@ void *sock_time_server_thread(void *arg) 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)); + //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); @@ -172,8 +178,13 @@ void *pwm_thread(void *arg) void *sock_server_thread(void *arg) { (void) arg; + Data buf; + int compteur = 5; + int deadline; 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; @@ -186,14 +197,42 @@ void *sock_server_thread(void *arg) sock_udp_ep_t remote; ssize_t res; - if ((res = sock_udp_recv(&sock, buf, sizeof(buf), SOCK_NO_TIMEOUT, + if ((res = sock_udp_recv(&sock, &buf, sizeof(buf), SOCK_NO_TIMEOUT, &remote)) >= 0) { // puts("Received a message"); //printf("%s\n",buf); - if (sock_udp_send(&sock, buf, res, &remote) < 0) { + /*if (sock_udp_send(&sock, buf, res, &remote) < 0) { puts("Error sending reply"); - } - if(strcmp((char *)buf,"go")==0) + }*/ + if (sntp_sync(&server, SOCK_NO_TIMEOUT) < 0) { + puts("Error in synchronization"); + return NULL; + } + offset = sntp_get_offset(); + deadline = xtimer_now_usec() + offset - buf.heure_actuelle; + printf("tps de transmission : %i\n",deadline); + printf("compteur : %d\n",compteur); + if(deadline<=70000 && compteur >=5) + { + ordre = 1; + timer_clear(TIMER_DEV(1),0); + } + else if(deadline<=70000 && (ordre == 2 || ordre ==0)) + { + compteur++; + } + else + { + ordre = 2; + compteur = 0; + if(timer_run == 0) + { + timer_set(TIMER_DEV(1),0,25200); + timer_run = 1; + } + } + + /*if(strcmp((char *)buf,"go")==0) { ordre = 1; timer_set(XTIMER_DEV,0,8400); @@ -203,15 +242,20 @@ void *sock_server_thread(void *arg) { ordre = 0; } - } + }*/ + memset(&buf,0,sizeof(buf)); } + } return NULL; } void *sock_client_thread(void *arg) { (void) arg; - uint_8t paquet[]; + Data data; + data.donnees[0] = 'g'; + data.donnees[1] = 'o'; + //uint8_t paquet[]; sock_udp_ep_t remote = { .family = AF_INET6 }; remote.port = 1234; @@ -225,7 +269,9 @@ void *sock_client_thread(void *arg) while (1) { // //ipv6_addr_set_all_nodes_multicast((ipv6_addr_t *)&remote.addr.ipv6, // // IPV6_ADDR_MCAST_SCP_LINK_LOCAL); - if (sock_udp_send(NULL, "go", sizeof("go"), &remote) < 0) { + data.heure_actuelle = xtimer_now_usec(); + + if (sock_udp_send(NULL, &data, sizeof(data), &remote) < 0) { puts("Error sending message"); } xtimer_sleep(1); @@ -237,23 +283,24 @@ static void arret_urgence(void *arg,int channel) { //pwm_set(PWM_DEV(0),1,0); ordre=0; + timer_run = 0; printf("Arret d'urgence\n"); } -static void degradation(void *arg,int channel) +/*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(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)); } diff --git a/RIOT/examples/static_network_app_sock_udp/README.md b/RIOT/examples/static_network_app_sock_udp/README.md deleted file mode 100644 index fd32831..0000000 --- a/RIOT/examples/static_network_app_sock_udp/README.md +++ /dev/null @@ -1,142 +0,0 @@ -# gnrc_networking example - -This example shows you how to try out the code in two different ways: Either by communicating -between the RIOT machine and its Linux host, or by communicating between two RIOT instances. -Note that the former only works with native, i.e. if you run RIOT on your Linux machine. - -## Connecting RIOT native and the Linux host - -> **Note:** RIOT does not support IPv4, so you need to stick to IPv6 anytime. To -establish a connection between RIOT and the Linux host, you will need `netcat` -(with IPv6 support). Ubuntu 14.04 comes with netcat IPv6 support pre-installed. -On Debian it's available in the package `netcat-openbsd`. Be aware that many -programs require you to add an option such as -6 to tell them to use IPv6, otherwise they -will fail. If you're using a _Raspberry Pi_, run `sudo modprobe ipv6` before trying -this example, because raspbian does not load the IPv6 module automatically. -On some systems (openSUSE for example), the _firewall_ may interfere, and prevent -some packets to arrive at the application (they will however show up in Wireshark, -which can be confusing). So be sure to adjust your firewall rules, or turn it off -(who needs security anyway). - -First, create a tap interface: - - sudo ip tuntap add tap0 mode tap user ${USER} - sudo ip link set tap0 up - -Now you can start the `gnrc_networking` example by invoking `make term`. This should -automatically connect to the `tap0` interface. If this doesn't work for any reason, -run make term with the tap0 interface as the PORT environment variable: - - PORT=tap0 make term - -To verify that there is connectivity between RIOT and Linux, go to the RIOT console and run `ifconfig`: - - > ifconfig - Iface 7 HWaddr: ce:f5:e1:c5:f7:5a - inet6 addr: ff02::1/128 scope: local [multicast] - inet6 addr: fe80::ccf5:e1ff:fec5:f75a/64 scope: local - inet6 addr: ff02::1:ffc5:f75a/128 scope: local [multicast] - -Copy the [link-local address](https://en.wikipedia.org/wiki/Link-local_address) -of the RIOT node (prefixed with `fe80`) and try to ping it **from the Linux node**: - - ping6 fe80::ccf5:e1ff:fec5:f75a%tap0 - -Note that the interface on which to send the ping needs to be appended to the IPv6 -address, `%tap0` in the above example. When talking to the RIOT node, you always want -to send to/receive from the `tap0` interface. - -If the pings succeed you can go on to send UDP packets. To do that, first start a -UDP server on the RIOT node: - - > udp server start 8808 - Success: started UDP server on port 8808 - -Now, on the Linux host, you can run netcat to connect with RIOT's UDP server: - - nc -6uv fe80::ccf5:e1ff:fec5:f75a%tap0 8808 - -The `-6` option is necessary to tell netcat to use IPv6 only, the `-u` option tells -it to use UDP only, and the `-v` option makes it give more verbose output (this one is optional). - -You should now see that UDP messages are received on the RIOT side. Opening a UDP -server on the Linux side is also possible. To do that, write down the IP address -of the host (run on Linux): - - ifconfig tap0 - tap0 Link encap:Ethernet HWaddr ce:f5:e1:c5:f7:59 - inet6 addr: fe80::4049:5fff:fe17:b3ae/64 Scope:Link - UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 - RX packets:6 errors:0 dropped:0 overruns:0 frame:0 - TX packets:36 errors:0 dropped:0 overruns:0 carrier:0 - collisions:0 txqueuelen:0 - RX bytes:488 (488.0 B) TX bytes:3517 (3.5 KB) - -Then open a UDP server on Linux (the `-l` option makes netcat listen for incoming connections): - - nc -6ul 8808 - -Now, on the RIOT side, send a UDP packet using: - - udp send fe80::4049:5fff:fe17:b3ae 8808 testmessage - -You should see `testmessage` appear in netcat. Instead of using netcat, you can of -course write your own software, but you may have to bind the socket to a specific -interface (tap0 in this case). For an example that shows how to do so, see -[here](https://gist.github.com/backenklee/dad5e80b764b3b3d0d3e). - -## Connecting two RIOT instances - -When using native (i.e. when you're trying this on your Linux machine), you first -need to set up two tap devices and a bridge that connects them. This constitutes a -virtual network that the RIOT instances can use to communicate. - - ./../../dist/tools/tapsetup/tapsetup --create 2 - -Then, make sure you've compiled the application by calling `make` and start the -first RIOT instance by invoking `make term`. In the RIOT shell, get to know the -IP address of this node: - - > ifconfig - Iface 7 HWaddr: ce:f5:e1:c5:f7:5a - inet6 addr: ff02::1/128 scope: local [multicast] - inet6 addr: fe80::ccf5:e1ff:fec5:f75a/64 scope: local - inet6 addr: ff02::1:ffc5:f75a/128 scope: local [multicast] - -and start a UDP server. - - > udp server start 8808 - -This node is now ready to receive data on port `8808`. - -In a second terminal, start a second RIOT instance, this time listening on `tap1`: - - PORT=tap1 make term - -In the RIOT shell, you can now send a message to the first RIOT instance: - - > udp send fe80::ccf5:e1ff:fec5:f75 8808 testmessage - -*(Make sure to copy the actual -[link-local address](https://en.wikipedia.org/wiki/Link-local_address) of your first -RIOT instance into the above command)* - -In your first terminal, you should now see output that looks like this. - - > PKTDUMP: data received: - ~~ SNIP 0 - size: 11 byte, type: NETTYPE_UNDEF (0) - 000000 74 65 73 74 6d 65 73 73 61 67 65 - ~~ SNIP 1 - size: 8 byte, type: NETTYPE_UDP (3) - src-port: 8808 dst-port: 8808 - length: 19 cksum: 0x4d95f - ~~ SNIP 2 - size: 40 byte, type: NETTYPE_IPV6 (1) - traffic class: 0x00 (ECN: 0x0, DSCP: 0x00) - flow label: 0x00000 - length: 19 next header: 17 hop limit: 64 - source address: fe80::a08a:84ff:fe68:544f - destination address: fe80::60fc:3cff:fe5e:40df - ~~ SNIP 3 - size: 20 byte, type: NETTYPE_NETIF (-1) - if_pid: 6 rssi: 0 lqi: 0 - src_l2addr: a2:8a:84:68:54:4f - dst_l2addr: 62:fc:3c:5e:40:df - ~~ PKT - 4 snips, total size: 79 byte diff --git a/RIOT/examples/static_network_app_sock_udp/udp.c b/RIOT/examples/static_network_app_sock_udp/udp.c deleted file mode 100644 index 74189c1..0000000 --- a/RIOT/examples/static_network_app_sock_udp/udp.c +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright (C) 2015 Freie Universität Berlin - * - * This file is subject to the terms and conditions of the GNU Lesser - * General Public License v2.1. See the file LICENSE in the top level - * directory for more details. - */ - -/** - * @ingroup examples - * @{ - * - * @file - * @brief Demonstrating the sending and receiving of UDP data - * - * @author Hauke Petersen - * - * @} - */ - -#include -#include - -#include "net/gnrc.h" -#include "net/gnrc/ipv6.h" -#include "net/gnrc/udp.h" -#include "net/gnrc/pktdump.h" -#include "timex.h" -#include "xtimer.h" - -//static gnrc_netreg_entry_t server = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL, - // KERNEL_PID_UNDEF); - - -static void send(char *addr_str, char *port_str, char *data, unsigned int num, - unsigned int delay) -{ - uint16_t port; - ipv6_addr_t addr; - - /* parse destination address */ - if (ipv6_addr_from_str(&addr, addr_str) == NULL) { - puts("Error: unable to parse destination address"); - return; - } - /* parse port */ - port = (uint16_t)atoi(port_str); - if (port == 0) { - puts("Error: unable to parse destination port"); - return; - } - - for (unsigned int i = 0; i < num; i++) { - gnrc_pktsnip_t *payload, *udp, *ip; - unsigned payload_size; - /* allocate payload */ - payload = gnrc_pktbuf_add(NULL, data, strlen(data), GNRC_NETTYPE_UNDEF); - if (payload == NULL) { - puts("Error: unable to copy data to packet buffer"); - return; - } - /* store size for output */ - payload_size = (unsigned)payload->size; - /* allocate UDP header, set source port := destination port */ - udp = gnrc_udp_hdr_build(payload, port, port); - if (udp == NULL) { - puts("Error: unable to allocate UDP header"); - gnrc_pktbuf_release(payload); - return; - } - /* allocate IPv6 header */ - ip = gnrc_ipv6_hdr_build(udp, NULL, &addr); - if (ip == NULL) { - puts("Error: unable to allocate IPv6 header"); - gnrc_pktbuf_release(udp); - return; - } - /* send packet */ - if (!gnrc_netapi_dispatch_send(GNRC_NETTYPE_UDP, GNRC_NETREG_DEMUX_CTX_ALL, ip)) { - puts("Error: unable to locate UDP thread"); - gnrc_pktbuf_release(ip); - return; - } - /* access to `payload` was implicitly given up with the send operation above - * => use temporary variable for output */ - printf("Success: send %u byte to [%s]:%u\n", payload_size, addr_str, - port); - xtimer_usleep(delay); - } -} - -static void start_server(char *port_str) -{ -// uint16_t port; -// -// /* check if server is already running */ -// if (server.target.pid != KERNEL_PID_UNDEF) { -// printf("Error: server already running on port %" PRIu32 "\n", -// server.demux_ctx); -// return; -// } -// /* parse port */ -// port = (uint16_t)atoi(port_str); -// if (port == 0) { -// puts("Error: invalid port specified"); -// return; -// } -// /* start server (which means registering pktdump for the chosen port) */ -// server.target.pid = gnrc_pktdump_pid; -// server.demux_ctx = (uint32_t)port; -// gnrc_netreg_register(GNRC_NETTYPE_UDP, &server); -// printf("Success: started UDP server on port %" PRIu16 "\n", port); -} - -static void stop_server(void) -{ -// /* check if server is running at all */ -// if (server.target.pid == KERNEL_PID_UNDEF) { -// printf("Error: server was not running\n"); -// return; -// } -// /* stop server */ -// gnrc_netreg_unregister(GNRC_NETTYPE_UDP, &server); -// server.target.pid = KERNEL_PID_UNDEF; -// puts("Success: stopped UDP server"); -} - -int udp_cmd(int argc, char **argv) -{ - if (argc < 2) { - printf("usage: %s [send|server]\n", argv[0]); - return 1; - } - - if (strcmp(argv[1], "send") == 0) { - uint32_t num = 1; - uint32_t delay = 1000000; - if (argc < 5) { - printf("usage: %s send [ []]\n", - argv[0]); - return 1; - } - if (argc > 5) { - num = (uint32_t)atoi(argv[5]); - } - if (argc > 6) { - delay = (uint32_t)atoi(argv[6]); - } - send(argv[2], argv[3], argv[4], num, delay); - } - else if (strcmp(argv[1], "server") == 0) { - if (argc < 3) { - printf("usage: %s server [start|stop]\n", argv[0]); - return 1; - } - if (strcmp(argv[2], "start") == 0) { - if (argc < 4) { - printf("usage %s server start \n", argv[0]); - return 1; - } - start_server(argv[3]); - } - else if (strcmp(argv[2], "stop") == 0) { - stop_server(); - } - else { - puts("error: invalid command"); - } - } - else { - puts("error: invalid command"); - } - return 0; -} diff --git a/RIOT/sys/net/application_layer/sntp/sntp.c b/RIOT/sys/net/application_layer/sntp/sntp.c index 3f0429f..04cb16a 100755 --- a/RIOT/sys/net/application_layer/sntp/sntp.c +++ b/RIOT/sys/net/application_layer/sntp/sntp.c @@ -68,8 +68,6 @@ int sntp_sync(sock_udp_ep_t *server, uint32_t timeout) DEBUG("Error receiving message\n"); sock_udp_close(&_sntp_sock); mutex_unlock(&_sntp_mutex); - printf("result : %d\n",result); - return result; } //xtimer_ticks64_t now = xtimer_now64(); @@ -78,8 +76,6 @@ int sntp_sync(sock_udp_ep_t *server, uint32_t timeout) /* _sntp_offset = (byteorder_ntohl(_sntp_packet.transmit.seconds) * SEC_IN_USEC) + ((byteorder_ntohl(_sntp_packet.transmit.fraction) * 232) / 1000000) - xtimer_now_usec();*/ - printf("TT: %lu\n", byteorder_ntohl(_sntp_packet.transmit.seconds)); - printf("heure actuelle : %lu\n",xtimer_now_usec()); mutex_unlock(&_sntp_mutex); return 0; } -- libgit2 0.21.2