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

Committer:
sk398
Date:
Fri Mar 04 23:07:43 2016 +0000
Revision:
10:55cb02b00338
Parent:
9:8e0a7d3f2f39
Child:
11:b5f4a9e69d96
Beginnings of checking included into getCommData method.; ; Need to add in legal ballast commands

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sk398 6:74b5ac7719f4 1 /* #####################################################################
sk398 6:74b5ac7719f4 2 SerialComms.cpp
sk398 6:74b5ac7719f4 3 ---------------
sk398 6:74b5ac7719f4 4
sk398 6:74b5ac7719f4 5 Surface Ship, Group 5
sk398 6:74b5ac7719f4 6 ---------------------
sk398 6:74b5ac7719f4 7
sk398 6:74b5ac7719f4 8 Written by: Steven Kay
sk398 6:74b5ac7719f4 9
sk398 6:74b5ac7719f4 10 Date: February 2016
sk398 6:74b5ac7719f4 11
sk398 6:74b5ac7719f4 12 Function: This
sk398 6:74b5ac7719f4 13
sk398 6:74b5ac7719f4 14 Version: 1.0
sk398 6:74b5ac7719f4 15
sk398 6:74b5ac7719f4 16 Version History
sk398 6:74b5ac7719f4 17 ---------------
sk398 6:74b5ac7719f4 18
sk398 6:74b5ac7719f4 19 1.1 rgdfgdfgdfggdfgdg
sk398 6:74b5ac7719f4 20
sk398 6:74b5ac7719f4 21 1.0 gdgddfdddgd
sk398 6:74b5ac7719f4 22
sk398 6:74b5ac7719f4 23 ##################################################################### */
sk398 6:74b5ac7719f4 24
sk398 0:8ac1280934b4 25 #include "mbed.h"
sk398 0:8ac1280934b4 26 #include "SerialComms.h"
sk398 0:8ac1280934b4 27
sk398 1:bf3fb80028d8 28 SerialComms::SerialComms(PinName tx,PinName rx)
sk398 0:8ac1280934b4 29 {
sk398 3:b608ee5b9b5d 30 _HLC_Conn = new RawSerial(tx,rx);
sk398 0:8ac1280934b4 31 _HLC_Conn-> baud(SERIAL_BAUD_RATE);
sk398 0:8ac1280934b4 32 _HLC_Conn -> format(8,SerialBase::None,1);
sk398 0:8ac1280934b4 33
sk398 3:b608ee5b9b5d 34 _HLC_Conn -> attach(this,&SerialComms::incomingDataISR,RawSerial::RxIrq);
sk398 0:8ac1280934b4 35
sk398 2:cb74b330b285 36 incomingDataUpdate = FALSE;
sk398 0:8ac1280934b4 37 }
sk398 0:8ac1280934b4 38
sk398 2:cb74b330b285 39 void SerialComms::incomingDataISR()
sk398 0:8ac1280934b4 40 {
sk398 6:74b5ac7719f4 41 receiverBuffer = _HLC_Conn -> getc();
sk398 2:cb74b330b285 42 incomingDataUpdate = TRUE;
sk398 0:8ac1280934b4 43 }
sk398 0:8ac1280934b4 44
sk398 6:74b5ac7719f4 45 uint8_t SerialComms::getCommData()
sk398 0:8ac1280934b4 46 {
sk398 6:74b5ac7719f4 47 if(incomingDataUpdate == TRUE)
sk398 0:8ac1280934b4 48 {
sk398 8:2cbaea485ddb 49 if( (receiverBuffer&0x0F)==MOTORS_FORWARD ||
sk398 8:2cbaea485ddb 50 (receiverBuffer&0x0F)==MOTORS_BACKWARD ||
sk398 8:2cbaea485ddb 51 (receiverBuffer&0x0F)==MOTORS_LEFT ||
sk398 8:2cbaea485ddb 52 (receiverBuffer&0x0F)==MOTORS_RIGHT ||
sk398 8:2cbaea485ddb 53 (receiverBuffer&0x0F)==MOTORS_ARM
sk398 7:34c5934a01f0 54 /* AND BALLAST REQUIREMENTS */)
sk398 7:34c5934a01f0 55 {
sk398 7:34c5934a01f0 56 incomingDataUpdate = FALSE;
sk398 7:34c5934a01f0 57 return receiverBuffer;
sk398 7:34c5934a01f0 58 }
sk398 0:8ac1280934b4 59 }
sk398 0:8ac1280934b4 60 else
sk398 0:8ac1280934b4 61 {
sk398 9:8e0a7d3f2f39 62 incomingDataUpdate = FALSE;
sk398 6:74b5ac7719f4 63 return 0xFF;
sk398 0:8ac1280934b4 64 }
sk398 10:55cb02b00338 65 return;
sk398 0:8ac1280934b4 66 }