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

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