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

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