source: ntrip/trunk/BNC/bncapp.cpp@ 2899

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