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.
Diff: com.cpp
- Revision:
- 1:4f53de75bc96
- Parent:
- 0:26a151d2c6db
- Child:
- 2:bd1621102cad
--- 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.
}