mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-14 12:22:00 -05:00
SDRdaemon: specific parser
This commit is contained in:
parent
a1fbc790bf
commit
44fe60b56f
@ -27,10 +27,10 @@
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
|
||||
#include "mainparser.h"
|
||||
#include "loggerwithfile.h"
|
||||
#include "sdrdaemonmain.h"
|
||||
#include "dsp/dsptypes.h"
|
||||
#include "loggerwithfile.h"
|
||||
#include "sdrdaemonparser.h"
|
||||
#include "sdrdaemonmain.h"
|
||||
|
||||
void handler(int sig) {
|
||||
fprintf(stderr, "quit the application by signal(%d).\n", sig);
|
||||
@ -67,7 +67,7 @@ static int runQtApplication(int argc, char* argv[], qtwebapp::LoggerWithFile *lo
|
||||
std::vector<int> vsig(catchSignals, catchSignals + sizeof(catchSignals) / sizeof(int));
|
||||
catchUnixSignals(vsig);
|
||||
|
||||
MainParser parser;
|
||||
SDRDaemonParser parser;
|
||||
parser.parse(a);
|
||||
|
||||
#if QT_VERSION >= 0x050400
|
||||
|
@ -4,6 +4,7 @@ set(sdrdaemon_SOURCES
|
||||
sdrdaemonmain.cpp
|
||||
sdrdaemonpreferences.cpp
|
||||
sdrdaemonsettings.cpp
|
||||
sdrdaemonparser.cpp
|
||||
webapi/webapiadapterdaemon.cpp
|
||||
webapi/webapirequestmapper.cpp
|
||||
webapi/webapiserver.cpp
|
||||
@ -13,6 +14,7 @@ set(sdrdaemon_HEADERS
|
||||
sdrdaemonmain.h
|
||||
sdrdaemonpreferences.h
|
||||
sdrdaemonsettings.h
|
||||
sdrdaemonparser.h
|
||||
webapi/webapiadapterdaemon.h
|
||||
webapi/webapirequestmapper.h
|
||||
webapi/webapiserver.h
|
||||
|
@ -24,21 +24,21 @@
|
||||
#include <QResource>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "mainparser.h"
|
||||
#include "dsp/dspengine.h"
|
||||
#include "dsp/dspdevicesourceengine.h"
|
||||
#include "plugin/pluginmanager.h"
|
||||
#include "util/message.h"
|
||||
#include "loggerwithfile.h"
|
||||
#include "sdrdaemonmain.h"
|
||||
|
||||
#include "webapi/webapiadapterdaemon.h"
|
||||
#include "webapi/webapirequestmapper.h"
|
||||
#include "webapi/webapiserver.h"
|
||||
#include "sdrdaemonparser.h"
|
||||
#include "sdrdaemonmain.h"
|
||||
|
||||
SDRDaemonMain *SDRDaemonMain::m_instance = 0;
|
||||
|
||||
SDRDaemonMain::SDRDaemonMain(qtwebapp::LoggerWithFile *logger, const MainParser& parser, QObject *parent) :
|
||||
SDRDaemonMain::SDRDaemonMain(qtwebapp::LoggerWithFile *logger, const SDRDaemonParser& parser, QObject *parent) :
|
||||
QObject(parent),
|
||||
m_logger(logger),
|
||||
m_settings(),
|
||||
|
@ -38,7 +38,7 @@ namespace qtwebapp {
|
||||
class LoggerWithFile;
|
||||
}
|
||||
|
||||
class MainParser;
|
||||
class SDRDaemonParser;
|
||||
class DSPEngine;
|
||||
class PluginManager;
|
||||
class Message;
|
||||
@ -47,7 +47,7 @@ class WebAPIAdapterDaemon;
|
||||
class SDRDaemonMain : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SDRDaemonMain(qtwebapp::LoggerWithFile *logger, const MainParser& parser, QObject *parent = 0);
|
||||
explicit SDRDaemonMain(qtwebapp::LoggerWithFile *logger, const SDRDaemonParser& parser, QObject *parent = 0);
|
||||
~SDRDaemonMain();
|
||||
static SDRDaemonMain *getInstance() { return m_instance; } // Main Core is de facto a singleton so this just returns its reference
|
||||
|
||||
|
151
sdrdaemon/sdrdaemonparser.cpp
Normal file
151
sdrdaemon/sdrdaemonparser.cpp
Normal file
@ -0,0 +1,151 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// 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",
|
||||
"Web API server address.",
|
||||
"address",
|
||||
"127.0.0.1"),
|
||||
m_serverPortOption(QStringList() << "p" << "api-port",
|
||||
"Web API server port.",
|
||||
"port",
|
||||
"9091"),
|
||||
m_deviceTypeOption(QStringList() << "T" << "device-type",
|
||||
"Device type.",
|
||||
"deviceType",
|
||||
"TestSource"),
|
||||
m_txOption(QStringList() << "t" << "tx",
|
||||
"Tx indicator.",
|
||||
"tx"),
|
||||
m_serialOption(QStringList() << "s" << "serial",
|
||||
"Device serial number.",
|
||||
"serial"),
|
||||
m_sequenceOption(QStringList() << "n" << "sequence",
|
||||
"Device sequence number in enumeration for the same device type.",
|
||||
"serial")
|
||||
|
||||
{
|
||||
m_serverAddress = "127.0.0.1";
|
||||
m_serverPort = 9091;
|
||||
m_deviceType = "TestSource";
|
||||
m_tx = false;
|
||||
m_sequence = 0;
|
||||
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);
|
||||
m_parser.addOption(m_deviceTypeOption);
|
||||
m_parser.addOption(m_txOption);
|
||||
m_parser.addOption(m_serialOption);
|
||||
m_parser.addOption(m_sequenceOption);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if (ipValidator.validate(serverAddress, pos) == QValidator::Acceptable) {
|
||||
m_serverAddress = serverAddress;
|
||||
} else {
|
||||
qWarning() << "SDRDaemonParser::parse: server address invalid. Defaulting to " << m_serverAddress;
|
||||
}
|
||||
|
||||
// server port
|
||||
|
||||
QString serverPortStr = m_parser.value(m_serverPortOption);
|
||||
int serverPort = serverPortStr.toInt(&ok);
|
||||
|
||||
if (ok && (serverPort > 1023) && (serverPort < 65536)) {
|
||||
m_serverPort = serverPort;
|
||||
} else {
|
||||
qWarning() << "SDRDaemonParser::parse: server port invalid. Defaulting to " << m_serverPort;
|
||||
}
|
||||
|
||||
// hardware Id
|
||||
|
||||
QString deviceType = m_parser.value(m_deviceTypeOption);
|
||||
|
||||
QRegExp deviceTypeRegex("^[A-Z][a-z][A-Za-z0-9]+$");
|
||||
QRegExpValidator deviceTypeValidator(deviceTypeRegex);
|
||||
|
||||
if (deviceTypeValidator.validate(deviceType, pos) == QValidator::Acceptable) {
|
||||
m_deviceType = deviceType;
|
||||
} else {
|
||||
qWarning() << "SDRDaemonParser::parse: device type invalid. Defaulting to " << deviceType;
|
||||
}
|
||||
|
||||
// tx
|
||||
m_tx = m_parser.isSet(m_txOption);
|
||||
|
||||
// serial
|
||||
m_hasSerial = m_parser.isSet(m_serialOption);
|
||||
|
||||
if (m_hasSerial) {
|
||||
m_serial = m_parser.value(m_serialOption);
|
||||
}
|
||||
|
||||
// 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;
|
||||
} else {
|
||||
qWarning() << "SDRDaemonParser::parse: sequence invalid. Defaulting to " << m_sequence;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
68
sdrdaemon/sdrdaemonparser.h
Normal file
68
sdrdaemon/sdrdaemonparser.h
Normal file
@ -0,0 +1,68 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// 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/>. //
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SDRDAEMON_SDRDAEMONPARSER_H_
|
||||
#define SDRDAEMON_SDRDAEMONPARSER_H_
|
||||
|
||||
#include <QCommandLineParser>
|
||||
#include <stdint.h>
|
||||
|
||||
class SDRDaemonParser
|
||||
{
|
||||
public:
|
||||
SDRDaemonParser();
|
||||
~SDRDaemonParser();
|
||||
|
||||
void parse(const QCoreApplication& app);
|
||||
|
||||
const QString& getServerAddress() const { return m_serverAddress; }
|
||||
uint16_t getServerPort() const { return m_serverPort; }
|
||||
const QString& getDeviceType() const { return m_deviceType; }
|
||||
bool getTx() const { return m_tx; }
|
||||
const QString& getSerial() const { return m_serial; }
|
||||
uint16_t getSequence() const { return m_sequence; }
|
||||
|
||||
bool hasSequence() const { return m_hasSequence; }
|
||||
bool hasSerial() const { return m_hasSerial; }
|
||||
|
||||
private:
|
||||
QString m_serverAddress;
|
||||
uint16_t m_serverPort;
|
||||
QString m_deviceType; //!< Identifies the type of device
|
||||
bool m_tx; //!< True for Tx
|
||||
QString m_serial; //!< Serial number of the device
|
||||
uint16_t m_sequence; //!< Sequence of the device for the same type of device in enumeration process
|
||||
bool m_hasSerial; //!< True if serial was specified
|
||||
bool m_hasSequence; //!< True if sequence was specified
|
||||
|
||||
QCommandLineParser m_parser;
|
||||
QCommandLineOption m_serverAddressOption;
|
||||
QCommandLineOption m_serverPortOption;
|
||||
QCommandLineOption m_deviceTypeOption;
|
||||
QCommandLineOption m_txOption;
|
||||
QCommandLineOption m_serialOption;
|
||||
QCommandLineOption m_sequenceOption;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* SDRDAEMON_SDRDAEMONPARSER_H_ */
|
Loading…
Reference in New Issue
Block a user