Revision 1968
Added an alternate main that merely outputs the wireless
packets that are being thrown across the air to usb.
It translates Traffic Navigation packet id's into names.
trunk/code/projects/traffic_navigation/main-wirelesswatcher.c | ||
---|---|---|
1 |
#ifdef WIRELESSWATCH |
|
2 |
/* |
|
3 |
* main.c for for watching and outputting to console Traffic Navigation wireless |
|
4 |
* packets |
|
5 |
* Author: Colony Project, CMU Robotics Club |
|
6 |
*/ |
|
7 |
#include "traffic_navigation.h" |
|
8 |
|
|
9 |
/* Wireless packet parsing */ |
|
10 |
int wirelessPacketWatch(); |
|
11 |
|
|
12 |
int main (void) { |
|
13 |
|
|
14 |
/* Initialize the dragonfly boards, the xbee, encoders, lineFollowing */ |
|
15 |
dragonfly_init(ALL_ON); |
|
16 |
xbee_init(); |
|
17 |
encoders_init(); |
|
18 |
rtc_init(SIXTEENTH_SECOND, NULL); |
|
19 |
wl_basic_init_default(); |
|
20 |
wl_set_channel(13); |
|
21 |
|
|
22 |
int clockval = rtc_get(); |
|
23 |
usb_puts("Hello! Ready to Recieve Packets...\n[TIME] Packet: <DATA>\n"); |
|
24 |
orb1_set_color(BLUE); |
|
25 |
while(1) { |
|
26 |
wirelessPacketWatch(); |
|
27 |
|
|
28 |
if(clockval != rtc_get()){ |
|
29 |
orb2_set_color(ORB_OFF); |
|
30 |
clockval = rtc_get(); |
|
31 |
} |
|
32 |
} |
|
33 |
|
|
34 |
} |
|
35 |
|
|
36 |
int wirelessPacketWatch(){ |
|
37 |
int dataLength = 0; |
|
38 |
unsigned char *packet = NULL; |
|
39 |
packet = wl_basic_do_default(&dataLength); |
|
40 |
|
|
41 |
/* sanity check */ |
|
42 |
if(dataLength == 0 || packet == NULL){ //no packet |
|
43 |
//usb_puts("No Packet\n"); |
|
44 |
return ENOPACKET; |
|
45 |
} |
|
46 |
|
|
47 |
if(dataLength != PACKET_LENGTH){ |
|
48 |
usb_puts("Packet wrong length (this is a bad problem...)\n"); |
|
49 |
return EPACKETLEN; |
|
50 |
} |
|
51 |
|
|
52 |
orb2_set_color(GREEN); |
|
53 |
usb_puts("["); usb_puti(rtc_get()); usb_puts("] Packet:"); |
|
54 |
switch (packet[0]){ |
|
55 |
case WROADENTRY: //[type, bot, road] |
|
56 |
usb_puts("WROADENTRY: bot: "); |
|
57 |
usb_puti(packet[1]); |
|
58 |
usb_puts(" road: "); |
|
59 |
usb_puti(packet[2]); |
|
60 |
usb_puts("\n"); |
|
61 |
break; |
|
62 |
case WROADEXIT: //[type, bot, road] |
|
63 |
usb_puts("WROADEXIT: bot: "); |
|
64 |
usb_puti(packet[1]); |
|
65 |
usb_puts(" road: "); |
|
66 |
usb_puti(packet[2]); |
|
67 |
usb_puts("\n"); |
|
68 |
break; |
|
69 |
case WROADSTOP: //[type, bot, road] |
|
70 |
usb_puts("WROADSTOP: bot: "); |
|
71 |
usb_puti(packet[1]); |
|
72 |
usb_puts(" road: "); |
|
73 |
usb_puti(packet[2]); |
|
74 |
usb_puts("\n"); |
|
75 |
break; |
|
76 |
case WINTERSECTIONENTRY: //[type, bot, intersection, fromDir, toDir] |
|
77 |
usb_puts("WINTERSECTIONENTRY: bot: "); |
|
78 |
usb_puti(packet[1]); |
|
79 |
usb_puts(" intersection: "); |
|
80 |
usb_puti(packet[2]); |
|
81 |
usb_puts(" fromDir: "); |
|
82 |
usb_puti(packet[3]); |
|
83 |
usb_puts(" toDir: "); |
|
84 |
usb_puti(packet[4]); |
|
85 |
usb_puts("\n"); |
|
86 |
break; |
|
87 |
case WINTERSECTIONREPLY: //[type, fromBot, intersection, toBot] |
|
88 |
usb_puts("WINTERSECTIONREPLY: bot: "); |
|
89 |
usb_puti(packet[1]); |
|
90 |
usb_puts(" interesction: "); |
|
91 |
usb_puti(packet[2]); |
|
92 |
usb_puts(" tobot: "); |
|
93 |
usb_puti(packet[3]); |
|
94 |
usb_puts("\n"); |
|
95 |
break; |
|
96 |
case WINTERSECTIONEXIT: //[type, bot, intersection] |
|
97 |
usb_puts("WINTERSECTIONEXIT: bot: "); |
|
98 |
usb_puti(packet[1]); |
|
99 |
usb_puts(" interesction: "); |
|
100 |
usb_puti(packet[2]); |
|
101 |
usb_puts("\n"); |
|
102 |
break; |
|
103 |
case WINTERSECTIONGO: //[type, bot, intersection] |
|
104 |
usb_puts("WINTERSECTIONGO: bot: "); |
|
105 |
usb_puti(packet[1]); |
|
106 |
usb_puts(" interesction: "); |
|
107 |
usb_puti(packet[2]); |
|
108 |
usb_puts("\n"); |
|
109 |
break; |
|
110 |
case WINTERSECTIONPOLICEENTRY: //[?] |
|
111 |
break; |
|
112 |
case WINTERSECTIONRESOLVERACE: //[type, bot, intersection, num] |
|
113 |
//in the case robots draw the same number these will be |
|
114 |
//arbitrated using the sending robot's id, prefering |
|
115 |
//lower ids |
|
116 |
usb_puts("WINTERSECTIONRESOLVERACE: bot: "); |
|
117 |
usb_puti(packet[1]); |
|
118 |
usb_puts(" intersection: "); |
|
119 |
usb_puti(packet[2]); |
|
120 |
usb_puts(" num: "); |
|
121 |
usb_puti(packet[3]); |
|
122 |
usb_puts("\n"); |
|
123 |
break; |
|
124 |
case WHIGHWAYENTRY: //[type, bot, highway] |
|
125 |
usb_puts("WHIGHWAYENTRY: bot: "); |
|
126 |
usb_puti(packet[1]); |
|
127 |
usb_puts(" highway: "); |
|
128 |
usb_puti(packet[2]); |
|
129 |
usb_puts("\n"); |
|
130 |
break; |
|
131 |
case WHIGHWAYREPLY: //[type, fromBot, highway, toBot] |
|
132 |
usb_puts("WHIGHWAYREPLY: bot: "); |
|
133 |
usb_puti(packet[1]); |
|
134 |
usb_puts(" highway: "); |
|
135 |
usb_puti(packet[2]); |
|
136 |
usb_puts(" toBot: "); |
|
137 |
usb_puti(packet[2]); |
|
138 |
usb_puts("\n"); |
|
139 |
break; |
|
140 |
case WHIGHWAYEXIT: //[type, bot, highway] |
|
141 |
usb_puts("WHIGHWAYEXIT: bot: "); |
|
142 |
usb_puti(packet[1]); |
|
143 |
usb_puts(" highway: "); |
|
144 |
usb_puti(packet[2]); |
|
145 |
usb_puts("\n"); |
|
146 |
break; |
|
147 |
case WPINGGLOBAL: //[type, bot] |
|
148 |
usb_puts("WPINGGLOBAL: bot: "); |
|
149 |
usb_puti(packet[1]); |
|
150 |
usb_puts("\n"); |
|
151 |
break; |
|
152 |
case WPINGBOT: //[type, fromBot, toBot] |
|
153 |
usb_puts("WPINGBOT: bot: "); |
|
154 |
usb_puti(packet[1]); |
|
155 |
usb_puts(" tobot: "); |
|
156 |
usb_puti(packet[2]); |
|
157 |
usb_puts("\n"); |
|
158 |
break; |
|
159 |
case WPINGQUEUE: //[type, fromBot, toBot] |
|
160 |
usb_puts("WPINGQUEUE: bot: "); |
|
161 |
usb_puti(packet[1]); |
|
162 |
usb_puts(" tobot: "); |
|
163 |
usb_puti(packet[2]); |
|
164 |
usb_puts("\n"); |
|
165 |
break; |
|
166 |
case WPINGREPLY: //[type, fromBot, toBot] |
|
167 |
usb_puts("WPINGREPLY: bot: "); |
|
168 |
usb_puti(packet[1]); |
|
169 |
usb_puts(" tobot: "); |
|
170 |
usb_puti(packet[2]); |
|
171 |
usb_puts("\n"); |
|
172 |
break; |
|
173 |
case WCOLLISIONAVOID: //[type, bot, intersection, collision-int] //Note: collision is an int and thus takes two spaces |
|
174 |
usb_puts("WCOLLISIONAVOID: bot: "); |
|
175 |
usb_puti(packet[1]); |
|
176 |
usb_puts(" intersection: "); |
|
177 |
usb_puti(packet[2]); |
|
178 |
usb_puts(" collision-int : "); |
|
179 |
usb_puti(packet[3]); |
|
180 |
usb_puts("\n"); |
|
181 |
break; |
|
182 |
default: |
|
183 |
usb_puts("Got undefined packet\n"); |
|
184 |
break; |
|
185 |
} |
|
186 |
return 0; |
|
187 |
} |
|
188 |
#endif |
Also available in: Unified diff