mirror of
https://github.com/azaion/autopilot.git
synced 2026-04-22 08:26:33 +00:00
33399370f3
Simple program to control Siyi A8 mini (actually some other Siyi cameras too). Receiving responce sometimes gives error when checking CRC.
60 lines
1.6 KiB
C++
60 lines
1.6 KiB
C++
#include "serialCommand.h"
|
|
#include "serialPort.h"
|
|
#include "serialResponse.h"
|
|
#include <QCoreApplication>
|
|
#include <QThread>
|
|
#include <iostream>
|
|
|
|
int main(int argc, char *argv[]) {
|
|
QCoreApplication app(argc, argv);
|
|
|
|
// Replace with your actual port name
|
|
const QString portName = "/dev/ttyUSB0";
|
|
|
|
// Create SerialPort object
|
|
SerialPort serial(portName);
|
|
|
|
// Open the serial port
|
|
if (!serial.openPort()) {
|
|
qDebug() << "Failed to open serial port";
|
|
return 1;
|
|
}
|
|
|
|
SerialCommand commands;
|
|
|
|
while (true) {
|
|
commands.printCommands();
|
|
|
|
// Get user input
|
|
std::cout << "Enter a command (0 to exit): ";
|
|
int16_t number;
|
|
std::cin >> number;
|
|
|
|
// Check if the input is within the valid range for uint8_t
|
|
if (number < 0 || number > commands.getCommandCount() - 1) {
|
|
qWarning() << "Number (" << qPrintable(QString::number(number))
|
|
<< ") out of range 0 -"
|
|
<< qPrintable(QString::number(commands.getCommandCount() - 1));
|
|
continue;
|
|
}
|
|
|
|
// Exit loop if user enters 0
|
|
if (number == 0)
|
|
break;
|
|
|
|
// Example command to send (replace with actual Siyi A8 mini camera
|
|
// commands)
|
|
QByteArray command = commands.getCommand((uint8_t)number);
|
|
serial.sendCommand(command);
|
|
|
|
// Read response from the camera
|
|
QByteArray response = serial.readResponse();
|
|
SerialResponse::printResponse(response);
|
|
}
|
|
|
|
// Close the serial port
|
|
serial.closePort();
|
|
|
|
return 0;
|
|
}
|