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-04-20
- Revision:
- 2:bd1621102cad
- Parent:
- 1:4f53de75bc96
- Child:
- 4:f8e953201251
File content as of revision 2:bd1621102cad:
/******************************* 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" 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(); void write( short, short ); // Write to the port. short * read(); // Read from the queue. void setAPImode(bool mode); private: Serial xbeeTx; // tx - DIN, rx - DOUT Serial xbeeRx; // tx - DIN, rx - DOUT queue *rxBuffer; // queue of commands ready to be read. PwmIn rssi; bool api_mode; 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; }; #endif