UART Driver to receive asynchronous Serial Comms from a Raspberry Pi and parse the results.
Diff: SerialComms.cpp
- Revision:
- 0:8ac1280934b4
- Child:
- 1:bf3fb80028d8
diff -r 000000000000 -r 8ac1280934b4 SerialComms.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SerialComms.cpp Mon Feb 15 19:49:37 2016 +0000 @@ -0,0 +1,52 @@ +#include "mbed.h" +#include "SerialComms.h" + +SerialComms::SerialComms(Serial *HLC_Conn) +{ + _HLC_Conn = HLC_Conn; + _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; + } +}