XBee API mode library
Diff: Receive.cpp
- Revision:
- 10:3da24a020e67
- Parent:
- 8:776b8dc51932
- Child:
- 14:af6e497bbf52
diff -r 850306f22153 -r 3da24a020e67 Receive.cpp --- a/Receive.cpp Tue Jan 29 14:18:18 2013 +0000 +++ b/Receive.cpp Wed Mar 13 19:09:55 2013 +0000 @@ -77,19 +77,16 @@ * if the frame is found before timeout, returns the index of the packet, otherwise -1. * */ -int XBee::seekFor(FrameType type, char id, float timeout) -{ +int XBee::seekFor(FrameType type, char id, float timeout) { int index = out; - while (true) { - if (index != in) { + + while (timeout > 0) { + if (index != in) { if (getFrameType(buf[INDEX(index + 2)]) == type && (id == 0 || buf[INDEX(index + 3)] == id)) return index; int size = SIZE(buf, index); index = INDEX(index + 2 + size); - continue; - } else if (timeout <= 0) { - return -1; - } + } else { #ifndef XBEE_RTOS wait(0.001); timeout -= 0.001; @@ -97,7 +94,10 @@ Thread::wait(10); timeout -= 0.01; #endif + } } + + return -1; } XBee::FrameType XBee::getFrameType(char c) @@ -236,7 +236,7 @@ if (c != -1) { rxBuf = c; - signal(); + notify(); } } @@ -245,7 +245,7 @@ bool escaped = false; while (true) { - signalWait(); + wait(); mutex.lock(); if (debug && rxBuf.readable()) leds = leds ^ 4; // x@xx @@ -282,7 +282,7 @@ if (debug) leds = (leds & 12) | 2; // xx10 } else { state = UNKNOWN; - leds = leds & 12; //** update leds + if (debug) leds = leds & 12; //** update leds } //::printf("<length2 in = %04X, out = %04X, free = %d\n", in, out, free); break;