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:
- 20:95244d4f47f6
- Parent:
- 19:dc9d18037565
- Child:
- 21:117e01fc0373
diff -r dc9d18037565 -r 95244d4f47f6 com.cpp --- a/com.cpp Tue Oct 21 21:22:21 2014 +0000 +++ b/com.cpp Wed Oct 22 16:09:56 2014 +0000 @@ -26,6 +26,7 @@ com::com(PinName tx, PinName rx): xbee(NC,rx), xbtx(tx,NC) { + xbtx.baud(BAUDRATE); xbee.baud(BAUDRATE); xbee.attach(this,&com::callback); } @@ -40,7 +41,7 @@ while(xbee.readable()) { char data = xbee.getc(); -// xbee.putc(data); + xbtx.putc(data); rxBuffer.add(data); } __enable_irq(); @@ -58,7 +59,7 @@ while ( !rxBuffer.isEmpty() ) { char data = rxBuffer.pop(); - __enable_irq(); +// __enable_irq(); // PRINTF("d: %d \n\r", data); switch (packetIndex) { @@ -108,7 +109,7 @@ pack_checksum = data; if ( temp == pack_checksum ) { - __disable_irq(); +// __disable_irq(); short * ackPacket = new short[2]; ackPacket[0] = pack_cmd; ackPacket[1] = pack_seq; @@ -118,7 +119,7 @@ array[0] = pack_cmd; array[1] = pack_value[1] * 128 + pack_value[0]; cmdBuffer.add( array ); - __enable_irq(); +// __enable_irq(); } packetIndex = 0; @@ -129,7 +130,7 @@ break; } - __disable_irq(); +// __disable_irq(); } __enable_irq(); @@ -153,7 +154,7 @@ void com::sendACK() { __disable_irq(); - if( !txBuffer.isEmpty()) + if( !txBuffer.isEmpty() && xbtx.writeable() ) { short * pkt = txBuffer.pop(); write(pkt[0],pkt[1]); //may need to disable interrupt