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.
Fork of com by
Revision 13:2fb7b19dcd70, committed 2014-05-22
- Comitter:
- oprospero
- Date:
- Thu May 22 05:58:40 2014 +0000
- Parent:
- 12:bf4642578682
- Child:
- 14:d2acb373d81c
- Commit message:
- fixed random burst hopefully and improved packet drops
Changed in this revision
com.cpp | Show annotated file Show diff for this revision Revisions of this file |
com.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/com.cpp Sat Apr 26 02:38:08 2014 +0000 +++ b/com.cpp Thu May 22 05:58:40 2014 +0000 @@ -16,8 +16,30 @@ /* 4 -> Yaw */ /*************************************************************************/ -#include "mbed.h" #include "com.h" +#ifdef DEBUG_COM + Timer timerCom; + #define NL "\n\r" + #define PRINT(x) xbeeTx.printf(x) //Serial.print(x) + #define PRINTF(x, y) xbeeTx.printf( (x) ,(y) ) //Serial.print(x, y) + #define PRINTLN(x) PRINT(x);PRINT(NL) + #define PRINTLNF(x, y) PRINTF((x) ,(y));PRINT(NL) + #define START timerCom.start(); + #define STOP timerCom.stop() + #define RESET timerCom.reset() + #define READ timerCom.read_us() + #define GET(x) x = READ +#else + #define PRINT(x) + #define PRINTF(x, y) + #define PRINTLN(x) + #define PRINTLNF(x, y) + #define START + #define STOP + #define RESET + #define READ + #define GET(x) +#endif /*********************** com( PinName, PinName ) *************************/ @@ -26,18 +48,19 @@ com::com( PinName tx, PinName rx , PinName rssipin) : xbeeTx( tx, NC), xbeeRx( NC, rx), rssi(rssipin) { - index1 = 0; // How many bytes are in the buffer. - index2 = 0; // How many bytes are in the buffer. - pindex = 0; // How many bytes are in the buffer. - rdy2build = false; // Xbee is in transparent mode. - xbeeTx.baud(BAUDRATE); // Setup the serial baud rate. - xbeeRx.baud(BAUDRATE); // Setup the serial baud rate. + index1 = 0; // How many bytes are in the buffer. + index2 = 0; // How many bytes are in the buffer. + pindex = 0; // How many bytes are in the buffer. + rdy2build = false; // Xbee is in transparent mode. + xbeeTx.baud(BAUDRATE); // Setup the serial baud rate. + xbeeRx.baud(BAUDRATE); // Setup the serial baud rate. txBuffer = new queue(); signalStrength = 0; xbeeRx.attach( this, &com::callback ); // Set callback as the interrupt handler. - #ifdef DEBUG + #ifdef DEBUG_COM xbeeTx.printf("Communication.....Done\n\r"); #endif + START; } /************************* bool isData() ********************************/ @@ -46,7 +69,6 @@ bool com::isData() { - return rdy2build; } @@ -79,13 +101,20 @@ void com::ackCheck() { - if( !txBuffer->isEmpty() && xbeeTx.writeable()) + if( !txBuffer->isEmpty()) { __disable_irq(); short * pkt = txBuffer->pop(); + __enable_irq(); write(pkt[0],pkt[1]); //may need to disable interrupt + #ifdef DEBUG_COM + if(pkt[1] % 5 == 0) + { + PRINTLNF("len: %d",txBuffer->queueLength()); + } + #endif delete[] pkt; - __enable_irq(); + } } @@ -106,7 +135,7 @@ while( xbeeRx.readable() ) { char data = xbeeRx.getc(); - +// xbeeRx.putc(data); if (isA1) { if ( data == 255 && index1 > 4 ) @@ -118,6 +147,7 @@ } else if ( index1 < BUFFERSIZE ) { + buffer1[index1++] = data; } } @@ -149,7 +179,8 @@ { if (rdy2build) { - char * commandData = new char[pindex]; + rdy2build = false; + char * commandData = new char[5]; if (!isA1) { commandData[4] = buffer1[--pindex]; // Sequence Number. @@ -167,6 +198,7 @@ commandData[0] = buffer2[--pindex]; // Command. } +// xbeeTx.printf("Copied: %d %d %d %d %d\n\r",commandData[0],commandData[1],commandData[2],commandData[3],commandData[4]); if( commandData[0] + commandData[2] == commandData[3] ) // Validate checksum. {
--- a/com.h Sat Apr 26 02:38:08 2014 +0000 +++ b/com.h Thu May 22 05:58:40 2014 +0000 @@ -19,6 +19,9 @@ #include "queue.h" #include "PwmIn.h" +//#define DEBUG_COM + + const int BAUDRATE = 38400; const int BUFFERSIZE = 18; @@ -34,8 +37,8 @@ private: void write( short, short ); // Write to the port. - Serial xbeeTx; // tx - DIN, rx - DOUT - Serial xbeeRx; // tx - DIN, rx - DOUT + RawSerial xbeeTx; // tx - DIN, rx - DOUT + RawSerial xbeeRx; // tx - DIN, rx - DOUT queue *txBuffer; PwmIn rssi;