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