UART Driver to receive asynchronous Serial Comms from a Raspberry Pi and parse the results.
SerialComms.cpp
- Committer:
- sk398
- Date:
- 2016-03-04
- Revision:
- 10:55cb02b00338
- Parent:
- 9:8e0a7d3f2f39
- Child:
- 11:b5f4a9e69d96
File content as of revision 10:55cb02b00338:
/* ##################################################################### 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; } 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; } return; }