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