UART Driver to receive asynchronous Serial Comms from a Raspberry Pi and parse the results.
SerialComms.cpp
- Committer:
- sk398
- Date:
- 2016-02-15
- Revision:
- 1:bf3fb80028d8
- Parent:
- 0:8ac1280934b4
- Child:
- 2:cb74b330b285
File content as of revision 1:bf3fb80028d8:
#include "mbed.h" #include "SerialComms.h" SerialComms::SerialComms(PinName tx,PinName rx) { _HLC_Conn = new Serial(tx,rx); _HLC_Conn-> baud(SERIAL_BAUD_RATE); _HLC_Conn -> format(8,SerialBase::None,1); _HLC_Conn -> attach(this,&SerialComms::incoming,Serial::RxIrq); dataUpdate = FALSE; } void SerialComms::incoming() { int a = 0; for(uint8_t charCount=0; charCount<(2*NUM_BYTES_RECEIVING); charCount++) { if((charCount%2) == 1) { receiverBuffer[a] = _HLC_Conn -> getc(); a++; } else { _HLC_Conn -> getc(); } } dataUpdate = TRUE; // for(int c = 0; c < 4; c++) // { // printf("recieved: %d\r\n",receiverBuffer[c]); // } } int *SerialComms::returnMotorSpeeds() { if(SerialComms::dataUpdate == TRUE) { SerialComms::dataUpdate = FALSE; return receiverBuffer; } else { int noNewData = -1; int *noNewDataPtr = &noNewData; return noNewDataPtr; } }