UART Driver to receive asynchronous Serial Comms from a Raspberry Pi and parse the results.
Revision 2:cb74b330b285, committed 2016-02-15
- Comitter:
- sk398
- Date:
- Mon Feb 15 20:09:32 2016 +0000
- Parent:
- 1:bf3fb80028d8
- Child:
- 3:b608ee5b9b5d
- Commit message:
- basic data check added on the wasted identifiers
Changed in this revision
SerialComms.cpp | Show annotated file Show diff for this revision Revisions of this file |
SerialComms.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/SerialComms.cpp Mon Feb 15 19:59:59 2016 +0000 +++ b/SerialComms.cpp Mon Feb 15 20:09:32 2016 +0000 @@ -7,15 +7,16 @@ _HLC_Conn-> baud(SERIAL_BAUD_RATE); _HLC_Conn -> format(8,SerialBase::None,1); - _HLC_Conn -> attach(this,&SerialComms::incoming,Serial::RxIrq); + _HLC_Conn -> attach(this,&SerialComms::incomingDataISR,Serial::RxIrq); - dataUpdate = FALSE; + incomingDataUpdate = FALSE; } -void SerialComms::incoming() +void SerialComms::incomingDataISR() { int a = 0; + dataCheck = 0; for(uint8_t charCount=0; charCount<(2*NUM_BYTES_RECEIVING); charCount++) { if((charCount%2) == 1) @@ -25,10 +26,10 @@ } else { - _HLC_Conn -> getc(); + dataCheck += _HLC_Conn -> getc(); } } - dataUpdate = TRUE; + incomingDataUpdate = TRUE; // for(int c = 0; c < 4; c++) // { @@ -38,9 +39,9 @@ int *SerialComms::returnMotorSpeeds() { - if(SerialComms::dataUpdate == TRUE) + if(SerialComms::incomingDataUpdate == TRUE && dataCheck == 10) { - SerialComms::dataUpdate = FALSE; + SerialComms::incomingDataUpdate = FALSE; return receiverBuffer; } else
--- a/SerialComms.h Mon Feb 15 19:59:59 2016 +0000 +++ b/SerialComms.h Mon Feb 15 20:09:32 2016 +0000 @@ -16,15 +16,15 @@ SerialComms(PinName tx,PinName rx); int *returnMotorSpeeds(); -private: - bool dataUpdate; +private: + void incomingDataISR(); + +protected: + int dataCheck; + bool incomingDataUpdate; int receiverBuffer[NUM_BYTES_RECEIVING]; - Serial *_HLC_Conn; - void incoming(); - -protected: };