Commit 929398b3da44b86e424e8ee070d9e96f2a7c7ed1

Authored by vrobic
1 parent f85b2c6e

test offset horloge via sntp ok

RIOT/examples/sntp_app/Makefile 0 → 100755
... ... @@ -0,0 +1,67 @@
  1 +# name of your application
  2 +APPLICATION = sntp_app
  3 +
  4 +# If no BOARD is found in the environment, use this default:
  5 +BOARD ?= native
  6 +
  7 +# This has to be the absolute path to the RIOT base directory:
  8 +RIOTBASE ?= $(CURDIR)/../..
  9 +
  10 +BOARD_INSUFFICIENT_MEMORY := airfy-beacon chronos msb-430 msb-430h nrf51dongle \
  11 + nrf6310 nucleo-f103 nucleo-f334 pca10000 pca10005 spark-core \
  12 + stm32f0discovery telosb weio wsn430-v1_3b wsn430-v1_4 \
  13 + yunjia-nrf51822 z1 nucleo-f072 nucleo-f030 nucleo-f070 \
  14 + microbit calliope-mini
  15 +
  16 +# Include packages that pull up and auto-init the link layer.
  17 +# NOTE: 6LoWPAN will be included if IEEE802.15.4 devices are present
  18 +USEMODULE += gnrc_netdev_default
  19 +USEMODULE += auto_init_gnrc_netif
  20 +# Specify the mandatory networking modules for IPv6 and UDP
  21 +#USEMODULE += gnrc_ipv6_router_default
  22 +USEMODULE += gnrc_ipv6_default
  23 +#USEMODULE += gnrc_udp
  24 +USEMODULE += gnrc_sock_udp
  25 +USEMODULE += sntp
  26 +# Add a routing protocol
  27 +#USEMODULE += gnrc_rpl
  28 +#USEMODULE += auto_init_gnrc_rpl
  29 +# This application dumps received packets to STDIO using the pktdump module
  30 +USEMODULE += gnrc_pktdump
  31 +# Additional networking modules that can be dropped if not needed
  32 +#USEMODULE += gnrc_icmpv6_echo
  33 +# Add also the shell, some shell commands
  34 +USEMODULE += shell
  35 +USEMODULE += shell_commands
  36 +USEMODULE += ps
  37 +#USEMODULE += netstats_l2
  38 +#USEMODULE += netstats_ipv6
  39 +#USEMODULE += netstats_rpl
  40 +USEMODULE += at86rf231
  41 +# Comment this out to disable code in RIOT that does safety checking
  42 +# which is not needed in a production environment but helps in the
  43 +# development process:
  44 +CFLAGS += -DDEVELHELP
  45 +
  46 +# Comment this out to join RPL DODAGs even if DIOs do not contain
  47 +# DODAG Configuration Options (see the doc for more info)
  48 +# CFLAGS += -DGNRC_RPL_DODAG_CONF_OPTIONAL_ON_JOIN
  49 +
  50 +# Change this to 0 show compiler invocation lines by default:
  51 +QUIET ?= 1
  52 +
  53 +include $(RIOTBASE)/Makefile.include
  54 +
  55 +# Set a custom channel if needed
  56 +ifneq (,$(filter cc110x,$(USEMODULE))) # radio is cc110x sub-GHz
  57 + DEFAULT_CHANNEL ?= 0
  58 + CFLAGS += -DCC110X_DEFAULT_CHANNEL=$(DEFAULT_CHANNEL)
  59 +else
  60 + ifneq (,$(filter at86rf212b,$(USEMODULE))) # radio is IEEE 802.15.4 sub-GHz
  61 + DEFAULT_CHANNEL ?= 5
  62 + FLAGS += -DIEEE802154_DEFAULT_SUBGHZ_CHANNEL=$(DEFAULT_CHANNEL)
  63 + else # radio is IEEE 802.15.4 2.4 GHz
  64 + DEFAULT_CHANNEL ?= 26
  65 + CFLAGS += -DIEEE802154_DEFAULT_CHANNEL=$(DEFAULT_CHANNEL)
  66 + endif
  67 +endif
... ...
RIOT/examples/sntp_app/README.md 0 → 100755
... ... @@ -0,0 +1,142 @@
  1 +# gnrc_networking example
  2 +
  3 +This example shows you how to try out the code in two different ways: Either by communicating
  4 +between the RIOT machine and its Linux host, or by communicating between two RIOT instances.
  5 +Note that the former only works with native, i.e. if you run RIOT on your Linux machine.
  6 +
  7 +## Connecting RIOT native and the Linux host
  8 +
  9 +> **Note:** RIOT does not support IPv4, so you need to stick to IPv6 anytime. To
  10 +establish a connection between RIOT and the Linux host, you will need `netcat`
  11 +(with IPv6 support). Ubuntu 14.04 comes with netcat IPv6 support pre-installed.
  12 +On Debian it's available in the package `netcat-openbsd`. Be aware that many
  13 +programs require you to add an option such as -6 to tell them to use IPv6, otherwise they
  14 +will fail. If you're using a _Raspberry Pi_, run `sudo modprobe ipv6` before trying
  15 +this example, because raspbian does not load the IPv6 module automatically.
  16 +On some systems (openSUSE for example), the _firewall_ may interfere, and prevent
  17 +some packets to arrive at the application (they will however show up in Wireshark,
  18 +which can be confusing). So be sure to adjust your firewall rules, or turn it off
  19 +(who needs security anyway).
  20 +
  21 +First, create a tap interface:
  22 +
  23 + sudo ip tuntap add tap0 mode tap user ${USER}
  24 + sudo ip link set tap0 up
  25 +
  26 +Now you can start the `gnrc_networking` example by invoking `make term`. This should
  27 +automatically connect to the `tap0` interface. If this doesn't work for any reason,
  28 +run make term with the tap0 interface as the PORT environment variable:
  29 +
  30 + PORT=tap0 make term
  31 +
  32 +To verify that there is connectivity between RIOT and Linux, go to the RIOT console and run `ifconfig`:
  33 +
  34 + > ifconfig
  35 + Iface 7 HWaddr: ce:f5:e1:c5:f7:5a
  36 + inet6 addr: ff02::1/128 scope: local [multicast]
  37 + inet6 addr: fe80::ccf5:e1ff:fec5:f75a/64 scope: local
  38 + inet6 addr: ff02::1:ffc5:f75a/128 scope: local [multicast]
  39 +
  40 +Copy the [link-local address](https://en.wikipedia.org/wiki/Link-local_address)
  41 +of the RIOT node (prefixed with `fe80`) and try to ping it **from the Linux node**:
  42 +
  43 + ping6 fe80::ccf5:e1ff:fec5:f75a%tap0
  44 +
  45 +Note that the interface on which to send the ping needs to be appended to the IPv6
  46 +address, `%tap0` in the above example. When talking to the RIOT node, you always want
  47 +to send to/receive from the `tap0` interface.
  48 +
  49 +If the pings succeed you can go on to send UDP packets. To do that, first start a
  50 +UDP server on the RIOT node:
  51 +
  52 + > udp server start 8808
  53 + Success: started UDP server on port 8808
  54 +
  55 +Now, on the Linux host, you can run netcat to connect with RIOT's UDP server:
  56 +
  57 + nc -6uv fe80::ccf5:e1ff:fec5:f75a%tap0 8808
  58 +
  59 +The `-6` option is necessary to tell netcat to use IPv6 only, the `-u` option tells
  60 +it to use UDP only, and the `-v` option makes it give more verbose output (this one is optional).
  61 +
  62 +You should now see that UDP messages are received on the RIOT side. Opening a UDP
  63 +server on the Linux side is also possible. To do that, write down the IP address
  64 +of the host (run on Linux):
  65 +
  66 + ifconfig tap0
  67 + tap0 Link encap:Ethernet HWaddr ce:f5:e1:c5:f7:59
  68 + inet6 addr: fe80::4049:5fff:fe17:b3ae/64 Scope:Link
  69 + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
  70 + RX packets:6 errors:0 dropped:0 overruns:0 frame:0
  71 + TX packets:36 errors:0 dropped:0 overruns:0 carrier:0
  72 + collisions:0 txqueuelen:0
  73 + RX bytes:488 (488.0 B) TX bytes:3517 (3.5 KB)
  74 +
  75 +Then open a UDP server on Linux (the `-l` option makes netcat listen for incoming connections):
  76 +
  77 + nc -6ul 8808
  78 +
  79 +Now, on the RIOT side, send a UDP packet using:
  80 +
  81 + udp send fe80::4049:5fff:fe17:b3ae 8808 testmessage
  82 +
  83 +You should see `testmessage` appear in netcat. Instead of using netcat, you can of
  84 +course write your own software, but you may have to bind the socket to a specific
  85 +interface (tap0 in this case). For an example that shows how to do so, see
  86 +[here](https://gist.github.com/backenklee/dad5e80b764b3b3d0d3e).
  87 +
  88 +## Connecting two RIOT instances
  89 +
  90 +When using native (i.e. when you're trying this on your Linux machine), you first
  91 +need to set up two tap devices and a bridge that connects them. This constitutes a
  92 +virtual network that the RIOT instances can use to communicate.
  93 +
  94 + ./../../dist/tools/tapsetup/tapsetup --create 2
  95 +
  96 +Then, make sure you've compiled the application by calling `make` and start the
  97 +first RIOT instance by invoking `make term`. In the RIOT shell, get to know the
  98 +IP address of this node:
  99 +
  100 + > ifconfig
  101 + Iface 7 HWaddr: ce:f5:e1:c5:f7:5a
  102 + inet6 addr: ff02::1/128 scope: local [multicast]
  103 + inet6 addr: fe80::ccf5:e1ff:fec5:f75a/64 scope: local
  104 + inet6 addr: ff02::1:ffc5:f75a/128 scope: local [multicast]
  105 +
  106 +and start a UDP server.
  107 +
  108 + > udp server start 8808
  109 +
  110 +This node is now ready to receive data on port `8808`.
  111 +
  112 +In a second terminal, start a second RIOT instance, this time listening on `tap1`:
  113 +
  114 + PORT=tap1 make term
  115 +
  116 +In the RIOT shell, you can now send a message to the first RIOT instance:
  117 +
  118 + > udp send fe80::ccf5:e1ff:fec5:f75 8808 testmessage
  119 +
  120 +*(Make sure to copy the actual
  121 +[link-local address](https://en.wikipedia.org/wiki/Link-local_address) of your first
  122 +RIOT instance into the above command)*
  123 +
  124 +In your first terminal, you should now see output that looks like this.
  125 +
  126 + > PKTDUMP: data received:
  127 + ~~ SNIP 0 - size: 11 byte, type: NETTYPE_UNDEF (0)
  128 + 000000 74 65 73 74 6d 65 73 73 61 67 65
  129 + ~~ SNIP 1 - size: 8 byte, type: NETTYPE_UDP (3)
  130 + src-port: 8808 dst-port: 8808
  131 + length: 19 cksum: 0x4d95f
  132 + ~~ SNIP 2 - size: 40 byte, type: NETTYPE_IPV6 (1)
  133 + traffic class: 0x00 (ECN: 0x0, DSCP: 0x00)
  134 + flow label: 0x00000
  135 + length: 19 next header: 17 hop limit: 64
  136 + source address: fe80::a08a:84ff:fe68:544f
  137 + destination address: fe80::60fc:3cff:fe5e:40df
  138 + ~~ SNIP 3 - size: 20 byte, type: NETTYPE_NETIF (-1)
  139 + if_pid: 6 rssi: 0 lqi: 0
  140 + src_l2addr: a2:8a:84:68:54:4f
  141 + dst_l2addr: 62:fc:3c:5e:40:df
  142 + ~~ PKT - 4 snips, total size: 79 byte
... ...
RIOT/examples/sntp_app/main.c 0 → 100755
... ... @@ -0,0 +1,123 @@
  1 +/*
  2 + * Copyright (C) 2015 Freie Universität Berlin
  3 + *
  4 + * This file is subject to the terms and conditions of the GNU Lesser
  5 + * General Public License v2.1. See the file LICENSE in the top level
  6 + * directory for more details.
  7 + */
  8 +
  9 +/**
  10 + * @ingroup examples
  11 + * @{
  12 + *
  13 + * @file
  14 + * @brief Example application for demonstrating the RIOT network stack
  15 + *
  16 + * @author Hauke Petersen <hauke.petersen@fu-berlin.de>
  17 + *
  18 + * @}
  19 + */
  20 +
  21 +#include <stdio.h>
  22 +
  23 +#include "shell.h"
  24 +#include "msg.h"
  25 +#include "../../boards/stm32f4discovery/include/board.h"
  26 +#include "../../boards/stm32f4discovery/include/periph_conf.h"
  27 +#include "net/sock/udp.h"
  28 +#include "net/gnrc/ipv6.h"
  29 +#include "net/af.h"
  30 +#include "net/sixlowpan.h"
  31 +#include "shell_commands.h"
  32 +#include "thread.h"
  33 +#include "sched.h"
  34 +#include "thread.h"
  35 +#include "kernel_types.h"
  36 +#include "net/netstats.h"
  37 +#include "net/ipv6/addr.h"
  38 +#include "periph/timer.h"
  39 +#include "net/gnrc/ipv6/netif.h"
  40 +#include "net/gnrc/netif.h"
  41 +#include "net/gnrc/netapi.h"
  42 +#include "net/netopt.h"
  43 +#include "net/gnrc/pkt.h"
  44 +#include "net/gnrc/pktbuf.h"
  45 +#include "net/gnrc/netif/hdr.h"
  46 +#include "net/gnrc/sixlowpan/netif.h"
  47 +#include "net/fib.h"
  48 +#include "net/gnrc/udp.h"
  49 +#include "periph/pwm.h"
  50 +#include "od.h"
  51 +#include "net/sntp.h"
  52 +#include "net/ntp_packet.h"
  53 +#define MAIN_QUEUE_SIZE (8)
  54 +
  55 +static msg_t _main_msg_queue[MAIN_QUEUE_SIZE];
  56 +extern int udp_cmd(int argc, char **argv);
  57 +
  58 +static const shell_command_t shell_commands[] = {
  59 + { NULL, NULL, NULL }
  60 +};
  61 +//uint8_t buf[128];
  62 +/*char sock_time_server_stack[THREAD_STACKSIZE_MAIN];
  63 +
  64 +static ntp_packet_t sntp_packet;
  65 +
  66 +sock_udp_ep_t local = SOCK_IPV6_EP_ANY;
  67 +sock_udp_t sock;
  68 +
  69 +void *sock_time_server_thread(void *arg)
  70 +{
  71 + (void) arg;
  72 + local.port = NTP_PORT;
  73 +
  74 + if (sock_udp_create(&sock, &local, NULL, 0) < 0) {
  75 + puts("Error creating UDP sock");
  76 + return NULL;
  77 + }
  78 +
  79 + while (1) {
  80 + sock_udp_ep_t remote;
  81 + ssize_t res;
  82 +
  83 + if ((res = sock_udp_recv(&sock,&sntp_packet, sizeof(sntp_packet), SOCK_NO_TIMEOUT,
  84 + &remote)) >= 0) {
  85 + puts("Received a message");
  86 + printf("TT: %lu\n", byteorder_ntohl(sntp_packet.transmit.seconds));
  87 +
  88 + // printf("%c\n",remote.addr.ipv6[15]);
  89 + //xtimer_ticks64_t now = xtimer_now64();
  90 + // heure actuelle du serveur
  91 + sntp_packet.receive.seconds=byteorder_htonl( xtimer_now_usec());
  92 + sntp_packet.origin.seconds=sntp_packet.transmit.seconds;
  93 + sntp_packet.transmit.seconds=byteorder_htonl( xtimer_now_usec());
  94 + printf("heure actuelle : %lu\n",xtimer_now_usec());
  95 + printf("TT2: %lu\n", byteorder_ntohl(sntp_packet.transmit.seconds));
  96 + //memset(&sntp_packet, 0, sizeof(sntp_packet));
  97 + //ntp_packet_set_vn(&sntp_packet);
  98 + //ntp_packet_set_mode(&sntp_packet, NTP_MODE_SERVER);
  99 + if (sock_udp_send(&sock, &sntp_packet, sizeof(sntp_packet), &remote) < 0) {
  100 + puts("Error sending reply");
  101 + }
  102 + }
  103 + }
  104 + return NULL;
  105 +}*/
  106 +int main(void)
  107 +{
  108 + /* we need a message queue for the thread running the shell in order to
  109 + * receive potentially fast incoming networking packets */
  110 + msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE);
  111 + puts("RIOT network stack example application");
  112 +
  113 +//(void) thread_create(sock_time_server_stack,sizeof(sock_time_server_stack),THREAD_PRIORITY_MAIN - 1, THREAD_CREATE_STACKTEST,sock_time_server_thread,NULL,"sock_time_server_thread");
  114 + // xtimer_sleep(1);
  115 + printf("Offset: %i\n", (int)sntp_get_offset());
  116 + /* start shell */
  117 + puts("All up, running the shell now");
  118 + char line_buf[SHELL_DEFAULT_BUFSIZE];
  119 + shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
  120 +
  121 + /* should be never reached */
  122 + return 0;
  123 +}
... ...
RIOT/examples/sntp_app/udp.c 0 → 100755
... ... @@ -0,0 +1,174 @@
  1 +/*
  2 + * Copyright (C) 2015 Freie Universität Berlin
  3 + *
  4 + * This file is subject to the terms and conditions of the GNU Lesser
  5 + * General Public License v2.1. See the file LICENSE in the top level
  6 + * directory for more details.
  7 + */
  8 +
  9 +/**
  10 + * @ingroup examples
  11 + * @{
  12 + *
  13 + * @file
  14 + * @brief Demonstrating the sending and receiving of UDP data
  15 + *
  16 + * @author Hauke Petersen <hauke.petersen@fu-berlin.de>
  17 + *
  18 + * @}
  19 + */
  20 +
  21 +#include <stdio.h>
  22 +#include <inttypes.h>
  23 +
  24 +#include "net/gnrc.h"
  25 +#include "net/gnrc/ipv6.h"
  26 +#include "net/gnrc/udp.h"
  27 +#include "net/gnrc/pktdump.h"
  28 +#include "timex.h"
  29 +#include "xtimer.h"
  30 +
  31 +static gnrc_netreg_entry_t server = GNRC_NETREG_ENTRY_INIT_PID(GNRC_NETREG_DEMUX_CTX_ALL,
  32 + KERNEL_PID_UNDEF);
  33 +
  34 +
  35 +static void send(char *addr_str, char *port_str, char *data, unsigned int num,
  36 + unsigned int delay)
  37 +{
  38 + uint16_t port;
  39 + ipv6_addr_t addr;
  40 +
  41 + /* parse destination address */
  42 + if (ipv6_addr_from_str(&addr, addr_str) == NULL) {
  43 + puts("Error: unable to parse destination address");
  44 + return;
  45 + }
  46 + /* parse port */
  47 + port = (uint16_t)atoi(port_str);
  48 + if (port == 0) {
  49 + puts("Error: unable to parse destination port");
  50 + return;
  51 + }
  52 +
  53 + for (unsigned int i = 0; i < num; i++) {
  54 + gnrc_pktsnip_t *payload, *udp, *ip;
  55 + unsigned payload_size;
  56 + /* allocate payload */
  57 + payload = gnrc_pktbuf_add(NULL, data, strlen(data), GNRC_NETTYPE_UNDEF);
  58 + if (payload == NULL) {
  59 + puts("Error: unable to copy data to packet buffer");
  60 + return;
  61 + }
  62 + /* store size for output */
  63 + payload_size = (unsigned)payload->size;
  64 + /* allocate UDP header, set source port := destination port */
  65 + udp = gnrc_udp_hdr_build(payload, port, port);
  66 + if (udp == NULL) {
  67 + puts("Error: unable to allocate UDP header");
  68 + gnrc_pktbuf_release(payload);
  69 + return;
  70 + }
  71 + /* allocate IPv6 header */
  72 + ip = gnrc_ipv6_hdr_build(udp, NULL, &addr);
  73 + if (ip == NULL) {
  74 + puts("Error: unable to allocate IPv6 header");
  75 + gnrc_pktbuf_release(udp);
  76 + return;
  77 + }
  78 + /* send packet */
  79 + if (!gnrc_netapi_dispatch_send(GNRC_NETTYPE_UDP, GNRC_NETREG_DEMUX_CTX_ALL, ip)) {
  80 + puts("Error: unable to locate UDP thread");
  81 + gnrc_pktbuf_release(ip);
  82 + return;
  83 + }
  84 + /* access to `payload` was implicitly given up with the send operation above
  85 + * => use temporary variable for output */
  86 + printf("Success: send %u byte to [%s]:%u\n", payload_size, addr_str,
  87 + port);
  88 + xtimer_usleep(delay);
  89 + }
  90 +}
  91 +
  92 +static void start_server(char *port_str)
  93 +{
  94 + uint16_t port;
  95 +
  96 + /* check if server is already running */
  97 + if (server.target.pid != KERNEL_PID_UNDEF) {
  98 + printf("Error: server already running on port %" PRIu32 "\n",
  99 + server.demux_ctx);
  100 + return;
  101 + }
  102 + /* parse port */
  103 + port = (uint16_t)atoi(port_str);
  104 + if (port == 0) {
  105 + puts("Error: invalid port specified");
  106 + return;
  107 + }
  108 + /* start server (which means registering pktdump for the chosen port) */
  109 + server.target.pid = gnrc_pktdump_pid;
  110 + server.demux_ctx = (uint32_t)port;
  111 + gnrc_netreg_register(GNRC_NETTYPE_UDP, &server);
  112 + printf("Success: started UDP server on port %" PRIu16 "\n", port);
  113 +}
  114 +
  115 +static void stop_server(void)
  116 +{
  117 + /* check if server is running at all */
  118 + if (server.target.pid == KERNEL_PID_UNDEF) {
  119 + printf("Error: server was not running\n");
  120 + return;
  121 + }
  122 + /* stop server */
  123 + gnrc_netreg_unregister(GNRC_NETTYPE_UDP, &server);
  124 + server.target.pid = KERNEL_PID_UNDEF;
  125 + puts("Success: stopped UDP server");
  126 +}
  127 +
  128 +int udp_cmd(int argc, char **argv)
  129 +{
  130 + if (argc < 2) {
  131 + printf("usage: %s [send|server]\n", argv[0]);
  132 + return 1;
  133 + }
  134 +
  135 + if (strcmp(argv[1], "send") == 0) {
  136 + uint32_t num = 1;
  137 + uint32_t delay = 1000000;
  138 + if (argc < 5) {
  139 + printf("usage: %s send <addr> <port> <data> [<num> [<delay in us>]]\n",
  140 + argv[0]);
  141 + return 1;
  142 + }
  143 + if (argc > 5) {
  144 + num = (uint32_t)atoi(argv[5]);
  145 + }
  146 + if (argc > 6) {
  147 + delay = (uint32_t)atoi(argv[6]);
  148 + }
  149 + send(argv[2], argv[3], argv[4], num, delay);
  150 + }
  151 + else if (strcmp(argv[1], "server") == 0) {
  152 + if (argc < 3) {
  153 + printf("usage: %s server [start|stop]\n", argv[0]);
  154 + return 1;
  155 + }
  156 + if (strcmp(argv[2], "start") == 0) {
  157 + if (argc < 4) {
  158 + printf("usage %s server start <port>\n", argv[0]);
  159 + return 1;
  160 + }
  161 + start_server(argv[3]);
  162 + }
  163 + else if (strcmp(argv[2], "stop") == 0) {
  164 + stop_server();
  165 + }
  166 + else {
  167 + puts("error: invalid command");
  168 + }
  169 + }
  170 + else {
  171 + puts("error: invalid command");
  172 + }
  173 + return 0;
  174 +}
... ...
RIOT/examples/static_network_app_sock_udp/Makefile
1 1 # name of your application
2   -APPLICATION = static_network_app
  2 +APPLICATION = static_network_app_sock_udp
3 3  
4 4 # If no BOARD is found in the environment, use this default:
5 5 BOARD ?= native
... ...
RIOT/sys/net/application_layer/sntp/sntp.c
... ... @@ -26,7 +26,7 @@
26 26 #include "mutex.h"
27 27 #include "byteorder.h"
28 28  
29   -#define ENABLE_DEBUG (0)
  29 +#define ENABLE_DEBUG (1)
30 30 #include "debug.h"
31 31  
32 32 static sock_udp_t _sntp_sock;
... ... @@ -50,7 +50,7 @@ int sntp_sync(sock_udp_ep_t *server, uint32_t timeout)
50 50 memset(&_sntp_packet, 0, sizeof(_sntp_packet));
51 51 ntp_packet_set_vn(&_sntp_packet);
52 52 ntp_packet_set_mode(&_sntp_packet, NTP_MODE_CLIENT);
53   -
  53 + _sntp_packet.transmit.seconds=byteorder_htonl( xtimer_now_usec());
54 54 if ((result = (int)sock_udp_send(&_sntp_sock,
55 55 &_sntp_packet,
56 56 sizeof(_sntp_packet),
... ... @@ -63,18 +63,23 @@ 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   - timeout,
  66 + SOCK_NO_TIMEOUT,
67 67 NULL)) < 0) {
68 68 DEBUG("Error receiving message\n");
69 69 sock_udp_close(&_sntp_sock);
70 70 mutex_unlock(&_sntp_mutex);
  71 + printf("result : %d\n",result);
  72 +
71 73 return result;
72 74 }
73   - xtimer_ticks64_t now = xtimer_now64();
  75 + //xtimer_ticks64_t now = xtimer_now64();
74 76 sock_udp_close(&_sntp_sock);
75   - _sntp_offset = (byteorder_ntohl(_sntp_packet.transmit.seconds) * SEC_IN_USEC) +
  77 + _sntp_offset= (byteorder_ntohl(_sntp_packet.receive.seconds)+ byteorder_ntohl(_sntp_packet.transmit.seconds))/2 - (byteorder_ntohl(_sntp_packet.origin.seconds) + xtimer_now_usec())/2;
  78 + /* _sntp_offset = (byteorder_ntohl(_sntp_packet.transmit.seconds) * SEC_IN_USEC) +
76 79 ((byteorder_ntohl(_sntp_packet.transmit.fraction) * 232)
77   - / 1000000) - now.ticks64;
  80 + / 1000000) - xtimer_now_usec();*/
  81 + printf("TT: %lu\n", byteorder_ntohl(_sntp_packet.transmit.seconds));
  82 + printf("heure actuelle : %lu\n",xtimer_now_usec());
78 83 mutex_unlock(&_sntp_mutex);
79 84 return 0;
80 85 }
... ...