mirror of
https://github.com/azaion/autopilot.git
synced 2026-04-22 12:06:34 +00:00
db2652d979
Added functionality to capture camera frame from RTSP stream. Refactored code. Fixed some minor issues.
62 lines
1.4 KiB
C++
62 lines
1.4 KiB
C++
#include "serialPort.h"
|
|
#include <QDebug>
|
|
#include "defines.h"
|
|
|
|
SerialPort::SerialPort(const QString &portName)
|
|
: mSerialPort(portName)
|
|
{
|
|
mSerialPort.setPortName(portName);
|
|
mSerialPort.setBaudRate(QSerialPort::Baud115200);
|
|
mSerialPort.setDataBits(QSerialPort::Data8);
|
|
mSerialPort.setStopBits(QSerialPort::OneStop);
|
|
mSerialPort.setFlowControl(QSerialPort::NoFlowControl);
|
|
}
|
|
|
|
SerialPort::~SerialPort()
|
|
{
|
|
closePort(); // Close port if open on destruction
|
|
}
|
|
|
|
bool SerialPort::openPort()
|
|
{
|
|
if (mSerialPort.isOpen()) {
|
|
qDebug() << "Port already open";
|
|
return true;
|
|
}
|
|
|
|
return mSerialPort.open(QIODevice::ReadWrite);
|
|
}
|
|
|
|
void SerialPort::closePort()
|
|
{
|
|
if (mSerialPort.isOpen()) {
|
|
mSerialPort.close();
|
|
}
|
|
}
|
|
|
|
void SerialPort::sendCommand(const QByteArray &command)
|
|
{
|
|
if (!mSerialPort.isOpen()) {
|
|
qDebug() << "Error: Port not open";
|
|
return;
|
|
}
|
|
|
|
mSerialPort.write(command);
|
|
}
|
|
|
|
QByteArray SerialPort::readResponse()
|
|
{
|
|
if (!mSerialPort.isOpen()) {
|
|
qDebug() << "Error: Port not open";
|
|
return QByteArray();
|
|
}
|
|
|
|
// Read data from serial port until timeout or specific criteria met
|
|
QByteArray response;
|
|
while (mSerialPort.waitForReadyRead(SERIAL_RESPONSE_WAIT_TIME)) { // Adjust timeout as needed
|
|
response.append(mSerialPort.readAll());
|
|
}
|
|
|
|
return response;
|
|
}
|