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: bncApp
|
---|
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 <QMessageBox>
|
---|
43 | #include <cmath>
|
---|
44 |
|
---|
45 | #include "bncapp.h"
|
---|
46 | #include "bncutils.h"
|
---|
47 | #include "bncrinex.h"
|
---|
48 | #include "bncsettings.h"
|
---|
49 | #include "bncversion.h"
|
---|
50 | #include "RTCM3/ephemeris.h"
|
---|
51 |
|
---|
52 | #ifdef USE_COMBINATION
|
---|
53 | #include "combination/bnccomb.h"
|
---|
54 | #endif
|
---|
55 |
|
---|
56 | using namespace std;
|
---|
57 |
|
---|
58 | // Constructor
|
---|
59 | ////////////////////////////////////////////////////////////////////////////
|
---|
60 | bncApp::bncApp(int& argc, char* argv[], bool GUIenabled) :
|
---|
61 | QApplication(argc, argv, GUIenabled) {
|
---|
62 |
|
---|
63 | _GUIenabled = GUIenabled;
|
---|
64 | _logFileFlag = 0;
|
---|
65 | _logFile = 0;
|
---|
66 | _logStream = 0;
|
---|
67 | _caster = 0;
|
---|
68 | _rawFile = 0;
|
---|
69 | #ifdef USE_COMBINATION
|
---|
70 | _bncComb = 0;
|
---|
71 | #endif
|
---|
72 |
|
---|
73 | // Lists of Ephemeris
|
---|
74 | // ------------------
|
---|
75 | for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
|
---|
76 | _gpsEph[ii-PRN_GPS_START] = 0;
|
---|
77 | }
|
---|
78 | for (int ii = PRN_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
|
---|
79 | _glonassEph[ii-PRN_GLONASS_START] = 0;
|
---|
80 | }
|
---|
81 | for (int ii = PRN_GALILEO_START; ii <= PRN_GALILEO_END; ii++) {
|
---|
82 | _galileoEph[ii-PRN_GALILEO_START] = 0;
|
---|
83 | }
|
---|
84 |
|
---|
85 | // Eph file(s)
|
---|
86 | // -----------
|
---|
87 | _rinexVers = 0;
|
---|
88 | _ephFileGPS = 0;
|
---|
89 | _ephStreamGPS = 0;
|
---|
90 | _ephFileGlonass = 0;
|
---|
91 | _ephStreamGlonass = 0;
|
---|
92 | _ephFileGalileo = 0;
|
---|
93 | _ephStreamGalileo = 0;
|
---|
94 |
|
---|
95 | _port = 0;
|
---|
96 | _server = 0;
|
---|
97 | _sockets = 0;
|
---|
98 |
|
---|
99 | _portCorr = 0;
|
---|
100 | _serverCorr = 0;
|
---|
101 | _socketsCorr = 0;
|
---|
102 |
|
---|
103 | _pgmName = QString(BNCPGMNAME).leftJustified(20, ' ', true);
|
---|
104 | #ifdef WIN32
|
---|
105 | _userName = QString("${USERNAME}");
|
---|
106 | #else
|
---|
107 | _userName = QString("${USER}");
|
---|
108 | #endif
|
---|
109 | expandEnvVar(_userName);
|
---|
110 | _userName = _userName.leftJustified(20, ' ', true);
|
---|
111 |
|
---|
112 | _lastDumpCoSec = 0;
|
---|
113 |
|
---|
114 | _corrs = new QMultiMap<long, QString>;
|
---|
115 |
|
---|
116 | _currentDateAndTimeGPS = 0;
|
---|
117 |
|
---|
118 | for (int ii = 0; ii < PRN_GLONASS_NUM; ++ii) {
|
---|
119 | _GLOFreq[ii] = 0;
|
---|
120 | }
|
---|
121 |
|
---|
122 | _bncPPPclient = 0;
|
---|
123 |
|
---|
124 | _mainWindow = 0;
|
---|
125 | }
|
---|
126 |
|
---|
127 | // Destructor
|
---|
128 | ////////////////////////////////////////////////////////////////////////////
|
---|
129 | bncApp::~bncApp() {
|
---|
130 | delete _logStream;
|
---|
131 | delete _logFile;
|
---|
132 | delete _ephStreamGPS;
|
---|
133 | delete _ephFileGPS;
|
---|
134 | delete _server;
|
---|
135 | delete _sockets;
|
---|
136 | delete _serverCorr;
|
---|
137 | delete _socketsCorr;
|
---|
138 | if (_rinexVers == 2) {
|
---|
139 | delete _ephStreamGlonass;
|
---|
140 | delete _ephFileGlonass;
|
---|
141 | }
|
---|
142 | for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
|
---|
143 | delete _gpsEph[ii-PRN_GPS_START];
|
---|
144 | }
|
---|
145 | for (int ii = PRN_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
|
---|
146 | delete _glonassEph[ii-PRN_GLONASS_START];
|
---|
147 | }
|
---|
148 | for (int ii = PRN_GALILEO_START; ii <= PRN_GALILEO_END; ii++) {
|
---|
149 | delete _galileoEph[ii-PRN_GALILEO_START];
|
---|
150 | }
|
---|
151 |
|
---|
152 | delete _corrs;
|
---|
153 |
|
---|
154 | delete _currentDateAndTimeGPS;
|
---|
155 |
|
---|
156 | delete _rawFile;
|
---|
157 |
|
---|
158 | #ifdef USE_COMBINATION
|
---|
159 | delete _bncComb;
|
---|
160 | #endif
|
---|
161 | }
|
---|
162 |
|
---|
163 | // Write a Program Message
|
---|
164 | ////////////////////////////////////////////////////////////////////////////
|
---|
165 | void bncApp::slotMessage(QByteArray msg, bool showOnScreen) {
|
---|
166 |
|
---|
167 | QMutexLocker locker(&_mutexMessage);
|
---|
168 |
|
---|
169 | messagePrivate(msg);
|
---|
170 | emit newMessage(msg, showOnScreen);
|
---|
171 | }
|
---|
172 |
|
---|
173 | // Write a Program Message (private, no lock)
|
---|
174 | ////////////////////////////////////////////////////////////////////////////
|
---|
175 | void bncApp::messagePrivate(const QByteArray& msg) {
|
---|
176 |
|
---|
177 | // First time resolve the log file name
|
---|
178 | // ------------------------------------
|
---|
179 | QDate currDate = currentDateAndTimeGPS().date();
|
---|
180 | if (_logFileFlag == 0 || _fileDate != currDate) {
|
---|
181 | delete _logStream; _logStream = 0;
|
---|
182 | delete _logFile; _logFile = 0;
|
---|
183 | _logFileFlag = 1;
|
---|
184 | bncSettings settings;
|
---|
185 | QString logFileName = settings.value("logFile").toString();
|
---|
186 | if ( !logFileName.isEmpty() ) {
|
---|
187 | expandEnvVar(logFileName);
|
---|
188 | _logFile = new QFile(logFileName + "_" +
|
---|
189 | currDate.toString("yyMMdd").toAscii().data());
|
---|
190 | _fileDate = currDate;
|
---|
191 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
|
---|
192 | _logFile->open(QIODevice::WriteOnly | QIODevice::Append);
|
---|
193 | }
|
---|
194 | else {
|
---|
195 | _logFile->open(QIODevice::WriteOnly);
|
---|
196 | }
|
---|
197 | _logStream = new QTextStream();
|
---|
198 | _logStream->setDevice(_logFile);
|
---|
199 | }
|
---|
200 | }
|
---|
201 |
|
---|
202 | if (_logStream) {
|
---|
203 | QByteArray msgLocal = msg;
|
---|
204 | if (msg.indexOf('\n') == 0) {
|
---|
205 | *_logStream << endl;
|
---|
206 | msgLocal = msg.mid(1);
|
---|
207 | }
|
---|
208 | *_logStream << currentDateAndTimeGPS().toString("yy-MM-dd hh:mm:ss ").toAscii().data();
|
---|
209 | *_logStream << msgLocal.data() << endl;
|
---|
210 | _logStream->flush();
|
---|
211 | _logFile->flush();
|
---|
212 | }
|
---|
213 | }
|
---|
214 |
|
---|
215 | // New GPS Ephemeris
|
---|
216 | ////////////////////////////////////////////////////////////////////////////
|
---|
217 | void bncApp::slotNewGPSEph(gpsephemeris* gpseph) {
|
---|
218 |
|
---|
219 | QMutexLocker locker(&_mutex);
|
---|
220 |
|
---|
221 | gpsephemeris copy_gpseph = *gpseph;
|
---|
222 | emit newEphGPS(copy_gpseph);
|
---|
223 |
|
---|
224 | printEphHeader();
|
---|
225 |
|
---|
226 | gpsephemeris** ee = &_gpsEph[gpseph->satellite-1];
|
---|
227 |
|
---|
228 | if ( *ee != 0 &&
|
---|
229 | gpseph->GPSweek == (*ee)->GPSweek && gpseph->TOC == (*ee)->TOC ) {
|
---|
230 | checkEphemeris(*ee, gpseph);
|
---|
231 | }
|
---|
232 |
|
---|
233 | if ( *ee == 0 ||
|
---|
234 | gpseph->GPSweek > (*ee)->GPSweek ||
|
---|
235 | (gpseph->GPSweek == (*ee)->GPSweek && gpseph->TOC > (*ee)->TOC) ) {
|
---|
236 | delete *ee;
|
---|
237 | *ee = gpseph;
|
---|
238 | printGPSEph(gpseph, true);
|
---|
239 | }
|
---|
240 | else {
|
---|
241 | printGPSEph(gpseph, false);
|
---|
242 | delete gpseph;
|
---|
243 | }
|
---|
244 | }
|
---|
245 |
|
---|
246 | // New Glonass Ephemeris
|
---|
247 | ////////////////////////////////////////////////////////////////////////////
|
---|
248 | void bncApp::slotNewGlonassEph(glonassephemeris* glonasseph) {
|
---|
249 |
|
---|
250 | QMutexLocker locker(&_mutex);
|
---|
251 |
|
---|
252 | // Check wrong Ephemerides
|
---|
253 | // -----------------------
|
---|
254 | if (glonasseph->x_pos == 0.0 &&
|
---|
255 | glonasseph->y_pos == 0.0 &&
|
---|
256 | glonasseph->z_pos == 0.0) {
|
---|
257 | delete glonasseph;
|
---|
258 | return;
|
---|
259 | }
|
---|
260 |
|
---|
261 | glonassephemeris copy_glonasseph = *glonasseph;
|
---|
262 | emit newEphGlonass(copy_glonasseph);
|
---|
263 |
|
---|
264 | printEphHeader();
|
---|
265 |
|
---|
266 | glonassephemeris** ee = &_glonassEph[glonasseph->almanac_number-1];
|
---|
267 |
|
---|
268 | int wwOld, towOld, wwNew, towNew;
|
---|
269 | if (*ee != 0) {
|
---|
270 | wwOld = (*ee)->GPSWeek;
|
---|
271 | towOld = (*ee)->GPSTOW;
|
---|
272 | updatetime(&wwOld, &towOld, (*ee)->tb*1000, 0); // Moscow -> GPS
|
---|
273 |
|
---|
274 | wwNew = glonasseph->GPSWeek;
|
---|
275 | towNew = glonasseph->GPSTOW;
|
---|
276 | updatetime(&wwNew, &towNew, glonasseph->tb*1000, 0); // Moscow -> GPS
|
---|
277 | }
|
---|
278 |
|
---|
279 | if ( *ee == 0 ||
|
---|
280 | wwNew > wwOld ||
|
---|
281 | (wwNew == wwOld && towNew > towOld) ) {
|
---|
282 | delete *ee;
|
---|
283 | *ee = glonasseph;
|
---|
284 | printGlonassEph(glonasseph, true);
|
---|
285 | }
|
---|
286 | else {
|
---|
287 | printGlonassEph(glonasseph, false);
|
---|
288 | delete glonasseph;
|
---|
289 | }
|
---|
290 | }
|
---|
291 |
|
---|
292 | // New Galileo Ephemeris
|
---|
293 | ////////////////////////////////////////////////////////////////////////////
|
---|
294 | void bncApp::slotNewGalileoEph(galileoephemeris* galileoeph) {
|
---|
295 |
|
---|
296 | QMutexLocker locker(&_mutex);
|
---|
297 |
|
---|
298 | galileoephemeris copy_galileoeph = *galileoeph;
|
---|
299 | emit newEphGalileo(copy_galileoeph);
|
---|
300 |
|
---|
301 | printEphHeader();
|
---|
302 |
|
---|
303 | int galIndex = galileoeph->satellite;
|
---|
304 | /* GIOVE */
|
---|
305 | if(galIndex == 51) galIndex = 1;
|
---|
306 | else if(galIndex == 52) galIndex = 16;
|
---|
307 | if (galIndex < 0 || galIndex > PRN_GALILEO_END - PRN_GALILEO_START) {
|
---|
308 | emit( newMessage("Wrong Galileo Satellite Number", true) );
|
---|
309 | exit(1);
|
---|
310 | }
|
---|
311 |
|
---|
312 | galileoephemeris** ee = &_galileoEph[galIndex];
|
---|
313 |
|
---|
314 | if ( *ee == 0 ||
|
---|
315 | galileoeph->Week > (*ee)->Week ||
|
---|
316 | (galileoeph->Week == (*ee)->Week && galileoeph->TOC > (*ee)->TOC) ) {
|
---|
317 | delete *ee;
|
---|
318 | *ee = galileoeph;
|
---|
319 | printGalileoEph(galileoeph, true);
|
---|
320 | }
|
---|
321 | else {
|
---|
322 | printGalileoEph(galileoeph, false);
|
---|
323 | delete galileoeph;
|
---|
324 | }
|
---|
325 | }
|
---|
326 |
|
---|
327 | // Print Header of the output File(s)
|
---|
328 | ////////////////////////////////////////////////////////////////////////////
|
---|
329 | void bncApp::printEphHeader() {
|
---|
330 |
|
---|
331 | bncSettings settings;
|
---|
332 |
|
---|
333 | // Initialization
|
---|
334 | // --------------
|
---|
335 | if (_rinexVers == 0) {
|
---|
336 |
|
---|
337 | if ( Qt::CheckState(settings.value("ephV3").toInt()) == Qt::Checked) {
|
---|
338 | _rinexVers = 3;
|
---|
339 | }
|
---|
340 | else {
|
---|
341 | _rinexVers = 2;
|
---|
342 | }
|
---|
343 |
|
---|
344 | _ephPath = settings.value("ephPath").toString();
|
---|
345 |
|
---|
346 | if ( !_ephPath.isEmpty() ) {
|
---|
347 | if ( _ephPath[_ephPath.length()-1] != QDir::separator() ) {
|
---|
348 | _ephPath += QDir::separator();
|
---|
349 | }
|
---|
350 | expandEnvVar(_ephPath);
|
---|
351 | }
|
---|
352 | }
|
---|
353 |
|
---|
354 | // (Re-)Open output File(s)
|
---|
355 | // ------------------------
|
---|
356 | if (!_ephPath.isEmpty()) {
|
---|
357 |
|
---|
358 | QDateTime datTim = currentDateAndTimeGPS();
|
---|
359 |
|
---|
360 | QString ephFileNameGPS = _ephPath + "BRDC" +
|
---|
361 | QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0'));
|
---|
362 |
|
---|
363 | QString hlpStr = bncRinex::nextEpochStr(datTim,
|
---|
364 | settings.value("ephIntr").toString());
|
---|
365 |
|
---|
366 | if (_rinexVers == 3) {
|
---|
367 | ephFileNameGPS += hlpStr + datTim.toString(".yyP");
|
---|
368 | }
|
---|
369 | else {
|
---|
370 | ephFileNameGPS += hlpStr + datTim.toString(".yyN");
|
---|
371 | }
|
---|
372 |
|
---|
373 | if (_ephFileNameGPS == ephFileNameGPS) {
|
---|
374 | return;
|
---|
375 | }
|
---|
376 | else {
|
---|
377 | _ephFileNameGPS = ephFileNameGPS;
|
---|
378 | }
|
---|
379 |
|
---|
380 | for (int ii = PRN_GPS_START; ii <= PRN_GPS_END; ii++) {
|
---|
381 | delete _gpsEph[ii-PRN_GPS_START];
|
---|
382 | _gpsEph[ii-PRN_GPS_START] = 0;
|
---|
383 | }
|
---|
384 | for (int ii = PRN_GLONASS_START; ii <= PRN_GLONASS_END; ii++) {
|
---|
385 | delete _glonassEph[ii-PRN_GLONASS_START];
|
---|
386 | _glonassEph[ii-PRN_GLONASS_START] = 0;
|
---|
387 | }
|
---|
388 | for (int ii = PRN_GALILEO_START; ii <= PRN_GALILEO_END; ii++) {
|
---|
389 | delete _galileoEph[ii-PRN_GALILEO_START];
|
---|
390 | _galileoEph[ii-PRN_GALILEO_START] = 0;
|
---|
391 | }
|
---|
392 |
|
---|
393 | delete _ephStreamGPS;
|
---|
394 | delete _ephFileGPS;
|
---|
395 |
|
---|
396 | QFlags<QIODevice::OpenModeFlag> appendFlagGPS;
|
---|
397 | QFlags<QIODevice::OpenModeFlag> appendFlagGlonass;
|
---|
398 | QFlags<QIODevice::OpenModeFlag> appendFlagGalileo;
|
---|
399 |
|
---|
400 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
|
---|
401 | QFile::exists(ephFileNameGPS) ) {
|
---|
402 | appendFlagGPS = QIODevice::Append;
|
---|
403 | }
|
---|
404 |
|
---|
405 | _ephFileGPS = new QFile(ephFileNameGPS);
|
---|
406 | _ephFileGPS->open(QIODevice::WriteOnly | appendFlagGPS);
|
---|
407 | _ephStreamGPS = new QTextStream();
|
---|
408 | _ephStreamGPS->setDevice(_ephFileGPS);
|
---|
409 |
|
---|
410 | if (_rinexVers == 3) {
|
---|
411 | _ephFileGlonass = _ephFileGPS;
|
---|
412 | _ephStreamGlonass = _ephStreamGPS;
|
---|
413 | _ephFileGalileo = _ephFileGPS;
|
---|
414 | _ephStreamGalileo = _ephStreamGPS;
|
---|
415 | }
|
---|
416 | else if (_rinexVers == 2) {
|
---|
417 | QString ephFileNameGlonass = _ephPath + "BRDC" +
|
---|
418 | QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
|
---|
419 | hlpStr + datTim.toString(".yyG");
|
---|
420 |
|
---|
421 | delete _ephStreamGlonass;
|
---|
422 | delete _ephFileGlonass;
|
---|
423 |
|
---|
424 | if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked &&
|
---|
425 | QFile::exists(ephFileNameGlonass) ) {
|
---|
426 | appendFlagGlonass = QIODevice::Append;
|
---|
427 | }
|
---|
428 |
|
---|
429 | _ephFileGlonass = new QFile(ephFileNameGlonass);
|
---|
430 | _ephFileGlonass->open(QIODevice::WriteOnly | appendFlagGlonass);
|
---|
431 | _ephStreamGlonass = new QTextStream();
|
---|
432 | _ephStreamGlonass->setDevice(_ephFileGlonass);
|
---|
433 | }
|
---|
434 |
|
---|
435 | // Header - RINEX Version 3
|
---|
436 | // ------------------------
|
---|
437 | if (_rinexVers == 3) {
|
---|
438 | if ( ! (appendFlagGPS & QIODevice::Append)) {
|
---|
439 | QString line;
|
---|
440 | line.sprintf(
|
---|
441 | "%9.2f%11sN: GNSS NAV DATA M: Mixed%12sRINEX VERSION / TYPE\n",
|
---|
442 | 3.0, "", "");
|
---|
443 | *_ephStreamGPS << line;
|
---|
444 |
|
---|
445 | QString hlp = currentDateAndTimeGPS().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
|
---|
446 | *_ephStreamGPS << _pgmName.toAscii().data()
|
---|
447 | << _userName.toAscii().data()
|
---|
448 | << hlp.toAscii().data()
|
---|
449 | << "PGM / RUN BY / DATE" << endl;
|
---|
450 |
|
---|
451 | line.sprintf("%60sEND OF HEADER\n", "");
|
---|
452 | *_ephStreamGPS << line;
|
---|
453 |
|
---|
454 | _ephStreamGPS->flush();
|
---|
455 | }
|
---|
456 | }
|
---|
457 |
|
---|
458 | // Headers - RINEX Version 2
|
---|
459 | // -------------------------
|
---|
460 | else if (_rinexVers == 2) {
|
---|
461 | if (! (appendFlagGPS & QIODevice::Append)) {
|
---|
462 | QString line;
|
---|
463 | line.sprintf(
|
---|
464 | "%9.2f%11sN: GPS NAV DATA%25sRINEX VERSION / TYPE\n", 2.10, "", "");
|
---|
465 | *_ephStreamGPS << line;
|
---|
466 |
|
---|
467 | QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
|
---|
468 | *_ephStreamGPS << _pgmName.toAscii().data()
|
---|
469 | << _userName.toAscii().data()
|
---|
470 | << hlp.toAscii().data()
|
---|
471 | << "PGM / RUN BY / DATE" << endl;
|
---|
472 |
|
---|
473 | line.sprintf("%60sEND OF HEADER\n", "");
|
---|
474 | *_ephStreamGPS << line;
|
---|
475 |
|
---|
476 | _ephStreamGPS->flush();
|
---|
477 | }
|
---|
478 | if (! (appendFlagGlonass & QIODevice::Append)) {
|
---|
479 | QString line;
|
---|
480 | line.sprintf(
|
---|
481 | "%9.2f%11sG: GLONASS NAV DATA%21sRINEX VERSION / TYPE\n",2.10,"","");
|
---|
482 | *_ephStreamGlonass << line;
|
---|
483 |
|
---|
484 | QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
|
---|
485 | *_ephStreamGlonass << _pgmName.toAscii().data()
|
---|
486 | << _userName.toAscii().data()
|
---|
487 | << hlp.toAscii().data()
|
---|
488 | << "PGM / RUN BY / DATE" << endl;
|
---|
489 |
|
---|
490 | line.sprintf("%60sEND OF HEADER\n", "");
|
---|
491 | *_ephStreamGlonass << line;
|
---|
492 |
|
---|
493 | _ephStreamGlonass->flush();
|
---|
494 | }
|
---|
495 | }
|
---|
496 | }
|
---|
497 | }
|
---|
498 |
|
---|
499 | // Print One GPS Ephemeris
|
---|
500 | ////////////////////////////////////////////////////////////////////////////
|
---|
501 | void bncApp::printGPSEph(gpsephemeris* ep, bool printFile) {
|
---|
502 |
|
---|
503 | t_ephGPS eph;
|
---|
504 | eph.set(ep);
|
---|
505 |
|
---|
506 | QString strV2 = eph.toString(2.11);
|
---|
507 | QString strV3 = eph.toString(3.01);
|
---|
508 |
|
---|
509 | printOutput(printFile, _ephStreamGPS, strV2, strV3);
|
---|
510 | }
|
---|
511 |
|
---|
512 | // Print One Glonass Ephemeris
|
---|
513 | ////////////////////////////////////////////////////////////////////////////
|
---|
514 | void bncApp::printGlonassEph(glonassephemeris* ep, bool printFile) {
|
---|
515 |
|
---|
516 | t_ephGlo eph;
|
---|
517 | bool timeChanged;
|
---|
518 | eph.set(ep, timeChanged);
|
---|
519 |
|
---|
520 | QString strV2 = eph.toString(2.11);
|
---|
521 | QString strV3 = eph.toString(3.01);
|
---|
522 |
|
---|
523 | printOutput(printFile, _ephStreamGlonass, strV2, strV3);
|
---|
524 | }
|
---|
525 |
|
---|
526 | // Print One Galileo Ephemeris
|
---|
527 | ////////////////////////////////////////////////////////////////////////////
|
---|
528 | void bncApp::printGalileoEph(galileoephemeris* ep, bool printFile) {
|
---|
529 |
|
---|
530 | t_ephGal eph;
|
---|
531 | eph.set(ep);
|
---|
532 |
|
---|
533 | QString strV2 = eph.toString(2.11);
|
---|
534 | QString strV3 = eph.toString(3.01);
|
---|
535 |
|
---|
536 | printOutput(printFile, _ephStreamGalileo, strV2, strV3);
|
---|
537 | }
|
---|
538 |
|
---|
539 | // Output
|
---|
540 | ////////////////////////////////////////////////////////////////////////////
|
---|
541 | void bncApp::printOutput(bool printFile, QTextStream* stream,
|
---|
542 | const QString& strV2, const QString& strV3) {
|
---|
543 |
|
---|
544 | // Output into file
|
---|
545 | // ----------------
|
---|
546 | if (printFile && stream) {
|
---|
547 | if (_rinexVers == 2) {
|
---|
548 | *stream << strV2.toAscii();
|
---|
549 | }
|
---|
550 | else {
|
---|
551 | *stream << strV3.toAscii();
|
---|
552 | }
|
---|
553 | stream->flush();
|
---|
554 | }
|
---|
555 |
|
---|
556 | // Output into the socket
|
---|
557 | // ----------------------
|
---|
558 | if (_sockets) {
|
---|
559 | QMutableListIterator<QTcpSocket*> is(*_sockets);
|
---|
560 | while (is.hasNext()) {
|
---|
561 | QTcpSocket* sock = is.next();
|
---|
562 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
---|
563 | if (sock->write(strV3.toAscii()) == -1) {
|
---|
564 | delete sock;
|
---|
565 | is.remove();
|
---|
566 | }
|
---|
567 | }
|
---|
568 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
---|
569 | delete sock;
|
---|
570 | is.remove();
|
---|
571 | }
|
---|
572 | }
|
---|
573 | }
|
---|
574 | }
|
---|
575 |
|
---|
576 | // Set Port Number
|
---|
577 | ////////////////////////////////////////////////////////////////////////////
|
---|
578 | void bncApp::setPort(int port) {
|
---|
579 | _port = port;
|
---|
580 | if (_port != 0) {
|
---|
581 | delete _server;
|
---|
582 | _server = new QTcpServer;
|
---|
583 | if ( !_server->listen(QHostAddress::Any, _port) ) {
|
---|
584 | slotMessage("bncApp: Cannot listen on ephemeris port", true);
|
---|
585 | }
|
---|
586 | connect(_server, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));
|
---|
587 | delete _sockets;
|
---|
588 | _sockets = new QList<QTcpSocket*>;
|
---|
589 | }
|
---|
590 | }
|
---|
591 |
|
---|
592 | // Set Port Number
|
---|
593 | ////////////////////////////////////////////////////////////////////////////
|
---|
594 | void bncApp::setPortCorr(int port) {
|
---|
595 | _portCorr = port;
|
---|
596 | if (_portCorr != 0) {
|
---|
597 | delete _serverCorr;
|
---|
598 | _serverCorr = new QTcpServer;
|
---|
599 | if ( !_serverCorr->listen(QHostAddress::Any, _portCorr) ) {
|
---|
600 | slotMessage("bncApp: Cannot listen on correction port", true);
|
---|
601 | }
|
---|
602 | connect(_serverCorr, SIGNAL(newConnection()), this, SLOT(slotNewConnectionCorr()));
|
---|
603 | delete _socketsCorr;
|
---|
604 | _socketsCorr = new QList<QTcpSocket*>;
|
---|
605 | }
|
---|
606 | }
|
---|
607 |
|
---|
608 | // New Connection
|
---|
609 | ////////////////////////////////////////////////////////////////////////////
|
---|
610 | void bncApp::slotNewConnection() {
|
---|
611 | _sockets->push_back( _server->nextPendingConnection() );
|
---|
612 | }
|
---|
613 |
|
---|
614 | // New Connection
|
---|
615 | ////////////////////////////////////////////////////////////////////////////
|
---|
616 | void bncApp::slotNewConnectionCorr() {
|
---|
617 | _socketsCorr->push_back( _serverCorr->nextPendingConnection() );
|
---|
618 | }
|
---|
619 |
|
---|
620 | //
|
---|
621 | ////////////////////////////////////////////////////////////////////////////
|
---|
622 | void bncApp::slotQuit() {
|
---|
623 | cout << "bncApp::slotQuit" << endl;
|
---|
624 | delete _caster;
|
---|
625 | quit();
|
---|
626 | }
|
---|
627 |
|
---|
628 | //
|
---|
629 | ////////////////////////////////////////////////////////////////////////////
|
---|
630 | void bncApp::slotNewCorrLine(QString line, QString staID, long coTime) {
|
---|
631 |
|
---|
632 | QMutexLocker locker(&_mutex);
|
---|
633 |
|
---|
634 | // Combination of Corrections
|
---|
635 | // --------------------------
|
---|
636 | #ifdef USE_COMBINATION
|
---|
637 | if (_bncComb) {
|
---|
638 | _bncComb->processCorrLine(staID, line);
|
---|
639 | }
|
---|
640 | #endif
|
---|
641 |
|
---|
642 | bncSettings settings;
|
---|
643 | _waitCoTime = settings.value("corrTime").toInt();
|
---|
644 | if (_waitCoTime < 0) {
|
---|
645 | _waitCoTime = 0;
|
---|
646 | }
|
---|
647 |
|
---|
648 | // First time, set the _lastDumpSec immediately
|
---|
649 | // --------------------------------------------
|
---|
650 | if (_lastDumpCoSec == 0) {
|
---|
651 | _lastDumpCoSec = coTime - 1;
|
---|
652 | }
|
---|
653 |
|
---|
654 | // An old correction - throw it away
|
---|
655 | // ---------------------------------
|
---|
656 | if (_waitCoTime > 0 && coTime <= _lastDumpCoSec) {
|
---|
657 | if (!_bncComb) {
|
---|
658 | QString line = staID + ": Correction for one sat neglected because overaged by " +
|
---|
659 | QString().sprintf(" %ld sec",
|
---|
660 | _lastDumpCoSec - coTime + _waitCoTime);
|
---|
661 | messagePrivate(line.toAscii());
|
---|
662 | emit( newMessage(line.toAscii(), true) );
|
---|
663 | }
|
---|
664 | return;
|
---|
665 | }
|
---|
666 |
|
---|
667 | _corrs->insert(coTime, QString(line + " " + staID));
|
---|
668 |
|
---|
669 | // Dump Corrections
|
---|
670 | // ----------------
|
---|
671 | if (_waitCoTime == 0) {
|
---|
672 | dumpCorrs();
|
---|
673 | }
|
---|
674 | else if (coTime - _waitCoTime > _lastDumpCoSec) {
|
---|
675 | dumpCorrs(_lastDumpCoSec + 1, coTime - _waitCoTime);
|
---|
676 | _lastDumpCoSec = coTime - _waitCoTime;
|
---|
677 | }
|
---|
678 | }
|
---|
679 |
|
---|
680 | // Dump Complete Correction Epochs
|
---|
681 | ////////////////////////////////////////////////////////////////////////////
|
---|
682 | void bncApp::dumpCorrs(long minTime, long maxTime) {
|
---|
683 | for (long sec = minTime; sec <= maxTime; sec++) {
|
---|
684 | QList<QString> allCorrs = _corrs->values(sec);
|
---|
685 | dumpCorrs(allCorrs);
|
---|
686 | _corrs->remove(sec);
|
---|
687 | }
|
---|
688 | }
|
---|
689 |
|
---|
690 | // Dump all corrections
|
---|
691 | ////////////////////////////////////////////////////////////////////////////
|
---|
692 | void bncApp::dumpCorrs() {
|
---|
693 | QList<QString> allCorrs;
|
---|
694 | QMutableMapIterator<long, QString> it(*_corrs);
|
---|
695 | while (it.hasNext()) {
|
---|
696 | allCorrs << it.next().value();
|
---|
697 | it.remove();
|
---|
698 | }
|
---|
699 | dumpCorrs(allCorrs);
|
---|
700 | }
|
---|
701 |
|
---|
702 | // Dump List of Corrections
|
---|
703 | ////////////////////////////////////////////////////////////////////////////
|
---|
704 | void bncApp::dumpCorrs(const QList<QString>& allCorrs) {
|
---|
705 | emit newCorrections(allCorrs);
|
---|
706 | if (_socketsCorr) {
|
---|
707 | QListIterator<QString> it(allCorrs);
|
---|
708 | while (it.hasNext()) {
|
---|
709 | QString corrLine = it.next() + "\n";
|
---|
710 |
|
---|
711 | QMutableListIterator<QTcpSocket*> is(*_socketsCorr);
|
---|
712 | while (is.hasNext()) {
|
---|
713 | QTcpSocket* sock = is.next();
|
---|
714 | if (sock->state() == QAbstractSocket::ConnectedState) {
|
---|
715 | if (sock->write(corrLine.toAscii()) == -1) {
|
---|
716 | delete sock;
|
---|
717 | is.remove();
|
---|
718 | }
|
---|
719 | }
|
---|
720 | else if (sock->state() != QAbstractSocket::ConnectingState) {
|
---|
721 | delete sock;
|
---|
722 | is.remove();
|
---|
723 | }
|
---|
724 | }
|
---|
725 | }
|
---|
726 | }
|
---|
727 | }
|
---|
728 |
|
---|
729 | //
|
---|
730 | ////////////////////////////////////////////////////////////////////////////
|
---|
731 | void bncApp::setConfFileName(const QString& confFileName) {
|
---|
732 | if (confFileName.isEmpty()) {
|
---|
733 | _confFileName = QDir::homePath() + QDir::separator()
|
---|
734 | + ".config" + QDir::separator()
|
---|
735 | + organizationName() + QDir::separator()
|
---|
736 | + applicationName() + ".bnc";
|
---|
737 | }
|
---|
738 | else {
|
---|
739 | _confFileName = confFileName;
|
---|
740 | }
|
---|
741 | }
|
---|
742 |
|
---|
743 | // Raw Output
|
---|
744 | ////////////////////////////////////////////////////////////////////////////
|
---|
745 | void bncApp::writeRawData(const QByteArray& data, const QByteArray& staID,
|
---|
746 | const QByteArray& format) {
|
---|
747 |
|
---|
748 | QMutexLocker locker(&_mutex);
|
---|
749 |
|
---|
750 | if (!_rawFile) {
|
---|
751 | bncSettings settings;
|
---|
752 | QByteArray fileName = settings.value("rawOutFile").toByteArray();
|
---|
753 | if (!fileName.isEmpty()) {
|
---|
754 | _rawFile = new bncRawFile(fileName, staID, bncRawFile::output);
|
---|
755 | }
|
---|
756 | }
|
---|
757 |
|
---|
758 | if (_rawFile) {
|
---|
759 | _rawFile->writeRawData(data, staID, format);
|
---|
760 | }
|
---|
761 | }
|
---|
762 |
|
---|
763 | // Get Glonass Slot Numbers from Global Array
|
---|
764 | ////////////////////////////////////////////////////////////////////////////
|
---|
765 | void bncApp::getGlonassSlotNums(int GLOFreq[]) {
|
---|
766 |
|
---|
767 | QMutexLocker locker(&_mutex);
|
---|
768 |
|
---|
769 | for (int ii = 0; ii < PRN_GLONASS_NUM; ++ii) {
|
---|
770 | if (_GLOFreq[ii] != 0) {
|
---|
771 | GLOFreq[ii] = _GLOFreq[ii];
|
---|
772 | }
|
---|
773 | }
|
---|
774 | }
|
---|
775 |
|
---|
776 | // Store Glonass Slot Numbers to Global Array
|
---|
777 | ////////////////////////////////////////////////////////////////////////////
|
---|
778 | void bncApp::storeGlonassSlotNums(const int GLOFreq[]) {
|
---|
779 |
|
---|
780 | QMutexLocker locker(&_mutex);
|
---|
781 |
|
---|
782 | for (int ii = 0; ii < PRN_GLONASS_NUM; ++ii) {
|
---|
783 | if (GLOFreq[ii] != 0) {
|
---|
784 | _GLOFreq[ii] = GLOFreq[ii];
|
---|
785 | }
|
---|
786 | }
|
---|
787 | }
|
---|
788 |
|
---|
789 | //
|
---|
790 | ////////////////////////////////////////////////////////////////////////////
|
---|
791 | void bncApp::initCombination() {
|
---|
792 | #ifdef USE_COMBINATION
|
---|
793 | _bncComb = new bncComb();
|
---|
794 | if (_bncComb->nStreams() < 1) {
|
---|
795 | delete _bncComb;
|
---|
796 | _bncComb = 0;
|
---|
797 | }
|
---|
798 | #endif
|
---|
799 | }
|
---|
800 |
|
---|
801 | //
|
---|
802 | ////////////////////////////////////////////////////////////////////////////
|
---|
803 | void bncApp::stopCombination() {
|
---|
804 | #ifdef USE_COMBINATION
|
---|
805 | delete _bncComb;
|
---|
806 | _bncComb = 0;
|
---|
807 | #endif
|
---|
808 | }
|
---|
809 |
|
---|
810 | // Handling Events (virtual)
|
---|
811 | ////////////////////////////////////////////////////////////////////////////
|
---|
812 | bool bncApp::event(QEvent* ev) {
|
---|
813 |
|
---|
814 | if (ev->type() == QEvent::FileOpen) { // currently happens on Mac only
|
---|
815 | QString fileName = static_cast<QFileOpenEvent*>(ev)->file();
|
---|
816 | setConfFileName(fileName);
|
---|
817 | return true;
|
---|
818 | }
|
---|
819 |
|
---|
820 | return QApplication::event(ev);
|
---|
821 | }
|
---|
822 |
|
---|
823 | // Check Ephemeris Consistency
|
---|
824 | ////////////////////////////////////////////////////////////////////////////
|
---|
825 | void bncApp::checkEphemeris(gpsephemeris* oldEph, gpsephemeris* newEph) {
|
---|
826 | if (oldEph->clock_bias != newEph->clock_bias ||
|
---|
827 | oldEph->clock_drift != newEph->clock_drift ||
|
---|
828 | oldEph->clock_driftrate != newEph->clock_driftrate) {
|
---|
829 | QString msg = currentDateAndTimeGPS().toString(Qt::ISODate) +
|
---|
830 | QString(" %1 EPH DIFFERS\n").arg(oldEph->satellite);
|
---|
831 | messagePrivate(msg.toAscii());
|
---|
832 | }
|
---|
833 | }
|
---|