-
Notifications
You must be signed in to change notification settings - Fork 0
/
control_ipv6.c
executable file
·119 lines (95 loc) · 3.39 KB
/
control_ipv6.c
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
113
114
115
116
117
118
119
#include "control.h"
#include "contiki-net.h"
#include "settings.h"
#include <stdio.h>
#include <stdlib.h>
#include "node-id.h"
#include "net/uip-debug.h"
#define DEBUG DEBUG_PRINT
#define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
PROCESS(default_app_process, "Controller process");
AUTOSTART_PROCESSES(&default_app_process);
static struct etimer timer;
static int16_t x = 0;
static int count = 0;
/*---------------------------------------------------------------------------*/
static struct uip_udp_conn *client_conn;
/*---------------------------------------------------------------------------*/
static void udp_send_data(void) {
char buffer[2];
itoa((int)CONTROL,buffer,10);
uip_udp_packet_send(client_conn, buffer, 2/*strlen(buf)*/);
printf("Sende Daten: %s\n", buffer);
}
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
static void print_local_addresses(void) {
int i;
uint8_t state;
PRINTF("Server IPv6 addresses: ");
for(i = 0; i < UIP_DS6_ADDR_NB; i++) {
state = uip_ds6_if.addr_list[i].state;
if(uip_ds6_if.addr_list[i].isused && (state == ADDR_TENTATIVE || state == ADDR_PREFERRED)) {
PRINT6ADDR(&uip_ds6_if.addr_list[i].ipaddr);
PRINTF("\n");
}
}
}
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
static void set_connection_address(uip_ipaddr_t *ipaddr) {
//fe80::f00:22ff:fe33:4455 is node 13
//if (node_id == 12)
// uip_ip6addr(ipaddr,0xfe80,0,0,0,0xf00,0x22ff,0xfe33,0x4455);
//fe80::e00:22ff:fe33:4455 is node 12
//else if (node_id == 13)
// uip_ip6addr(ipaddr,0xfe80,0,0,0,0xe00,0x22ff,0xfe33,0x4455);
// else
// printf("No destiniation!");
//uip_ip6addr(ipaddr,0xfe80,0,0,0,0x3301,0x22ff,0xfe33,0x4455);
uip_ip6addr(ipaddr,0xfe80,0,0,0,0x3513,0,0,0);
}
static void print_control() {
#if CONTROL == 0
printf("CROSS");
#elif CONTROL == 1
printf("CIRCLE");
#elif CONTROL == 2
printf("TRIANGLE");
#elif CONTROL == 3
printf("SQUARE");
#endif
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(default_app_process, ev, data) {
uip_ipaddr_t ipaddr;
PROCESS_BEGIN();
set_connection_address(&ipaddr);
/* new connection with remote host */
client_conn = udp_new(&ipaddr, UIP_HTONS(3002), NULL);
udp_bind(client_conn, UIP_HTONS(3003));
PRINTF("Created a connection with the server ");
PRINT6ADDR(&client_conn->ripaddr);
PRINTF(" local/remote port %u/%u\n",
UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport));
SENSORS_ACTIVATE(acc_sensor);
etimer_set(&timer, CLOCK_SECOND * 0.05);
printf("Node configured as ");
print_control();
printf("\n");
while (1) {
PROCESS_YIELD();
if ( etimer_expired(&timer) ) {
etimer_set(&timer, CLOCK_SECOND*0.05);
x = acc_sensor.value(ACC_Y_RAW);
if (x > 380) {
//send
udp_send_data();
etimer_set(&timer, CLOCK_SECOND*0.3);
count++;
}
}
}
PROCESS_END();
}
/*---------------------------------------------------------------------------*/