| 1 | // Part of BNC, a utility for retrieving decoding and
|
|---|
| 2 | // converting GNSS data streams from NTRIP broadcasters.
|
|---|
| 3 | //
|
|---|
| 4 | // Copyright (C) 2007
|
|---|
| 5 | // German Federal Agency for Cartography and Geodesy (BKG)
|
|---|
| 6 | // http://www.bkg.bund.de
|
|---|
| 7 | // Czech Technical University Prague, Department of Geodesy
|
|---|
| 8 | // http://www.fsv.cvut.cz
|
|---|
| 9 | //
|
|---|
| 10 | // Email: euref-ip@bkg.bund.de
|
|---|
| 11 | //
|
|---|
| 12 | // This program is free software; you can redistribute it and/or
|
|---|
| 13 | // modify it under the terms of the GNU General Public License
|
|---|
| 14 | // as published by the Free Software Foundation, version 2.
|
|---|
| 15 | //
|
|---|
| 16 | // This program is distributed in the hope that it will be useful,
|
|---|
| 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 19 | // GNU General Public License for more details.
|
|---|
| 20 | //
|
|---|
| 21 | // You should have received a copy of the GNU General Public License
|
|---|
| 22 | // along with this program; if not, write to the Free Software
|
|---|
| 23 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|---|
| 24 |
|
|---|
| 25 | /* -------------------------------------------------------------------------
|
|---|
| 26 | * BKG NTRIP Client
|
|---|
| 27 | * -------------------------------------------------------------------------
|
|---|
| 28 | *
|
|---|
| 29 | * Class: main
|
|---|
| 30 | *
|
|---|
| 31 | * Purpose: Application starts here
|
|---|
| 32 | *
|
|---|
| 33 | * Author: L. Mervart
|
|---|
| 34 | *
|
|---|
| 35 | * Created: 24-Dec-2005
|
|---|
| 36 | *
|
|---|
| 37 | * Changes:
|
|---|
| 38 | *
|
|---|
| 39 | * -----------------------------------------------------------------------*/
|
|---|
| 40 |
|
|---|
| 41 | #include <unistd.h>
|
|---|
| 42 | #include <signal.h>
|
|---|
| 43 | #include <QApplication>
|
|---|
| 44 | #include <QFile>
|
|---|
| 45 | #include <iostream>
|
|---|
| 46 |
|
|---|
| 47 | #include "bncapp.h"
|
|---|
| 48 | #include "bncwindow.h"
|
|---|
| 49 |
|
|---|
| 50 | using namespace std;
|
|---|
| 51 |
|
|---|
| 52 | void catch_signal(int) {
|
|---|
| 53 | cout << "Program Interrupted by Ctrl-C" << endl;
|
|---|
| 54 | ((bncApp*)qApp)->slotQuit();
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | // Main Program
|
|---|
| 58 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 59 | int main(int argc, char *argv[]) {
|
|---|
| 60 |
|
|---|
| 61 | bool GUIenabled = true;
|
|---|
| 62 | bool fileInput = false;
|
|---|
| 63 | bool confFile = false;
|
|---|
| 64 | QByteArray fileName;
|
|---|
| 65 | QByteArray format;
|
|---|
| 66 | QString dateString;
|
|---|
| 67 | QString timeString;
|
|---|
| 68 | QString confFileName;
|
|---|
| 69 | QString confFileIs;
|
|---|
| 70 |
|
|---|
| 71 | for (int ii = 1; ii < argc; ii++) {
|
|---|
| 72 | if (QByteArray(argv[ii]) == "-nw") {
|
|---|
| 73 | GUIenabled = false;
|
|---|
| 74 | break;
|
|---|
| 75 | }
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | for (int ii = 1; ii < argc; ii++) {
|
|---|
| 79 | if (QByteArray(argv[ii]) == "-file" || QByteArray(argv[ii]) == "--file") {
|
|---|
| 80 | GUIenabled = false;
|
|---|
| 81 | fileInput = true;
|
|---|
| 82 | if (ii+1 < argc) {
|
|---|
| 83 | fileName = QByteArray(argv[ii+1]);
|
|---|
| 84 | }
|
|---|
| 85 | }
|
|---|
| 86 | if (QByteArray(argv[ii]) == "-format" || QByteArray(argv[ii]) == "--format") {
|
|---|
| 87 | GUIenabled = false;
|
|---|
| 88 | fileInput = true;
|
|---|
| 89 | if (ii+1 < argc) {
|
|---|
| 90 | format = QByteArray(argv[ii+1]);
|
|---|
| 91 | }
|
|---|
| 92 | }
|
|---|
| 93 | if (QByteArray(argv[ii]) == "-date" || QByteArray(argv[ii]) == "--date") {
|
|---|
| 94 | if (ii+1 < argc) {
|
|---|
| 95 | dateString = QString(argv[ii+1]);
|
|---|
| 96 | }
|
|---|
| 97 | }
|
|---|
| 98 | if (QByteArray(argv[ii]) == "-time" || QByteArray(argv[ii]) == "--time") {
|
|---|
| 99 | if (ii+1 < argc) {
|
|---|
| 100 | timeString = QString(argv[ii+1]);
|
|---|
| 101 | }
|
|---|
| 102 | }
|
|---|
| 103 | if (QByteArray(argv[ii]) == "-conf" || QByteArray(argv[ii]) == "--conf") {
|
|---|
| 104 | confFile = true;
|
|---|
| 105 | if (ii+1 < argc) {
|
|---|
| 106 | confFileName = QString(argv[ii+1]);
|
|---|
| 107 | }
|
|---|
| 108 | }
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | QString printHelp;
|
|---|
| 112 | printHelp = "Usage: bnc --conf <confFileName>\n"
|
|---|
| 113 | " --file <inputFileName>\n"
|
|---|
| 114 | " --format <RTIGS | RTCM_2 | RTCM_3>\n"
|
|---|
| 115 | " --date YYYY-MM-DD --time HH:MM:SS";
|
|---|
| 116 |
|
|---|
| 117 | if (confFile && confFileName.isEmpty() ) {
|
|---|
| 118 | cout << printHelp.toAscii().data() << endl;
|
|---|
| 119 | exit(0);
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | QCoreApplication::setOrganizationName("BKG");
|
|---|
| 123 | QCoreApplication::setOrganizationDomain("www.bkg.bund.de");
|
|---|
| 124 | if (!confFileName.isEmpty()) {
|
|---|
| 125 | confFileIs = confFileName;
|
|---|
| 126 | } else {
|
|---|
| 127 | confFileIs = "BKG_NTRIP_Client";
|
|---|
| 128 | }
|
|---|
| 129 | QCoreApplication::setApplicationName(confFileIs);
|
|---|
| 130 |
|
|---|
| 131 | // Default Settings
|
|---|
| 132 | // ----------------
|
|---|
| 133 | QSettings settings;
|
|---|
| 134 | if (settings.allKeys().size() == 0) {
|
|---|
| 135 | settings.setValue("adviseFail", "15");
|
|---|
| 136 | settings.setValue("adviseReco", "5");
|
|---|
| 137 | settings.setValue("adviseScript", "");
|
|---|
| 138 | settings.setValue("autoStart", "0");
|
|---|
| 139 | settings.setValue("binSampl", "0");
|
|---|
| 140 | settings.setValue("casterHost", "www.euref-ip.net");
|
|---|
| 141 | settings.setValue("casterPort", "2101");
|
|---|
| 142 | settings.setValue("corrIntr", "1 day");
|
|---|
| 143 | settings.setValue("corrPath", "");
|
|---|
| 144 | settings.setValue("corrPort", "");
|
|---|
| 145 | settings.setValue("corrTime", "5");
|
|---|
| 146 | settings.setValue("ephIntr", "1 day");
|
|---|
| 147 | settings.setValue("ephPath", "");
|
|---|
| 148 | settings.setValue("ephV3", "0");
|
|---|
| 149 | settings.setValue("logFile", "");
|
|---|
| 150 | settings.setValue("makePause", "0");
|
|---|
| 151 | settings.setValue("miscMount", "");
|
|---|
| 152 | settings.setValue("obsRate", "");
|
|---|
| 153 | settings.setValue("onTheFlyInterval", "1 day");
|
|---|
| 154 | settings.setValue("outEphPort", "");
|
|---|
| 155 | settings.setValue("outFile", "");
|
|---|
| 156 | settings.setValue("outPort", "");
|
|---|
| 157 | settings.setValue("outUPort", "");
|
|---|
| 158 | settings.setValue("perfIntr", "");
|
|---|
| 159 | settings.setValue("proxyHost", "");
|
|---|
| 160 | settings.setValue("proxyPort", "");
|
|---|
| 161 | settings.setValue("rnxAppend", "0");
|
|---|
| 162 | settings.setValue("rnxIntr", "15 min");
|
|---|
| 163 | settings.setValue("rnxPath", "");
|
|---|
| 164 | settings.setValue("rnxSampl", "0");
|
|---|
| 165 | settings.setValue("rnxScript", "");
|
|---|
| 166 | settings.setValue("rnxSkel", "SKL");
|
|---|
| 167 | settings.setValue("rnxV3", "0");
|
|---|
| 168 | settings.setValue("scanRTCM", "0");
|
|---|
| 169 | settings.setValue("serialAutoNMEA", "0");
|
|---|
| 170 | settings.setValue("serialBaudRate", "9600");
|
|---|
| 171 | settings.setValue("serialDataBits", "8");
|
|---|
| 172 | settings.setValue("serialMountPoint", "");
|
|---|
| 173 | settings.setValue("serialParity", "NONE");
|
|---|
| 174 | settings.setValue("serialPortName", "");
|
|---|
| 175 | settings.setValue("serialStopBits", "1");
|
|---|
| 176 | settings.setValue("startTab", "0");
|
|---|
| 177 | settings.setValue("waitTime", "5");
|
|---|
| 178 |
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 | // Truncate list of casters
|
|---|
| 182 | // ------------------------
|
|---|
| 183 | int maxListSize = 5;
|
|---|
| 184 | QStringList casterHostList = settings.value("casterHostList").toStringList();
|
|---|
| 185 | if ( casterHostList.count() > maxListSize ) {
|
|---|
| 186 | QStringList listCopy;
|
|---|
| 187 | for (int ii = 0; ii < maxListSize; ii++) {
|
|---|
| 188 | listCopy.push_back(casterHostList[ii]);
|
|---|
| 189 | }
|
|---|
| 190 | settings.setValue("casterHostList", listCopy);
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 | bncApp app(argc, argv, GUIenabled);
|
|---|
| 195 |
|
|---|
| 196 | int waitCoTime = settings.value("corrTime").toInt();
|
|---|
| 197 | if (waitCoTime < 1) {
|
|---|
| 198 | waitCoTime = 1;
|
|---|
| 199 | }
|
|---|
| 200 | app.setWaitCoTime(waitCoTime);
|
|---|
| 201 |
|
|---|
| 202 | // Interactive Mode - open the main window
|
|---|
| 203 | // ---------------------------------------
|
|---|
| 204 | if (GUIenabled) {
|
|---|
| 205 |
|
|---|
| 206 | QString fontString = settings.value("font").toString();
|
|---|
| 207 | if ( !fontString.isEmpty() ) {
|
|---|
| 208 | QFont newFont;
|
|---|
| 209 | if (newFont.fromString(fontString)) {
|
|---|
| 210 | QApplication::setFont(newFont);
|
|---|
| 211 | }
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | app.setWindowIcon(QPixmap(":ntrip-logo.png"));
|
|---|
| 215 |
|
|---|
| 216 | bncWindow* bncWin = new bncWindow();
|
|---|
| 217 | bncWin->show();
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | // Non-Interactive (Batch) Mode
|
|---|
| 221 | // ----------------------------
|
|---|
| 222 | else {
|
|---|
| 223 |
|
|---|
| 224 | signal(SIGINT, catch_signal);
|
|---|
| 225 |
|
|---|
| 226 | bncCaster* caster = new bncCaster(settings.value("outFile").toString(),
|
|---|
| 227 | settings.value("outPort").toInt());
|
|---|
| 228 |
|
|---|
| 229 | app.setCaster(caster);
|
|---|
| 230 | app.setPort(settings.value("outEphPort").toInt());
|
|---|
| 231 | app.setPortCorr(settings.value("corrPort").toInt());
|
|---|
| 232 |
|
|---|
| 233 | app.connect(caster, SIGNAL(getThreadErrors()), &app, SLOT(quit()));
|
|---|
| 234 |
|
|---|
| 235 | ((bncApp*)qApp)->slotMessage("============ Start BNC ============", true);
|
|---|
| 236 |
|
|---|
| 237 | // Normal case - data from Internet
|
|---|
| 238 | // --------------------------------
|
|---|
| 239 | if (!fileInput) {
|
|---|
| 240 | caster->slotReadMountPoints();
|
|---|
| 241 | if (caster->numStations() == 0) {
|
|---|
| 242 | return 0;
|
|---|
| 243 | }
|
|---|
| 244 | }
|
|---|
| 245 |
|
|---|
| 246 | // Special case - data from file
|
|---|
| 247 | // -----------------------------
|
|---|
| 248 | else {
|
|---|
| 249 | if ( fileName.isEmpty() || format.isEmpty() ||
|
|---|
| 250 | dateString.isEmpty() || timeString.isEmpty() ) {
|
|---|
| 251 | cout << printHelp.toAscii().data() << endl;
|
|---|
| 252 | exit(0);
|
|---|
| 253 | }
|
|---|
| 254 |
|
|---|
| 255 | app._currentDateAndTimeGPS =
|
|---|
| 256 | new QDateTime(QDate::fromString(dateString, Qt::ISODate),
|
|---|
| 257 | QTime::fromString(timeString, Qt::ISODate), Qt::UTC);
|
|---|
| 258 |
|
|---|
| 259 | bncGetThread* getThread = new bncGetThread(fileName, format);
|
|---|
| 260 | caster->addGetThread(getThread);
|
|---|
| 261 | }
|
|---|
| 262 | }
|
|---|
| 263 |
|
|---|
| 264 | // Start the application
|
|---|
| 265 | // ---------------------
|
|---|
| 266 | return app.exec();
|
|---|
| 267 | }
|
|---|