XBee API mode library
Diff: Send.cpp
- Revision:
- 10:3da24a020e67
- Parent:
- 8:776b8dc51932
- Child:
- 16:cdfcb63b2c4b
diff -r 850306f22153 -r 3da24a020e67 Send.cpp --- a/Send.cpp Tue Jan 29 14:18:18 2013 +0000 +++ b/Send.cpp Wed Mar 13 19:09:55 2013 +0000 @@ -131,7 +131,11 @@ frame_id = frame_id % 255 + 1; } -bool XBee::send(const char *data, int length, bool confirm = true) { +bool XBee::send(const char *data, int length) { + return send(data, length, sendConfirmation); +} + +bool XBee::send(const char *data, int length, float timeout) { if (length == 0) length = strlen(data); @@ -139,26 +143,23 @@ createTxRequest(frame_id, data, length, buf, sizeof(buf)); sendFrame(buf, length + 14); + frame_id = frame_id % 255 + 1; - if (confirm) { - int index = seekFor(ZigBeeTransmitStatus, frame_id, 3.0); + if (timeout > 0) { + int index = seekFor(ZigBeeTransmitStatus, frame_id, timeout); if (index != -1) { char delivery; scan(index, DeliveryStatus, &delivery); buf[INDEX(index + 2)] = 0x00; - frame_id = frame_id % 255 + 1; - return delivery == 0; - } + } else + return false; } - - frame_id = frame_id % 255 + 1; - - return false; + return true; } -bool XBee::sendConfirm(const char *data, int length) { - return send(data, length, true); +void XBee::setSendConfirmation(float sendConfirmation) { + this->sendConfirmation = sendConfirmation; } int XBee::printf(const char *format, ...) { @@ -166,11 +167,11 @@ va_start(argv, format); char buf[256]; int length = vsnprintf(buf, sizeof buf, format, argv); - return length > 0 && sendConfirm(buf, length) ? length : -1; + return length > 0 && send(buf, length) ? length : -1; } void XBee::send(char c) { - while (!writeable()) wait_us(100); + while (!writeable()) wait(0.001); putc(c); }