UART Driver to receive asynchronous Serial Comms from a Raspberry Pi and parse the results.

SerialComms.cpp

Committer:
sk398
Date:
2016-02-15
Revision:
3:b608ee5b9b5d
Parent:
2:cb74b330b285
Child:
4:85353bd571f2

File content as of revision 3:b608ee5b9b5d:

#include "mbed.h"
#include "SerialComms.h"

SerialComms::SerialComms(PinName tx,PinName rx)
{
    _HLC_Conn = new RawSerial(tx,rx);
    _HLC_Conn-> baud(SERIAL_BAUD_RATE);
    _HLC_Conn -> format(8,SerialBase::None,1);
    
    _HLC_Conn -> attach(this,&SerialComms::incomingDataISR,RawSerial::RxIrq);
    
    incomingDataUpdate = FALSE;
}


void SerialComms::incomingDataISR()
{
    int a = 0;
    dataCheck = 0;
    for(uint8_t charCount=0; charCount<(2*NUM_BYTES_RECEIVING); charCount++)
    {
        if((charCount%2) == 1)
        {
            receiverBuffer[a] = _HLC_Conn -> getc();
            a++;                        
        }
        else
        {
            dataCheck += _HLC_Conn -> getc();
        }
    }
    incomingDataUpdate = TRUE;
}

int *SerialComms::returnMotorSpeeds()
{
    if(SerialComms::incomingDataUpdate == TRUE && dataCheck == 10)
    {
        SerialComms::incomingDataUpdate = FALSE;
        return receiverBuffer;
    }
    else
    {
        int noNewData = -1;
        int *noNewDataPtr = &noNewData;
        return noNewDataPtr;
    }
}