xbee communication for UWB quadcopter project Originally by Greg Abdo Forking to reduce impact of interrupt by moving packetbuilder out of the interrupt and letting be handled in the main loop
Fork of com by
Diff: com.cpp
- Revision:
- 21:117e01fc0373
- Parent:
- 20:95244d4f47f6
- Child:
- 22:0e8e22f161ff
diff -r 95244d4f47f6 -r 117e01fc0373 com.cpp --- a/com.cpp Wed Oct 22 16:09:56 2014 +0000 +++ b/com.cpp Thu Oct 23 04:46:10 2014 +0000 @@ -24,9 +24,10 @@ #define GET(x) #endif -com::com(PinName tx, PinName rx): xbee(NC,rx), xbtx(tx,NC) +//com::com(PinName tx, PinName rx): xbee(NC,rx), xbtx(tx,NC) +com::com(PinName tx, PinName rx): xbee(tx,rx) { - xbtx.baud(BAUDRATE); +// xbtx.baud(BAUDRATE); xbee.baud(BAUDRATE); xbee.attach(this,&com::callback); } @@ -41,7 +42,7 @@ while(xbee.readable()) { char data = xbee.getc(); - xbtx.putc(data); + xbee.putc(data); rxBuffer.add(data); } __enable_irq(); @@ -154,7 +155,7 @@ void com::sendACK() { __disable_irq(); - if( !txBuffer.isEmpty() && xbtx.writeable() ) + if( !txBuffer.isEmpty() && xbee.writeable() ) { short * pkt = txBuffer.pop(); write(pkt[0],pkt[1]); //may need to disable interrupt @@ -166,10 +167,10 @@ void com::write( short command, short seq ) { - xbtx.putc( 255 ); // End of message. - xbtx.putc( (char)command ); // Command - xbtx.putc( (char) seq); // Second 8 bits in array. - xbtx.putc( (char) command + seq ); // Checksum array[0] + array[1]. + xbee.putc( 255 ); // End of message. + xbee.putc( (char)command ); // Command + xbee.putc( (char) seq); // Second 8 bits in array. + xbee.putc( (char) command + seq ); // Checksum array[0] + array[1]. } void com::print(char* str)