XBee API mode library

Revision:
14:af6e497bbf52
Parent:
12:0d32e2d0b50a
Child:
16:cdfcb63b2c4b
--- a/XBee.cpp	Thu Mar 14 08:02:24 2013 +0000
+++ b/XBee.cpp	Thu Mar 14 09:38:54 2013 +0000
@@ -25,40 +25,35 @@
 #ifndef XBEE_RTOS
 XBee::XBee(Serial& ser, int apiMode, bool debug)
     : Serial(ser), mon(USBTX, USBRX), leds(LED1, LED2, LED3, LED4), apiMode(apiMode),
-      state(UNKNOWN), in(0), out(0), received(-1), free(BUFSIZE), frame_id(1), sendConfirmation(0), debug(debug)
-{
+      state(UNKNOWN), in(0), out(0), received(-1), free(BUFSIZE), frame_id(1), sendConfirmation(0), debug(debug) {
     memset(buf, 0, BUFSIZE);
     attach(this, &XBee::rxInterruptHandler, RxIrq);
 }
 
 XBee::XBee(PinName tx, PinName rx, int apiMode, bool debug)
     : Serial(tx, rx), mon(USBTX, USBRX), leds(LED1, LED2, LED3, LED4), apiMode(apiMode),
-      state(UNKNOWN), in(0), out(0), received(-1), free(BUFSIZE), frame_id(1), sendConfirmation(0), debug(debug)
-{
+      state(UNKNOWN), in(0), out(0), received(-1), free(BUFSIZE), frame_id(1), sendConfirmation(0), debug(debug) {
     memset(buf, 0, BUFSIZE);
     attach(this, &XBee::rxInterruptHandler, RxIrq);
 }
 
 XBee::XBee(Serial& ser, Serial& mon, int apiMode, bool debug)
     : Serial(ser), mon(mon), leds(LED1, LED2, LED3, LED4), apiMode(apiMode),
-      state(UNKNOWN), in(0), out(0), received(-1), free(BUFSIZE), frame_id(1), sendConfirmation(0), debug(debug)
-{
+      state(UNKNOWN), in(0), out(0), received(-1), free(BUFSIZE), frame_id(1), sendConfirmation(0), debug(debug) {
     memset(buf, 0, BUFSIZE);
     attach(this, &XBee::rxInterruptHandler, RxIrq);
 }
 
 XBee::XBee(PinName tx, PinName rx, Serial& mon, int apiMode, bool debug)
     : Serial(tx, rx), mon(mon), leds(LED1, LED2, LED3, LED4), apiMode(apiMode),
-      state(UNKNOWN), in(0), out(0), received(-1), free(BUFSIZE), frame_id(1), sendConfirmation(0), debug(debug)
-{
+      state(UNKNOWN), in(0), out(0), received(-1), free(BUFSIZE), frame_id(1), sendConfirmation(0), debug(debug) {
     memset(buf, 0, BUFSIZE);
     attach(this, &XBee::rxInterruptHandler, RxIrq);
 }
 #else
 XBee::XBee(Serial& ser, int apiMode, bool debug)
     : Serial(ser), AbstractThread(osPriorityAboveNormal), mon(USBTX, USBRX), leds(LED1, LED2, LED3, LED4), apiMode(apiMode),
-      state(UNKNOWN), in(0), out(0), received(-1), free(BUFSIZE), frame_id(1), sendConfirmation(0), debug(debug)
-{
+      state(UNKNOWN), in(0), out(0), received(-1), free(BUFSIZE), frame_id(1), sendConfirmation(0), debug(debug) {
     memset(buf, 0, BUFSIZE);
     start();
     attach(this, &XBee::rxISR, RxIrq);
@@ -66,8 +61,7 @@
 
 XBee::XBee(PinName tx, PinName rx, int apiMode, bool debug)
     : Serial(tx, rx), AbstractThread(osPriorityAboveNormal), mon(USBTX, USBRX), leds(LED1, LED2, LED3, LED4), apiMode(apiMode),
-      state(UNKNOWN), in(0), out(0), received(-1), free(BUFSIZE), frame_id(1), sendConfirmation(0), debug(debug)
-{
+      state(UNKNOWN), in(0), out(0), received(-1), free(BUFSIZE), frame_id(1), sendConfirmation(0), debug(debug) {
     memset(buf, 0, BUFSIZE);
     start();
     attach(this, &XBee::rxISR, RxIrq);
@@ -75,8 +69,7 @@
 
 XBee::XBee(Serial& ser, Serial& mon, int apiMode, bool debug)
     : Serial(ser), AbstractThread(osPriorityAboveNormal), mon(mon), leds(LED1, LED2, LED3, LED4), apiMode(apiMode),
-      state(UNKNOWN), in(0), out(0), received(-1), free(BUFSIZE), frame_id(1), sendConfirmation(0), debug(debug)
-{
+      state(UNKNOWN), in(0), out(0), received(-1), free(BUFSIZE), frame_id(1), sendConfirmation(0), debug(debug) {
     memset(buf, 0, BUFSIZE);
     start();
     attach(this, &XBee::rxISR, RxIrq);
@@ -84,16 +77,14 @@
 
 XBee::XBee(PinName tx, PinName rx, Serial& mon, int apiMode, bool debug)
     : Serial(tx, rx), AbstractThread(osPriorityAboveNormal), mon(mon), leds(LED1, LED2, LED3, LED4), apiMode(apiMode),
-      state(UNKNOWN), in(0), out(0), received(-1), free(BUFSIZE), frame_id(1), sendConfirmation(0), debug(debug)
-{
+      state(UNKNOWN), in(0), out(0), received(-1), free(BUFSIZE), frame_id(1), sendConfirmation(0), debug(debug) {
     memset(buf, 0, BUFSIZE);
     start();
     attach(this, &XBee::rxISR, RxIrq);
 }
 #endif
 
-bool XBee::init(float timeout)
-{
+bool XBee::init(float timeout) {
     while (readable()) getc();
     while (timeout > 0 && getFirmwareVersion() == -1) {
         timeout -= 1;
@@ -115,73 +106,60 @@
     }
 }
 
-void XBee::setDestination(XBeeAddress64 address64, XBeeAddress16 address16)
-{
+void XBee::setDestination(XBeeAddress64 address64, XBeeAddress16 address16) {
     setDestination(address64.raw_address(), address16.raw_address());
 }
 
-void XBee::setDestination(uint64_t address64, uint16_t address16)
-{
+void XBee::setDestination(uint64_t address64, uint16_t address16) {
     for (int i = 0; i < 8; i++, address64 >>= 8)
         destination64[7 - i] = address64 & 255;
     destination16[0] = (address16 >> 8) & 255;
     destination16[1] = address16 & 255;
 }
 
-void XBee::setDestination(char address64[], char address16[])
-{
+void XBee::setDestination(char address64[], char address16[]) {
     memcpy(destination64, address64, 8);
     destination16[0] = address16[0];
     destination16[1] = address16[1];
 }
 
-XBee::operator bool()
-{
+XBee::operator bool() {
     return getFirmwareVersion() != -1;
 }
 
-char XBee::getFrameID()
-{
+char XBee::getFrameID() {
     return frame_id;
 }
 
-void *XBee::executeCommand(const char *command, int8_t param)
-{
+void *XBee::executeCommand(const char *command, int8_t param) {
     return executeCommand(command, (uint64_t) param);
 }
 
-void *XBee::executeCommand(const char *command, int16_t param)
-{
+void *XBee::executeCommand(const char *command, int16_t param) {
     return executeCommand(command, (uint64_t) param);
 }
 
-void *XBee::executeCommand(const char *command, int32_t param)
-{
+void *XBee::executeCommand(const char *command, int32_t param) {
     return executeCommand(command, (uint64_t) param);
 }
 
-void *XBee::executeCommand(const char *command, int64_t param)
-{
+void *XBee::executeCommand(const char *command, int64_t param) {
     return executeCommand(command, (uint64_t) param);
 }
 
-void *XBee::executeCommand(const char *command, uint8_t param)
-{
+void *XBee::executeCommand(const char *command, uint8_t param) {
     return executeCommand(command, (uint64_t) param);
 }
 
-void *XBee::executeCommand(const char *command, uint16_t param)
-{
+void *XBee::executeCommand(const char *command, uint16_t param) {
     return executeCommand(command, (uint64_t) param);
 }
 
-void *XBee::executeCommand(const char *command, uint32_t param)
-{
+void *XBee::executeCommand(const char *command, uint32_t param) {
     return executeCommand(command, (uint64_t) param);
 }
 
-void *XBee::executeCommand(const char *command, uint64_t param)
-{
+void *XBee::executeCommand(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),
@@ -195,13 +173,11 @@
     return executeCommand(command, param_buf + n, 8 - n);
 }
 
-void *XBee::executeCommand(const char *command, const char *param)
-{
+void *XBee::executeCommand(const char *command, const char *param) {
     return executeCommand(command, (uint8_t *) param, strlen(param));
 }
 
-void *XBee::executeCommand(const char *command, const uint8_t *param, int param_length)
-{
+void *XBee::executeCommand(const char *command, const uint8_t *param, int param_length) {
     static char data[21];
     bool succeeded = false;
     char id = getFrameID();
@@ -232,8 +208,7 @@
     return succeeded ? data : 0;
 }
 
-int XBee::getFirmwareVersion()
-{
+int XBee::getFirmwareVersion() {
     static int firmwareVersion = -1;
 
     if (firmwareVersion == -1) {
@@ -243,15 +218,13 @@
     return firmwareVersion;
 }
 
-void XBee::copy(char *toBuf, int fromIndex, int length)
-{
+void XBee::copy(char *toBuf, int fromIndex, int length) {
     int length1 = min(BUFSIZE - fromIndex, length);
     memcpy(toBuf, &buf[fromIndex], length1);
     if (length1 < length)
         memcpy(toBuf + length1, &buf[0], length - length1);
 }
 
-void XBee::setDebug(bool debug)
-{
+void XBee::setDebug(bool debug) {
     this->debug = debug;
 }
\ No newline at end of file