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 1:4f53de75bc96, committed 2014-02-15
- Comitter:
- oprospero
- Date:
- Sat Feb 15 19:54:45 2014 +0000
- Parent:
- 0:26a151d2c6db
- Child:
- 2:bd1621102cad
- Commit message:
- Update new commands tirms
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 Wed Jan 08 07:32:30 2014 +0000 +++ b/com.cpp Sat Feb 15 19:54:45 2014 +0000 @@ -19,19 +19,22 @@ #include "mbed.h" #include "com.h" + /*********************** com( PinName, PinName ) *************************/ /* */ /*************************************************************************/ -com::com( PinName tx, PinName rx , PinName rssipin) : xbeeRx( tx, rx), xbeeTx( tx, rx), rssi(rssipin) +com::com( PinName tx, PinName rx , PinName rssipin) : xbeeTx( tx, rx), xbeeRx( tx, rx), rssi(rssipin) { bLength = 0; // How many bytes are in the buffer. + xbeeTx.baud(BAUDRATE); // Setup the serial baud rate. xbeeRx.baud(BAUDRATE); // Setup the serial baud rate. - xbeeTx.baud(BAUDRATE); // Setup the serial baud rate. rxBuffer = new queue(); // Point to the rxQueue. signalStrength = 0; xbeeRx.attach( this, &com::callback ); // Set callback as the interrupt handler. + #ifdef DEBUG xbeeTx.printf("Communication.....Done\n\r"); + #endif } /************************* bool isData() ********************************/ @@ -40,10 +43,7 @@ bool com::isData() { - if( rxBuffer->isEmpty() ) - return false; - - return true; + return !rxBuffer->isEmpty(); } /************************ void write( char ) *****************************/ @@ -60,11 +60,12 @@ void com::write( short command, short value ) { + short lvalue = (value % 128); xbeeTx.putc( (char)command ); // Command - xbeeTx.putc( 0 ); // First 8 bits in array. - xbeeTx.putc( (char)value ); // Second 8 bits in array. - xbeeTx.putc( command + value ); // Checksum array[0] + array[1]. - xbeeTx.putc( 0 ); // Sequence number. + xbeeTx.putc( (char) value / 128 ); // First 8 bits in array. + xbeeTx.putc( (char) lvalue); // Second 8 bits in array. + xbeeTx.putc( command + lvalue ); // Checksum array[0] + array[1]. + xbeeTx.putc( (char)value ); // Sequence number. xbeeTx.putc( 255 ); // End of message. }
--- a/com.h Wed Jan 08 07:32:30 2014 +0000 +++ b/com.h Sat Feb 15 19:54:45 2014 +0000 @@ -20,7 +20,7 @@ #include "PwmIn.h" const int BAUDRATE = 38400; -const int BUFFERSIZE = 10; +const int BUFFERSIZE = 12; class com { @@ -31,18 +31,19 @@ void write( short, short ); // Write to the port. short * read(); // Read from the queue. - private: + private: + Serial xbeeTx; // tx - DIN, rx - DOUT + Serial xbeeRx; // tx - DIN, rx - DOUT + queue *rxBuffer; // queue of commands ready to be read. + PwmIn rssi; + void callback(); // Handle the interrupts. void packetBuilder(); // Called by callback to place commandes into the queue. char buffer[BUFFERSIZE]; // Buffer for holding serial data. int bLength; // Location in the buffer to place next data. int signalStrength; - - Serial xbeeRx; // tx - DIN, rx - DOUT - Serial xbeeTx; // tx - DIN, rx - DOUT - queue *rxBuffer; // queue of commands ready to be read. - PwmIn rssi; + }; #endif \ No newline at end of file