Base class for interfacing with sensors over a serial port (UART/RS-232). More...

#include <serialsensor.hh>

Inheritance diagram for dfti::SerialSensor:
Collaboration diagram for dfti::SerialSensor:

Public Slots

virtual void readData (void)=0
Slot to read in data over serial and parse complete packets.
 

Public Member Functions

 SerialSensor (Settings *_settings, QObject *_parent=nullptr)
Constructor. More...
 
 ~SerialSensor ()
Destructor.
 
void configureSerial (QString _portName)
Set the serial port parameters. More...
 
void init ()
Initialize the serial port.
 
bool isOpen (void)
Returns true if the serial port is open. More...
 
virtual void open (void)
Opens the serial port. More...
 
void setBaudRate (quint32 rate)
Set the serial port baud rate. More...
 
void threadStart (void)
Start the sensor in a thread.
 

Protected Member Functions

QString validateSerialPort (QString _port)
Validates a proposed serial port. More...
 

Protected Attributes

QPointer< Settingssettings = nullptr
Settings object.
 
QString portName {""}
Serial port name.
 
QSerialPort::BaudRate baudRate {QSerialPort::Baud115200}
Serial port baud rate.
 
bool _valid_serial = false
Indicates if serial port passed validation.
 
QPointer< QSerialPort > _port = nullptr
Serial port object.
 

Detailed Description

Base class for interfacing with sensors over a serial port (UART/RS-232).

Constructor & Destructor Documentation

dfti::SerialSensor::SerialSensor ( Settings _settings,
QObject *  _parent = nullptr 
)
inlineexplicit

Constructor.

Parameters
_settingsPointer to settings object.
_parentPointer to parent QObject.

Member Function Documentation

void dfti::SerialSensor::configureSerial ( QString  _portName)

Set the serial port parameters.

Parameters
_portNameThe serial port name.
bool dfti::SerialSensor::isOpen ( void  )

Returns true if the serial port is open.

Returns
True if the serial port is open.
void dfti::SerialSensor::open ( void  )
virtual

Opens the serial port.

Since we may not initially know which serial port corresponds to which sensor, we need to wait to open the serial port associated with the sensor until we know which port it is. Once we do, we call this open method to start reading the serial port.

Reimplemented in dfti::Autopilot.

void dfti::SerialSensor::setBaudRate ( quint32  rate)

Set the serial port baud rate.

Parameters
rateThe serial port baud rate. Must be one of 57600, 115200.
Remarks
If an unsupported baud rate is given, the sensor falls back to 57600 baud.
QString dfti::SerialSensor::validateSerialPort ( QString  _port)
protected

Validates a proposed serial port.

Checks to see if the given serial port name is a valid serial port.

Parameters
_portProposed serial port.
Returns
True if the port name corresponds to a valid system serial port.

The documentation for this class was generated from the following files: