| 1 | // Part of BNC, a utility for retrieving decoding and
|
|---|
| 2 | // converting GNSS data streams from NTRIP broadcasters.
|
|---|
| 3 | //
|
|---|
| 4 | // Copyright (C) 2007
|
|---|
| 5 | // German Federal Agency for Cartography and Geodesy (BKG)
|
|---|
| 6 | // http://www.bkg.bund.de
|
|---|
| 7 | // Czech Technical University Prague, Department of Geodesy
|
|---|
| 8 | // http://www.fsv.cvut.cz
|
|---|
| 9 | //
|
|---|
| 10 | // Email: euref-ip@bkg.bund.de
|
|---|
| 11 | //
|
|---|
| 12 | // This program is free software; you can redistribute it and/or
|
|---|
| 13 | // modify it under the terms of the GNU General Public License
|
|---|
| 14 | // as published by the Free Software Foundation, version 2.
|
|---|
| 15 | //
|
|---|
| 16 | // This program is distributed in the hope that it will be useful,
|
|---|
| 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 19 | // GNU General Public License for more details.
|
|---|
| 20 | //
|
|---|
| 21 | // You should have received a copy of the GNU General Public License
|
|---|
| 22 | // along with this program; if not, write to the Free Software
|
|---|
| 23 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|---|
| 24 |
|
|---|
| 25 | /* -------------------------------------------------------------------------
|
|---|
| 26 | * BKG NTRIP Client
|
|---|
| 27 | * -------------------------------------------------------------------------
|
|---|
| 28 | *
|
|---|
| 29 | * Class: bncRinex
|
|---|
| 30 | *
|
|---|
| 31 | * Purpose: writes RINEX files
|
|---|
| 32 | *
|
|---|
| 33 | * Author: L. Mervart
|
|---|
| 34 | *
|
|---|
| 35 | * Created: 27-Aug-2006
|
|---|
| 36 | *
|
|---|
| 37 | * Changes:
|
|---|
| 38 | *
|
|---|
| 39 | * -----------------------------------------------------------------------*/
|
|---|
| 40 |
|
|---|
| 41 | #include <stdlib.h>
|
|---|
| 42 | #include <iostream>
|
|---|
| 43 | #include <iomanip>
|
|---|
| 44 | #include <math.h>
|
|---|
| 45 |
|
|---|
| 46 | #include <QtCore>
|
|---|
| 47 | #include <QUrl>
|
|---|
| 48 | #include <QString>
|
|---|
| 49 |
|
|---|
| 50 | #include "bncrinex.h"
|
|---|
| 51 | #include "bncapp.h"
|
|---|
| 52 | #include "bncutils.h"
|
|---|
| 53 | #include "bncconst.h"
|
|---|
| 54 | #include "bnctabledlg.h"
|
|---|
| 55 | #include "bncgetthread.h"
|
|---|
| 56 | #include "RTCM3/rtcm3torinex.h"
|
|---|
| 57 |
|
|---|
| 58 | using namespace std;
|
|---|
| 59 |
|
|---|
| 60 | // Constructor
|
|---|
| 61 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 62 | bncRinex::bncRinex(const QByteArray& statID, const QUrl& mountPoint,
|
|---|
| 63 | const QByteArray& format, const QByteArray& latitude,
|
|---|
| 64 | const QByteArray& longitude, const QByteArray& nmea) {
|
|---|
| 65 | _statID = statID;
|
|---|
| 66 | _mountPoint = mountPoint;
|
|---|
| 67 | _format = format.left(6);
|
|---|
| 68 | _latitude = latitude;
|
|---|
| 69 | _longitude = longitude;
|
|---|
| 70 | _nmea = nmea;
|
|---|
| 71 | _headerWritten = false;
|
|---|
| 72 | _reconnectFlag = false;
|
|---|
| 73 | _reloadTable = false;
|
|---|
| 74 | _reloadDone = false;
|
|---|
| 75 |
|
|---|
| 76 | QSettings settings;
|
|---|
| 77 | _rnxScriptName = settings.value("rnxScript").toString();
|
|---|
| 78 | expandEnvVar(_rnxScriptName);
|
|---|
| 79 |
|
|---|
| 80 | _pgmName = ((bncApp*)qApp)->bncVersion().leftJustified(20, ' ', true);
|
|---|
| 81 | #ifdef WIN32
|
|---|
| 82 | _userName = QString("${USERNAME}");
|
|---|
| 83 | #else
|
|---|
| 84 | _userName = QString("${USER}");
|
|---|
| 85 | #endif
|
|---|
| 86 | expandEnvVar(_userName);
|
|---|
| 87 | _userName = _userName.leftJustified(20, ' ', true);
|
|---|
| 88 |
|
|---|
| 89 | if ( Qt::CheckState(settings.value("rnxV3").toInt()) == Qt::Checked) {
|
|---|
| 90 | _rinexVers = 3;
|
|---|
| 91 | }
|
|---|
| 92 | else {
|
|---|
| 93 | _rinexVers = 2;
|
|---|
| 94 | }
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | // Destructor
|
|---|
| 98 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 99 | bncRinex::~bncRinex() {
|
|---|
| 100 | QListIterator<p_obs> it(_obs);
|
|---|
| 101 | while (it.hasNext()) {
|
|---|
| 102 | delete it.next();
|
|---|
| 103 | }
|
|---|
| 104 | QSettings settings;
|
|---|
| 105 | if ((_rinexVers == 3) && ( Qt::CheckState(settings.value("rnxAppend").toInt()) != Qt::Checked) ) {
|
|---|
| 106 | _out << "> 4 1" << endl;
|
|---|
| 107 | _out << "END OF FILE" << endl;
|
|---|
| 108 | }
|
|---|
| 109 | _out.close();
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | // Download Skeleton Header File
|
|---|
| 113 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 114 | t_irc bncRinex::downloadSkeleton() {
|
|---|
| 115 |
|
|---|
| 116 | t_irc irc = failure;
|
|---|
| 117 |
|
|---|
| 118 | QStringList table;
|
|---|
| 119 | bncTableDlg::getFullTable(_mountPoint.host(), _mountPoint.port(),
|
|---|
| 120 | table, _reloadTable);
|
|---|
| 121 | QString net;
|
|---|
| 122 | QStringListIterator it(table);
|
|---|
| 123 | while (it.hasNext()) {
|
|---|
| 124 | QString line = it.next();
|
|---|
| 125 | if (line.indexOf("STR") == 0) {
|
|---|
| 126 | QStringList tags = line.split(";");
|
|---|
| 127 | if (tags.at(1) == _mountPoint.path().mid(1).toAscii()) {
|
|---|
| 128 | net = tags.at(7);
|
|---|
| 129 | break;
|
|---|
| 130 | }
|
|---|
| 131 | }
|
|---|
| 132 | }
|
|---|
| 133 | QString sklDir;
|
|---|
| 134 | it.toFront();
|
|---|
| 135 | while (it.hasNext()) {
|
|---|
| 136 | QString line = it.next();
|
|---|
| 137 | if (line.indexOf("NET") == 0) {
|
|---|
| 138 | QStringList tags = line.split(";");
|
|---|
| 139 | if (tags.at(1) == net) {
|
|---|
| 140 | sklDir = tags.at(6).trimmed();
|
|---|
| 141 | break;
|
|---|
| 142 | }
|
|---|
| 143 | }
|
|---|
| 144 | }
|
|---|
| 145 | if (!sklDir.isEmpty() && sklDir != "none") {
|
|---|
| 146 | QUrl url(sklDir + "/" + _mountPoint.path().mid(1,4).toLower() + ".skl");
|
|---|
| 147 | if (url.port() == -1) {
|
|---|
| 148 | url.setPort(80);
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | const int timeOut = 10*1000;
|
|---|
| 152 | QString msg;
|
|---|
| 153 | QByteArray _latitude;
|
|---|
| 154 | QByteArray _longitude;
|
|---|
| 155 | QByteArray _nmea;
|
|---|
| 156 | QTcpSocket* socket = bncGetThread::request(url, _latitude, _longitude, _nmea, timeOut, msg);
|
|---|
| 157 |
|
|---|
| 158 | if (socket) {
|
|---|
| 159 | _headerLines.clear();
|
|---|
| 160 | bool firstLineRead = false;
|
|---|
| 161 | while (true) {
|
|---|
| 162 | if (socket->canReadLine()) {
|
|---|
| 163 | QString line = socket->readLine();
|
|---|
| 164 | line.chop(1);
|
|---|
| 165 | if (line.indexOf("MARKER NAME") != -1) {
|
|---|
| 166 | irc = success;
|
|---|
| 167 | }
|
|---|
| 168 | if (line.indexOf("RINEX VERSION") != -1) {
|
|---|
| 169 | if (_rinexVers == 3) {
|
|---|
| 170 | _headerLines.append(" 3.00 OBSERVATION DATA"
|
|---|
| 171 | " M (MIXED)"
|
|---|
| 172 | " RINEX VERSION / TYPE");
|
|---|
| 173 | }
|
|---|
| 174 | else {
|
|---|
| 175 | _headerLines.append(" 2.11 OBSERVATION DATA"
|
|---|
| 176 | " M (MIXED)"
|
|---|
| 177 | " RINEX VERSION / TYPE");
|
|---|
| 178 | }
|
|---|
| 179 | _headerLines.append("PGM / RUN BY / DATE");
|
|---|
| 180 | firstLineRead = true;
|
|---|
| 181 | }
|
|---|
| 182 | else if (firstLineRead) {
|
|---|
| 183 | if (line.indexOf("END OF HEADER") != -1) {
|
|---|
| 184 | _headerLines.append("# / TYPES OF OBSERV");
|
|---|
| 185 | if (_rinexVers == 2) {
|
|---|
| 186 | _headerLines.append(
|
|---|
| 187 | QString(" 1 1").leftJustified(60, ' ', true) +
|
|---|
| 188 | "WAVELENGTH FACT L1/2");
|
|---|
| 189 | }
|
|---|
| 190 | _headerLines.append("TIME OF FIRST OBS");
|
|---|
| 191 | _headerLines.append( line );
|
|---|
| 192 | break;
|
|---|
| 193 | }
|
|---|
| 194 | else {
|
|---|
| 195 | _headerLines.append( line );
|
|---|
| 196 | }
|
|---|
| 197 | }
|
|---|
| 198 | }
|
|---|
| 199 | else {
|
|---|
| 200 | socket->waitForReadyRead(timeOut);
|
|---|
| 201 | if (socket->bytesAvailable() > 0) {
|
|---|
| 202 | continue;
|
|---|
| 203 | }
|
|---|
| 204 | else {
|
|---|
| 205 | break;
|
|---|
| 206 | }
|
|---|
| 207 | }
|
|---|
| 208 | }
|
|---|
| 209 | delete socket;
|
|---|
| 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 {
|
|---|
| 236 | QDate currDate = QDateTime::currentDateTime().toUTC().date();
|
|---|
| 237 | if ( !_skeletonDate.isValid() || _skeletonDate != currDate ) {
|
|---|
| 238 | if ( downloadSkeleton() == success) {
|
|---|
| 239 | _skeletonDate = currDate;
|
|---|
| 240 | _reloadDone = false;
|
|---|
| 241 | }
|
|---|
| 242 | else {
|
|---|
| 243 | if(!_reloadDone) {
|
|---|
| 244 | _reloadTable = true;
|
|---|
| 245 | if ( downloadSkeleton() == success) {
|
|---|
| 246 | _skeletonDate = currDate;
|
|---|
| 247 | }
|
|---|
| 248 | _reloadTable = false;
|
|---|
| 249 | _reloadDone = true;
|
|---|
| 250 | }
|
|---|
| 251 | }
|
|---|
| 252 | }
|
|---|
| 253 | }
|
|---|
| 254 | }
|
|---|
| 255 |
|
|---|
| 256 | // Next File Epoch (static)
|
|---|
| 257 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 258 | QString bncRinex::nextEpochStr(const QDateTime& datTim,
|
|---|
| 259 | const QString& intStr, QDateTime* nextEpoch) {
|
|---|
| 260 |
|
|---|
| 261 | QString epoStr;
|
|---|
| 262 |
|
|---|
| 263 | QTime nextTime;
|
|---|
| 264 | QDate nextDate;
|
|---|
| 265 |
|
|---|
| 266 | int indHlp = intStr.indexOf("min");
|
|---|
| 267 |
|
|---|
| 268 | if ( indHlp != -1) {
|
|---|
| 269 | int step = intStr.left(indHlp-1).toInt();
|
|---|
| 270 | char ch = 'A' + datTim.time().hour();
|
|---|
| 271 | epoStr = ch;
|
|---|
| 272 | if (datTim.time().minute() >= 60-step) {
|
|---|
| 273 | epoStr += QString("%1").arg(60-step, 2, 10, QChar('0'));
|
|---|
| 274 | if (datTim.time().hour() < 23) {
|
|---|
| 275 | nextTime.setHMS(datTim.time().hour() + 1 , 0, 0);
|
|---|
| 276 | nextDate = datTim.date();
|
|---|
| 277 | }
|
|---|
| 278 | else {
|
|---|
| 279 | nextTime.setHMS(0, 0, 0);
|
|---|
| 280 | nextDate = datTim.date().addDays(1);
|
|---|
| 281 | }
|
|---|
| 282 | }
|
|---|
| 283 | else {
|
|---|
| 284 | for (int limit = step; limit <= 60-step; limit += step) {
|
|---|
| 285 | if (datTim.time().minute() < limit) {
|
|---|
| 286 | epoStr += QString("%1").arg(limit-step, 2, 10, QChar('0'));
|
|---|
| 287 | nextTime.setHMS(datTim.time().hour(), limit, 0);
|
|---|
| 288 | nextDate = datTim.date();
|
|---|
| 289 | break;
|
|---|
| 290 | }
|
|---|
| 291 | }
|
|---|
| 292 | }
|
|---|
| 293 | }
|
|---|
| 294 | else if (intStr == "1 hour") {
|
|---|
| 295 | char ch = 'A' + datTim.time().hour();
|
|---|
| 296 | epoStr = ch;
|
|---|
| 297 | if (datTim.time().hour() < 23) {
|
|---|
| 298 | nextTime.setHMS(datTim.time().hour() + 1 , 0, 0);
|
|---|
| 299 | nextDate = datTim.date();
|
|---|
| 300 | }
|
|---|
| 301 | else {
|
|---|
| 302 | nextTime.setHMS(0, 0, 0);
|
|---|
| 303 | nextDate = datTim.date().addDays(1);
|
|---|
| 304 | }
|
|---|
| 305 | }
|
|---|
| 306 | else {
|
|---|
| 307 | epoStr = "0";
|
|---|
| 308 | nextTime.setHMS(0, 0, 0);
|
|---|
| 309 | nextDate = datTim.date().addDays(1);
|
|---|
| 310 | }
|
|---|
| 311 |
|
|---|
| 312 | if (nextEpoch) {
|
|---|
| 313 | *nextEpoch = QDateTime(nextDate, nextTime);
|
|---|
| 314 | }
|
|---|
| 315 |
|
|---|
| 316 | return epoStr;
|
|---|
| 317 | }
|
|---|
| 318 |
|
|---|
| 319 | // File Name according to RINEX Standards
|
|---|
| 320 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 321 | void bncRinex::resolveFileName(const QDateTime& datTim) {
|
|---|
| 322 |
|
|---|
| 323 | QSettings settings;
|
|---|
| 324 | QString path = settings.value("rnxPath").toString();
|
|---|
| 325 | expandEnvVar(path);
|
|---|
| 326 |
|
|---|
| 327 | if ( path.length() > 0 && path[path.length()-1] != QDir::separator() ) {
|
|---|
| 328 | path += QDir::separator();
|
|---|
| 329 | }
|
|---|
| 330 |
|
|---|
| 331 | QString hlpStr = nextEpochStr(datTim, settings.value("rnxIntr").toString(),
|
|---|
| 332 | &_nextCloseEpoch);
|
|---|
| 333 |
|
|---|
| 334 | QString ID4 = _statID.left(4);
|
|---|
| 335 |
|
|---|
| 336 | // Check name conflict
|
|---|
| 337 | // -------------------
|
|---|
| 338 | QString distStr;
|
|---|
| 339 | int num = 0;
|
|---|
| 340 | QListIterator<QString> it(settings.value("mountPoints").toStringList());
|
|---|
| 341 | while (it.hasNext()) {
|
|---|
| 342 | QString mp = it.next();
|
|---|
| 343 | if (mp.indexOf(ID4) != -1) {
|
|---|
| 344 | ++num;
|
|---|
| 345 | }
|
|---|
| 346 | }
|
|---|
| 347 | if (num > 1) {
|
|---|
| 348 | distStr = "_" + _statID.mid(4);
|
|---|
| 349 | }
|
|---|
| 350 |
|
|---|
| 351 | QString sklExt = settings.value("rnxSkel").toString();
|
|---|
| 352 | if (!sklExt.isEmpty()) {
|
|---|
| 353 | _sklName = path + ID4 + distStr + "." + sklExt;
|
|---|
| 354 | }
|
|---|
| 355 |
|
|---|
| 356 | path += ID4 +
|
|---|
| 357 | QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
|
|---|
| 358 | hlpStr + distStr + datTim.toString(".yyO");
|
|---|
| 359 |
|
|---|
| 360 | _fName = path.toAscii();
|
|---|
| 361 | }
|
|---|
| 362 |
|
|---|
| 363 | // Write RINEX Header
|
|---|
| 364 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 365 | void bncRinex::writeHeader(const QDateTime& datTim,
|
|---|
| 366 | const QDateTime& datTimNom) {
|
|---|
| 367 |
|
|---|
| 368 | QSettings settings;
|
|---|
| 369 |
|
|---|
| 370 | // Open the Output File
|
|---|
| 371 | // --------------------
|
|---|
| 372 | resolveFileName(datTimNom);
|
|---|
| 373 |
|
|---|
| 374 | // Append to existing file and return
|
|---|
| 375 | // ----------------------------------
|
|---|
| 376 | if ( QFile::exists(_fName) ) {
|
|---|
| 377 | if (_reconnectFlag ||
|
|---|
| 378 | Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
|
|---|
| 379 | _out.open(_fName.data(), ios::app);
|
|---|
| 380 | _out.setf(ios::showpoint | ios::fixed);
|
|---|
| 381 | _headerWritten = true;
|
|---|
| 382 | _reconnectFlag = false;
|
|---|
| 383 | return;
|
|---|
| 384 | }
|
|---|
| 385 | }
|
|---|
| 386 |
|
|---|
| 387 | _out.open(_fName.data());
|
|---|
| 388 | _out.setf(ios::showpoint | ios::fixed);
|
|---|
| 389 |
|
|---|
| 390 | // Copy Skeleton Header
|
|---|
| 391 | // --------------------
|
|---|
| 392 | readSkeleton();
|
|---|
| 393 | if (_headerLines.size() > 0) {
|
|---|
| 394 | QStringListIterator it(_headerLines);
|
|---|
| 395 | while (it.hasNext()) {
|
|---|
| 396 | QString line = it.next();
|
|---|
| 397 | if (line.indexOf("PGM / RUN BY / DATE") != -1) {
|
|---|
| 398 | if (_rinexVers == 3) {
|
|---|
| 399 | QString hlp = QDateTime::currentDateTime().toUTC().toString("yyyyMMdd hhmmss UTC").leftJustified(20, ' ', true);
|
|---|
| 400 | _out << _pgmName.toAscii().data() << _userName.toAscii().data()
|
|---|
| 401 | << hlp.toAscii().data() << "PGM / RUN BY / DATE" << endl;
|
|---|
| 402 | }
|
|---|
| 403 | else {
|
|---|
| 404 | QString hlp = QDateTime::currentDateTime().toUTC().date().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
|
|---|
| 405 | _out << _pgmName.toAscii().data() << _userName.toAscii().data()
|
|---|
| 406 | << hlp.toAscii().data() << "PGM / RUN BY / DATE" << endl;
|
|---|
| 407 | }
|
|---|
| 408 | }
|
|---|
| 409 | else if (line.indexOf("# / TYPES OF OBSERV") != -1) {
|
|---|
| 410 | if (_rinexVers == 3) {
|
|---|
| 411 | // Changed declaration of data types, consistent with Rinex3 Perlt
|
|---|
| 412 | _out << "G 10 C1C C1P L1C S1C C2X C2P L2X S2X L2P S2P SYS / # / OBS TYPES" << endl;
|
|---|
| 413 | _out << "R 10 C1C C1P L1C S1C C2C C2P L2C S2C L2P S2P SYS / # / OBS TYPES" << endl;
|
|---|
| 414 | _out << "S 3 C1C L1C S1C SYS / # / OBS TYPES" << endl;
|
|---|
| 415 | }
|
|---|
| 416 | else {
|
|---|
| 417 | _out << " 8 C1 C2 P1 P2 L1 L2 S1 S2"
|
|---|
| 418 | " # / TYPES OF OBSERV" << endl;
|
|---|
| 419 | }
|
|---|
| 420 | }
|
|---|
| 421 | else if (line.indexOf("TIME OF FIRST OBS") != -1) {
|
|---|
| 422 | _out << datTim.toString(" yyyy MM dd"
|
|---|
| 423 | " hh mm ss.zzz0000").toAscii().data();
|
|---|
| 424 | _out << " GPS TIME OF FIRST OBS" << endl;
|
|---|
| 425 | QString hlp = (_format + QString(" %1").arg(_mountPoint.host() +
|
|---|
| 426 | _mountPoint.path())).leftJustified(60, ' ', true);
|
|---|
| 427 | _out << hlp.toAscii().data() << "COMMENT" << endl;
|
|---|
| 428 | }
|
|---|
| 429 | // Added header line for Rinex3 regarding mandatory MARKER TYPE field Perlt
|
|---|
| 430 | else if (line.indexOf("MARKER NAME") != -1) {
|
|---|
| 431 | if (_rinexVers == 3) {
|
|---|
| 432 | _out << line.toAscii().data() << endl;
|
|---|
| 433 | _out << setw(71) << "GEODETIC MARKER TYPE" << endl;
|
|---|
| 434 | }
|
|---|
| 435 | else {
|
|---|
| 436 | _out << line.toAscii().data() << endl;
|
|---|
| 437 | }
|
|---|
| 438 | // End
|
|---|
| 439 | }
|
|---|
| 440 | else {
|
|---|
| 441 | _out << line.toAscii().data() << endl;
|
|---|
| 442 | }
|
|---|
| 443 | }
|
|---|
| 444 | }
|
|---|
| 445 |
|
|---|
| 446 | // Write Dummy Header
|
|---|
| 447 | // ------------------
|
|---|
| 448 | else {
|
|---|
| 449 | double approxPos[3]; approxPos[0] = approxPos[1] = approxPos[2] = 0.0;
|
|---|
| 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 = QDateTime::currentDateTime().toUTC().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 = QDateTime::currentDateTime().toUTC().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 | // Added header line for Rinex3 regarding mandatory MARKER TYPE field Perlt
|
|---|
| 467 | if (_rinexVers == 3) {
|
|---|
| 468 | _out << setw(60) << "unknown" << "MARKER TYPE " << endl;
|
|---|
| 469 | }
|
|---|
| 470 | // End
|
|---|
| 471 | _out << setw(60) << "unknown unknown" << "OBSERVER / AGENCY" << endl;
|
|---|
| 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;
|
|---|
| 478 | _out.unsetf(ios::left);
|
|---|
| 479 | _out << setw(14) << setprecision(4) << approxPos[0]
|
|---|
| 480 | << setw(14) << setprecision(4) << approxPos[1]
|
|---|
| 481 | << setw(14) << setprecision(4) << approxPos[2]
|
|---|
| 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;
|
|---|
| 487 | if (_rinexVers == 3) {
|
|---|
| 488 | // Changed declaration of data types, consistent with Rinex3 Perlt
|
|---|
| 489 | _out << "G 10 C1C C1P L1C S1C C2X C2P L2X S2X L2P S2P SYS / # / OBS TYPES" << endl;
|
|---|
| 490 | _out << "R 10 C1C C1P L1C S1C C2C C2P L2C S2C L2P S2P SYS / # / OBS TYPES" << endl;
|
|---|
| 491 | _out << "S 3 C1C L1C S1C SYS / # / OBS TYPES" << endl;
|
|---|
| 492 |
|
|---|
| 493 | }
|
|---|
| 494 | else {
|
|---|
| 495 | _out << " 1 1 WAVELENGTH FACT L1/2" << endl;
|
|---|
| 496 | _out << " 8 C1 C2 P1 P2 L1 L2 S1 S2 # / TYPES OF OBSERV" << endl;
|
|---|
| 497 | }
|
|---|
| 498 | _out << datTim.toString(" yyyy MM dd"
|
|---|
| 499 | " hh mm ss.zzz0000").toAscii().data();
|
|---|
| 500 | _out << " GPS TIME OF FIRST OBS" << endl;
|
|---|
| 501 | QString hlp = (_format + QString(" %1").arg(_mountPoint.host() +
|
|---|
| 502 | _mountPoint.path())).leftJustified(60, ' ', true);
|
|---|
| 503 | _out << hlp.toAscii().data() << "COMMENT" << endl;
|
|---|
| 504 |
|
|---|
| 505 | if (_nmea == "yes") {
|
|---|
| 506 | hlp = ("NMEA LAT=" + _latitude + " " + "LONG=" + _longitude).leftJustified(60, ' ',true);
|
|---|
| 507 | _out << hlp.toAscii().data() << "COMMENT" << endl; }
|
|---|
| 508 |
|
|---|
| 509 | _out << " END OF HEADER" << endl;
|
|---|
| 510 | }
|
|---|
| 511 |
|
|---|
| 512 | _headerWritten = true;
|
|---|
| 513 | }
|
|---|
| 514 |
|
|---|
| 515 | // Stores Observation into Internal Array
|
|---|
| 516 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 517 | void bncRinex::deepCopy(const p_obs obs) {
|
|---|
| 518 | p_obs newObs = new t_obs();
|
|---|
| 519 | memcpy(&newObs->_o, &obs->_o, sizeof(t_obsInternal));
|
|---|
| 520 | _obs.push_back(newObs);
|
|---|
| 521 | }
|
|---|
| 522 |
|
|---|
| 523 | // Write One Epoch into the RINEX File
|
|---|
| 524 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 525 | void bncRinex::dumpEpoch(long maxTime) {
|
|---|
| 526 |
|
|---|
| 527 | // Select observations older than maxTime
|
|---|
| 528 | // --------------------------------------
|
|---|
| 529 | QList<p_obs> dumpList;
|
|---|
| 530 | QMutableListIterator<p_obs> mIt(_obs);
|
|---|
| 531 | while (mIt.hasNext()) {
|
|---|
| 532 | p_obs obs = mIt.next();
|
|---|
| 533 | if (obs->_o.GPSWeek * 7*24*3600 + obs->_o.GPSWeeks < maxTime - 0.05) {
|
|---|
| 534 | dumpList.push_back(obs);
|
|---|
| 535 | mIt.remove();
|
|---|
| 536 | }
|
|---|
| 537 | }
|
|---|
| 538 |
|
|---|
| 539 | // Easy Return
|
|---|
| 540 | // -----------
|
|---|
| 541 | if (dumpList.isEmpty()) {
|
|---|
| 542 | return;
|
|---|
| 543 | }
|
|---|
| 544 |
|
|---|
| 545 | // Time of Epoch
|
|---|
| 546 | // -------------
|
|---|
| 547 | p_obs fObs = *dumpList.begin();
|
|---|
| 548 | QDateTime datTim = dateAndTimeFromGPSweek(fObs->_o.GPSWeek, fObs->_o.GPSWeeks);
|
|---|
| 549 | QDateTime datTimNom = dateAndTimeFromGPSweek(fObs->_o.GPSWeek,
|
|---|
| 550 | floor(fObs->_o.GPSWeeks+0.5));
|
|---|
| 551 |
|
|---|
| 552 | // Close the file
|
|---|
| 553 | // --------------
|
|---|
| 554 | if (_nextCloseEpoch.isValid() && datTimNom >= _nextCloseEpoch) {
|
|---|
| 555 | closeFile();
|
|---|
| 556 | _headerWritten = false;
|
|---|
| 557 | }
|
|---|
| 558 |
|
|---|
| 559 | // Write RINEX Header
|
|---|
| 560 | // ------------------
|
|---|
| 561 | if (!_headerWritten) {
|
|---|
| 562 | writeHeader(datTim, datTimNom);
|
|---|
| 563 | }
|
|---|
| 564 |
|
|---|
| 565 | double sec = double(datTim.time().second()) + fmod(fObs->_o.GPSWeeks,1.0);
|
|---|
| 566 |
|
|---|
| 567 | // RINEX Version 3
|
|---|
| 568 | // ---------------
|
|---|
| 569 | if (_rinexVers == 3) {
|
|---|
| 570 | char sbasflag = 'S';
|
|---|
| 571 | _out << datTim.toString("> yyyy MM dd hh mm ").toAscii().data()
|
|---|
| 572 | << setw(10) << setprecision(7) << sec
|
|---|
| 573 | << " " << 0 << setw(3) << dumpList.size() << endl;
|
|---|
| 574 |
|
|---|
| 575 | QListIterator<p_obs> it(dumpList);
|
|---|
| 576 | while (it.hasNext()) {
|
|---|
| 577 | p_obs obs = it.next();
|
|---|
| 578 | // Changed data output, C1P, C2C|X, L2C|X, S2C|X added. Changed Output for SBAS Perlt
|
|---|
| 579 | if (sbasflag != obs->_o.satSys) {
|
|---|
| 580 | _out << obs->_o.satSys
|
|---|
| 581 | << setw(2) << setfill('0') << obs->_o.satNum << setfill(' ')
|
|---|
| 582 | << setw(14) << setprecision(3) << obs->_o.C1 << " "
|
|---|
| 583 | << setw(14) << setprecision(3) << obs->_o.P1 << " "
|
|---|
| 584 | << setw(14) << setprecision(3) << obs->_o.L1 << " "
|
|---|
| 585 | << setw(1) << obs->_o.SNR1
|
|---|
| 586 | << setw(14) << setprecision(3) << obs->_o.S1 << " "
|
|---|
| 587 | << setw(14) << setprecision(3) << obs->_o.C2 << " "
|
|---|
| 588 | << setw(14) << setprecision(3) << obs->_o.P2 << " " ;
|
|---|
| 589 | if ((obs->_o.C2 != 0.0) && (obs->_o.P2 == 0.0)) {
|
|---|
| 590 | _out << setw(14) << setprecision(3) << obs->_o.L2 << " "
|
|---|
| 591 | << setw(1) << obs->_o.SNR2
|
|---|
| 592 | << setw(14) << setprecision(3) << obs->_o.S2 << " "
|
|---|
| 593 | << " 0.000 0.000 ";
|
|---|
| 594 | }
|
|---|
| 595 | else {
|
|---|
| 596 | _out << " 0.000 0.000 "
|
|---|
| 597 | << setw(14) << setprecision(3) << obs->_o.L2 << " "
|
|---|
| 598 | << setw(1) << obs->_o.SNR2
|
|---|
| 599 | << setw(14) << setprecision(3) << obs->_o.S2;
|
|---|
| 600 | }
|
|---|
| 601 | _out << endl;
|
|---|
| 602 | }
|
|---|
| 603 | else {
|
|---|
| 604 | _out << obs->_o.satSys
|
|---|
| 605 | << setw(2) << setfill('0') << obs->_o.satNum << setfill(' ')
|
|---|
| 606 | << setw(14) << setprecision(3) << obs->_o.C1 << " "
|
|---|
| 607 | << setw(14) << setprecision(3) << obs->_o.P1 << " "
|
|---|
| 608 | << setw(14) << setprecision(3) << obs->_o.L1 << " "
|
|---|
| 609 | << setw(1) << obs->_o.SNR1
|
|---|
| 610 | << setw(14) << setprecision(3) << obs->_o.S1 << endl;
|
|---|
| 611 | }
|
|---|
| 612 | delete obs;
|
|---|
| 613 | }
|
|---|
| 614 | }
|
|---|
| 615 |
|
|---|
| 616 | // RINEX Version 2
|
|---|
| 617 | // ---------------
|
|---|
| 618 | else {
|
|---|
| 619 | _out << datTim.toString(" yy MM dd hh mm ").toAscii().data()
|
|---|
| 620 | << setw(10) << setprecision(7) << sec
|
|---|
| 621 | << " " << 0 << setw(3) << dumpList.size();
|
|---|
| 622 |
|
|---|
| 623 | QListIterator<p_obs> it(dumpList); int iSat = 0;
|
|---|
| 624 | while (it.hasNext()) {
|
|---|
| 625 | iSat++;
|
|---|
| 626 | p_obs obs = it.next();
|
|---|
| 627 | _out << obs->_o.satSys << setw(2) << obs->_o.satNum;
|
|---|
| 628 | if (iSat == 12 && it.hasNext()) {
|
|---|
| 629 | _out << endl << " ";
|
|---|
| 630 | iSat = 0;
|
|---|
| 631 | }
|
|---|
| 632 | }
|
|---|
| 633 | _out << endl;
|
|---|
| 634 |
|
|---|
| 635 | it.toFront();
|
|---|
| 636 | while (it.hasNext()) {
|
|---|
| 637 | p_obs obs = it.next();
|
|---|
| 638 |
|
|---|
| 639 | char lli = ' ';
|
|---|
| 640 | char snr = ' ';
|
|---|
| 641 | _out << setw(14) << setprecision(3) << obs->_o.C1 << lli << snr;
|
|---|
| 642 | _out << setw(14) << setprecision(3) << obs->_o.C2 << lli << snr;
|
|---|
| 643 | _out << setw(14) << setprecision(3) << obs->_o.P1 << lli << snr;
|
|---|
| 644 | _out << setw(14) << setprecision(3) << obs->_o.P2 << lli << snr;
|
|---|
| 645 | _out << setw(14) << setprecision(3) << obs->_o.L1 << lli
|
|---|
| 646 | << setw(1) << obs->_o.SNR1 << endl;
|
|---|
| 647 | _out << setw(14) << setprecision(3) << obs->_o.L2 << lli
|
|---|
| 648 | << setw(1) << obs->_o.SNR2;
|
|---|
| 649 | _out << setw(14) << setprecision(3) << obs->_o.S1 ;
|
|---|
| 650 | _out << setw(16) << setprecision(3) << obs->_o.S2 ;
|
|---|
| 651 | _out << endl;
|
|---|
| 652 |
|
|---|
| 653 | delete obs;
|
|---|
| 654 | }
|
|---|
| 655 | }
|
|---|
| 656 |
|
|---|
| 657 | _out.flush();
|
|---|
| 658 | }
|
|---|
| 659 |
|
|---|
| 660 | // Close the Old RINEX File
|
|---|
| 661 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 662 | void bncRinex::closeFile() {
|
|---|
| 663 | QMutexLocker locker(&_mutex);
|
|---|
| 664 | if (_rinexVers == 3) {
|
|---|
| 665 | _out << "> 4 1" << endl;
|
|---|
| 666 | _out << "END OF FILE" << endl;
|
|---|
| 667 | }
|
|---|
| 668 | _out.close();
|
|---|
| 669 | if (!_rnxScriptName.isEmpty()) {
|
|---|
| 670 | msleep(1);
|
|---|
| 671 | #ifdef WIN32
|
|---|
| 672 | QProcess::startDetached(_rnxScriptName, QStringList() << _fName) ;
|
|---|
| 673 | #else
|
|---|
| 674 | QProcess::startDetached("nohup", QStringList() << _rnxScriptName << _fName) ;
|
|---|
| 675 | #endif
|
|---|
| 676 |
|
|---|
| 677 | }
|
|---|
| 678 | }
|
|---|