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@16:89695823d407, 2014-09-25 (annotated)
- Committer:
- oprospero
- Date:
- Thu Sep 25 02:30:25 2014 +0000
- Revision:
- 16:89695823d407
- Parent:
- 15:3f742edaa359
- Child:
- 17:acef0fb07510
changed to started char instead of ending
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 | 16:89695823d407 | 22 | #define DEBUG_COM |
oprospero | 13:2fb7b19dcd70 | 23 | |
oprospero | 13:2fb7b19dcd70 | 24 | |
oprospero | 0:26a151d2c6db | 25 | const int BAUDRATE = 38400; |
oprospero | 14:d2acb373d81c | 26 | const int BUFFERSIZE = 16; |
oprospero | 0:26a151d2c6db | 27 | |
oprospero | 0:26a151d2c6db | 28 | class com |
oprospero | 0:26a151d2c6db | 29 | { |
oprospero | 0:26a151d2c6db | 30 | public: |
oprospero | 0:26a151d2c6db | 31 | com( PinName, PinName, PinName ); // Setup the com serial port. (tx, rx) |
oprospero | 0:26a151d2c6db | 32 | bool isData(); // Is there data to be read? |
oprospero | 0:26a151d2c6db | 33 | bool isSignalGood(); |
oprospero | 0:26a151d2c6db | 34 | short * read(); // Read from the queue. |
oprospero | 14:d2acb373d81c | 35 | void sendACK(); |
oprospero | 5:7cdf299ea7a4 | 36 | bool rdy2ack(); |
oprospero | 0:26a151d2c6db | 37 | |
oprospero | 1:4f53de75bc96 | 38 | private: |
oprospero | 12:bf4642578682 | 39 | void write( short, short ); // Write to the port. |
oprospero | 13:2fb7b19dcd70 | 40 | RawSerial xbeeTx; // tx - DIN, rx - DOUT |
oprospero | 13:2fb7b19dcd70 | 41 | RawSerial xbeeRx; // tx - DIN, rx - DOUT |
oprospero | 4:f8e953201251 | 42 | queue *txBuffer; |
oprospero | 15:3f742edaa359 | 43 | queue *rxBuffer; |
oprospero | 15:3f742edaa359 | 44 | queue *cmdBuffer; |
oprospero | 1:4f53de75bc96 | 45 | PwmIn rssi; |
oprospero | 1:4f53de75bc96 | 46 | |
oprospero | 12:bf4642578682 | 47 | bool rdy2build; |
oprospero | 12:bf4642578682 | 48 | bool isA1; |
oprospero | 0:26a151d2c6db | 49 | void callback(); // Handle the interrupts. |
oprospero | 0:26a151d2c6db | 50 | |
oprospero | 12:bf4642578682 | 51 | char buffer1[BUFFERSIZE]; // Buffer for holding serial data. |
oprospero | 12:bf4642578682 | 52 | char buffer2[BUFFERSIZE]; // Buffer for holding serial data. |
oprospero | 12:bf4642578682 | 53 | int index1; // Location in the buffer to place next data. |
oprospero | 12:bf4642578682 | 54 | int index2; // Location in the buffer to place next data. |
oprospero | 12:bf4642578682 | 55 | int pindex; // Location in the buffer to place next data. |
oprospero | 0:26a151d2c6db | 56 | int signalStrength; |
oprospero | 1:4f53de75bc96 | 57 | |
oprospero | 0:26a151d2c6db | 58 | }; |
oprospero | 0:26a151d2c6db | 59 | |
oprospero | 0:26a151d2c6db | 60 | #endif |