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 Prosper Van

com.h

Committer:
oprospero
Date:
2014-02-15
Revision:
1:4f53de75bc96
Parent:
0:26a151d2c6db
Child:
2:bd1621102cad

File content as of revision 1:4f53de75bc96:

/******************************* 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    = 12;

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.
        
    private:         
        Serial xbeeTx;                // tx - DIN, rx - DOUT
        Serial xbeeRx;                // tx - DIN, rx - DOUT
        queue *rxBuffer;            // queue of commands ready to be read.
        PwmIn rssi;
          
        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