2 #include <contiki-lib.h>
3 #include <contiki-net.h>
6 #include <dev/button-sensor.h>
9 //#include <net/psock.h>
12 ////////////////// DEBUGGING STUFF
13 #define DEBUG DEBUG_PRINT
14 #include "net/uip-debug.h"
15 //////////////////////////////////
17 //extern struct uip_eth_addr uip_ethaddr;
19 PROCESS(led_remote_control
, "binary LED counter via button over UDP");
20 AUTOSTART_PROCESSES(&led_remote_control
);
23 static uint16_t node_addr
;
24 static uip_ipaddr_t ipaddr
;
25 /** UDP connection object */
26 static struct uip_udp_conn
* udp_conn
;
27 /** Port used for the connection */
29 #define MAX_PAYLOAD_LEN 40
30 #define UIP_IP_BUF ((struct uip_ip_hdr *)&uip_buf[UIP_LLH_LEN])
32 /** somehow these need to be defined... */
34 /*---------------------------------------------------------------------------*/
36 print_local_addresses(void)
41 PRINTF("Server IPv6 addresses: ");
42 for(i
= 0; i
< UIP_DS6_ADDR_NB
; i
++) {
43 state
= uip_ds6_if
.addr_list
[i
].state
;
44 if(uip_ds6_if
.addr_list
[i
].isused
&&
45 (state
== ADDR_TENTATIVE
|| state
== ADDR_PREFERRED
)) {
46 PRINT6ADDR(&uip_ds6_if
.addr_list
[i
].ipaddr
);
52 //PT_THREAD(recv(struct psock * ps)) {
56 // printf("node %d: recv from %d: %d\n", /* FIXME */ 0, 0, buffer);
59 // leds_toggle(LEDS_GREEN);
61 // leds_toggle(LEDS_YELLOW);
62 // printf("toggled LEDs\n");
66 PROCESS_THREAD(led_remote_control
, ev
, data
) {
72 SENSORS_ACTIVATE(button_sensor
);
75 node_addr
= settings_get_uint16(SETTINGS_KEY_PAN_ADDR
, 0);
76 printf("node address is %d\n", node_addr
);
80 // uip_lladdr.addr[4] = 0xfe;
81 // uip_lladdr.addr[5] = 0x33;
82 // uip_lladdr.addr[6] = (node_addr >> 8) & 0xff;
83 // uip_lladdr.addr[7] = node_addr & 0xff;
84 // settings_set(SETTINGS_KEY_EUI64, &uip_lladdr.addr, sizeof(uip_lladdr));
90 print_local_addresses();
91 // static struct uip_eth_addr eth_addr = {{0x00, 0x06, 0x98, 0x01, 0x00, 0x00}};
92 // uip_setethaddr(eth_addr);
94 // uip_ip6addr(&ipaddr, 0xfe80, 0x1234, 0x5678, 0x90ab, 0xcdef, 0x1357, 0x9ace,
96 // uip_sethostaddr(&ipaddr);
97 // uip_ipaddr(&ipaddr, 255, 255, 0, 0);
98 // uip_setnetmask(&ipaddr);
100 // uip_gethostaddr(&ipaddr);
101 // PRINTF("IP address is ");
102 // PRINT6ADDR(&ipaddr);
105 // udp_conn = udp_broadcast_new(uip_htons(UDP_PORT), 0);
106 uip_ip6addr(&ipaddr
, 0xfe80, 0, 0, 0, 0x1d00, 0x22ff, 0xfe33, 0x001f);
107 udp_conn
= udp_new(&ipaddr
, uip_htons(UDP_PORT
), 0);
109 udp_bind(udp_conn
, UIP_HTONS(UDP_PORT
));
111 static struct etimer timer
;
113 PROCESS_WAIT_EVENT_UNTIL(
114 (ev
== sensors_event
&& data
== &button_sensor
) ||
117 printf("event detected\n");
118 if(ev
== sensors_event
) {
119 printf("surprise, it's a button event!\n");
120 // debounce for 250 ms
121 etimer_set(&timer
, CLOCK_SECOND
* 0.25);
122 PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer
));
125 char buf
[MAX_PAYLOAD_LEN
];
127 //uip_create_linklocal_allnodes_mcast(&udp_conn->ripaddr);
128 //uip_ipaddr_copy(&udp_conn->ripaddr, &ipaddr);
129 PRINTF("Sending message from ");
130 PRINT6ADDR(&UIP_IP_BUF
->srcipaddr
);
132 PRINT6ADDR(&udp_conn
->ripaddr
);
133 sprintf(buf
, "Hello! (%d)", ++seq_id
);
134 PRINTF(": %s\n", buf
);
136 uip_udp_packet_send(udp_conn
, buf
, strlen(buf
));
140 } else if(ev
== tcpip_event
) {
141 PRINTF("tcpip_event detected\n");
143 ((char *)uip_appdata
)[uip_datalen()] = 0;
144 PRINTF("Received: '%s' from ", (char *)uip_appdata
);
145 PRINT6ADDR(&UIP_IP_BUF
->srcipaddr
);
148 /* Restore server connection to allow data from any node */
149 //memset(&udp_conn->ripaddr, 0, sizeof(udp_conn->ripaddr));
This page took 0.052984 seconds and 5 git commands to generate.