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

Committer:
sk398
Date:
Fri Mar 04 06:43:50 2016 +0000
Revision:
7:34c5934a01f0
Parent:
6:74b5ac7719f4
Child:
8:2cbaea485ddb
Added beginnings of checks on Data received being valid

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 7:34c5934a01f0 39 #define MOTORS_FORWARD 0x09
sk398 7:34c5934a01f0 40 #define MOTORS_BACKWARD 0x06
sk398 7:34c5934a01f0 41 #define MOTORS_LEFT 0x05
sk398 7:34c5934a01f0 42 #define MOTORS_RIGHT 0x0A
sk398 7:34c5934a01f0 43 #define MOTORS_ARM 0x01
sk398 7:34c5934a01f0 44
sk398 7:34c5934a01f0 45
sk398 0:8ac1280934b4 46
sk398 2:cb74b330b285 47 void SerialComms::incomingDataISR()
sk398 0:8ac1280934b4 48 {
sk398 6:74b5ac7719f4 49 receiverBuffer = _HLC_Conn -> getc();
sk398 2:cb74b330b285 50 incomingDataUpdate = TRUE;
sk398 0:8ac1280934b4 51 }
sk398 0:8ac1280934b4 52
sk398 6:74b5ac7719f4 53 uint8_t SerialComms::getCommData()
sk398 0:8ac1280934b4 54 {
sk398 6:74b5ac7719f4 55 if(incomingDataUpdate == TRUE)
sk398 0:8ac1280934b4 56 {
sk398 7:34c5934a01f0 57 if( (receiverBuffer>&0x0F)==MOTORS_FORWARD ||
sk398 7:34c5934a01f0 58 (receiverBuffer>&0x0F)==MOTORS_BACKWARD ||
sk398 7:34c5934a01f0 59 (receiverBuffer>&0x0F)==MOTORS_LEFT ||
sk398 7:34c5934a01f0 60 (receiverBuffer>&0x0F)==MOTORS_RIGHT ||
sk398 7:34c5934a01f0 61 (receiverBuffer>&0x0F)==MOTORS_ARM
sk398 7:34c5934a01f0 62 /* AND BALLAST REQUIREMENTS */)
sk398 7:34c5934a01f0 63 {
sk398 7:34c5934a01f0 64 incomingDataUpdate = FALSE;
sk398 7:34c5934a01f0 65 return receiverBuffer;
sk398 7:34c5934a01f0 66 }
sk398 0:8ac1280934b4 67 }
sk398 0:8ac1280934b4 68 else
sk398 0:8ac1280934b4 69 {
sk398 6:74b5ac7719f4 70 return 0xFF;
sk398 0:8ac1280934b4 71 }
sk398 0:8ac1280934b4 72 }