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 "RTCM3/rtcm3torinex.h"
|
---|
57 |
|
---|
58 | using namespace std;
|
---|
59 |
|
---|
60 | // Constructor
|
---|
61 | ////////////////////////////////////////////////////////////////////////////
|
---|
62 | bncRinex::bncRinex(const QByteArray& statID, const QUrl& mountPoint,
|
---|
63 | const QByteArray& format, const QByteArray& latitude,
|
---|
64 | const QByteArray& longitude, const QByteArray& nmea) {
|
---|
65 | _statID = statID;
|
---|
66 | _mountPoint = mountPoint;
|
---|
67 | _format = format.left(6);
|
---|
68 | _latitude = latitude;
|
---|
69 | _longitude = longitude;
|
---|
70 | _nmea = nmea;
|
---|
71 | _headerWritten = false;
|
---|
72 | _reconnectFlag = false;
|
---|
73 | _reloadTable = false;
|
---|
74 | _reloadDone = false;
|
---|
75 |
|
---|
76 | QSettings settings;
|
---|
77 | _rnxScriptName = settings.value("rnxScript").toString();
|
---|
78 | expandEnvVar(_rnxScriptName);
|
---|
79 |
|
---|
80 | _pgmName = ((bncApp*)qApp)->bncVersion().leftJustified(20, ' ', true);
|
---|
81 | #ifdef WIN32
|
---|
82 | _userName = QString("${USERNAME}");
|
---|
83 | #else
|
---|
84 | _userName = QString("${USER}");
|
---|
85 | #endif
|
---|
86 | expandEnvVar(_userName);
|
---|
87 | _userName = _userName.leftJustified(20, ' ', true);
|
---|
88 |
|
---|
89 | if ( Qt::CheckState(settings.value("rnxV3").toInt()) == Qt::Checked) {
|
---|
90 | _rinexVers = 3;
|
---|
91 | }
|
---|
92 | else {
|
---|
93 | _rinexVers = 2;
|
---|
94 | }
|
---|
95 |
|
---|
96 | _approxPos[0] = _approxPos[1] = _approxPos[2] = 0.0;
|
---|
97 | }
|
---|
98 |
|
---|
99 | // Destructor
|
---|
100 | ////////////////////////////////////////////////////////////////////////////
|
---|
101 | bncRinex::~bncRinex() {
|
---|
102 | QListIterator<p_obs> it(_obs);
|
---|
103 | while (it.hasNext()) {
|
---|
104 | delete it.next();
|
---|
105 | }
|
---|
106 | QSettings settings;
|
---|
107 | if ((_rinexVers == 3) && ( Qt::CheckState(settings.value("rnxAppend").toInt()) != Qt::Checked) ) {
|
---|
108 | _out << "> 4 1" << endl;
|
---|
109 | _out << "END OF FILE" << endl;
|
---|
110 | }
|
---|
111 | _out.close();
|
---|
112 | }
|
---|
113 |
|
---|
114 | // Download Skeleton Header File
|
---|
115 | ////////////////////////////////////////////////////////////////////////////
|
---|
116 | t_irc bncRinex::downloadSkeleton() {
|
---|
117 |
|
---|
118 | t_irc irc = failure;
|
---|
119 |
|
---|
120 | QStringList table;
|
---|
121 | bncTableDlg::getFullTable(_mountPoint.host(), _mountPoint.port(),
|
---|
122 | table, _reloadTable);
|
---|
123 | QString net;
|
---|
124 | QStringListIterator it(table);
|
---|
125 | while (it.hasNext()) {
|
---|
126 | QString line = it.next();
|
---|
127 | if (line.indexOf("STR") == 0) {
|
---|
128 | QStringList tags = line.split(";");
|
---|
129 | if (tags.at(1) == _mountPoint.path().mid(1).toAscii()) {
|
---|
130 | net = tags.at(7);
|
---|
131 | break;
|
---|
132 | }
|
---|
133 | }
|
---|
134 | }
|
---|
135 | QString sklDir;
|
---|
136 | it.toFront();
|
---|
137 | while (it.hasNext()) {
|
---|
138 | QString line = it.next();
|
---|
139 | if (line.indexOf("NET") == 0) {
|
---|
140 | QStringList tags = line.split(";");
|
---|
141 | if (tags.at(1) == net) {
|
---|
142 | sklDir = tags.at(6).trimmed();
|
---|
143 | break;
|
---|
144 | }
|
---|
145 | }
|
---|
146 | }
|
---|
147 | if (!sklDir.isEmpty() && sklDir != "none") {
|
---|
148 | QUrl url(sklDir + "/" + _mountPoint.path().mid(1,4).toLower() + ".skl");
|
---|
149 | if (url.port() == -1) {
|
---|
150 | url.setPort(80);
|
---|
151 | }
|
---|
152 |
|
---|
153 | const int timeOut = 10*1000;
|
---|
154 | QString msg;
|
---|
155 | QByteArray _latitude;
|
---|
156 | QByteArray _longitude;
|
---|
157 | QByteArray _nmea;
|
---|
158 | QTcpSocket* socket = bncGetThread::request(url, _latitude, _longitude, _nmea, timeOut, msg);
|
---|
159 |
|
---|
160 | if (socket) {
|
---|
161 | _headerLines.clear();
|
---|
162 | bool firstLineRead = false;
|
---|
163 | while (true) {
|
---|
164 | if (socket->canReadLine()) {
|
---|
165 | QString line = socket->readLine();
|
---|
166 | line.chop(1);
|
---|
167 | if (line.indexOf("MARKER NAME") != -1) {
|
---|
168 | irc = success;
|
---|
169 | }
|
---|
170 | if (line.indexOf("RINEX VERSION") != -1) {
|
---|
171 | if (_rinexVers == 3) {
|
---|
172 | _headerLines.append(" 3.00 OBSERVATION DATA"
|
---|
173 | " M (MIXED)"
|
---|
174 | " RINEX VERSION / TYPE");
|
---|
175 | }
|
---|
176 | else {
|
---|
177 | _headerLines.append(" 2.11 OBSERVATION DATA"
|
---|
178 | " M (MIXED)"
|
---|
179 | " RINEX VERSION / TYPE");
|
---|
180 | }
|
---|
181 | _headerLines.append("PGM / RUN BY / DATE");
|
---|
182 | firstLineRead = true;
|
---|
183 | }
|
---|
184 | else if (firstLineRead) {
|
---|
185 | if (line.indexOf("END OF HEADER") != -1) {
|
---|
186 | _headerLines.append("# / TYPES OF OBSERV");
|
---|
187 | if (_rinexVers == 2) {
|
---|
188 | _headerLines.append(
|
---|
189 | QString(" 1 1").leftJustified(60, ' ', true) +
|
---|
190 | "WAVELENGTH FACT L1/2");
|
---|
191 | }
|
---|
192 | _headerLines.append("TIME OF FIRST OBS");
|
---|
193 | _headerLines.append( line );
|
---|
194 | break;
|
---|
195 | }
|
---|
196 | else {
|
---|
197 | _headerLines.append( line );
|
---|
198 | }
|
---|
199 | }
|
---|
200 | }
|
---|
201 | else {
|
---|
202 | socket->waitForReadyRead(timeOut);
|
---|
203 | if (socket->bytesAvailable() > 0) {
|
---|
204 | continue;
|
---|
205 | }
|
---|
206 | else {
|
---|
207 | break;
|
---|
208 | }
|
---|
209 | }
|
---|
210 | }
|
---|
211 | delete socket;
|
---|
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 {
|
---|
238 | QDate currDate = QDateTime::currentDateTime().toUTC().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 | QSettings 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 | QSettings 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 = QDateTime::currentDateTime().toUTC().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 = QDateTime::currentDateTime().toUTC().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 = QDateTime::currentDateTime().toUTC().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 = QDateTime::currentDateTime().toUTC().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 | int lli1 = 0;
|
---|
609 | int lli2 = 0;
|
---|
610 | if ( _slip_cnt_L1.find(prn) != _slip_cnt_L1.end() &&
|
---|
611 | _slip_cnt_L1.find(prn).value() != obs->_o.slip_cnt_L1 ) {
|
---|
612 | lli1 = 1;
|
---|
613 | }
|
---|
614 | if ( _slip_cnt_L2.find(prn) != _slip_cnt_L2.end() &&
|
---|
615 | _slip_cnt_L2.find(prn).value() != obs->_o.slip_cnt_L2 ) {
|
---|
616 | lli2 = 1;
|
---|
617 | }
|
---|
618 | _slip_cnt_L1[prn]= obs->_o.slip_cnt_L1;
|
---|
619 | _slip_cnt_L2[prn]= obs->_o.slip_cnt_L2;
|
---|
620 |
|
---|
621 | // RINEX Version 3
|
---|
622 | // ---------------
|
---|
623 | if (_rinexVers == 3) {
|
---|
624 | char sbasflag = 'S';
|
---|
625 | // Changed data output, C1P, C2C|X, L2C|X, S2C|X added. Changed Output for SBAS Perlt
|
---|
626 | if (sbasflag != obs->_o.satSys) {
|
---|
627 | _out << obs->_o.satSys
|
---|
628 | << setw(2) << setfill('0') << obs->_o.satNum << setfill(' ')
|
---|
629 | << setw(14) << setprecision(3) << obs->_o.C1 << " "
|
---|
630 | << setw(14) << setprecision(3) << obs->_o.P1 << " "
|
---|
631 | << setw(14) << setprecision(3) << obs->_o.L1 << lli1
|
---|
632 | << setw(1) << obs->_o.SNR1
|
---|
633 | << setw(14) << setprecision(3) << obs->_o.S1 << " "
|
---|
634 | << setw(14) << setprecision(3) << obs->_o.C2 << " "
|
---|
635 | << setw(14) << setprecision(3) << obs->_o.P2 << " " ;
|
---|
636 | if ((obs->_o.C2 != 0.0) && (obs->_o.P2 == 0.0)) {
|
---|
637 | _out << setw(14) << setprecision(3) << obs->_o.L2 << lli2
|
---|
638 | << setw(1) << obs->_o.SNR2
|
---|
639 | << setw(14) << setprecision(3) << obs->_o.S2 << " "
|
---|
640 | << " 0.000 0.000 ";
|
---|
641 | }
|
---|
642 | else {
|
---|
643 | _out << " 0.000 0.000 "
|
---|
644 | << setw(14) << setprecision(3) << obs->_o.L2 << " "
|
---|
645 | << setw(1) << obs->_o.SNR2
|
---|
646 | << setw(14) << setprecision(3) << obs->_o.S2;
|
---|
647 | }
|
---|
648 | _out << endl;
|
---|
649 | }
|
---|
650 | else {
|
---|
651 | _out << obs->_o.satSys
|
---|
652 | << setw(2) << setfill('0') << obs->_o.satNum << setfill(' ')
|
---|
653 | << setw(14) << setprecision(3) << obs->_o.C1 << " "
|
---|
654 | << setw(14) << setprecision(3) << obs->_o.P1 << " "
|
---|
655 | << setw(14) << setprecision(3) << obs->_o.L1 << lli1
|
---|
656 | << setw(1) << obs->_o.SNR1
|
---|
657 | << setw(14) << setprecision(3) << obs->_o.S1 << endl;
|
---|
658 | }
|
---|
659 | }
|
---|
660 |
|
---|
661 | // RINEX Version 2
|
---|
662 | // ---------------
|
---|
663 | else {
|
---|
664 | char lli = ' ';
|
---|
665 | char snr = ' ';
|
---|
666 | _out << setw(14) << setprecision(3) << obs->_o.C1 << lli << snr;
|
---|
667 | _out << setw(14) << setprecision(3) << obs->_o.C2 << lli << snr;
|
---|
668 | _out << setw(14) << setprecision(3) << obs->_o.P1 << lli << snr;
|
---|
669 | _out << setw(14) << setprecision(3) << obs->_o.P2 << lli << snr;
|
---|
670 | _out << setw(14) << setprecision(3) << obs->_o.L1 << lli1
|
---|
671 | << setw(1) << obs->_o.SNR1 << endl;
|
---|
672 | _out << setw(14) << setprecision(3) << obs->_o.L2 << lli2
|
---|
673 | << setw(1) << obs->_o.SNR2;
|
---|
674 | _out << setw(14) << setprecision(3) << obs->_o.S1 ;
|
---|
675 | _out << setw(16) << setprecision(3) << obs->_o.S2 ;
|
---|
676 | _out << endl;
|
---|
677 | }
|
---|
678 |
|
---|
679 | delete obs;
|
---|
680 | }
|
---|
681 |
|
---|
682 | _out.flush();
|
---|
683 | }
|
---|
684 |
|
---|
685 | // Close the Old RINEX File
|
---|
686 | ////////////////////////////////////////////////////////////////////////////
|
---|
687 | void bncRinex::closeFile() {
|
---|
688 | QMutexLocker locker(&_mutex);
|
---|
689 | if (_rinexVers == 3) {
|
---|
690 | _out << "> 4 1" << endl;
|
---|
691 | _out << "END OF FILE" << endl;
|
---|
692 | }
|
---|
693 | _out.close();
|
---|
694 | if (!_rnxScriptName.isEmpty()) {
|
---|
695 | msleep(1);
|
---|
696 | #ifdef WIN32
|
---|
697 | QProcess::startDetached(_rnxScriptName, QStringList() << _fName) ;
|
---|
698 | #else
|
---|
699 | QProcess::startDetached("nohup", QStringList() << _rnxScriptName << _fName) ;
|
---|
700 | #endif
|
---|
701 |
|
---|
702 | }
|
---|
703 | }
|
---|