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: t_bncCore
|
---|
30 | *
|
---|
31 | * Purpose: This class implements the main application
|
---|
32 | *
|
---|
33 | * Author: L. Mervart
|
---|
34 | *
|
---|
35 | * Created: 29-Aug-2006
|
---|
36 | *
|
---|
37 | * Changes:
|
---|
38 | *
|
---|
39 | * -----------------------------------------------------------------------*/
|
---|
40 |
|
---|
41 | #include <iostream>
|
---|
42 | #include <sstream>
|
---|
43 | #include <QMessageBox>
|
---|
44 | #include <cmath>
|
---|
45 |
|
---|
46 | #include "bnccore.h"
|
---|
47 | #include "bncutils.h"
|
---|
48 | #include "bncrinex.h"
|
---|
49 | #include "bncsettings.h"
|
---|
50 | #include "bncversion.h"
|
---|
51 | #include "ephemeris.h"
|
---|
52 | #include "rinex/rnxobsfile.h"
|
---|
53 | #include "rinex/rnxnavfile.h"
|
---|
54 | #include "pppMain.h"
|
---|
55 | #include "combination/bnccomb.h"
|
---|
56 |
|
---|
57 | using namespace std;
|
---|
58 |
|
---|
59 | // Singleton
|
---|
60 | ////////////////////////////////////////////////////////////////////////////
|
---|
61 | t_bncCore* t_bncCore::instance() {
|
---|
62 | static t_bncCore _bncCore;
|
---|
63 | return &_bncCore;
|
---|
64 | }
|
---|
65 |
|
---|
66 | // Constructor
|
---|
67 | ////////////////////////////////////////////////////////////////////////////
|
---|
68 | t_bncCore::t_bncCore() : _ephUser(false) {
|
---|
69 | _GUIenabled = true;
|
---|
70 | _logFileFlag = 0;
|
---|
71 | _logFile = 0;
|
---|
72 | _logStream = 0;
|
---|
73 | _rawFile = 0;
|
---|
74 | _caster = 0;
|
---|
75 | _bncComb = 0;
|
---|
76 |
|
---|
77 | // Eph file(s)
|
---|
78 | // -----------
|
---|
79 | _rinexVers = 0;
|
---|
80 | _ephFileGPS = 0;
|
---|
81 | _ephStreamGPS = 0;
|
---|
82 | _ephFileGlonass = 0;
|
---|
83 | _ephStreamGlonass = 0;
|
---|
84 | _ephFileGalileo = 0;
|
---|
85 | _ephStreamGalileo = 0;
|
---|
86 | _ephFileSBAS = 0;
|
---|
87 | _ephStreamSBAS = 0;
|
---|
88 |
|
---|
89 | _portEph = 0;
|
---|
90 | _serverEph = 0;
|
---|
91 | _socketsEph = 0;
|
---|
92 |
|
---|
93 | _portCorr = 0;
|
---|
94 | _serverCorr = 0;
|
---|
95 | _socketsCorr = 0;
|
---|
96 |
|
---|
97 | _pgmName = QString(BNCPGMNAME).leftJustified(20, ' ', true);
|
---|
98 | #ifdef WIN32
|
---|
99 | _userName = QString("${USERNAME}");
|
---|
100 | #else
|
---|
101 | _userName = QString("${USER}");
|
---|
102 | #endif
|
---|
103 | expandEnvVar(_userName);
|
---|
104 |
|
---|
105 | _userName = _userName.leftJustified(20, ' ', true);
|
---|
106 | _dateAndTimeGPS = 0;
|
---|
107 | _mainWindow = 0;
|
---|
108 |
|
---|
109 | _pppMain = new BNC_PPP::t_pppMain();
|
---|
110 | qRegisterMetaType< QVector<double> > ("QVector<double>");
|
---|
111 | qRegisterMetaType<bncTime> ("bncTime");
|
---|
112 | qRegisterMetaType<t_ephGPS> ("t_ephGPS");
|
---|
113 | qRegisterMetaType<t_ephGlo> ("t_ephGlo");
|
---|
114 | qRegisterMetaType<t_ephGal> ("t_ephGal");
|
---|
115 | qRegisterMetaType<t_ephSBAS> ("t_ephSBAS");
|
---|
116 | qRegisterMetaType<t_ephBDS> ("t_ephBDS");
|
---|
117 | qRegisterMetaType<QList<t_orbCorr> > ("QList<t_orbCorr>");
|
---|
118 | qRegisterMetaType<QList<t_clkCorr> > ("QList<t_clkCorr>");
|
---|
119 | qRegisterMetaType<QList<t_satCodeBias> > ("QList<t_satCodeBias>");
|
---|
120 | qRegisterMetaType<QList<t_satPhaseBias> > ("QList<t_satPhaseBias>");
|
---|
121 | qRegisterMetaType<t_vTec> ("t_vTec");
|
---|
122 | }
|
---|
123 |
|
---|
124 | // Destructor
|
---|
125 | ////////////////////////////////////////////////////////////////////////////
|
---|
126 | t_bncCore::~t_bncCore() {
|
---|
127 | delete _logStream;
|
---|
128 | delete _logFile;
|
---|
129 | delete _ephStreamGPS;
|
---|
130 | delete _ephFileGPS;
|
---|
131 | delete _serverEph;
|
---|
132 | delete _socketsEph;
|
---|
133 | delete _serverCorr;
|
---|
134 | delete _socketsCorr;
|
---|
135 | if (_rinexVers == 2) {
|
---|
136 | delete _ephStreamGlonass;
|
---|
137 | delete _ephFileGlonass;
|
---|
138 | }
|
---|
139 |
|
---|
140 | delete _dateAndTimeGPS;
|
---|
141 | delete _rawFile;
|
---|
142 | delete _bncComb;
|
---|
143 | delete _pppMain;
|
---|
144 | }
|
---|
145 |
|
---|
146 | // Write a Program Message
|
---|
147 | ////////////////////////////////////////////////////////////////////////////
|
---|
148 | void t_bncCore::slotMessage(QByteArray msg, bool showOnScreen) {
|
---|
149 |
|
---|
150 | QMutexLocker locker(&_mutexMessage);
|
---|
151 |
|
---|
152 | messagePrivate(msg);
|
---|
153 | emit newMessage(msg, showOnScreen);
|
---|
154 | }
|
---|
155 |
|
---|
156 | // Write a Program Message (private, no lock)
|
---|
157 | ////////////////////////////////////////////////////////////////////////////
|
---|
158 | void t_bncCore::messagePrivate(const QByteArray& msg) {
|
---|
159 |
|
---|
160 | // First time resolve the log file name
|
---|
161 | // ------------------------------------
|
---|
162 | QDate currDate = currentDateAndTimeGPS().date();
|
---|
163 | if (_logFileFlag == 0 || _fileDate != currDate) {
|
---|
164 | delete _logStream; _logStream = 0;
|
---|
165 | delete _logFile; _logFile = 0;
|
---|
166 | _logFileFlag = 1;
|
---|
167 | bncSettings settings;
|
---|
168 | QString logFileName = settings.value("logFile").toString();
|
---|
169 | if ( !logFileName.isEmpty() ) {
|
---|
170 | expandEnvVar(logFileName);
|
---|
171 | _logFile = new QFile(logFileName + "_" +
|
---|
172 | currDate.toString("yyMMdd").toLatin1().data());
|
---|
173 | _fileDate = currDate;
|
---|
174 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
|
---|
175 | _logFile->open(QIODevice::WriteOnly | QIODevice::Append);
|
---|
176 | }
|
---|
177 | else {
|
---|
178 | _logFile->open(QIODevice::WriteOnly);
|
---|
179 | }
|
---|
180 | _logStream = new QTextStream();
|
---|
181 | _logStream->setDevice(_logFile);
|
---|
182 | }
|
---|
183 | }
|
---|
184 |
|
---|
185 | if (_logStream) {
|
---|
186 | QByteArray msgLocal = msg;
|
---|
187 | if (msg.indexOf('\n') == 0) {
|
---|
188 | *_logStream << endl;
|
---|
189 | msgLocal = msg.mid(1);
|
---|
190 | }
|
---|
191 | *_logStream << currentDateAndTimeGPS().toString("yy-MM-dd hh:mm:ss ").toLatin1().data();
|
---|
192 | *_logStream << msgLocal.data() << endl;
|
---|
193 | _logStream->flush();
|
---|
194 | _logFile->flush();
|
---|
195 | }
|
---|
196 | }
|
---|
197 |
|
---|
198 | //
|
---|
199 | ////////////////////////////////////////////////////////////////////////////
|
---|
200 | t_irc t_bncCore::checkPrintEph(t_eph* eph) {
|
---|
201 | QMutexLocker locker(&_mutex);
|
---|
202 | t_irc ircPut = _ephUser.putNewEph(eph, true);
|
---|
203 | if (eph->checkState() == t_eph::bad) {
|
---|
204 | messagePrivate("WRONG EPHEMERIS\n" + eph->toString(3.0).toLatin1());
|
---|
205 | return failure;
|
---|
206 | }
|
---|
207 | else if (eph->checkState() == t_eph::outdated) {
|
---|
208 | messagePrivate("OUTDATED EPHEMERIS\n" + eph->toString(3.0).toLatin1());
|
---|
209 | return failure;
|
---|
210 | }
|
---|
211 | else if (eph->checkState() == t_eph::unhealthy) {
|
---|
212 | messagePrivate("UNHEALTHY EPHEMERIS\n" + eph->toString(3.0).toLatin1());
|
---|
213 | }
|
---|
214 | printEphHeader();
|
---|
215 | printEph(*eph, (ircPut == success));
|
---|
216 | return success;
|
---|
217 | }
|
---|
218 |
|
---|
219 | // New GPS Ephemeris
|
---|
220 | ////////////////////////////////////////////////////////////////////////////
|
---|
221 | void t_bncCore::slotNewGPSEph(t_ephGPS eph) {
|
---|
222 | if (checkPrintEph(&eph) == success) {
|
---|
223 | emit newGPSEph(eph);
|
---|
224 | }
|
---|
225 | }
|
---|
226 |
|
---|
227 | // New Glonass Ephemeris
|
---|
228 | ////////////////////////////////////////////////////////////////////////////
|
---|
229 | void t_bncCore::slotNewGlonassEph(t_ephGlo eph) {
|
---|
230 | if (checkPrintEph(&eph) == success) {
|
---|
231 | emit newGlonassEph(eph);
|
---|
232 | }
|
---|
233 | }
|
---|
234 |
|
---|
235 | // New Galileo Ephemeris
|
---|
236 | ////////////////////////////////////////////////////////////////////////////
|
---|
237 | void t_bncCore::slotNewGalileoEph(t_ephGal eph) {
|
---|
238 | if (checkPrintEph(&eph) == success) {
|
---|
239 | emit newGalileoEph(eph);
|
---|
240 | }
|
---|
241 | }
|
---|
242 |
|
---|
243 | // New SBAS Ephemeris
|
---|
244 | ////////////////////////////////////////////////////////////////////////////
|
---|
245 | void t_bncCore::slotNewSBASEph(t_ephSBAS eph) {
|
---|
246 | if (checkPrintEph(&eph) == success) {
|
---|
247 | emit newSBASEph(eph);
|
---|
248 | }
|
---|
249 | }
|
---|
250 |
|
---|
251 | // New BDS Ephemeris
|
---|
252 | ////////////////////////////////////////////////////////////////////////////
|
---|
253 | void t_bncCore::slotNewBDSEph(t_ephBDS eph) {
|
---|
254 | if (checkPrintEph(&eph) == success) {
|
---|
255 | emit newBDSEph(eph);
|
---|
256 | }
|
---|
257 | }
|
---|
258 |
|
---|
259 | // Print Header of the output File(s)
|
---|
260 | ////////////////////////////////////////////////////////////////////////////
|
---|
261 | void t_bncCore::printEphHeader() {
|
---|
262 |
|
---|
263 | bncSettings settings;
|
---|
264 | QStringList comments;
|
---|
265 |
|
---|
266 | QListIterator<QString> it(settings.value("mountPoints").toStringList());
|
---|
267 | while (it.hasNext()) {
|
---|
268 | QStringList hlp = it.next().split(" ");
|
---|
269 | if (hlp.size() < 7)
|
---|
270 | continue;
|
---|
271 | QUrl url(hlp[0]);
|
---|
272 | QString decoder = hlp[1];
|
---|
273 | comments.append("Source: " + decoder +
|
---|
274 | " " + QUrl::toAce(url.host()) +
|
---|
275 | "/" + url.path().mid(1).toLatin1());
|
---|
276 | }
|
---|
277 |
|
---|
278 | // Initialization
|
---|
279 | // --------------
|
---|
280 | if (_rinexVers == 0) {
|
---|
281 |
|
---|
282 | if ( Qt::CheckState(settings.value("ephV3").toInt()) == Qt::Checked) {
|
---|
283 | _rinexVers = 3;
|
---|
284 | }
|
---|
285 | else {
|
---|
286 | _rinexVers = 2;
|
---|
287 | }
|
---|
288 |
|
---|
289 | _ephPath = settings.value("ephPath").toString();
|
---|
290 |
|
---|
291 | if ( !_ephPath.isEmpty() ) {
|
---|
292 | if ( _ephPath[_ephPath.length()-1] != QDir::separator() ) {
|
---|
293 | _ephPath += QDir::separator();
|
---|
294 | }
|
---|
295 | expandEnvVar(_ephPath);
|
---|
296 | }
|
---|
297 | }
|
---|
298 |
|
---|
299 | // (Re-)Open output File(s)
|
---|
300 | // ------------------------
|
---|
301 | if (!_ephPath.isEmpty()) {
|
---|
302 |
|
---|
303 | QDateTime datTim = currentDateAndTimeGPS();
|
---|
304 |
|
---|
305 | QString ephFileNameGPS = _ephPath + "BRDC";
|
---|
306 |
|
---|
307 | bool ephV3 = (_rinexVers == 3)? true : false;
|
---|
308 |
|
---|
309 | QString hlpStr = bncRinex::nextEpochStr(datTim,
|
---|
310 | settings.value("ephIntr").toString(), ephV3);
|
---|
311 |
|
---|
312 | if (_rinexVers == 3) {
|
---|
313 | QString country = "WRD"; // WORLD
|
---|
314 | QString monNum = "0";
|
---|
315 | QString recNum = "0";
|
---|
316 | ephFileNameGPS += QString("%1").arg(monNum, 1, 10) +
|
---|
317 | QString("%1").arg(recNum, 1, 10) +
|
---|
318 | country +
|
---|
319 | "_S_" + // stream
|
---|
320 | QString("%1").arg(datTim.date().year()) +
|
---|
321 | QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
|
---|
322 | hlpStr + // HM_period
|
---|
323 | "_MN.rnx"; // mixed BRDC
|
---|
324 | }
|
---|
325 | else { // RNX v2.11
|
---|
326 | ephFileNameGPS += QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
|
---|
327 | hlpStr + datTim.toString(".yyN");
|
---|
328 | }
|
---|
329 |
|
---|
330 | if (_ephFileNameGPS == ephFileNameGPS) {
|
---|
331 | return;
|
---|
332 | }
|
---|
333 | else {
|
---|
334 | _ephFileNameGPS = ephFileNameGPS;
|
---|
335 | }
|
---|
336 |
|
---|
337 | delete _ephStreamGPS;
|
---|
338 | delete _ephFileGPS;
|
---|
339 |
|
---|
340 | QFlags<QIODevice::OpenModeFlag> appendFlagGPS;
|
---|
341 | QFlags<QIODevice::OpenModeFlag> appendFlagGlonass;
|
---|
342 |
|
---|
343 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
|
---|
344 | QFile::exists(ephFileNameGPS) ) {
|
---|
345 | appendFlagGPS = QIODevice::Append;
|
---|
346 | }
|
---|
347 |
|
---|
348 | _ephFileGPS = new QFile(ephFileNameGPS);
|
---|
349 | _ephFileGPS->open(QIODevice::WriteOnly | appendFlagGPS);
|
---|
350 | _ephStreamGPS = new QTextStream();
|
---|
351 | _ephStreamGPS->setDevice(_ephFileGPS);
|
---|
352 |
|
---|
353 | if (_rinexVers == 3) {
|
---|
354 | _ephFileGlonass = _ephFileGPS;
|
---|
355 | _ephStreamGlonass = _ephStreamGPS;
|
---|
356 | _ephFileGalileo = _ephFileGPS;
|
---|
357 | _ephStreamGalileo = _ephStreamGPS;
|
---|
358 | _ephFileSBAS = _ephFileGPS;
|
---|
359 | _ephStreamSBAS = _ephStreamGPS;
|
---|
360 | }
|
---|
361 | else if (_rinexVers == 2) {
|
---|
362 | QString ephFileNameGlonass = _ephPath + "BRDC" +
|
---|
363 | QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
|
---|
364 | hlpStr + datTim.toString(".yyG");
|
---|
365 |
|
---|
366 | delete _ephStreamGlonass;
|
---|
367 | delete _ephFileGlonass;
|
---|
368 |
|
---|
369 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
|
---|
370 | QFile::exists(ephFileNameGlonass) ) {
|
---|
371 | appendFlagGlonass = QIODevice::Append;
|
---|
372 | }
|
---|
373 |
|
---|
374 | _ephFileGlonass = new QFile(ephFileNameGlonass);
|
---|
375 | _ephFileGlonass->open(QIODevice::WriteOnly | appendFlagGlonass);
|
---|
376 | _ephStreamGlonass = new QTextStream();
|
---|
377 | _ephStreamGlonass->setDevice(_ephFileGlonass);
|
---|
378 | }
|
---|
379 |
|
---|
380 | // Header - RINEX Version 3
|
---|
381 | // ------------------------
|
---|
382 | if (_rinexVers == 3) {
|
---|
383 | if ( ! (appendFlagGPS & QIODevice::Append)) {
|
---|
384 | QString line;
|
---|
385 | line.sprintf(
|
---|
386 | "%9.2f%11sN: GNSS NAV DATA M: Mixed%12sRINEX VERSION / TYPE\n",
|
---|
387 | defaultRnxNavVersion3, "", "");
|
---|
388 | *_ephStreamGPS << line;
|
---|
389 |
|
---|
390 | QString hlp = currentDateAndTimeGPS().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
|
---|
391 | *_ephStreamGPS << _pgmName.toLatin1().data()
|
---|
392 | << _userName.toLatin1().data()
|
---|
393 | << hlp.toLatin1().data()
|
---|
394 | << "PGM / RUN BY / DATE" << endl;
|
---|
395 |
|
---|
396 | QStringListIterator it(comments);
|
---|
397 | while (it.hasNext()) {
|
---|
398 | *_ephStreamGPS << it.next().trimmed().left(60).leftJustified(60) << "COMMENT\n";
|
---|
399 | }
|
---|
400 |
|
---|
401 | line.sprintf("%60sEND OF HEADER\n", "");
|
---|
402 | *_ephStreamGPS << line;
|
---|
403 |
|
---|
404 | _ephStreamGPS->flush();
|
---|
405 | }
|
---|
406 | }
|
---|
407 |
|
---|
408 | // Headers - RINEX Version 2
|
---|
409 | // -------------------------
|
---|
410 | else if (_rinexVers == 2) {
|
---|
411 | if (! (appendFlagGPS & QIODevice::Append)) {
|
---|
412 | QString line;
|
---|
413 | line.sprintf("%9.2f%11sN: GPS NAV DATA%25sRINEX VERSION / TYPE\n",
|
---|
414 | defaultRnxNavVersion2, "", "");
|
---|
415 | *_ephStreamGPS << line;
|
---|
416 |
|
---|
417 | QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
|
---|
418 | *_ephStreamGPS << _pgmName.toLatin1().data()
|
---|
419 | << _userName.toLatin1().data()
|
---|
420 | << hlp.toLatin1().data()
|
---|
421 | << "PGM / RUN BY / DATE" << endl;
|
---|
422 |
|
---|
423 | QStringListIterator it(comments);
|
---|
424 | while (it.hasNext()) {
|
---|
425 | *_ephStreamGPS << it.next().trimmed().left(60).leftJustified(60) << "COMMENT\n";
|
---|
426 | }
|
---|
427 |
|
---|
428 | line.sprintf("%60sEND OF HEADER\n", "");
|
---|
429 | *_ephStreamGPS << line;
|
---|
430 |
|
---|
431 | _ephStreamGPS->flush();
|
---|
432 | }
|
---|
433 | if (! (appendFlagGlonass & QIODevice::Append)) {
|
---|
434 | QString line;
|
---|
435 | line.sprintf("%9.2f%11sG: GLONASS NAV DATA%21sRINEX VERSION / TYPE\n",
|
---|
436 | defaultRnxNavVersion2, "", "");
|
---|
437 | *_ephStreamGlonass << line;
|
---|
438 |
|
---|
439 | QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
|
---|
440 | *_ephStreamGlonass << _pgmName.toLatin1().data()
|
---|
441 | << _userName.toLatin1().data()
|
---|
442 | << hlp.toLatin1().data()
|
---|
443 | << "PGM / RUN BY / DATE" << endl;
|
---|
444 |
|
---|
445 | QStringListIterator it(comments);
|
---|
446 | while (it.hasNext()) {
|
---|
447 | *_ephStreamGlonass << it.next().trimmed().left(60).leftJustified(60) << "COMMENT\n";
|
---|
448 | }
|
---|
449 |
|
---|
450 | line.sprintf("%60sEND OF HEADER\n", "");
|
---|
451 | *_ephStreamGlonass << line;
|
---|
452 |
|
---|
453 | _ephStreamGlonass->flush();
|
---|
454 | }
|
---|
455 | }
|
---|
456 | }
|
---|
457 | }
|
---|
458 |
|
---|
459 | // Print One Ephemeris
|
---|
460 | ////////////////////////////////////////////////////////////////////////////
|
---|
461 | void t_bncCore::printEph(const t_eph& eph, bool printFile) {
|
---|
462 |
|
---|
463 | QString strV2 = eph.toString(defaultRnxNavVersion2);
|
---|
464 | QString strV3 = eph.toString(defaultRnxObsVersion3);
|
---|
465 |
|
---|
466 | if (_rinexVers == 2 && eph.type() == t_eph::GLONASS) {
|
---|
467 | printOutputEph(printFile, _ephStreamGlonass, strV2, strV3);
|
---|
468 | }
|
---|
469 | else if(_rinexVers == 2 && eph.type() == t_eph::GPS) {
|
---|
470 | printOutputEph(printFile, _ephStreamGPS, strV2, strV3);
|
---|
471 | }
|
---|
472 | else if (_rinexVers == 3) {
|
---|
473 | printOutputEph(printFile, _ephStreamGPS, strV2, strV3);
|
---|
474 | }
|
---|
475 | }
|
---|
476 |
|
---|
477 | // Output
|
---|
478 | ////////////////////////////////////////////////////////////////////////////
|
---|
479 | void t_bncCore::printOutputEph(bool printFile, QTextStream* stream,
|
---|
480 | const QString& strV2, const QString& strV3) {
|
---|
481 |
|
---|
482 | // Output into file
|
---|
483 | // ----------------
|
---|
484 | if (printFile && stream) {
|
---|
485 | if (_rinexVers == 2) {
|
---|
486 | *stream << strV2.toLatin1();
|
---|
487 | }
|
---|
488 | else {
|
---|
489 | *stream << strV3.toLatin1();
|
---|
490 | }
|
---|
491 | stream->flush();
|
---|
492 | }
|
---|
493 |
|
---|
494 | // Output into the socket
|
---|
495 | // ----------------------
|
---|
496 | if (_socketsEph) {
|
---|
497 | QMutableListIterator<QTcpSocket*> is(*_socketsEph);
|
---|
498 | while (is.hasNext()) {
|
---|
499 | QTcpSocket* sock = is.next();
|
---|
500 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
---|
501 | if (sock->write(strV3.toLatin1()) == -1) {
|
---|
502 | delete sock;
|
---|
503 | is.remove();
|
---|
504 | }
|
---|
505 | }
|
---|
506 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
---|
507 | delete sock;
|
---|
508 | is.remove();
|
---|
509 | }
|
---|
510 | }
|
---|
511 | }
|
---|
512 | }
|
---|
513 |
|
---|
514 | // Set Port Number
|
---|
515 | ////////////////////////////////////////////////////////////////////////////
|
---|
516 | void t_bncCore::setPortEph(int port) {
|
---|
517 | _portEph = port;
|
---|
518 | if (_portEph != 0) {
|
---|
519 | delete _serverEph;
|
---|
520 | _serverEph = new QTcpServer;
|
---|
521 | if ( !_serverEph->listen(QHostAddress::Any, _portEph) ) {
|
---|
522 | slotMessage("t_bncCore: Cannot listen on ephemeris port", true);
|
---|
523 | }
|
---|
524 | connect(_serverEph, SIGNAL(newConnection()), this, SLOT(slotNewConnectionEph()));
|
---|
525 | delete _socketsEph;
|
---|
526 | _socketsEph = new QList<QTcpSocket*>;
|
---|
527 | }
|
---|
528 | }
|
---|
529 |
|
---|
530 | // Set Port Number
|
---|
531 | ////////////////////////////////////////////////////////////////////////////
|
---|
532 | void t_bncCore::setPortCorr(int port) {
|
---|
533 | _portCorr = port;
|
---|
534 | if (_portCorr != 0) {
|
---|
535 | delete _serverCorr;
|
---|
536 | _serverCorr = new QTcpServer;
|
---|
537 | if ( !_serverCorr->listen(QHostAddress::Any, _portCorr) ) {
|
---|
538 | slotMessage("t_bncCore: Cannot listen on correction port", true);
|
---|
539 | }
|
---|
540 | connect(_serverCorr, SIGNAL(newConnection()), this, SLOT(slotNewConnectionCorr()));
|
---|
541 | delete _socketsCorr;
|
---|
542 | _socketsCorr = new QList<QTcpSocket*>;
|
---|
543 | }
|
---|
544 | }
|
---|
545 |
|
---|
546 | // New Connection
|
---|
547 | ////////////////////////////////////////////////////////////////////////////
|
---|
548 | void t_bncCore::slotNewConnectionEph() {
|
---|
549 | _socketsEph->push_back( _serverEph->nextPendingConnection() );
|
---|
550 | }
|
---|
551 |
|
---|
552 | // New Connection
|
---|
553 | ////////////////////////////////////////////////////////////////////////////
|
---|
554 | void t_bncCore::slotNewConnectionCorr() {
|
---|
555 | _socketsCorr->push_back( _serverCorr->nextPendingConnection() );
|
---|
556 | }
|
---|
557 |
|
---|
558 | //
|
---|
559 | ////////////////////////////////////////////////////////////////////////////
|
---|
560 | void t_bncCore::slotQuit() {
|
---|
561 | delete _caster; _caster = 0;
|
---|
562 | qApp->quit();
|
---|
563 | }
|
---|
564 |
|
---|
565 | //
|
---|
566 | ////////////////////////////////////////////////////////////////////////////
|
---|
567 | void t_bncCore::slotNewOrbCorrections(QList<t_orbCorr> orbCorrections) {
|
---|
568 | QMutexLocker locker(&_mutex);
|
---|
569 | emit newOrbCorrections(orbCorrections);
|
---|
570 | if (_socketsCorr) {
|
---|
571 | ostringstream out;
|
---|
572 | t_orbCorr::writeEpoch(&out, orbCorrections);
|
---|
573 | QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
|
---|
574 | while (is.hasNext()) {
|
---|
575 | QTcpSocket* sock = is.next();
|
---|
576 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
---|
577 | if (sock->write(out.str().c_str()) == -1) {
|
---|
578 | delete sock;
|
---|
579 | is.remove();
|
---|
580 | }
|
---|
581 | }
|
---|
582 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
---|
583 | delete sock;
|
---|
584 | is.remove();
|
---|
585 | }
|
---|
586 | }
|
---|
587 | }
|
---|
588 | }
|
---|
589 |
|
---|
590 | //
|
---|
591 | ////////////////////////////////////////////////////////////////////////////
|
---|
592 | void t_bncCore::slotNewClkCorrections(QList<t_clkCorr> clkCorrections) {
|
---|
593 | QMutexLocker locker(&_mutex);
|
---|
594 | emit newClkCorrections(clkCorrections);
|
---|
595 | if (_socketsCorr) {
|
---|
596 | ostringstream out;
|
---|
597 | t_clkCorr::writeEpoch(&out, clkCorrections);
|
---|
598 | QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
|
---|
599 | while (is.hasNext()) {
|
---|
600 | QTcpSocket* sock = is.next();
|
---|
601 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
---|
602 | if (sock->write(out.str().c_str()) == -1) {
|
---|
603 | delete sock;
|
---|
604 | is.remove();
|
---|
605 | }
|
---|
606 | }
|
---|
607 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
---|
608 | delete sock;
|
---|
609 | is.remove();
|
---|
610 | }
|
---|
611 | }
|
---|
612 | }
|
---|
613 | }
|
---|
614 |
|
---|
615 | //
|
---|
616 | ////////////////////////////////////////////////////////////////////////////
|
---|
617 | void t_bncCore::slotNewCodeBiases(QList<t_satCodeBias> codeBiases) {
|
---|
618 | QMutexLocker locker(&_mutex);
|
---|
619 | emit newCodeBiases(codeBiases);
|
---|
620 | if (_socketsCorr) {
|
---|
621 | ostringstream out;
|
---|
622 | t_satCodeBias::writeEpoch(&out, codeBiases);
|
---|
623 | QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
|
---|
624 | while (is.hasNext()) {
|
---|
625 | QTcpSocket* sock = is.next();
|
---|
626 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
---|
627 | if (sock->write(out.str().c_str()) == -1) {
|
---|
628 | delete sock;
|
---|
629 | is.remove();
|
---|
630 | }
|
---|
631 | }
|
---|
632 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
---|
633 | delete sock;
|
---|
634 | is.remove();
|
---|
635 | }
|
---|
636 | }
|
---|
637 | }
|
---|
638 | }
|
---|
639 |
|
---|
640 | //
|
---|
641 | ////////////////////////////////////////////////////////////////////////////
|
---|
642 | void t_bncCore::slotNewPhaseBiases(QList<t_satPhaseBias> phaseBiases) {
|
---|
643 | QMutexLocker locker(&_mutex);
|
---|
644 | emit newPhaseBiases(phaseBiases);
|
---|
645 | if (_socketsCorr) {
|
---|
646 | ostringstream out;
|
---|
647 | t_satPhaseBias::writeEpoch(&out, phaseBiases);
|
---|
648 | QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
|
---|
649 | while (is.hasNext()) {
|
---|
650 | QTcpSocket* sock = is.next();
|
---|
651 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
---|
652 | if (sock->write(out.str().c_str()) == -1) {
|
---|
653 | delete sock;
|
---|
654 | is.remove();
|
---|
655 | }
|
---|
656 | }
|
---|
657 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
---|
658 | delete sock;
|
---|
659 | is.remove();
|
---|
660 | }
|
---|
661 | }
|
---|
662 | }
|
---|
663 | }
|
---|
664 |
|
---|
665 | //
|
---|
666 | ////////////////////////////////////////////////////////////////////////////
|
---|
667 | void t_bncCore::slotNewTec(t_vTec vTec) {
|
---|
668 | QMutexLocker locker(&_mutex);
|
---|
669 | emit newTec(vTec);
|
---|
670 | if (_socketsCorr) {
|
---|
671 | ostringstream out;
|
---|
672 | t_vTec::write(&out, vTec);
|
---|
673 | QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
|
---|
674 | while (is.hasNext()) {
|
---|
675 | QTcpSocket* sock = is.next();
|
---|
676 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
---|
677 | if (sock->write(out.str().c_str()) == -1) {
|
---|
678 | delete sock;
|
---|
679 | is.remove();
|
---|
680 | }
|
---|
681 | }
|
---|
682 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
---|
683 | delete sock;
|
---|
684 | is.remove();
|
---|
685 | }
|
---|
686 | }
|
---|
687 | }
|
---|
688 | }
|
---|
689 |
|
---|
690 | //
|
---|
691 | ////////////////////////////////////////////////////////////////////////////
|
---|
692 | void t_bncCore::setConfFileName(const QString& confFileName) {
|
---|
693 | if (confFileName.isEmpty()) {
|
---|
694 | _confFileName = QDir::homePath() + QDir::separator()
|
---|
695 | + ".config" + QDir::separator()
|
---|
696 | + qApp->organizationName() + QDir::separator()
|
---|
697 | + qApp->applicationName() + ".bnc";
|
---|
698 | }
|
---|
699 | else {
|
---|
700 | _confFileName = confFileName;
|
---|
701 | }
|
---|
702 | }
|
---|
703 |
|
---|
704 | // Raw Output
|
---|
705 | ////////////////////////////////////////////////////////////////////////////
|
---|
706 | void t_bncCore::writeRawData(const QByteArray& data, const QByteArray& staID,
|
---|
707 | const QByteArray& format) {
|
---|
708 |
|
---|
709 | QMutexLocker locker(&_mutex);
|
---|
710 |
|
---|
711 | if (!_rawFile) {
|
---|
712 | bncSettings settings;
|
---|
713 | QByteArray fileName = settings.value("rawOutFile").toByteArray();
|
---|
714 | if (!fileName.isEmpty()) {
|
---|
715 | _rawFile = new bncRawFile(fileName, staID, bncRawFile::output);
|
---|
716 | }
|
---|
717 | }
|
---|
718 |
|
---|
719 | if (_rawFile) {
|
---|
720 | _rawFile->writeRawData(data, staID, format);
|
---|
721 | }
|
---|
722 | }
|
---|
723 |
|
---|
724 | //
|
---|
725 | ////////////////////////////////////////////////////////////////////////////
|
---|
726 | void t_bncCore::initCombination() {
|
---|
727 | _bncComb = new bncComb();
|
---|
728 | if (_bncComb->nStreams() < 1) {
|
---|
729 | delete _bncComb;
|
---|
730 | _bncComb = 0;
|
---|
731 | }
|
---|
732 | }
|
---|
733 |
|
---|
734 | //
|
---|
735 | ////////////////////////////////////////////////////////////////////////////
|
---|
736 | void t_bncCore::stopCombination() {
|
---|
737 | delete _bncComb;
|
---|
738 | _bncComb = 0;
|
---|
739 | }
|
---|
740 |
|
---|
741 | //
|
---|
742 | ////////////////////////////////////////////////////////////////////////////
|
---|
743 | bool t_bncCore::dateAndTimeGPSSet() const {
|
---|
744 | QMutexLocker locker(&_mutexDateAndTimeGPS);
|
---|
745 | if (_dateAndTimeGPS) {
|
---|
746 | return true;
|
---|
747 | }
|
---|
748 | else {
|
---|
749 | return false;
|
---|
750 | }
|
---|
751 | }
|
---|
752 |
|
---|
753 | //
|
---|
754 | ////////////////////////////////////////////////////////////////////////////
|
---|
755 | QDateTime t_bncCore::dateAndTimeGPS() const {
|
---|
756 | QMutexLocker locker(&_mutexDateAndTimeGPS);
|
---|
757 | if (_dateAndTimeGPS) {
|
---|
758 | return *_dateAndTimeGPS;
|
---|
759 | }
|
---|
760 | else {
|
---|
761 | return QDateTime();
|
---|
762 | }
|
---|
763 | }
|
---|
764 |
|
---|
765 | //
|
---|
766 | ////////////////////////////////////////////////////////////////////////////
|
---|
767 | void t_bncCore::setDateAndTimeGPS(QDateTime dateTime) {
|
---|
768 | QMutexLocker locker(&_mutexDateAndTimeGPS);
|
---|
769 | delete _dateAndTimeGPS;
|
---|
770 | _dateAndTimeGPS = new QDateTime(dateTime);
|
---|
771 | }
|
---|
772 |
|
---|
773 | //
|
---|
774 | ////////////////////////////////////////////////////////////////////////////
|
---|
775 | void t_bncCore::startPPP() {
|
---|
776 | _pppMain->start();
|
---|
777 | }
|
---|
778 |
|
---|
779 | //
|
---|
780 | ////////////////////////////////////////////////////////////////////////////
|
---|
781 | void t_bncCore::stopPPP() {
|
---|
782 | _pppMain->stop();
|
---|
783 | emit stopRinexPPP();
|
---|
784 | }
|
---|
785 |
|
---|