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

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