mirror of
https://github.com/azaion/autopilot.git
synced 2026-04-22 12:06:34 +00:00
33399370f3
Simple program to control Siyi A8 mini (actually some other Siyi cameras too). Receiving responce sometimes gives error when checking CRC.
54 lines
1.3 KiB
C++
54 lines
1.3 KiB
C++
#include "serialPort.h"
|
|
#include <QDebug>
|
|
|
|
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(5000)) { // Adjust timeout as needed
|
|
response.append(mSerialPort.readAll());
|
|
}
|
|
|
|
return response;
|
|
}
|