Revision 793
Updated bay board wireless library... Doesn't work at all.
wireless.c | ||
---|---|---|
44 | 44 |
#include <signal.h> |
45 | 45 |
#else |
46 | 46 |
#include <time.h> |
47 |
#ifndef FIREFLY |
|
48 |
#ifdef BAYBOARD |
|
49 |
#include <lbom.h> |
|
50 |
#else |
|
51 |
#include <bom.h> |
|
52 |
#endif |
|
53 |
#endif |
|
47 |
#include <bom.h> |
|
54 | 48 |
#endif |
55 | 49 |
|
56 | 50 |
/*Function Prototypes*/ |
... | ... | |
64 | 58 |
/*Data Members*/ |
65 | 59 |
|
66 | 60 |
//used to store incoming and outgoing packets |
61 |
//TODO: does this need to be 128? can it be smaller to save memory? |
|
62 |
//TODO: this shouldn't be hardcoded as 128. it should be a define. |
|
67 | 63 |
static unsigned char wl_buf[128]; |
68 | 64 |
//1 if we have timed out since we last checked, 0 otherwise. |
69 | 65 |
static int wl_timeout = 0; |
... | ... | |
106 | 102 |
int wl_init() |
107 | 103 |
{ |
108 | 104 |
int i; |
105 |
//TODO: using memset here instead of this loop, *might* be less instructions and *might* reduce code size but not sure |
|
109 | 106 |
for (i = 0; i < WL_MAX_PACKET_GROUPS; i++) |
110 | 107 |
wl_packet_groups[i] = NULL; |
111 | 108 |
|
... | ... | |
174 | 171 |
* |
175 | 172 |
* @see wl_get_pan |
176 | 173 |
**/ |
174 |
//TODO: this function is so simple, it *may* be beneficial to inline this function. testing of if |
|
175 |
// it reduces code size or not should be done to be sure. |
|
177 | 176 |
int wl_set_pan(int pan) |
178 | 177 |
{ |
179 | 178 |
return xbee_set_pan_id(pan); |
... | ... | |
186 | 185 |
* |
187 | 186 |
* @see wl_set_pan |
188 | 187 |
**/ |
188 |
//TODO: this function is so simple, it *may* be beneficial to inline this function. testing of if |
|
189 |
// it reduces code size or not should be done to be sure. |
|
189 | 190 |
int wl_get_pan(void) |
190 | 191 |
{ |
191 | 192 |
return xbee_get_pan_id(); |
... | ... | |
198 | 199 |
* |
199 | 200 |
* @see wl_get_channel |
200 | 201 |
**/ |
202 |
//TODO: this function is so simple, it *may* be beneficial to inline this function. testing of if |
|
203 |
// it reduces code size or not should be done to be sure. |
|
201 | 204 |
int wl_set_channel(int channel) |
202 | 205 |
{ |
203 | 206 |
return xbee_set_channel(channel); |
... | ... | |
210 | 213 |
* |
211 | 214 |
* @see wl_set_channel |
212 | 215 |
**/ |
216 |
//TODO: this function is so simple, it *may* be beneficial to inline this function. testing of if |
|
217 |
// it reduces code size or not should be done to be sure. |
|
213 | 218 |
int wl_get_channel(void) |
214 | 219 |
{ |
215 | 220 |
return xbee_get_channel(); |
... | ... | |
220 | 225 |
* |
221 | 226 |
* @return the 16-bit address of the XBee module. |
222 | 227 |
**/ |
228 |
//TODO: this function is so simple, it *may* be beneficial to inline this function. testing of if |
|
229 |
// it reduces code size or not should be done to be sure. |
|
223 | 230 |
int wl_get_xbee_id() |
224 | 231 |
{ |
225 | 232 |
return xbee_get_address(); |
... | ... | |
235 | 242 |
* @param dest the 16-bit address of the XBee to send the packet to |
236 | 243 |
* @param frame the frame number to see with a TX_STATUS response |
237 | 244 |
**/ |
245 |
//TODO: this function is so simple, it *may* be beneficial to inline this function. testing of if |
|
246 |
// it reduces code size or not should be done to be sure. |
|
238 | 247 |
int wl_send_robot_to_robot_global_packet(char group, char type, char* data, int len, int dest, char frame) |
239 | 248 |
{ |
240 | 249 |
return wl_send_packet(group, type, data, len, dest, XBEE_OPTIONS_BROADCAST_ALL_PANS, frame); |
... | ... | |
250 | 259 |
* @param dest the 16-bit address of the XBee to send the packet to |
251 | 260 |
* @param frame the frame number to see with a TX_STATUS response |
252 | 261 |
**/ |
262 |
//TODO: this function is so simple, it *may* be beneficial to inline this function. testing of if |
|
263 |
// it reduces code size or not should be done to be sure. |
|
253 | 264 |
int wl_send_robot_to_robot_packet(char group, char type, char* data, int len, int dest, char frame) |
254 | 265 |
{ |
255 | 266 |
return wl_send_packet(group, type, data, len, dest, XBEE_OPTIONS_NONE, frame); |
... | ... | |
264 | 275 |
* @param len the packet length in bytes |
265 | 276 |
* @param frame the frame number to see with a TX_STATUS response |
266 | 277 |
**/ |
278 |
//TODO: this function is so simple, it *may* be beneficial to inline this function. testing of if |
|
279 |
// it reduces code size or not should be done to be sure. |
|
267 | 280 |
int wl_send_global_packet(char group, char type, char* data, int len, char frame) |
268 | 281 |
{ |
269 | 282 |
return wl_send_packet(group, type, data, len, XBEE_BROADCAST, XBEE_OPTIONS_BROADCAST_ALL_PANS, frame); |
... | ... | |
278 | 291 |
* @param len the packet length in bytes |
279 | 292 |
* @param frame the frame number to see with a TX_STATUS response |
280 | 293 |
**/ |
294 |
//TODO: this function is so simple, it *may* be beneficial to inline this function. testing of if |
|
295 |
// it reduces code size or not should be done to be sure. |
|
281 | 296 |
void wl_send_pan_packet(char group, char type, char* data, int len, char frame) |
282 | 297 |
{ |
283 | 298 |
wl_send_packet(group, type, data, len, XBEE_BROADCAST, |
... | ... | |
297 | 312 |
**/ |
298 | 313 |
int wl_send_packet(char group, char type, char* data, int len, int dest, char options, char frame) |
299 | 314 |
{ |
315 |
//TODO: does this need to be 128? can it be smaller to save memory? |
|
316 |
//TODO: this shouldn't be hardcoded as 128. it should be a define. |
|
300 | 317 |
char buf[128]; |
301 | 318 |
int i; |
302 | 319 |
if (frame != 0) |
... | ... | |
374 | 391 |
} |
375 | 392 |
|
376 | 393 |
int len = xbee_get_packet(wl_buf); |
377 |
if (len == -1)
|
|
394 |
if (len < 0)//no packet received
|
|
378 | 395 |
return; |
379 | 396 |
|
380 | 397 |
if (wl_buf[0] == XBEE_TX_STATUS) |
... | ... | |
411 | 428 |
} |
412 | 429 |
else if (wl_buf[0] == XBEE_RX) |
413 | 430 |
{ |
431 |
//TODO: what does this 7 represent? It shouldn't be hardcoded. It should be set as a define |
|
414 | 432 |
if (len < 7) |
415 | 433 |
{ |
416 | 434 |
WL_DEBUG_PRINT("Packet is too small.\r\n"); |
... | ... | |
426 | 444 |
int options = wl_buf[4]; |
427 | 445 |
*/ |
428 | 446 |
|
447 |
//TODO: these indices, etc should be defined, not hardcoded |
|
429 | 448 |
int group = wl_buf[5]; |
430 | 449 |
int type = wl_buf[6]; |
431 | 450 |
int packetLen = len - 7; |
... | ... | |
442 | 461 |
|
443 | 462 |
|
444 | 463 |
#ifndef ROBOT |
464 |
//TODO: this function is so simple, it *may* be beneficial to inline this function. testing of if |
|
465 |
// it reduces code size or not should be done to be sure. |
|
445 | 466 |
void wl_set_com_port(char* port) |
446 | 467 |
{ |
447 | 468 |
xbee_set_com_port(port); |
Also available in: Unified diff