Library used to receive data through a wireless channel using XBEE.

Dependencies:   mbed

Dependents:   nxp_can

Fork of frdm_xbee by Jose Pesado

Revision:
1:11f87e6215f7
Parent:
0:06bd131cf762
Child:
2:ccf471fbd56c
--- a/xbee.cpp	Sat Oct 18 13:21:18 2014 +0000
+++ b/xbee.cpp	Sat Oct 18 16:46:04 2014 +0000
@@ -1,17 +1,19 @@
 #include "mbed.h"
 
-#define XBEE_SERVER         1
+#define XBEE_SERVER         0
 #define XBEE_CLIENT         1
 #define SERIAL_BAUDRATE     115200
-#define BUFFER_SIZE         9
-#define BUFFER_FORMAT       "%X %X %X %X %X %X %X %X %X"
-#define BUFFER_FORMAT_RX    "%c%c%c%c%c%c%c%c%c"
+#define BUFFER_SIZE         14
+#define BUFFER_FORMAT       "%X %X %X %X %X %X %X %X %X %X %X %X %X %X"
+#define BUFFER_FORMAT_RX    "%c%c%c%c%c%c%c%c%c%c%c%c%c%c"
 #define BUFFER_RX_DATA_WR   &CommandRx[0],&CommandRx[1],&CommandRx[2],&CommandRx[3],\
                             &CommandRx[4],&CommandRx[5],&CommandRx[6],&CommandRx[7],\
-                            &CommandRx[8]
+                            &CommandRx[8],&CommandRx[9],&CommandRx[10],&CommandRx[11],\
+                            &CommandRx[12],&CommandRx[13]
 #define BUFFER_RX_DATA_RD   CommandRx[0],CommandRx[1],CommandRx[2],CommandRx[3],\
                             CommandRx[4],CommandRx[5],CommandRx[6],CommandRx[7],\
-                            CommandRx[8]
+                            CommandRx[8],CommandRx[9],CommandRx[10],CommandRx[11],\
+                            CommandRx[12],CommandRx[13]
 
 Serial PC(USBTX, USBRX);
 DigitalOut Indicator(LED_GREEN);
@@ -19,7 +21,7 @@
 
 #if XBEE_SERVER == 1
 Serial XBeeServer(PTC17, PTC16); /* Tx, Rx*/
-char CommandTx[BUFFER_SIZE+1]={0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, '\0'};
+char CommandTx[BUFFER_SIZE]={0x55, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xAA, 0xAA, '\0'};
 DigitalOut RSTServer(PTB9);
 int XBee_u16TxResult;
 int XBee_u8TxRq;
@@ -28,7 +30,7 @@
 #if XBEE_CLIENT == 1
 Serial XBeeClient(PTE24, PTE25); /* Tx, Rx*/
 DigitalOut RSTClient(PTA1);
-char CommandRx[BUFFER_SIZE+1];
+char CommandRx[BUFFER_SIZE];
 volatile int XBee_u8RxResult;
 int XBee_boRxIndication = 0;
 int XBee_boRxAllowed = 1;
@@ -89,6 +91,7 @@
     wait_ms(1);
 }
 
+#if XBEE_SERVER == 1
 void XBee_vMain(void)
 {
     XBee_u16Loop++;
@@ -98,8 +101,10 @@
     {
         /* a Tx job request is active */
         PC.printf("\r\nTx... ");
+        #if XBEE_CLIENT == 1
         /* disable rx */
         XBee_boRxAllowed = 0;
+        #endif
         for (int i=0; i<BUFFER_SIZE; i++) 
         {
             while (true) 
@@ -115,16 +120,21 @@
         /* tx done */
         PC.printf("\r\nTx done. ");
         XBee_u8TxRq = 0;
+        #if XBEE_CLIENT == 1
         /* enable rx */
         XBee_boRxAllowed = 1;
+        #endif
     } 
 }
+#endif /*#if XBEE_SERVER == 1*/
 
 #if 1
 
 int main()
 {
-    char TxJob[BUFFER_SIZE+1] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, '\0'};    
+    #if XBEE_SERVER == 1
+    char TxJob[BUFFER_SIZE] = {0x55, 0x55, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xAA, 0xAA, '\0'};    
+    #endif
     
     XBee_vInit();
     
@@ -132,15 +142,16 @@
         wait(0.2f); // wait a small period of time
         Indicator = !Indicator; // toggle a led
         
+        #if XBEE_SERVER == 1
         XBee_vMain();  
-        
-        memcpy(CommandTx,TxJob,9);
-        //XBee_u8TxRq = 1;
+        memcpy(CommandTx,TxJob,BUFFER_SIZE);
+        XBee_u8TxRq = 1;
                 
-        for(int i=0;i<BUFFER_SIZE;i++)
+        for(int i=0;i<BUFFER_SIZE-1;i++)
         {
             TxJob[i]++;
         }
+        #endif
         
     }
 }