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
com.h
- Committer:
- oprospero
- Date:
- 2014-05-22
- Revision:
- 13:2fb7b19dcd70
- Parent:
- 12:bf4642578682
- Child:
- 14:d2acb373d81c
File content as of revision 13:2fb7b19dcd70:
/******************************* com.h ***********************************/ /* Version: 1.0 */ /* Last Updated: June 1, 2013 */ /* */ /* The com class implements reliable data transfer between two nodes */ /*using a checksum and a sequence number for guaranteed message delivery */ /*over an xbee modem connected to the passed in tx and rx pins. Messages */ /*are received and placed in the rxBuffer to be read when convenient. */ /*Messages are encoded by sending a byte with the value of the command */ /*then and int of the command. */ /* Alternative Pins RX = PTA1, TX PTA2 */ /*************************************************************************/ #ifndef COM_H #define COM_H #define RSSI_THRES 0.8 #include "mbed.h" #include "queue.h" #include "PwmIn.h" //#define DEBUG_COM const int BAUDRATE = 38400; const int BUFFERSIZE = 18; class com { public: com( PinName, PinName, PinName ); // Setup the com serial port. (tx, rx) bool isData(); // Is there data to be read? bool isSignalGood(); short * read(); // Read from the queue. void ackCheck(); bool rdy2ack(); private: void write( short, short ); // Write to the port. RawSerial xbeeTx; // tx - DIN, rx - DOUT RawSerial xbeeRx; // tx - DIN, rx - DOUT queue *txBuffer; PwmIn rssi; bool rdy2build; bool isA1; void callback(); // Handle the interrupts. char buffer1[BUFFERSIZE]; // Buffer for holding serial data. char buffer2[BUFFERSIZE]; // Buffer for holding serial data. int index1; // Location in the buffer to place next data. int index2; // Location in the buffer to place next data. int pindex; // Location in the buffer to place next data. int signalStrength; }; #endif