xbee communication for UWB quadcopter project

Dependencies:   PwmIn

Revision:
3:f8e953201251
Parent:
2:bd1621102cad
Child:
4:7cdf299ea7a4
diff -r bd1621102cad -r f8e953201251 com.cpp
--- a/com.cpp	Sun Apr 20 02:27:39 2014 +0000
+++ b/com.cpp	Tue Apr 22 05:43:33 2014 +0000
@@ -99,6 +99,21 @@
 /*                                                                       */
 /*************************************************************************/
 
+void com::ackCheck()
+{
+    if( !txBuffer->isEmpty())
+    {
+        short * pkt = rxBuffer->pop();
+        write(pkt[0],pkt[1]);
+    }
+        
+}
+
+
+/*************************** char read()  ********************************/
+/*                                                                       */
+/*************************************************************************/
+
 short * com::read()
 {
     if( !rxBuffer->isEmpty())
@@ -113,6 +128,7 @@
 
 void com::callback()
 {   
+    __disable_irq();
     while( xbeeRx.readable() )
     {
         char data = xbeeRx.getc(); 
@@ -121,10 +137,14 @@
 //        xbeeTx.putc( data );
         if( bLength++ < BUFFERSIZE )
             buffer[bLength] = data;      
-     
+     //
+//        xbeeTx.putc( bLength );
+//        xbeeTx.putc( bLength );
+//        xbeeTx.putc( 255 );
         if( data == 255 )
             packetBuilder();
     }
+    __enable_irq();
 }
 
 //void com::api_callback()
@@ -167,7 +187,13 @@
         rxBuffer->add( array );   // Add to read buffer.
 //        xbeeTx.putc( 255 );
 //        xbeeTx.putc( 255 );
-        write( (short)commandData[0], (short)commandData[4]); // Ack the packet with sequence nuber.
+        if ( commandData[0] != 0 )
+        {
+            short * ackPacket = new short[2];
+            ackPacket[1] = commandData[0];
+            ackPacket[1] = commandData[4];
+            txBuffer->add( ackPacket ); // Ack the packet with sequence nuber.
+        }
     } 
     delete[] commandData;
     bLength = 0;    // Reset the buffer length.