UART Driver to receive asynchronous Serial Comms from a Raspberry Pi and parse the results.
SerialComms.cpp
- Committer:
- sk398
- Date:
- 2016-03-04
- Revision:
- 9:8e0a7d3f2f39
- Parent:
- 8:2cbaea485ddb
- Child:
- 10:55cb02b00338
File content as of revision 9:8e0a7d3f2f39:
/* ##################################################################### SerialComms.cpp --------------- Surface Ship, Group 5 --------------------- Written by: Steven Kay Date: February 2016 Function: This Version: 1.0 Version History --------------- 1.1 rgdfgdfgdfggdfgdg 1.0 gdgddfdddgd ##################################################################### */ #include "mbed.h" #include "SerialComms.h" SerialComms::SerialComms(PinName tx,PinName rx) { _HLC_Conn = new RawSerial(tx,rx); _HLC_Conn-> baud(SERIAL_BAUD_RATE); _HLC_Conn -> format(8,SerialBase::None,1); _HLC_Conn -> attach(this,&SerialComms::incomingDataISR,RawSerial::RxIrq); incomingDataUpdate = FALSE; } #define MOTORS_FORWARD 0x09 #define MOTORS_BACKWARD 0x06 #define MOTORS_LEFT 0x05 #define MOTORS_RIGHT 0x0A #define MOTORS_ARM 0x01 void SerialComms::incomingDataISR() { receiverBuffer = _HLC_Conn -> getc(); incomingDataUpdate = TRUE; } uint8_t SerialComms::getCommData() { if(incomingDataUpdate == TRUE) { if( (receiverBuffer&0x0F)==MOTORS_FORWARD || (receiverBuffer&0x0F)==MOTORS_BACKWARD || (receiverBuffer&0x0F)==MOTORS_LEFT || (receiverBuffer&0x0F)==MOTORS_RIGHT || (receiverBuffer&0x0F)==MOTORS_ARM /* AND BALLAST REQUIREMENTS */) { incomingDataUpdate = FALSE; return receiverBuffer; } } else { incomingDataUpdate = FALSE; return 0xFF; } }