Derek McLean / Mbed 2 deprecated uwb-quadcopter

Dependencies:   mbed ESC SR04 TSI

com/com.h

Committer:
gabdo
Date:
2013-06-09
Revision:
32:d2b973c8d196

File content as of revision 32:d2b973c8d196:

/******************************* 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.                                           */
/*                                                                       */
/* Commands:    0 -> Ack, does not get placed in rxQueue.                */
/*              1 -> Throttle                                            */
/*              2 -> Pitch                                               */
/*              3 -> Roll                                                */
/*              4 -> Yaw                                                 */
/*************************************************************************/

//Example code
//
//com myCom( PTD3, PTD2 );  // Setup the com port.           
//
//while( true )
//{
//    if( myCom.isData() )
//    {    
//        char * command = myCom.read();
// 
//        if( command[0] == 1 )
//            for( int i = 0; i < 4; i++ )
//                myMotors[ i ]->setSpeed( command[2] );
//    }
//}

#ifndef COM_H
#define COM_H

#include "mbed.h"
#include "queue.h"

const int BAUDRATE = 38400;

class com
{  
    public:
        com( PinName, PinName  );   // Setup the com serial port. (tx, rx)
        bool isData();              // Is there data to be read?
        void write( char, int );    // Write to the port.
        char * read();              // Read from the queue.
        
    private:   
        void callback();            // Handle the interrupts.
        void packetBuilder();       // Called by callback to place commandes into the queue.
        
        char buffer[50];            // Buffer for holding serial data.
        int bLength;                // Location in the buffer to place next data.
        Serial xbee;                // tx - DIN, rx - DOUT
        
        
        queue *rxBuffer;            // queue of commands ready to be read.
};

#endif