Commit 0f803f1d32ae808ac3014252adbbe9de09b7ae2b

Authored by root
1 parent 41eae2a4

test application real-time

RIOT/examples/real_time_app/main.c
... ... @@ -100,13 +100,19 @@ char sock_time_server_stack[THREAD_STACKSIZE_MAIN];
100 100 //
101 101 kernel_pid_t server, client, time_server;
102 102 int ordre = 0;
103   -uint8_t buf[128];
  103 +int64_t offset = 0;
  104 +int timer_run = 0;
104 105 sock_udp_ep_t local = SOCK_IPV6_EP_ANY;
105 106 sock_udp_t sock;
106 107 sock_udp_ep_t local_ntp = SOCK_IPV6_EP_ANY;
107 108 sock_udp_t sock_ntp;
108 109 static ntp_packet_t sntp_packet;
109 110  
  111 +typedef struct tableau {
  112 + uint32_t heure_actuelle;
  113 + char donnees[2];
  114 +}Data;
  115 +
110 116  
111 117 void *sock_time_server_thread(void *arg)
112 118 {
... ... @@ -125,7 +131,7 @@ void *sock_time_server_thread(void *arg)
125 131 if ((res = sock_udp_recv(&sock_ntp,&sntp_packet, sizeof(sntp_packet), SOCK_NO_TIMEOUT,
126 132 &remote)) >= 0) {
127 133 puts("Received a message");
128   - printf("TT: %lu\n", byteorder_ntohl(sntp_packet.transmit.seconds));
  134 + //printf("TT: %lu\n", byteorder_ntohl(sntp_packet.transmit.seconds));
129 135  
130 136 // printf("%c\n",remote.addr.ipv6[15]);
131 137 //xtimer_ticks64_t now = xtimer_now64();
... ... @@ -133,8 +139,8 @@ void *sock_time_server_thread(void *arg)
133 139 sntp_packet.receive.seconds=byteorder_htonl( xtimer_now_usec());
134 140 sntp_packet.origin.seconds=sntp_packet.transmit.seconds;
135 141 sntp_packet.transmit.seconds=byteorder_htonl( xtimer_now_usec());
136   - printf("heure actuelle : %lu\n",xtimer_now_usec());
137   - printf("TT2: %lu\n", byteorder_ntohl(sntp_packet.transmit.seconds));
  142 + //printf("heure actuelle : %lu\n",xtimer_now_usec());
  143 + //printf("TT2: %lu\n", byteorder_ntohl(sntp_packet.transmit.seconds));
138 144 //memset(&sntp_packet, 0, sizeof(sntp_packet));
139 145 //ntp_packet_set_vn(&sntp_packet);
140 146 //ntp_packet_set_mode(&sntp_packet, NTP_MODE_SERVER);
... ... @@ -172,8 +178,13 @@ void *pwm_thread(void *arg)
172 178 void *sock_server_thread(void *arg)
173 179 {
174 180 (void) arg;
  181 + Data buf;
  182 + int compteur = 5;
  183 + int deadline;
175 184 local.port = 1234;
176   -
  185 + sock_udp_ep_t server = { .port = NTP_PORT, .family = AF_INET6 };
  186 + ipv6_addr_from_str((ipv6_addr_t *)&server.addr, "dead:beef::3402");
  187 +
177 188 if (sock_udp_create(&sock, &local, NULL, 0) < 0) {
178 189 puts("Error creating UDP sock");
179 190 return NULL;
... ... @@ -186,14 +197,42 @@ void *sock_server_thread(void *arg)
186 197 sock_udp_ep_t remote;
187 198 ssize_t res;
188 199  
189   - if ((res = sock_udp_recv(&sock, buf, sizeof(buf), SOCK_NO_TIMEOUT,
  200 + if ((res = sock_udp_recv(&sock, &buf, sizeof(buf), SOCK_NO_TIMEOUT,
190 201 &remote)) >= 0) {
191 202 // puts("Received a message");
192 203 //printf("%s\n",buf);
193   - if (sock_udp_send(&sock, buf, res, &remote) < 0) {
  204 + /*if (sock_udp_send(&sock, buf, res, &remote) < 0) {
194 205 puts("Error sending reply");
195   - }
196   - if(strcmp((char *)buf,"go")==0)
  206 + }*/
  207 + if (sntp_sync(&server, SOCK_NO_TIMEOUT) < 0) {
  208 + puts("Error in synchronization");
  209 + return NULL;
  210 + }
  211 + offset = sntp_get_offset();
  212 + deadline = xtimer_now_usec() + offset - buf.heure_actuelle;
  213 + printf("tps de transmission : %i\n",deadline);
  214 + printf("compteur : %d\n",compteur);
  215 + if(deadline<=70000 && compteur >=5)
  216 + {
  217 + ordre = 1;
  218 + timer_clear(TIMER_DEV(1),0);
  219 + }
  220 + else if(deadline<=70000 && (ordre == 2 || ordre ==0))
  221 + {
  222 + compteur++;
  223 + }
  224 + else
  225 + {
  226 + ordre = 2;
  227 + compteur = 0;
  228 + if(timer_run == 0)
  229 + {
  230 + timer_set(TIMER_DEV(1),0,25200);
  231 + timer_run = 1;
  232 + }
  233 + }
  234 +
  235 + /*if(strcmp((char *)buf,"go")==0)
197 236 {
198 237 ordre = 1;
199 238 timer_set(XTIMER_DEV,0,8400);
... ... @@ -203,15 +242,20 @@ void *sock_server_thread(void *arg)
203 242 {
204 243 ordre = 0;
205 244 }
206   - }
  245 + }*/
  246 + memset(&buf,0,sizeof(buf));
207 247 }
  248 + }
208 249 return NULL;
209 250 }
210 251  
211 252 void *sock_client_thread(void *arg)
212 253 {
213 254 (void) arg;
214   - uint_8t paquet[];
  255 + Data data;
  256 + data.donnees[0] = 'g';
  257 + data.donnees[1] = 'o';
  258 + //uint8_t paquet[];
215 259 sock_udp_ep_t remote = { .family = AF_INET6 };
216 260  
217 261 remote.port = 1234;
... ... @@ -225,7 +269,9 @@ void *sock_client_thread(void *arg)
225 269 while (1) {
226 270 // //ipv6_addr_set_all_nodes_multicast((ipv6_addr_t *)&remote.addr.ipv6,
227 271 // // IPV6_ADDR_MCAST_SCP_LINK_LOCAL);
228   - if (sock_udp_send(NULL, "go", sizeof("go"), &remote) < 0) {
  272 + data.heure_actuelle = xtimer_now_usec();
  273 +
  274 + if (sock_udp_send(NULL, &data, sizeof(data), &remote) < 0) {
229 275 puts("Error sending message");
230 276 }
231 277 xtimer_sleep(1);
... ... @@ -237,23 +283,24 @@ static void arret_urgence(void *arg,int channel)
237 283 {
238 284 //pwm_set(PWM_DEV(0),1,0);
239 285 ordre=0;
  286 + timer_run = 0;
240 287 printf("Arret d'urgence\n");
241 288 }
242 289  
243   -static void degradation(void *arg,int channel)
  290 +/*static void degradation(void *arg,int channel)
244 291 {
245 292 ordre=2;
246 293 //pwm_set(PWM_DEV(0),1,0);
247 294 printf("Ralentissement\n");
248 295 timer_set(TIMER_DEV(1),0,25200);
249   -}
  296 +}*/
250 297  
251 298 static void _init_timer(void)
252 299 {
253 300 printf("ok timer\n");
254   - timer_init(XTIMER_DEV, CLOCK_CORECLOCK/2 ,&degradation,NULL);
255   - timer_set(XTIMER_DEV, 0, 8400);
256   - timer_irq_enable(XTIMER_DEV);
  301 + //timer_init(XTIMER_DEV, CLOCK_CORECLOCK/2 ,&degradation,NULL);
  302 + //timer_set(XTIMER_DEV, 0, 8400);
  303 + //timer_irq_enable(XTIMER_DEV);
257 304 timer_init(TIMER_DEV(1), CLOCK_CORECLOCK/2 ,&arret_urgence,NULL);
258 305 timer_irq_enable(TIMER_DEV(1));
259 306 }
... ...
RIOT/examples/static_network_app_sock_udp/README.md deleted
... ... @@ -1,142 +0,0 @@
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/static_network_app_sock_udp/udp.c deleted
... ... @@ -1,174 +0,0 @@
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/sys/net/application_layer/sntp/sntp.c
... ... @@ -68,8 +68,6 @@ int sntp_sync(sock_udp_ep_t *server, uint32_t timeout)
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   -
73 71 return result;
74 72 }
75 73 //xtimer_ticks64_t now = xtimer_now64();
... ... @@ -78,8 +76,6 @@ int sntp_sync(sock_udp_ep_t *server, uint32_t timeout)
78 76 /* _sntp_offset = (byteorder_ntohl(_sntp_packet.transmit.seconds) * SEC_IN_USEC) +
79 77 ((byteorder_ntohl(_sntp_packet.transmit.fraction) * 232)
80 78 / 1000000) - xtimer_now_usec();*/
81   - printf("TT: %lu\n", byteorder_ntohl(_sntp_packet.transmit.seconds));
82   - printf("heure actuelle : %lu\n",xtimer_now_usec());
83 79 mutex_unlock(&_sntp_mutex);
84 80 return 0;
85 81 }
... ...