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

Committer:
sk398
Date:
Sat Mar 05 01:07:37 2016 +0000
Revision:
11:b5f4a9e69d96
Parent:
10:55cb02b00338
Most up to date

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 11:b5f4a9e69d96 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 11:b5f4a9e69d96 53 (receiverBuffer&0x0F)==MOTORS_ARM ||
sk398 11:b5f4a9e69d96 54 (receiverBuffer&0x0F)==MOTORS_OFF ||
sk398 11:b5f4a9e69d96 55 (receiverBuffer>>4)&(0x0F)==MAGNET_ON ||
sk398 11:b5f4a9e69d96 56 (receiverBuffer>>4)&(0x0F)==MAGNET_OFF
sk398 11:b5f4a9e69d96 57 /* AND BALLAST REQUIREMENTS */ ) )
sk398 7:34c5934a01f0 58 {
sk398 7:34c5934a01f0 59 incomingDataUpdate = FALSE;
sk398 7:34c5934a01f0 60 return receiverBuffer;
sk398 7:34c5934a01f0 61 }
sk398 11:b5f4a9e69d96 62 else
sk398 11:b5f4a9e69d96 63 {
sk398 11:b5f4a9e69d96 64 incomingDataUpdate = FALSE;
sk398 11:b5f4a9e69d96 65 return 0xFF;
sk398 11:b5f4a9e69d96 66 }
sk398 11:b5f4a9e69d96 67 }
sk398 0:8ac1280934b4 68 else
sk398 0:8ac1280934b4 69 {
sk398 9:8e0a7d3f2f39 70 incomingDataUpdate = FALSE;
sk398 6:74b5ac7719f4 71 return 0xFF;
sk398 11:b5f4a9e69d96 72 }
sk398 0:8ac1280934b4 73 }