2018-08-18 22:49:08 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Copyright (C) 2018 Edouard Griffiths, F4EXB. //
|
|
|
|
// //
|
|
|
|
// SDRdaemon command line parser //
|
|
|
|
// //
|
|
|
|
// SDRdaemon is a detached SDR front end that handles the interface with a //
|
|
|
|
// physical device and sends or receives the I/Q samples stream to or from a //
|
|
|
|
// SDRangel instance via UDP. It is controlled via a Web REST API. //
|
|
|
|
// //
|
|
|
|
// This program is free software; you can redistribute it and/or modify //
|
|
|
|
// it under the terms of the GNU General Public License as published by //
|
|
|
|
// the Free Software Foundation as version 3 of the License, or //
|
|
|
|
// //
|
|
|
|
// This program is distributed in the hope that it will be useful, //
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
|
|
|
// GNU General Public License V3 for more details. //
|
|
|
|
// //
|
|
|
|
// You should have received a copy of the GNU General Public License //
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "sdrdaemonparser.h"
|
|
|
|
|
|
|
|
#include <QCommandLineOption>
|
|
|
|
#include <QRegExpValidator>
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
SDRDaemonParser::SDRDaemonParser() :
|
|
|
|
m_serverAddressOption(QStringList() << "a" << "api-address",
|
2018-08-18 23:07:31 +00:00
|
|
|
"API server and data (Tx) address.",
|
|
|
|
"localAddress",
|
2018-08-18 22:49:08 +00:00
|
|
|
"127.0.0.1"),
|
|
|
|
m_serverPortOption(QStringList() << "p" << "api-port",
|
|
|
|
"Web API server port.",
|
2018-08-18 23:07:31 +00:00
|
|
|
"apiPort",
|
|
|
|
"9091"),
|
|
|
|
m_dataAddressOption(QStringList() << "A" << "data-address",
|
|
|
|
"Remote data address (Rx).",
|
|
|
|
"remoteAddress",
|
|
|
|
"127.0.0.1"),
|
|
|
|
m_dataPortOption(QStringList() << "D" << "data-port",
|
|
|
|
"UDP stream data port.",
|
|
|
|
"dataPort",
|
2018-08-22 19:45:24 +00:00
|
|
|
"9090"),
|
2018-08-18 22:49:08 +00:00
|
|
|
m_deviceTypeOption(QStringList() << "T" << "device-type",
|
|
|
|
"Device type.",
|
|
|
|
"deviceType",
|
|
|
|
"TestSource"),
|
|
|
|
m_txOption(QStringList() << "t" << "tx",
|
2018-08-18 23:07:31 +00:00
|
|
|
"Tx indicator."),
|
2018-08-18 22:49:08 +00:00
|
|
|
m_serialOption(QStringList() << "s" << "serial",
|
|
|
|
"Device serial number.",
|
|
|
|
"serial"),
|
2018-08-19 09:20:54 +00:00
|
|
|
m_sequenceOption(QStringList() << "i" << "sequence",
|
|
|
|
"Device sequence index in enumeration for the same device type.",
|
2018-08-21 13:18:23 +00:00
|
|
|
"sequence"),
|
|
|
|
m_txDelayOption(QStringList() << "d" << "tx-delay",
|
|
|
|
"delay between transmission of UDP blocks (ms).",
|
|
|
|
"txDelay",
|
2018-08-22 18:57:11 +00:00
|
|
|
"100"),
|
2018-08-21 13:18:23 +00:00
|
|
|
m_nbBlocksFECOption(QStringList() << "f" << "fec-blocks",
|
|
|
|
"Number of FEC blocks per frame.",
|
|
|
|
"nbBlocksFEC",
|
|
|
|
"8")
|
2018-08-18 22:49:08 +00:00
|
|
|
{
|
|
|
|
m_serverAddress = "127.0.0.1";
|
|
|
|
m_serverPort = 9091;
|
2018-08-18 23:07:31 +00:00
|
|
|
m_dataAddress = "127.0.0.1";
|
|
|
|
m_dataPort = 9090;
|
2018-08-18 22:49:08 +00:00
|
|
|
m_deviceType = "TestSource";
|
|
|
|
m_tx = false;
|
|
|
|
m_sequence = 0;
|
2018-08-21 13:18:23 +00:00
|
|
|
m_txDelay = 100;
|
|
|
|
m_nbBlocksFEC = 8;
|
2018-08-18 22:49:08 +00:00
|
|
|
m_hasSequence = false;
|
|
|
|
m_hasSerial = false;
|
|
|
|
|
|
|
|
m_parser.setApplicationDescription("Software Defined Radio RF header server");
|
|
|
|
m_parser.addHelpOption();
|
|
|
|
m_parser.addVersionOption();
|
|
|
|
|
|
|
|
m_parser.addOption(m_serverAddressOption);
|
|
|
|
m_parser.addOption(m_serverPortOption);
|
2018-08-18 23:07:31 +00:00
|
|
|
m_parser.addOption(m_dataAddressOption);
|
|
|
|
m_parser.addOption(m_dataPortOption);
|
2018-08-18 22:49:08 +00:00
|
|
|
m_parser.addOption(m_deviceTypeOption);
|
|
|
|
m_parser.addOption(m_txOption);
|
|
|
|
m_parser.addOption(m_serialOption);
|
|
|
|
m_parser.addOption(m_sequenceOption);
|
2018-08-21 13:18:23 +00:00
|
|
|
m_parser.addOption(m_txDelayOption);
|
|
|
|
m_parser.addOption(m_nbBlocksFECOption);
|
2018-08-18 22:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SDRDaemonParser::~SDRDaemonParser()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
void SDRDaemonParser::parse(const QCoreApplication& app)
|
|
|
|
{
|
|
|
|
m_parser.process(app);
|
|
|
|
|
|
|
|
int pos;
|
|
|
|
bool ok;
|
|
|
|
|
|
|
|
// server address
|
|
|
|
|
|
|
|
QString serverAddress = m_parser.value(m_serverAddressOption);
|
|
|
|
|
|
|
|
QString ipRange = "(?:[0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])";
|
|
|
|
QRegExp ipRegex ("^" + ipRange
|
|
|
|
+ "\\." + ipRange
|
|
|
|
+ "\\." + ipRange
|
|
|
|
+ "\\." + ipRange + "$");
|
|
|
|
QRegExpValidator ipValidator(ipRegex);
|
|
|
|
|
2018-08-22 18:57:11 +00:00
|
|
|
if (ipValidator.validate(serverAddress, pos) == QValidator::Acceptable)
|
|
|
|
{
|
2018-08-18 22:49:08 +00:00
|
|
|
m_serverAddress = serverAddress;
|
2018-08-22 18:57:11 +00:00
|
|
|
qDebug() << "SDRDaemonParser::parse: server address: " << m_serverAddress;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-18 22:49:08 +00:00
|
|
|
qWarning() << "SDRDaemonParser::parse: server address invalid. Defaulting to " << m_serverAddress;
|
|
|
|
}
|
|
|
|
|
|
|
|
// server port
|
|
|
|
|
|
|
|
QString serverPortStr = m_parser.value(m_serverPortOption);
|
|
|
|
int serverPort = serverPortStr.toInt(&ok);
|
|
|
|
|
2018-08-22 18:57:11 +00:00
|
|
|
if (ok && (serverPort > 1023) && (serverPort < 65536))
|
|
|
|
{
|
2018-08-18 22:49:08 +00:00
|
|
|
m_serverPort = serverPort;
|
2018-08-22 18:57:11 +00:00
|
|
|
qDebug() << "SDRDaemonParser::parse: server port: " << m_serverPort;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-18 22:49:08 +00:00
|
|
|
qWarning() << "SDRDaemonParser::parse: server port invalid. Defaulting to " << m_serverPort;
|
|
|
|
}
|
|
|
|
|
2018-08-18 23:07:31 +00:00
|
|
|
// data address
|
|
|
|
|
|
|
|
QString dataAddress = m_parser.value(m_dataAddressOption);
|
|
|
|
|
2018-08-22 18:57:11 +00:00
|
|
|
if (ipValidator.validate(dataAddress, pos) == QValidator::Acceptable)
|
|
|
|
{
|
2018-08-18 23:07:31 +00:00
|
|
|
m_dataAddress = dataAddress;
|
2018-08-22 18:57:11 +00:00
|
|
|
qDebug() << "SDRDaemonParser::parse: data address: " << m_dataAddress;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-18 23:07:31 +00:00
|
|
|
qWarning() << "SDRDaemonParser::parse: data address invalid. Defaulting to " << m_dataAddress;
|
|
|
|
}
|
|
|
|
|
2018-08-18 23:28:29 +00:00
|
|
|
// data port
|
2018-08-18 23:07:31 +00:00
|
|
|
|
|
|
|
QString dataPortStr = m_parser.value(m_dataPortOption);
|
2018-08-22 19:45:24 +00:00
|
|
|
serverPort = dataPortStr.toInt(&ok);
|
2018-08-18 23:07:31 +00:00
|
|
|
|
2018-08-22 18:57:11 +00:00
|
|
|
if (ok && (serverPort > 1023) && (serverPort < 65536))
|
|
|
|
{
|
2018-08-18 23:07:31 +00:00
|
|
|
m_dataPort = serverPort;
|
2018-08-22 19:45:24 +00:00
|
|
|
qDebug() << "SDRDaemonParser::parse: data port: " << m_dataPort;
|
2018-08-22 18:57:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-18 23:07:31 +00:00
|
|
|
qWarning() << "SDRDaemonParser::parse: data port invalid. Defaulting to " << m_dataPort;
|
|
|
|
}
|
|
|
|
|
2018-08-19 17:21:10 +00:00
|
|
|
// tx
|
|
|
|
m_tx = m_parser.isSet(m_txOption);
|
|
|
|
qDebug() << "SDRDaemonParser::parse: tx: " << m_tx;
|
|
|
|
|
2018-08-19 09:20:54 +00:00
|
|
|
// device type
|
2018-08-18 22:49:08 +00:00
|
|
|
|
2018-08-19 22:38:33 +00:00
|
|
|
if (m_parser.isSet(m_deviceTypeOption))
|
|
|
|
{
|
|
|
|
QString deviceType = m_parser.value(m_deviceTypeOption);
|
2018-08-18 22:49:08 +00:00
|
|
|
|
2018-08-19 22:38:33 +00:00
|
|
|
QRegExp deviceTypeRegex("^[A-Z][A-Za-z0-9]+$");
|
|
|
|
QRegExpValidator deviceTypeValidator(deviceTypeRegex);
|
2018-08-18 22:49:08 +00:00
|
|
|
|
2018-08-19 22:38:33 +00:00
|
|
|
if (deviceTypeValidator.validate(deviceType, pos) == QValidator::Acceptable)
|
|
|
|
{
|
|
|
|
m_deviceType = deviceType;
|
|
|
|
qDebug() << "SDRDaemonParser::parse: device type: " << m_deviceType;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_deviceType = m_tx ? "FileSink" : "TestSource";
|
|
|
|
qWarning() << "SDRDaemonParser::parse: device type invalid. Defaulting to " << m_deviceType;
|
|
|
|
}
|
2018-08-19 17:21:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_deviceType = m_tx ? "FileSink" : "TestSource";
|
2018-08-19 22:38:33 +00:00
|
|
|
qInfo() << "SDRDaemonParser::parse: device type not specified. defaulting to " << m_deviceType;
|
2018-08-18 22:49:08 +00:00
|
|
|
}
|
|
|
|
|
2018-08-19 22:38:33 +00:00
|
|
|
|
2018-08-18 22:49:08 +00:00
|
|
|
// serial
|
|
|
|
m_hasSerial = m_parser.isSet(m_serialOption);
|
|
|
|
|
2018-08-19 09:20:54 +00:00
|
|
|
if (m_hasSerial)
|
|
|
|
{
|
2018-08-18 22:49:08 +00:00
|
|
|
m_serial = m_parser.value(m_serialOption);
|
2018-08-19 09:20:54 +00:00
|
|
|
qDebug() << "SDRDaemonParser::parse: serial: " << m_serial;
|
2018-08-18 22:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// sequence
|
|
|
|
m_hasSequence = m_parser.isSet(m_sequenceOption);
|
|
|
|
|
|
|
|
if (m_hasSequence)
|
|
|
|
{
|
|
|
|
QString sequenceStr = m_parser.value(m_sequenceOption);
|
|
|
|
int sequence = sequenceStr.toInt(&ok);
|
|
|
|
|
|
|
|
if (ok && (sequence >= 0) && (sequence < 65536)) {
|
|
|
|
m_sequence = sequence;
|
2018-08-19 09:20:54 +00:00
|
|
|
qDebug() << "SDRDaemonParser::parse: sequence: " << m_sequence;
|
2018-08-18 22:49:08 +00:00
|
|
|
} else {
|
|
|
|
qWarning() << "SDRDaemonParser::parse: sequence invalid. Defaulting to " << m_sequence;
|
|
|
|
}
|
|
|
|
}
|
2018-08-21 13:18:23 +00:00
|
|
|
|
|
|
|
// Tx delay
|
|
|
|
if (m_parser.isSet(m_txDelayOption))
|
|
|
|
{
|
|
|
|
QString txDelayStr = m_parser.value(m_txDelayOption);
|
|
|
|
int txDelay = txDelayStr.toInt(&ok);
|
|
|
|
|
2018-08-23 20:17:26 +00:00
|
|
|
if (ok && (txDelay >= 0))
|
2018-08-22 18:57:11 +00:00
|
|
|
{
|
2018-08-21 13:18:23 +00:00
|
|
|
m_txDelay = txDelay;
|
2018-08-22 18:57:11 +00:00
|
|
|
qDebug() << "SDRDaemonParser::parse: Tx delay: " << m_txDelay;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-21 13:18:23 +00:00
|
|
|
qWarning() << "SDRDaemonParser::parse: Tx delay invalid. Defaulting to " << m_txDelay;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// nb FEC blocks
|
|
|
|
if (m_parser.isSet(m_nbBlocksFECOption))
|
|
|
|
{
|
|
|
|
QString nbBlocksFECStr = m_parser.value(m_nbBlocksFECOption);
|
|
|
|
int nbBlocksFEC = nbBlocksFECStr.toInt(&ok);
|
|
|
|
|
2018-08-22 18:57:11 +00:00
|
|
|
if (ok && (nbBlocksFEC >= 0) && (nbBlocksFEC < 128))
|
|
|
|
{
|
2018-08-21 13:18:23 +00:00
|
|
|
m_nbBlocksFEC = nbBlocksFEC;
|
2018-08-22 18:57:11 +00:00
|
|
|
qDebug() << "SDRDaemonParser::parse: number of FEC blocks: " << m_nbBlocksFEC;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning() << "SDRDaemonParser::parse: number of FEC blocks invalid. Defaulting to " << m_nbBlocksFEC;
|
2018-08-21 13:18:23 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-18 22:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|