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