SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
mainparser.cpp
Go to the documentation of this file.
1 // Copyright (C) 2017 F4EXB //
3 // written by Edouard Griffiths //
4 // //
5 // This program is free software; you can redistribute it and/or modify //
6 // it under the terms of the GNU General Public License as published by //
7 // the Free Software Foundation as version 3 of the License, or //
8 // (at your option) any later version. //
9 // //
10 // This program is distributed in the hope that it will be useful, //
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
13 // GNU General Public License V3 for more details. //
14 // //
15 // You should have received a copy of the GNU General Public License //
16 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
18 
19 #include <QCommandLineOption>
20 #include <QRegExpValidator>
21 #include <QDebug>
22 
23 #include "mainparser.h"
24 
26  m_serverAddressOption(QStringList() << "a" << "api-address",
27  "Web API server address.",
28  "address",
29  "127.0.0.1"),
30  m_serverPortOption(QStringList() << "p" << "api-port",
31  "Web API server port.",
32  "port",
33  "8091"),
34  m_mimoOption("mimo", "Activate MIMO functionality")
35 {
36  m_serverAddress = "127.0.0.1";
37  m_serverPort = 8091;
38  m_mimoSupport = false;
39  m_mimoOption.setFlags(QCommandLineOption::HiddenFromHelp);
40 
41  m_parser.setApplicationDescription("Software Defined Radio application");
42  m_parser.addHelpOption();
43  m_parser.addVersionOption();
44 
46  m_parser.addOption(m_serverPortOption);
47  m_parser.addOption(m_mimoOption);
48 }
49 
51 { }
52 
53 void MainParser::parse(const QCoreApplication& app)
54 {
55  m_parser.process(app);
56 
57  int pos;
58  bool ok;
59 
60  // server address
61 
62  QString serverAddress = m_parser.value(m_serverAddressOption);
63 
64  QString ipRange = "(?:[0-1]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])";
65  QRegExp ipRegex ("^" + ipRange
66  + "\\." + ipRange
67  + "\\." + ipRange
68  + "\\." + ipRange + "$");
69  QRegExpValidator ipValidator(ipRegex);
70 
71  if (ipValidator.validate(serverAddress, pos) == QValidator::Acceptable) {
72  m_serverAddress = serverAddress;
73  } else {
74  qWarning() << "MainParser::parse: server address invalid. Defaulting to " << m_serverAddress;
75  }
76 
77  // server port
78 
79  QString serverPortStr = m_parser.value(m_serverPortOption);
80  int serverPort = serverPortStr.toInt(&ok);
81 
82  if (ok && (serverPort > 1023) && (serverPort < 65536)) {
83  m_serverPort = serverPort;
84  } else {
85  qWarning() << "MainParser::parse: server port invalid. Defaulting to " << m_serverPort;
86  }
87 
88  // MIMO
89 
91 }
QCommandLineOption m_mimoOption
Definition: mainparser.h:47
QCommandLineOption m_serverAddressOption
Definition: mainparser.h:45
QCommandLineParser m_parser
Definition: mainparser.h:44
QCommandLineOption m_serverPortOption
Definition: mainparser.h:46
bool m_mimoSupport
Definition: mainparser.h:42
QString m_serverAddress
Definition: mainparser.h:40
uint16_t m_serverPort
Definition: mainparser.h:41
void parse(const QCoreApplication &app)
Definition: mainparser.cpp:53