mirror of
https://github.com/azaion/autopilot.git
synced 2026-04-22 11:26:35 +00:00
Added better handling for command line parameters
This commit is contained in:
+17
-9
@@ -1,3 +1,4 @@
|
|||||||
|
#include <QCommandLineParser>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
@@ -9,17 +10,24 @@
|
|||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QCoreApplication app(argc, argv);
|
QCoreApplication app(argc, argv);
|
||||||
SerialCommand serialCommand;
|
QCommandLineParser parser;
|
||||||
SerialPort serialPort;
|
QCommandLineOption lOption(QStringList() << "l", "Use local mode");
|
||||||
Config::setInitalValues(&serialPort, &serialCommand);
|
parser.addOption(lOption);
|
||||||
|
QCommandLineOption pOption(QStringList() << "p", "Use serial port", "value");
|
||||||
|
parser.addOption(pOption);
|
||||||
|
parser.process(app);
|
||||||
bool useRemoteMode = true;
|
bool useRemoteMode = true;
|
||||||
for (int i = 1; i < argc; ++i) {
|
if (parser.isSet(lOption)) {
|
||||||
if (QString(argv[i]) == "-l") {
|
useRemoteMode = false;
|
||||||
useRemoteMode = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
QString useSerialPort;
|
||||||
|
if (parser.isSet(pOption)) {
|
||||||
|
useSerialPort = parser.value(pOption);
|
||||||
|
}
|
||||||
|
|
||||||
|
SerialCommand serialCommand;
|
||||||
|
SerialPort serialPort(useSerialPort);
|
||||||
|
Config::setInitalValues(&serialPort, &serialCommand);
|
||||||
|
|
||||||
// Remote mode will read commands from pipe
|
// Remote mode will read commands from pipe
|
||||||
if (useRemoteMode == true) {
|
if (useRemoteMode == true) {
|
||||||
|
|||||||
@@ -5,11 +5,15 @@
|
|||||||
#include "defines.hpp"
|
#include "defines.hpp"
|
||||||
#include "utilsCRC16.hpp"
|
#include "utilsCRC16.hpp"
|
||||||
|
|
||||||
SerialPort::SerialPort()
|
SerialPort::SerialPort(QString usePort)
|
||||||
: QObject(nullptr)
|
: QObject(nullptr)
|
||||||
{
|
{
|
||||||
|
if (usePort.isEmpty() == true) {
|
||||||
|
usePort = SERIAL_PORT;
|
||||||
|
}
|
||||||
|
|
||||||
mSerialPort = new QSerialPort();
|
mSerialPort = new QSerialPort();
|
||||||
mSerialPort->setPortName(SERIAL_PORT);
|
mSerialPort->setPortName(usePort);
|
||||||
mSerialPort->setBaudRate(QSerialPort::Baud115200);
|
mSerialPort->setBaudRate(QSerialPort::Baud115200);
|
||||||
mSerialPort->setDataBits(QSerialPort::Data8);
|
mSerialPort->setDataBits(QSerialPort::Data8);
|
||||||
mSerialPort->setStopBits(QSerialPort::OneStop);
|
mSerialPort->setStopBits(QSerialPort::OneStop);
|
||||||
@@ -17,9 +21,11 @@ SerialPort::SerialPort()
|
|||||||
|
|
||||||
// Open the serial port
|
// Open the serial port
|
||||||
if (openPort() == false) {
|
if (openPort() == false) {
|
||||||
qCritical() << "SerialPort(): Unable to open port";
|
qCritical().noquote().nospace() << "SerialPort(): Unable to open port " << port;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qDebug().noquote().nospace() << "SerialPort(): Opened port " << port;
|
||||||
}
|
}
|
||||||
|
|
||||||
SerialPort::~SerialPort()
|
SerialPort::~SerialPort()
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class SerialPort : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SerialPort();
|
SerialPort(QString usePort);
|
||||||
~SerialPort();
|
~SerialPort();
|
||||||
|
|
||||||
bool openPort();
|
bool openPort();
|
||||||
|
|||||||
Reference in New Issue
Block a user