xbee communication for UWB quadcopter project
com.h@4:7cdf299ea7a4, 2014-04-22 (annotated)
- Committer:
- oprospero
- Date:
- Tue Apr 22 06:28:49 2014 +0000
- Revision:
- 4:7cdf299ea7a4
- Parent:
- 3:f8e953201251
fixed previous commit. Added txQueue initialization
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
oprospero | 0:26a151d2c6db | 1 | /******************************* com.h ***********************************/ |
oprospero | 0:26a151d2c6db | 2 | /* Version: 1.0 */ |
oprospero | 0:26a151d2c6db | 3 | /* Last Updated: June 1, 2013 */ |
oprospero | 0:26a151d2c6db | 4 | /* */ |
oprospero | 0:26a151d2c6db | 5 | /* The com class implements reliable data transfer between two nodes */ |
oprospero | 0:26a151d2c6db | 6 | /*using a checksum and a sequence number for guaranteed message delivery */ |
oprospero | 0:26a151d2c6db | 7 | /*over an xbee modem connected to the passed in tx and rx pins. Messages */ |
oprospero | 0:26a151d2c6db | 8 | /*are received and placed in the rxBuffer to be read when convenient. */ |
oprospero | 0:26a151d2c6db | 9 | /*Messages are encoded by sending a byte with the value of the command */ |
oprospero | 0:26a151d2c6db | 10 | /*then and int of the command. */ |
oprospero | 0:26a151d2c6db | 11 | /* Alternative Pins RX = PTA1, TX PTA2 */ |
oprospero | 0:26a151d2c6db | 12 | /*************************************************************************/ |
oprospero | 0:26a151d2c6db | 13 | |
oprospero | 0:26a151d2c6db | 14 | #ifndef COM_H |
oprospero | 0:26a151d2c6db | 15 | #define COM_H |
oprospero | 0:26a151d2c6db | 16 | #define RSSI_THRES 0.8 |
oprospero | 0:26a151d2c6db | 17 | |
oprospero | 0:26a151d2c6db | 18 | #include "mbed.h" |
oprospero | 0:26a151d2c6db | 19 | #include "queue.h" |
oprospero | 0:26a151d2c6db | 20 | #include "PwmIn.h" |
oprospero | 0:26a151d2c6db | 21 | |
oprospero | 0:26a151d2c6db | 22 | const int BAUDRATE = 38400; |
oprospero | 2:bd1621102cad | 23 | const int BUFFERSIZE = 18; |
oprospero | 0:26a151d2c6db | 24 | |
oprospero | 0:26a151d2c6db | 25 | class com |
oprospero | 0:26a151d2c6db | 26 | { |
oprospero | 0:26a151d2c6db | 27 | public: |
oprospero | 0:26a151d2c6db | 28 | com( PinName, PinName, PinName ); // Setup the com serial port. (tx, rx) |
oprospero | 0:26a151d2c6db | 29 | bool isData(); // Is there data to be read? |
oprospero | 0:26a151d2c6db | 30 | bool isSignalGood(); |
oprospero | 0:26a151d2c6db | 31 | void write( short, short ); // Write to the port. |
oprospero | 0:26a151d2c6db | 32 | short * read(); // Read from the queue. |
oprospero | 2:bd1621102cad | 33 | void setAPImode(bool mode); |
oprospero | 3:f8e953201251 | 34 | void ackCheck(); |
oprospero | 4:7cdf299ea7a4 | 35 | bool rdy2ack(); |
oprospero | 0:26a151d2c6db | 36 | |
oprospero | 1:4f53de75bc96 | 37 | private: |
oprospero | 1:4f53de75bc96 | 38 | Serial xbeeTx; // tx - DIN, rx - DOUT |
oprospero | 1:4f53de75bc96 | 39 | Serial xbeeRx; // tx - DIN, rx - DOUT |
oprospero | 1:4f53de75bc96 | 40 | queue *rxBuffer; // queue of commands ready to be read. |
oprospero | 3:f8e953201251 | 41 | queue *txBuffer; |
oprospero | 1:4f53de75bc96 | 42 | PwmIn rssi; |
oprospero | 1:4f53de75bc96 | 43 | |
oprospero | 2:bd1621102cad | 44 | bool api_mode; |
oprospero | 2:bd1621102cad | 45 | |
oprospero | 0:26a151d2c6db | 46 | void callback(); // Handle the interrupts. |
oprospero | 0:26a151d2c6db | 47 | void packetBuilder(); // Called by callback to place commandes into the queue. |
oprospero | 0:26a151d2c6db | 48 | |
oprospero | 0:26a151d2c6db | 49 | char buffer[BUFFERSIZE]; // Buffer for holding serial data. |
oprospero | 0:26a151d2c6db | 50 | int bLength; // Location in the buffer to place next data. |
oprospero | 0:26a151d2c6db | 51 | int signalStrength; |
oprospero | 1:4f53de75bc96 | 52 | |
oprospero | 0:26a151d2c6db | 53 | }; |
oprospero | 0:26a151d2c6db | 54 | |
oprospero | 0:26a151d2c6db | 55 | #endif |