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: bncRinex
|
---|
30 | *
|
---|
31 | * Purpose: writes RINEX files
|
---|
32 | *
|
---|
33 | * Author: L. Mervart
|
---|
34 | *
|
---|
35 | * Created: 27-Aug-2006
|
---|
36 | *
|
---|
37 | * Changes:
|
---|
38 | *
|
---|
39 | * -----------------------------------------------------------------------*/
|
---|
40 |
|
---|
41 | #include <stdlib.h>
|
---|
42 | #include <iostream>
|
---|
43 | #include <iomanip>
|
---|
44 | #include <math.h>
|
---|
45 |
|
---|
46 | #include <QtCore>
|
---|
47 | #include <QUrl>
|
---|
48 | #include <QString>
|
---|
49 |
|
---|
50 | #include "bncrinex.h"
|
---|
51 | #include "bncapp.h"
|
---|
52 | #include "bncutils.h"
|
---|
53 | #include "bncconst.h"
|
---|
54 | #include "bnctabledlg.h"
|
---|
55 | #include "bncgetthread.h"
|
---|
56 | #include "bncsocket.h"
|
---|
57 | #include "RTCM3/rtcm3torinex.h"
|
---|
58 |
|
---|
59 | using namespace std;
|
---|
60 |
|
---|
61 | // Constructor
|
---|
62 | ////////////////////////////////////////////////////////////////////////////
|
---|
63 | bncRinex::bncRinex(const QByteArray& statID, const QUrl& mountPoint,
|
---|
64 | const QByteArray& format, const QByteArray& latitude,
|
---|
65 | const QByteArray& longitude, const QByteArray& nmea,
|
---|
66 | const QByteArray& ntripVersion) {
|
---|
67 | _statID = statID;
|
---|
68 | _mountPoint = mountPoint;
|
---|
69 | _format = format.left(6);
|
---|
70 | _latitude = latitude;
|
---|
71 | _longitude = longitude;
|
---|
72 | _nmea = nmea;
|
---|
73 | _ntripVersion = ntripVersion;
|
---|
74 | _headerWritten = false;
|
---|
75 | _reconnectFlag = false;
|
---|
76 | _reloadTable = false;
|
---|
77 | _reloadDone = false;
|
---|
78 |
|
---|
79 | QSettings settings;
|
---|
80 | _rnxScriptName = settings.value("rnxScript").toString();
|
---|
81 | expandEnvVar(_rnxScriptName);
|
---|
82 |
|
---|
83 | _pgmName = ((bncApp*)qApp)->bncVersion().leftJustified(20, ' ', true);
|
---|
84 | #ifdef WIN32
|
---|
85 | _userName = QString("${USERNAME}");
|
---|
86 | #else
|
---|
87 | _userName = QString("${USER}");
|
---|
88 | #endif
|
---|
89 | expandEnvVar(_userName);
|
---|
90 | _userName = _userName.leftJustified(20, ' ', true);
|
---|
91 |
|
---|
92 | if ( Qt::CheckState(settings.value("rnxV3").toInt()) == Qt::Checked) {
|
---|
93 | _rinexVers = 3;
|
---|
94 | }
|
---|
95 | else {
|
---|
96 | _rinexVers = 2;
|
---|
97 | }
|
---|
98 |
|
---|
99 | _approxPos[0] = _approxPos[1] = _approxPos[2] = 0.0;
|
---|
100 | }
|
---|
101 |
|
---|
102 | // Destructor
|
---|
103 | ////////////////////////////////////////////////////////////////////////////
|
---|
104 | bncRinex::~bncRinex() {
|
---|
105 | QListIterator<p_obs> it(_obs);
|
---|
106 | while (it.hasNext()) {
|
---|
107 | delete it.next();
|
---|
108 | }
|
---|
109 | QSettings settings;
|
---|
110 | if ((_rinexVers == 3) && ( Qt::CheckState(settings.value("rnxAppend").toInt()) != Qt::Checked) ) {
|
---|
111 | _out << "> 4 1" << endl;
|
---|
112 | _out << "END OF FILE" << endl;
|
---|
113 | }
|
---|
114 | _out.close();
|
---|
115 | }
|
---|
116 |
|
---|
117 | // Download Skeleton Header File
|
---|
118 | ////////////////////////////////////////////////////////////////////////////
|
---|
119 | t_irc bncRinex::downloadSkeleton() {
|
---|
120 |
|
---|
121 | t_irc irc = failure;
|
---|
122 |
|
---|
123 | QStringList table;
|
---|
124 | bncTableDlg::getFullTable(_mountPoint.host(), _mountPoint.port(),
|
---|
125 | _ntripVersion, table, _reloadTable);
|
---|
126 | QString net;
|
---|
127 | QStringListIterator it(table);
|
---|
128 | while (it.hasNext()) {
|
---|
129 | QString line = it.next();
|
---|
130 | if (line.indexOf("STR") == 0) {
|
---|
131 | QStringList tags = line.split(";");
|
---|
132 | if (tags.at(1) == _mountPoint.path().mid(1).toAscii()) {
|
---|
133 | net = tags.at(7);
|
---|
134 | break;
|
---|
135 | }
|
---|
136 | }
|
---|
137 | }
|
---|
138 | QString sklDir;
|
---|
139 | it.toFront();
|
---|
140 | while (it.hasNext()) {
|
---|
141 | QString line = it.next();
|
---|
142 | if (line.indexOf("NET") == 0) {
|
---|
143 | QStringList tags = line.split(";");
|
---|
144 | if (tags.at(1) == net) {
|
---|
145 | sklDir = tags.at(6).trimmed();
|
---|
146 | break;
|
---|
147 | }
|
---|
148 | }
|
---|
149 | }
|
---|
150 | if (!sklDir.isEmpty() && sklDir != "none") {
|
---|
151 | QUrl url(sklDir + "/" + _mountPoint.path().mid(1,4).toLower() + ".skl");
|
---|
152 | if (url.port() == -1) {
|
---|
153 | url.setPort(80);
|
---|
154 | }
|
---|
155 |
|
---|
156 | const int timeOut = 10*1000;
|
---|
157 | QString msg;
|
---|
158 | QByteArray _latitude;
|
---|
159 | QByteArray _longitude;
|
---|
160 | QByteArray _nmea;
|
---|
161 | bncSocket* socket = new bncSocket();
|
---|
162 | if (socket->request(url, _latitude, _longitude,
|
---|
163 | _nmea, _ntripVersion, timeOut, msg) != success) {
|
---|
164 | delete socket;
|
---|
165 | return failure;
|
---|
166 | }
|
---|
167 |
|
---|
168 | _headerLines.clear();
|
---|
169 | bool firstLineRead = false;
|
---|
170 | while (true) {
|
---|
171 | if (socket->canReadLine()) {
|
---|
172 | QString line = socket->readLine();
|
---|
173 | line.chop(1);
|
---|
174 | if (line.indexOf("MARKER NAME") != -1) {
|
---|
175 | irc = success;
|
---|
176 | }
|
---|
177 | if (line.indexOf("RINEX VERSION") != -1) {
|
---|
178 | if (_rinexVers == 3) {
|
---|
179 | _headerLines.append(" 3.00 OBSERVATION DATA"
|
---|
180 | " M (MIXED)"
|
---|
181 | " RINEX VERSION / TYPE");
|
---|
182 | }
|
---|
183 | else {
|
---|
184 | _headerLines.append(" 2.11 OBSERVATION DATA"
|
---|
185 | " M (MIXED)"
|
---|
186 | " RINEX VERSION / TYPE");
|
---|
187 | }
|
---|
188 | _headerLines.append("PGM / RUN BY / DATE");
|
---|
189 | firstLineRead = true;
|
---|
190 | }
|
---|
191 | else if (firstLineRead) {
|
---|
192 | if (line.indexOf("END OF HEADER") != -1) {
|
---|
193 | _headerLines.append("# / TYPES OF OBSERV");
|
---|
194 | if (_rinexVers == 2) {
|
---|
195 | _headerLines.append(
|
---|
196 | QString(" 1 1").leftJustified(60, ' ', true) +
|
---|
197 | "WAVELENGTH FACT L1/2");
|
---|
198 | }
|
---|
199 | _headerLines.append("TIME OF FIRST OBS");
|
---|
200 | _headerLines.append( line );
|
---|
201 | break;
|
---|
202 | }
|
---|
203 | else {
|
---|
204 | _headerLines.append( line );
|
---|
205 | }
|
---|
206 | }
|
---|
207 | }
|
---|
208 | else {
|
---|
209 | socket->waitForReadyRead(timeOut);
|
---|
210 | if (socket->bytesAvailable() > 0) {
|
---|
211 | continue;
|
---|
212 | }
|
---|
213 | else {
|
---|
214 | break;
|
---|
215 | }
|
---|
216 | }
|
---|
217 | }
|
---|
218 | }
|
---|
219 | return irc;
|
---|
220 | }
|
---|
221 |
|
---|
222 | // Read Skeleton Header File
|
---|
223 | ////////////////////////////////////////////////////////////////////////////
|
---|
224 | void bncRinex::readSkeleton() {
|
---|
225 |
|
---|
226 | // Read the local file
|
---|
227 | // -------------------
|
---|
228 | QFile skl(_sklName);
|
---|
229 | if ( skl.exists() && skl.open(QIODevice::ReadOnly) ) {
|
---|
230 | _headerLines.clear();
|
---|
231 | QTextStream in(&skl);
|
---|
232 | while ( !in.atEnd() ) {
|
---|
233 | _headerLines.append( in.readLine() );
|
---|
234 | if (_headerLines.last().indexOf("END OF HEADER") != -1) {
|
---|
235 | break;
|
---|
236 | }
|
---|
237 | }
|
---|
238 | }
|
---|
239 |
|
---|
240 | // Read downloaded file
|
---|
241 | // --------------------
|
---|
242 | else {
|
---|
243 | QDate currDate = currentDateAndTimeGPS().date();
|
---|
244 | if ( !_skeletonDate.isValid() || _skeletonDate != currDate ) {
|
---|
245 | if ( downloadSkeleton() == success) {
|
---|
246 | _skeletonDate = currDate;
|
---|
247 | _reloadDone = false;
|
---|
248 | }
|
---|
249 | else {
|
---|
250 | if(!_reloadDone) {
|
---|
251 | _reloadTable = true;
|
---|
252 | if ( downloadSkeleton() == success) {
|
---|
253 | _skeletonDate = currDate;
|
---|
254 | }
|
---|
255 | _reloadTable = false;
|
---|
256 | _reloadDone = true;
|
---|
257 | }
|
---|
258 | }
|
---|
259 | }
|
---|
260 | }
|
---|
261 | }
|
---|
262 |
|
---|
263 | // Next File Epoch (static)
|
---|
264 | ////////////////////////////////////////////////////////////////////////////
|
---|
265 | QString bncRinex::nextEpochStr(const QDateTime& datTim,
|
---|
266 | const QString& intStr, QDateTime* nextEpoch) {
|
---|
267 |
|
---|
268 | QString epoStr;
|
---|
269 |
|
---|
270 | QTime nextTime;
|
---|
271 | QDate nextDate;
|
---|
272 |
|
---|
273 | int indHlp = intStr.indexOf("min");
|
---|
274 |
|
---|
275 | if ( indHlp != -1) {
|
---|
276 | int step = intStr.left(indHlp-1).toInt();
|
---|
277 | char ch = 'A' + datTim.time().hour();
|
---|
278 | epoStr = ch;
|
---|
279 | if (datTim.time().minute() >= 60-step) {
|
---|
280 | epoStr += QString("%1").arg(60-step, 2, 10, QChar('0'));
|
---|
281 | if (datTim.time().hour() < 23) {
|
---|
282 | nextTime.setHMS(datTim.time().hour() + 1 , 0, 0);
|
---|
283 | nextDate = datTim.date();
|
---|
284 | }
|
---|
285 | else {
|
---|
286 | nextTime.setHMS(0, 0, 0);
|
---|
287 | nextDate = datTim.date().addDays(1);
|
---|
288 | }
|
---|
289 | }
|
---|
290 | else {
|
---|
291 | for (int limit = step; limit <= 60-step; limit += step) {
|
---|
292 | if (datTim.time().minute() < limit) {
|
---|
293 | epoStr += QString("%1").arg(limit-step, 2, 10, QChar('0'));
|
---|
294 | nextTime.setHMS(datTim.time().hour(), limit, 0);
|
---|
295 | nextDate = datTim.date();
|
---|
296 | break;
|
---|
297 | }
|
---|
298 | }
|
---|
299 | }
|
---|
300 | }
|
---|
301 | else if (intStr == "1 hour") {
|
---|
302 | char ch = 'A' + datTim.time().hour();
|
---|
303 | epoStr = ch;
|
---|
304 | if (datTim.time().hour() < 23) {
|
---|
305 | nextTime.setHMS(datTim.time().hour() + 1 , 0, 0);
|
---|
306 | nextDate = datTim.date();
|
---|
307 | }
|
---|
308 | else {
|
---|
309 | nextTime.setHMS(0, 0, 0);
|
---|
310 | nextDate = datTim.date().addDays(1);
|
---|
311 | }
|
---|
312 | }
|
---|
313 | else {
|
---|
314 | epoStr = "0";
|
---|
315 | nextTime.setHMS(0, 0, 0);
|
---|
316 | nextDate = datTim.date().addDays(1);
|
---|
317 | }
|
---|
318 |
|
---|
319 | if (nextEpoch) {
|
---|
320 | *nextEpoch = QDateTime(nextDate, nextTime);
|
---|
321 | }
|
---|
322 |
|
---|
323 | return epoStr;
|
---|
324 | }
|
---|
325 |
|
---|
326 | // File Name according to RINEX Standards
|
---|
327 | ////////////////////////////////////////////////////////////////////////////
|
---|
328 | void bncRinex::resolveFileName(const QDateTime& datTim) {
|
---|
329 |
|
---|
330 | QSettings settings;
|
---|
331 | QString path = settings.value("rnxPath").toString();
|
---|
332 | expandEnvVar(path);
|
---|
333 |
|
---|
334 | if ( path.length() > 0 && path[path.length()-1] != QDir::separator() ) {
|
---|
335 | path += QDir::separator();
|
---|
336 | }
|
---|
337 |
|
---|
338 | QString hlpStr = nextEpochStr(datTim, settings.value("rnxIntr").toString(),
|
---|
339 | &_nextCloseEpoch);
|
---|
340 |
|
---|
341 | QString ID4 = _statID.left(4);
|
---|
342 |
|
---|
343 | // Check name conflict
|
---|
344 | // -------------------
|
---|
345 | QString distStr;
|
---|
346 | int num = 0;
|
---|
347 | QListIterator<QString> it(settings.value("mountPoints").toStringList());
|
---|
348 | while (it.hasNext()) {
|
---|
349 | QString mp = it.next();
|
---|
350 | if (mp.indexOf(ID4) != -1) {
|
---|
351 | ++num;
|
---|
352 | }
|
---|
353 | }
|
---|
354 | if (num > 1) {
|
---|
355 | distStr = "_" + _statID.mid(4);
|
---|
356 | }
|
---|
357 |
|
---|
358 | QString sklExt = settings.value("rnxSkel").toString();
|
---|
359 | if (!sklExt.isEmpty()) {
|
---|
360 | _sklName = path + ID4 + distStr + "." + sklExt;
|
---|
361 | }
|
---|
362 |
|
---|
363 | path += ID4 +
|
---|
364 | QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
|
---|
365 | hlpStr + distStr + datTim.toString(".yyO");
|
---|
366 |
|
---|
367 | _fName = path.toAscii();
|
---|
368 | }
|
---|
369 |
|
---|
370 | // Write RINEX Header
|
---|
371 | ////////////////////////////////////////////////////////////////////////////
|
---|
372 | void bncRinex::writeHeader(const QDateTime& datTim,
|
---|
373 | const QDateTime& datTimNom) {
|
---|
374 |
|
---|
375 | QSettings settings;
|
---|
376 |
|
---|
377 | // Open the Output File
|
---|
378 | // --------------------
|
---|
379 | resolveFileName(datTimNom);
|
---|
380 |
|
---|
381 | // Append to existing file and return
|
---|
382 | // ----------------------------------
|
---|
383 | if ( QFile::exists(_fName) ) {
|
---|
384 | if (_reconnectFlag ||
|
---|
385 | Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
|
---|
386 | _out.open(_fName.data(), ios::app);
|
---|
387 | _out.setf(ios::showpoint | ios::fixed);
|
---|
388 | _headerWritten = true;
|
---|
389 | _reconnectFlag = false;
|
---|
390 | return;
|
---|
391 | }
|
---|
392 | }
|
---|
393 |
|
---|
394 | _out.open(_fName.data());
|
---|
395 | _out.setf(ios::showpoint | ios::fixed);
|
---|
396 |
|
---|
397 | // Copy Skeleton Header
|
---|
398 | // --------------------
|
---|
399 | readSkeleton();
|
---|
400 | if (_headerLines.size() > 0) {
|
---|
401 | QStringListIterator it(_headerLines);
|
---|
402 | while (it.hasNext()) {
|
---|
403 | QString line = it.next();
|
---|
404 | if (line.indexOf("PGM / RUN BY / DATE") != -1) {
|
---|
405 | if (_rinexVers == 3) {
|
---|
406 | QString hlp = currentDateAndTimeGPS().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
|
---|
407 | _out << _pgmName.toAscii().data() << _userName.toAscii().data()
|
---|
408 | << hlp.toAscii().data() << "PGM / RUN BY / DATE" << endl;
|
---|
409 | }
|
---|
410 | else {
|
---|
411 | QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
|
---|
412 | _out << _pgmName.toAscii().data() << _userName.toAscii().data()
|
---|
413 | << hlp.toAscii().data() << "PGM / RUN BY / DATE" << endl;
|
---|
414 | }
|
---|
415 | }
|
---|
416 | else if (line.indexOf("# / TYPES OF OBSERV") != -1) {
|
---|
417 | if (_rinexVers == 3) {
|
---|
418 | // Changed declaration of data types, consistent with Rinex3 Perlt
|
---|
419 | _out << "G 10 C1C C1P L1C S1C C2X C2P L2X S2X L2P S2P SYS / # / OBS TYPES" << endl;
|
---|
420 | _out << "R 10 C1C C1P L1C S1C C2C C2P L2C S2C L2P S2P SYS / # / OBS TYPES" << endl;
|
---|
421 | _out << "S 3 C1C L1C S1C SYS / # / OBS TYPES" << endl;
|
---|
422 | }
|
---|
423 | else {
|
---|
424 | _out << " 8 C1 C2 P1 P2 L1 L2 S1 S2"
|
---|
425 | " # / TYPES OF OBSERV" << endl;
|
---|
426 | }
|
---|
427 | }
|
---|
428 | else if (line.indexOf("TIME OF FIRST OBS") != -1) {
|
---|
429 | _out << datTim.toString(" yyyy MM dd"
|
---|
430 | " hh mm ss.zzz0000").toAscii().data();
|
---|
431 | _out << " GPS TIME OF FIRST OBS" << endl;
|
---|
432 | QString hlp = (_format + QString(" %1").arg(_mountPoint.host() +
|
---|
433 | _mountPoint.path())).leftJustified(60, ' ', true);
|
---|
434 | _out << hlp.toAscii().data() << "COMMENT" << endl;
|
---|
435 | }
|
---|
436 | // Added header line for Rinex3 regarding mandatory MARKER TYPE field Perlt
|
---|
437 | else if (line.indexOf("MARKER NAME") != -1) {
|
---|
438 | if (_rinexVers == 3) {
|
---|
439 | _out << line.toAscii().data() << endl;
|
---|
440 | _out << setw(71) << "GEODETIC MARKER TYPE" << endl;
|
---|
441 | }
|
---|
442 | else {
|
---|
443 | _out << line.toAscii().data() << endl;
|
---|
444 | }
|
---|
445 | // End
|
---|
446 | }
|
---|
447 | else {
|
---|
448 | _out << line.toAscii().data() << endl;
|
---|
449 | }
|
---|
450 | }
|
---|
451 | }
|
---|
452 |
|
---|
453 | // Write Dummy Header
|
---|
454 | // ------------------
|
---|
455 | else {
|
---|
456 | double antennaNEU[3]; antennaNEU[0] = antennaNEU[1] = antennaNEU[2] = 0.0;
|
---|
457 |
|
---|
458 | if (_rinexVers == 3) {
|
---|
459 | _out << " 3.00 OBSERVATION DATA M (MIXED) RINEX VERSION / TYPE" << endl;
|
---|
460 | QString hlp = currentDateAndTimeGPS().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
|
---|
461 | _out << _pgmName.toAscii().data() << _userName.toAscii().data()
|
---|
462 | << hlp.toAscii().data() << "PGM / RUN BY / DATE" << endl;
|
---|
463 | }
|
---|
464 | else {
|
---|
465 | _out << " 2.11 OBSERVATION DATA M (MIXED) RINEX VERSION / TYPE" << endl;
|
---|
466 | QString hlp = currentDateAndTimeGPS().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
|
---|
467 | _out << _pgmName.toAscii().data() << _userName.toAscii().data()
|
---|
468 | << hlp.toAscii().data() << "PGM / RUN BY / DATE" << endl;
|
---|
469 | }
|
---|
470 | _out.setf(ios::left);
|
---|
471 | _out << setw(60) << _statID.data() << "MARKER NAME" << endl;
|
---|
472 | // Added header line for Rinex3 regarding mandatory MARKER TYPE field Perlt
|
---|
473 | if (_rinexVers == 3) {
|
---|
474 | _out << setw(60) << "unknown" << "MARKER TYPE " << endl;
|
---|
475 | }
|
---|
476 | // End
|
---|
477 | _out << setw(60) << "unknown unknown" << "OBSERVER / AGENCY" << endl;
|
---|
478 | _out << setw(20) << "unknown"
|
---|
479 | << setw(20) << "unknown"
|
---|
480 | << setw(20) << "unknown" << "REC # / TYPE / VERS" << endl;
|
---|
481 | _out << setw(20) << "unknown"
|
---|
482 | << setw(20) << "unknown"
|
---|
483 | << setw(20) << " " << "ANT # / TYPE" << endl;
|
---|
484 | _out.unsetf(ios::left);
|
---|
485 | _out << setw(14) << setprecision(4) << _approxPos[0]
|
---|
486 | << setw(14) << setprecision(4) << _approxPos[1]
|
---|
487 | << setw(14) << setprecision(4) << _approxPos[2]
|
---|
488 | << " " << "APPROX POSITION XYZ" << endl;
|
---|
489 | _out << setw(14) << setprecision(4) << antennaNEU[0]
|
---|
490 | << setw(14) << setprecision(4) << antennaNEU[1]
|
---|
491 | << setw(14) << setprecision(4) << antennaNEU[2]
|
---|
492 | << " " << "ANTENNA: DELTA H/E/N" << endl;
|
---|
493 | if (_rinexVers == 3) {
|
---|
494 | // Changed declaration of data types, consistent with Rinex3 Perlt
|
---|
495 | _out << "G 10 C1C C1P L1C S1C C2X C2P L2X S2X L2P S2P SYS / # / OBS TYPES" << endl;
|
---|
496 | _out << "R 10 C1C C1P L1C S1C C2C C2P L2C S2C L2P S2P SYS / # / OBS TYPES" << endl;
|
---|
497 | _out << "S 3 C1C L1C S1C SYS / # / OBS TYPES" << endl;
|
---|
498 |
|
---|
499 | }
|
---|
500 | else {
|
---|
501 | _out << " 1 1 WAVELENGTH FACT L1/2" << endl;
|
---|
502 | _out << " 8 C1 C2 P1 P2 L1 L2 S1 S2 # / TYPES OF OBSERV" << endl;
|
---|
503 | }
|
---|
504 | _out << datTim.toString(" yyyy MM dd"
|
---|
505 | " hh mm ss.zzz0000").toAscii().data();
|
---|
506 | _out << " GPS TIME OF FIRST OBS" << endl;
|
---|
507 | QString hlp = (_format + QString(" %1").arg(_mountPoint.host() +
|
---|
508 | _mountPoint.path())).leftJustified(60, ' ', true);
|
---|
509 | _out << hlp.toAscii().data() << "COMMENT" << endl;
|
---|
510 |
|
---|
511 | if (_nmea == "yes") {
|
---|
512 | hlp = ("NMEA LAT=" + _latitude + " " + "LONG=" + _longitude).leftJustified(60, ' ',true);
|
---|
513 | _out << hlp.toAscii().data() << "COMMENT" << endl; }
|
---|
514 |
|
---|
515 | _out << " END OF HEADER" << endl;
|
---|
516 | }
|
---|
517 |
|
---|
518 | _headerWritten = true;
|
---|
519 | }
|
---|
520 |
|
---|
521 | // Stores Observation into Internal Array
|
---|
522 | ////////////////////////////////////////////////////////////////////////////
|
---|
523 | void bncRinex::deepCopy(const p_obs obs) {
|
---|
524 | p_obs newObs = new t_obs();
|
---|
525 | memcpy(&newObs->_o, &obs->_o, sizeof(t_obsInternal));
|
---|
526 | _obs.push_back(newObs);
|
---|
527 | }
|
---|
528 |
|
---|
529 | // Write One Epoch into the RINEX File
|
---|
530 | ////////////////////////////////////////////////////////////////////////////
|
---|
531 | void bncRinex::dumpEpoch(long maxTime) {
|
---|
532 |
|
---|
533 | // Select observations older than maxTime
|
---|
534 | // --------------------------------------
|
---|
535 | QList<p_obs> dumpList;
|
---|
536 | QMutableListIterator<p_obs> mIt(_obs);
|
---|
537 | while (mIt.hasNext()) {
|
---|
538 | p_obs obs = mIt.next();
|
---|
539 | if (obs->_o.GPSWeek * 7*24*3600 + obs->_o.GPSWeeks < maxTime - 0.05) {
|
---|
540 | dumpList.push_back(obs);
|
---|
541 | mIt.remove();
|
---|
542 | }
|
---|
543 | }
|
---|
544 |
|
---|
545 | // Easy Return
|
---|
546 | // -----------
|
---|
547 | if (dumpList.isEmpty()) {
|
---|
548 | return;
|
---|
549 | }
|
---|
550 |
|
---|
551 | // Time of Epoch
|
---|
552 | // -------------
|
---|
553 | p_obs fObs = *dumpList.begin();
|
---|
554 | QDateTime datTim = dateAndTimeFromGPSweek(fObs->_o.GPSWeek, fObs->_o.GPSWeeks);
|
---|
555 | QDateTime datTimNom = dateAndTimeFromGPSweek(fObs->_o.GPSWeek,
|
---|
556 | floor(fObs->_o.GPSWeeks+0.5));
|
---|
557 |
|
---|
558 | // Close the file
|
---|
559 | // --------------
|
---|
560 | if (_nextCloseEpoch.isValid() && datTimNom >= _nextCloseEpoch) {
|
---|
561 | closeFile();
|
---|
562 | _headerWritten = false;
|
---|
563 | }
|
---|
564 |
|
---|
565 | // Write RINEX Header
|
---|
566 | // ------------------
|
---|
567 | if (!_headerWritten) {
|
---|
568 | writeHeader(datTim, datTimNom);
|
---|
569 | }
|
---|
570 |
|
---|
571 | double sec = double(datTim.time().second()) + fmod(fObs->_o.GPSWeeks,1.0);
|
---|
572 |
|
---|
573 | // Epoch header line: RINEX Version 3
|
---|
574 | // ----------------------------------
|
---|
575 | if (_rinexVers == 3) {
|
---|
576 | _out << datTim.toString("> yyyy MM dd hh mm ").toAscii().data()
|
---|
577 | << setw(10) << setprecision(7) << sec
|
---|
578 | << " " << 0 << setw(3) << dumpList.size() << endl;
|
---|
579 | }
|
---|
580 | // Epoch header line: RINEX Version 2
|
---|
581 | // ----------------------------------
|
---|
582 | else {
|
---|
583 | _out << datTim.toString(" yy MM dd hh mm ").toAscii().data()
|
---|
584 | << setw(10) << setprecision(7) << sec
|
---|
585 | << " " << 0 << setw(3) << dumpList.size();
|
---|
586 |
|
---|
587 | QListIterator<p_obs> it(dumpList); int iSat = 0;
|
---|
588 | while (it.hasNext()) {
|
---|
589 | iSat++;
|
---|
590 | p_obs obs = it.next();
|
---|
591 | _out << obs->_o.satSys << setw(2) << obs->_o.satNum;
|
---|
592 | if (iSat == 12 && it.hasNext()) {
|
---|
593 | _out << endl << " ";
|
---|
594 | iSat = 0;
|
---|
595 | }
|
---|
596 | }
|
---|
597 | _out << endl;
|
---|
598 | }
|
---|
599 |
|
---|
600 | QListIterator<p_obs> it(dumpList);
|
---|
601 | while (it.hasNext()) {
|
---|
602 | p_obs obs = it.next();
|
---|
603 |
|
---|
604 | // Cycle slips detection
|
---|
605 | // ---------------------
|
---|
606 | int prn = 0;
|
---|
607 | switch (obs->_o.satSys) {
|
---|
608 | case 'G': prn = obs->_o.satNum; break;
|
---|
609 | case 'R': prn = obs->_o.satNum + 200; break;
|
---|
610 | default: prn = obs->_o.satNum;
|
---|
611 | }
|
---|
612 |
|
---|
613 | char lli1 = ' ';
|
---|
614 | char lli2 = ' ';
|
---|
615 | if ( obs->_o.slip_cnt_L1 >= 0 ) {
|
---|
616 | if ( _slip_cnt_L1.find(prn) != _slip_cnt_L1.end() &&
|
---|
617 | _slip_cnt_L1.find(prn).value() != obs->_o.slip_cnt_L1 ) {
|
---|
618 | lli1 = '1';
|
---|
619 | }
|
---|
620 | }
|
---|
621 | else if ( obs->_o.lock_timei_L1 >= 0 ) {
|
---|
622 | if ( _lock_timei_L1.find(prn) != _lock_timei_L1.end() &&
|
---|
623 | _lock_timei_L1.find(prn).value() != obs->_o.lock_timei_L1 ) {
|
---|
624 | lli1 = '1';
|
---|
625 | }
|
---|
626 | }
|
---|
627 |
|
---|
628 | if ( obs->_o.slip_cnt_L2 >= 0 ) {
|
---|
629 | if ( _slip_cnt_L2.find(prn) != _slip_cnt_L2.end() &&
|
---|
630 | _slip_cnt_L2.find(prn).value() != obs->_o.slip_cnt_L2 ) {
|
---|
631 | lli2 = '1';
|
---|
632 | }
|
---|
633 | }
|
---|
634 | else if ( obs->_o.lock_timei_L2 >= 0 ) {
|
---|
635 | if ( _lock_timei_L2.find(prn) != _lock_timei_L2.end() &&
|
---|
636 | _lock_timei_L2.find(prn).value() != obs->_o.lock_timei_L2 ) {
|
---|
637 | lli2 = '1';
|
---|
638 | }
|
---|
639 | }
|
---|
640 |
|
---|
641 | _slip_cnt_L1[prn] = obs->_o.slip_cnt_L1;
|
---|
642 | _slip_cnt_L2[prn] = obs->_o.slip_cnt_L2;
|
---|
643 |
|
---|
644 | _lock_timei_L1[prn] = obs->_o.lock_timei_L1;
|
---|
645 | _lock_timei_L2[prn] = obs->_o.lock_timei_L2;
|
---|
646 |
|
---|
647 | // RINEX Version 3
|
---|
648 | // ---------------
|
---|
649 | if (_rinexVers == 3) {
|
---|
650 | char sbasflag = 'S';
|
---|
651 | // Changed data output, C1P, C2C|X, L2C|X, S2C|X added. Changed Output for SBAS Perlt
|
---|
652 | if (sbasflag != obs->_o.satSys) {
|
---|
653 | _out << obs->_o.satSys
|
---|
654 | << setw(2) << setfill('0') << obs->_o.satNum << setfill(' ')
|
---|
655 | << setw(14) << setprecision(3) << obs->_o.C1 << " "
|
---|
656 | << setw(14) << setprecision(3) << obs->_o.P1 << " "
|
---|
657 | << setw(14) << setprecision(3) << obs->_o.L1 << lli1
|
---|
658 | << setw(1) << obs->_o.SNR1
|
---|
659 | << setw(14) << setprecision(3) << obs->_o.S1 << " "
|
---|
660 | << setw(14) << setprecision(3) << obs->_o.C2 << " "
|
---|
661 | << setw(14) << setprecision(3) << obs->_o.P2 << " " ;
|
---|
662 | if ((obs->_o.C2 != 0.0) && (obs->_o.P2 == 0.0)) {
|
---|
663 | _out << setw(14) << setprecision(3) << obs->_o.L2 << lli2
|
---|
664 | << setw(1) << obs->_o.SNR2
|
---|
665 | << setw(14) << setprecision(3) << obs->_o.S2 << " "
|
---|
666 | << " 0.000 0.000 ";
|
---|
667 | }
|
---|
668 | else {
|
---|
669 | _out << " 0.000 0.000 "
|
---|
670 | << setw(14) << setprecision(3) << obs->_o.L2 << " "
|
---|
671 | << setw(1) << obs->_o.SNR2
|
---|
672 | << setw(14) << setprecision(3) << obs->_o.S2;
|
---|
673 | }
|
---|
674 | _out << endl;
|
---|
675 | }
|
---|
676 | else {
|
---|
677 | _out << obs->_o.satSys
|
---|
678 | << setw(2) << setfill('0') << obs->_o.satNum << setfill(' ')
|
---|
679 | << setw(14) << setprecision(3) << obs->_o.C1 << " "
|
---|
680 | << setw(14) << setprecision(3) << obs->_o.P1 << " "
|
---|
681 | << setw(14) << setprecision(3) << obs->_o.L1 << lli1
|
---|
682 | << setw(1) << obs->_o.SNR1
|
---|
683 | << setw(14) << setprecision(3) << obs->_o.S1 << endl;
|
---|
684 | }
|
---|
685 | }
|
---|
686 |
|
---|
687 | // RINEX Version 2
|
---|
688 | // ---------------
|
---|
689 | else {
|
---|
690 | char lli = ' ';
|
---|
691 | char snr = ' ';
|
---|
692 | _out << setw(14) << setprecision(3) << obs->_o.C1 << lli << snr;
|
---|
693 | _out << setw(14) << setprecision(3) << obs->_o.C2 << lli << snr;
|
---|
694 | _out << setw(14) << setprecision(3) << obs->_o.P1 << lli << snr;
|
---|
695 | _out << setw(14) << setprecision(3) << obs->_o.P2 << lli << snr;
|
---|
696 | _out << setw(14) << setprecision(3) << obs->_o.L1 << lli1
|
---|
697 | << setw(1) << obs->_o.SNR1 << endl;
|
---|
698 | _out << setw(14) << setprecision(3) << obs->_o.L2 << lli2
|
---|
699 | << setw(1) << obs->_o.SNR2;
|
---|
700 | _out << setw(14) << setprecision(3) << obs->_o.S1 ;
|
---|
701 | _out << setw(16) << setprecision(3) << obs->_o.S2 ;
|
---|
702 | _out << endl;
|
---|
703 | }
|
---|
704 |
|
---|
705 | delete obs;
|
---|
706 | }
|
---|
707 |
|
---|
708 | _out.flush();
|
---|
709 | }
|
---|
710 |
|
---|
711 | // Close the Old RINEX File
|
---|
712 | ////////////////////////////////////////////////////////////////////////////
|
---|
713 | void bncRinex::closeFile() {
|
---|
714 | QMutexLocker locker(&_mutex);
|
---|
715 | if (_rinexVers == 3) {
|
---|
716 | _out << "> 4 1" << endl;
|
---|
717 | _out << "END OF FILE" << endl;
|
---|
718 | }
|
---|
719 | _out.close();
|
---|
720 | if (!_rnxScriptName.isEmpty()) {
|
---|
721 | msleep(1);
|
---|
722 | #ifdef WIN32
|
---|
723 | QProcess::startDetached(_rnxScriptName, QStringList() << _fName) ;
|
---|
724 | #else
|
---|
725 | QProcess::startDetached("nohup", QStringList() << _rnxScriptName << _fName) ;
|
---|
726 | #endif
|
---|
727 |
|
---|
728 | }
|
---|
729 | }
|
---|