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