/* * 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 Example application for demonstrating the RIOT network stack * * @author Hauke Petersen * * @} */ #include #include "shell.h" #include "msg.h" #include "../../boards/stm32f4discovery/include/board.h" #include "../../boards/stm32f4discovery/include/periph_conf.h" #include "net/sock/udp.h" #include "net/gnrc/ipv6.h" #include "net/af.h" #include "net/sixlowpan.h" #include "shell_commands.h" #include "thread.h" #include "sched.h" #include "thread.h" #include "kernel_types.h" #include "net/netstats.h" #include "net/ipv6/addr.h" #include "periph/timer.h" #include "net/gnrc/ipv6/netif.h" #include "net/gnrc/netif.h" #include "net/gnrc/netapi.h" #include "net/netopt.h" #include "net/gnrc/pkt.h" #include "net/gnrc/pktbuf.h" #include "net/gnrc/netif/hdr.h" #include "net/gnrc/sixlowpan/netif.h" #include "net/fib.h" #include "net/gnrc/udp.h" #include "periph/pwm.h" #include "od.h" #include "net/sntp.h" #include "net/ntp_packet.h" #define MAIN_QUEUE_SIZE (8) static msg_t _main_msg_queue[MAIN_QUEUE_SIZE]; extern int udp_cmd(int argc, char **argv); static const shell_command_t shell_commands[] = { { NULL, NULL, NULL } }; //uint8_t buf[128]; /*char sock_time_server_stack[THREAD_STACKSIZE_MAIN]; static ntp_packet_t sntp_packet; sock_udp_ep_t local = SOCK_IPV6_EP_ANY; sock_udp_t sock; void *sock_time_server_thread(void *arg) { (void) arg; local.port = NTP_PORT; if (sock_udp_create(&sock, &local, 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,&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, &sntp_packet, sizeof(sntp_packet), &remote) < 0) { puts("Error sending reply"); } } } return NULL; }*/ int main(void) { /* we need a message queue for the thread running the shell in order to * receive potentially fast incoming networking packets */ msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE); puts("RIOT network stack example application"); (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"); // xtimer_sleep(1); printf("Offset: %i\n", (int)sntp_get_offset()); /* 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; }