Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: Send.cpp
- Revision:
- 3:48f7780963e2
- Parent:
- 0:ea8459db49ef
diff -r 3c20a64d4c24 -r 48f7780963e2 Send.cpp --- a/Send.cpp Fri Nov 25 05:11:51 2011 +0000 +++ b/Send.cpp Thu Apr 12 10:20:17 2012 +0000 @@ -21,10 +21,55 @@ */ #include "XBee.h" -#include "macros.h" #include <stdarg.h> -void XBee::sendCommand(char *command, char *param, int param_length, bool queue) { +void XBee::sendCommand(const char *command, int8_t param, bool queue) { + sendCommand(command, (uint64_t) param, queue); +} + +void XBee::sendCommand(const char *command, int16_t param, bool queue) { + sendCommand(command, (uint64_t) param, queue); +} + +void XBee::sendCommand(const char *command, int32_t param, bool queue) { + sendCommand(command, (uint64_t) param, queue); +} + +void XBee::sendCommand(const char *command, int64_t param, bool queue) { + sendCommand(command, (uint64_t) param, queue); +} + +void XBee::sendCommand(const char *command, uint8_t param, bool queue) { + sendCommand(command, (uint64_t) param, queue); +} + +void XBee::sendCommand(const char *command, uint16_t param, bool queue) { + sendCommand(command, (uint64_t) param, queue); +} + +void XBee::sendCommand(const char *command, uint32_t param, bool queue) { + sendCommand(command, (uint64_t) param, queue); +} + +void XBee::sendCommand(const char *command, uint64_t param, bool queue) { + uint8_t param_buf[8] = { + (uint8_t) (param >> 56), (uint8_t) (param >> 48), + (uint8_t) (param >> 40), (uint8_t) (param >> 32), + (uint8_t) (param >> 24), (uint8_t) (param >> 16), + (uint8_t) (param >> 8), (uint8_t) param + }; + + int n = 0; + while (n < 7 && param_buf[n] == 0) n++; + + sendCommand(command, param_buf + n, 8 - n, queue); +} + +void XBee::sendCommand(const char *command, const char *param, bool queue) { + sendCommand(command, (uint8_t *) param, strlen(param), queue); +} + +void XBee::sendCommand(const char *command, const uint8_t *param, int param_length, bool queue) { char buf[param_length + 4]; createAtRequest(frame_id, command, param, param_length, queue, buf, sizeof(buf)); @@ -32,7 +77,53 @@ frame_id = frame_id % 255 + 1; } -void XBee::sendRemoteCommand(char *command, char *param, int param_length, char options) { +void XBee::sendRemoteCommand(const char *command, int8_t param) { + sendRemoteCommand(command, (uint64_t) param); +} + +void XBee::sendRemoteCommand(const char *command, int16_t param) { + sendRemoteCommand(command, (uint64_t) param); +} + +void XBee::sendRemoteCommand(const char *command, int32_t param) { + sendRemoteCommand(command, (uint64_t) param); +} + +void XBee::sendRemoteCommand(const char *command, int64_t param) { + sendRemoteCommand(command, (uint64_t) param); +} + +void XBee::sendRemoteCommand(const char *command, uint8_t param) { + sendRemoteCommand(command, (uint64_t) param); +} + +void XBee::sendRemoteCommand(const char *command, uint16_t param) { + sendRemoteCommand(command, (uint64_t) param); +} + +void XBee::sendRemoteCommand(const char *command, uint32_t param) { + sendRemoteCommand(command, (uint64_t) param); +} + +void XBee::sendRemoteCommand(const char *command, uint64_t param) { + uint8_t param_buf[8] = { + (uint8_t) (param >> 56), (uint8_t) (param >> 48), + (uint8_t) (param >> 40), (uint8_t) (param >> 32), + (uint8_t) (param >> 24), (uint8_t) (param >> 16), + (uint8_t) (param >> 8), (uint8_t) param + }; + + int n = 0; + while (n < 7 && param_buf[n] == 0) n++; + + sendRemoteCommand(command, param_buf + n, 8 - n); +} + +void XBee::sendRemoteCommand(const char *command, const char *param) { + sendRemoteCommand(command, (uint8_t *) param, strlen(param)); +} + +void XBee::sendRemoteCommand(const char *command, const uint8_t *param, int param_length, char options) { char buf[param_length + 15]; createRemoteAtRequest(frame_id, command, param, param_length, options, buf, sizeof(buf)); @@ -40,25 +131,31 @@ frame_id = frame_id % 255 + 1; } -void XBee::send(char *data, int length) { +bool XBee::send(const char *data, int length, bool confirm = true) { + if (length == 0) + length = strlen(data); + char buf[length + 14]; createTxRequest(frame_id, data, length, buf, sizeof(buf)); sendFrame(buf, length + 14); frame_id = frame_id % 255 + 1; + + if (confirm) { + int index = seekFor(ZigBeeTransmitStatus, 3.0); + if (index != -1) { + char delivery; + scan(index, DeliveryStatus, &delivery); + buf[INDEX(index + 2)] = 0x00; + return delivery == 0; + } + } + + return false; } -bool XBee::sendConfirm(char *data, int length) { - send(data, length); - - int index = seekFor(ZigBeeTransmitStatus, 3.0); - if (index != -1) { - char delivery; - scan(index, DeliveryStatus, &delivery); - buf[INDEX(index + 2)] = 0x00; - return delivery == 0; - } - return false; +bool XBee::sendConfirm(const char *data, int length) { + return send(data, length, true); } int XBee::printf(const char *format, ...) { @@ -88,7 +185,7 @@ } } -void XBee::sendFrame(char* frame, int length) { +void XBee::sendFrame(const char *frame, int length) { char checksum = 255; if (debug) leds = leds | 8; //**LEDS=1xxx @@ -114,7 +211,7 @@ if (debug) leds = leds & 7; //**LEDS=0xxx } -int XBee::createTxRequest(char frame_id, char* data, int data_length, char* buf, int buf_size) { +int XBee::createTxRequest(char frame_id, const char *data, int data_length, char *buf, int buf_size) { if (data_length + 14 > buf_size) return -1; buf[0] = 0x10; // frame type @@ -129,7 +226,7 @@ return data_length + 14; } -int XBee::createAtRequest(char frame_id, char* command, char* param, int param_length, bool queue, char* buf, int buf_size) { +int XBee::createAtRequest(char frame_id, const char *command, const uint8_t *param, int param_length, bool queue, char *buf, int buf_size) { if (param_length + 4 > buf_size) return -1; buf[0] = queue ? 0x09 : 0x08; // frame type @@ -141,7 +238,7 @@ return param_length + 4; } -int XBee::createRemoteAtRequest(char frame_id, char* command, char* param, int param_length, char options, char* buf, int buf_size) { +int XBee::createRemoteAtRequest(char frame_id, const char *command, const uint8_t *param, int param_length, char options, char *buf, int buf_size) { if (param_length + 4 > buf_size) return -1; buf[0] = 0x17; // frame type