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