mirror of
https://github.com/azaion/autopilot.git
synced 2026-04-22 12:26:33 +00:00
Added functionality to calculate target location.
Added functionality to capture camera frame from RTSP stream. Refactored code. Fixed some minor issues.
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
#include "serialPort.h"
|
||||
#include <QDebug>
|
||||
#include "defines.h"
|
||||
|
||||
SerialPort::SerialPort(const QString &portName) : mSerialPort(portName) {
|
||||
SerialPort::SerialPort(const QString &portName)
|
||||
: mSerialPort(portName)
|
||||
{
|
||||
mSerialPort.setPortName(portName);
|
||||
mSerialPort.setBaudRate(QSerialPort::Baud115200);
|
||||
mSerialPort.setDataBits(QSerialPort::Data8);
|
||||
@@ -9,11 +12,13 @@ SerialPort::SerialPort(const QString &portName) : mSerialPort(portName) {
|
||||
mSerialPort.setFlowControl(QSerialPort::NoFlowControl);
|
||||
}
|
||||
|
||||
SerialPort::~SerialPort() {
|
||||
SerialPort::~SerialPort()
|
||||
{
|
||||
closePort(); // Close port if open on destruction
|
||||
}
|
||||
|
||||
bool SerialPort::openPort() {
|
||||
bool SerialPort::openPort()
|
||||
{
|
||||
if (mSerialPort.isOpen()) {
|
||||
qDebug() << "Port already open";
|
||||
return true;
|
||||
@@ -22,13 +27,15 @@ bool SerialPort::openPort() {
|
||||
return mSerialPort.open(QIODevice::ReadWrite);
|
||||
}
|
||||
|
||||
void SerialPort::closePort() {
|
||||
void SerialPort::closePort()
|
||||
{
|
||||
if (mSerialPort.isOpen()) {
|
||||
mSerialPort.close();
|
||||
}
|
||||
}
|
||||
|
||||
void SerialPort::sendCommand(const QByteArray &command) {
|
||||
void SerialPort::sendCommand(const QByteArray &command)
|
||||
{
|
||||
if (!mSerialPort.isOpen()) {
|
||||
qDebug() << "Error: Port not open";
|
||||
return;
|
||||
@@ -37,7 +44,8 @@ void SerialPort::sendCommand(const QByteArray &command) {
|
||||
mSerialPort.write(command);
|
||||
}
|
||||
|
||||
QByteArray SerialPort::readResponse() {
|
||||
QByteArray SerialPort::readResponse()
|
||||
{
|
||||
if (!mSerialPort.isOpen()) {
|
||||
qDebug() << "Error: Port not open";
|
||||
return QByteArray();
|
||||
@@ -45,7 +53,7 @@ QByteArray SerialPort::readResponse() {
|
||||
|
||||
// Read data from serial port until timeout or specific criteria met
|
||||
QByteArray response;
|
||||
while (mSerialPort.waitForReadyRead(5000)) { // Adjust timeout as needed
|
||||
while (mSerialPort.waitForReadyRead(SERIAL_RESPONSE_WAIT_TIME)) { // Adjust timeout as needed
|
||||
response.append(mSerialPort.readAll());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user