XBee API mode library
Diff: Send.cpp
- Revision:
- 16:cdfcb63b2c4b
- Parent:
- 10:3da24a020e67
- Child:
- 17:2f728fd13bc0
--- a/Send.cpp Thu Mar 14 09:45:41 2013 +0000 +++ b/Send.cpp Wed Mar 20 00:28:27 2013 +0000 @@ -23,6 +23,10 @@ #include "XBee.h" #include <stdarg.h> +#define LOCK() NVIC_DisableIRQ(UARTx_IRQn[_serial.index]) +#define UNLOCK() NVIC_EnableIRQ(UARTx_IRQn[_serial.index]) +const IRQn_Type UARTx_IRQn[] = {UART0_IRQn, UART1_IRQn, UART2_IRQn, UART3_IRQn}; + void XBee::sendCommand(const char *command, int8_t param, bool queue) { sendCommand(command, (uint64_t) param, queue); } @@ -143,19 +147,29 @@ createTxRequest(frame_id, data, length, buf, sizeof(buf)); sendFrame(buf, length + 14); - frame_id = frame_id % 255 + 1; + bool ret = true; if (timeout > 0) { int index = seekFor(ZigBeeTransmitStatus, frame_id, timeout); if (index != -1) { char delivery; scan(index, DeliveryStatus, &delivery); - buf[INDEX(index + 2)] = 0x00; - return delivery == 0; + this->buf[INDEX(index + 2)] = None; + //::printf("index = %02X, out = %02X, in = %02X\n", index, out, in); + if (index == out) { + LOCK(); + int size = SIZE(this->buf, out); + out = INDEX(out + 2 + size); + free += (2 + size); + UNLOCK(); + } + ret = (delivery == 0); } else - return false; + ret = false; } - return true; + + frame_id = frame_id % 255 + 1; + return ret; } void XBee::setSendConfirmation(float sendConfirmation) { @@ -191,7 +205,6 @@ void XBee::sendFrame(const char *frame, int length) { char checksum = 255; - if (debug) leds = leds | 8; //**LEDS=1xxx send(PREAMBLE); @@ -212,7 +225,6 @@ } send(checksum); } - if (debug) leds = leds & 7; //**LEDS=0xxx } int XBee::createTxRequest(char frame_id, const char *data, int data_length, char *buf, int buf_size) {