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