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