source: ntrip/branches/BNC_LM/bncapp.cpp@ 10160

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