5 #include <usb/usb-api.h>
6 #include <usb/cdc-acm.h>
8 #include <debug-uart.h>
10 #include <net/uip-fw-drv.h>
14 #include "contiki-main.h"
20 rimeaddr_t node_addr = {{0,129}};
26 static unsigned char input_buffer[128];
27 static unsigned char output_buffer[128];
28 static unsigned char interrupt_buffer[16];
30 #define DEV_TO_HOST 0x81
31 #define HOST_TO_DEV 0x02
33 #define GATEWAY_TRICKLE_CHANNEL 8
40 slip_arch_writeb(
unsigned char c)
42 while(usb_send_data(DEV_TO_HOST, &c, 1) != 1);
50 struct gateway_msg msg;
55 printf(
"%d.%d: making myself the gateway\n",
59 rimebuf_copyfrom(&msg,
sizeof(
struct gateway_msg));
60 trickle_send(&gateway_trickle);
66 PROCESS(gateway_process,
"Gateway process");
73 usb_set_user_process(process_current);
78 uip_over_mesh_set_gateway_netif(&slipif);
84 while(ev != PROCESS_EVENT_EXIT) {
86 if (ev == PROCESS_EVENT_TIMER) {
87 leds_toggle(LEDS_YELLOW);
90 }
else if (ev == PROCESS_EVENT_MSG) {
91 const struct usb_user_msg *
const msg = data;
93 case USB_USER_MSG_TYPE_CONFIG:
94 printf(
"User config\n");
95 if (msg->data.config != 0) {
96 usb_setup_bulk_endpoint(DEV_TO_HOST,
97 input_buffer,
sizeof(input_buffer));
98 usb_setup_bulk_endpoint(HOST_TO_DEV,
99 output_buffer,
sizeof(output_buffer));
100 usb_setup_interrupt_endpoint(0x83,interrupt_buffer,
101 sizeof(interrupt_buffer));
105 usb_disable_endpoint(DEV_TO_HOST);
106 usb_disable_endpoint(HOST_TO_DEV);
107 usb_disable_endpoint(0x83);
111 case USB_USER_MSG_TYPE_EP_OUT(2):
118 while((xfer = usb_recv_data(HOST_TO_DEV, &ch, 1)) > 0) {
120 if (slip_input_byte(ch))
break;
130 printf(
"USB test process exited\n");
134 AUTOSTART_PROCESSES(&gateway_process);