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