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