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