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 4:f8e953201251, committed 2014-04-22
- Comitter:
- oprospero
- Date:
- Tue Apr 22 05:43:33 2014 +0000
- Parent:
- 2:bd1621102cad
- Child:
- 5:7cdf299ea7a4
- Commit message:
- move acknowledge out of RX interrupt into loop
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 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.
--- a/com.h Sun Apr 20 02:27:39 2014 +0000 +++ b/com.h Tue Apr 22 05:43:33 2014 +0000 @@ -31,11 +31,13 @@ void write( short, short ); // Write to the port. short * read(); // Read from the queue. void setAPImode(bool mode); + void ackCheck(); private: Serial xbeeTx; // tx - DIN, rx - DOUT Serial xbeeRx; // tx - DIN, rx - DOUT queue *rxBuffer; // queue of commands ready to be read. + queue *txBuffer; PwmIn rssi; bool api_mode;