Revision 397
added error returns to some libwireless functions, handled in server.
xbee.c | ||
---|---|---|
69 | 69 |
/*Internal Function Prototypes*/ |
70 | 70 |
|
71 | 71 |
/*I/O Functions*/ |
72 |
void xbee_send(char* buf, int size);
|
|
73 |
void xbee_send_string(char* c); |
|
72 |
static int xbee_send(char* buf, int size);
|
|
73 |
static void xbee_send_string(char* c);
|
|
74 | 74 |
|
75 | 75 |
#ifndef ROBOT |
76 | 76 |
void xbee_read(char* buf, int size); |
... | ... | |
89 | 89 |
/*API Mode Functions*/ |
90 | 90 |
|
91 | 91 |
int xbee_handle_packet(char* packet, int len); |
92 |
void xbee_handle_at_command_response(char* command, char result, |
|
93 |
char* extra, int extraLen); |
|
92 |
void xbee_handle_at_command_response(char* command, char result, char* extra, int extraLen); |
|
94 | 93 |
void xbee_handle_status(char status); |
95 | 94 |
int xbee_verify_checksum(char* packet, int len); |
96 | 95 |
char xbee_compute_checksum(char* packet, int len); |
... | ... | |
291 | 290 |
* @param buf the buffer of data to send |
292 | 291 |
* @param size the number of bytes to send |
293 | 292 |
**/ |
294 |
void xbee_send(char* buf, int size)
|
|
293 |
int xbee_send(char* buf, int size)
|
|
295 | 294 |
{ |
296 | 295 |
#ifdef ROBOT |
297 | 296 |
int i; |
... | ... | |
301 | 300 |
int ret = write(xbee_stream, buf, size); |
302 | 301 |
//success |
303 | 302 |
if (ret == size) |
304 |
return; |
|
303 |
return 0;
|
|
305 | 304 |
if (ret == -1) |
306 | 305 |
{ |
307 | 306 |
//interrupted by system signal, probably timer interrupt. |
308 | 307 |
//just try again |
309 | 308 |
if (errno == 4) |
310 | 309 |
{ |
311 |
xbee_send(buf, size); |
|
312 |
return; |
|
310 |
return xbee_send(buf, size); |
|
313 | 311 |
} |
314 | 312 |
printf("Failed to write to xbee, error %i.\r\n", errno); |
315 |
return; |
|
313 |
return -1;
|
|
316 | 314 |
} |
317 | 315 |
|
318 | 316 |
//write was interrupted after writing ret bytes |
319 | 317 |
xbee_send(buf + ret, size - ret); |
320 | 318 |
#endif |
319 |
|
|
320 |
return 0; |
|
321 | 321 |
} |
322 | 322 |
|
323 | 323 |
/** |
... | ... | |
529 | 529 |
* the XBee alerts us as to whether or not our message |
530 | 530 |
* was received. |
531 | 531 |
**/ |
532 |
void xbee_send_packet(char* packet, int len, int dest, |
|
533 |
char options, char frame) |
|
532 |
int xbee_send_packet(char* packet, int len, int dest, char options, char frame) |
|
534 | 533 |
{ |
535 | 534 |
char buf[5]; |
536 | 535 |
char prefix[3]; |
... | ... | |
540 | 539 |
if (len > 100) |
541 | 540 |
{ |
542 | 541 |
WL_DEBUG_PRINT("Packet is too large.\r\n"); |
543 |
return; |
|
542 |
return -1;
|
|
544 | 543 |
} |
545 | 544 |
|
546 | 545 |
//data for sending request |
... | ... | |
560 | 559 |
for (i = 0; i < len; i++) |
561 | 560 |
checksum += (unsigned char)packet[i]; |
562 | 561 |
checksum = 0xFF - checksum; |
563 |
xbee_send(prefix, 3); |
|
564 |
xbee_send(buf, 5); |
|
565 |
xbee_send(packet, len); |
|
566 |
xbee_send((char*)&checksum, 1); |
|
562 |
|
|
563 |
if (xbee_send(prefix, 3) != 0) { |
|
564 |
return -1; |
|
565 |
} |
|
566 |
|
|
567 |
if (xbee_send(buf, 5) != 0) { |
|
568 |
return -1; |
|
569 |
} |
|
570 |
|
|
571 |
if (xbee_send(packet, len) != 0) { |
|
572 |
return -1; |
|
573 |
} |
|
574 |
|
|
575 |
if (xbee_send((char*)&checksum, 1) != 0) { |
|
576 |
return -1; |
|
577 |
} |
|
578 |
|
|
579 |
return 0; |
|
567 | 580 |
} |
568 | 581 |
|
569 | 582 |
/** |
Also available in: Unified diff