929398b3
vrobic
test offset horlo...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
/*
* 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 <hauke.petersen@fu-berlin.de>
*
* @}
*/
#include <stdio.h>
#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");
|
41eae2a4
vrobic
ajout serveur snt...
|
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");
|
929398b3
vrobic
test offset horlo...
|
114
115
116
117
118
119
120
121
122
123
|
// 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;
}
|