| [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"
|
|---|
| [5070] | 52 | #include "bnccore.h"
|
|---|
| [82] | 53 | #include "bncutils.h"
|
|---|
| [126] | 54 | #include "bncconst.h"
|
|---|
| [298] | 55 | #include "bnctabledlg.h"
|
|---|
| [301] | 56 | #include "bncgetthread.h"
|
|---|
| [3337] | 57 | #include "bncnetqueryv1.h"
|
|---|
| [1858] | 58 | #include "bncnetqueryv2.h"
|
|---|
| [1535] | 59 | #include "bncsettings.h"
|
|---|
| [2012] | 60 | #include "bncversion.h"
|
|---|
| [2492] | 61 | #include "rtcm3torinex.h"
|
|---|
| [75] | 62 |
|
|---|
| 63 | using namespace std;
|
|---|
| 64 |
|
|---|
| [73] | 65 | // Constructor
|
|---|
| 66 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| [408] | 67 | bncRinex::bncRinex(const QByteArray& statID, const QUrl& mountPoint,
|
|---|
| [3525] | 68 | const QByteArray& latitude, const QByteArray& longitude,
|
|---|
| 69 | const QByteArray& nmea, const QByteArray& ntripVersion) {
|
|---|
| [1387] | 70 |
|
|---|
| [408] | 71 | _statID = statID;
|
|---|
| [336] | 72 | _mountPoint = mountPoint;
|
|---|
| [366] | 73 | _latitude = latitude;
|
|---|
| 74 | _longitude = longitude;
|
|---|
| 75 | _nmea = nmea;
|
|---|
| [1639] | 76 | _ntripVersion = ntripVersion;
|
|---|
| [77] | 77 | _headerWritten = false;
|
|---|
| [369] | 78 | _reconnectFlag = false;
|
|---|
| [132] | 79 |
|
|---|
| [1535] | 80 | bncSettings settings;
|
|---|
| [132] | 81 | _rnxScriptName = settings.value("rnxScript").toString();
|
|---|
| 82 | expandEnvVar(_rnxScriptName);
|
|---|
| [153] | 83 |
|
|---|
| [2012] | 84 | _pgmName = QString(BNCPGMNAME).leftJustified(20, ' ', true);
|
|---|
| [319] | 85 | #ifdef WIN32
|
|---|
| 86 | _userName = QString("${USERNAME}");
|
|---|
| 87 | #else
|
|---|
| [158] | 88 | _userName = QString("${USER}");
|
|---|
| [319] | 89 | #endif
|
|---|
| [157] | 90 | expandEnvVar(_userName);
|
|---|
| [158] | 91 | _userName = _userName.leftJustified(20, ' ', true);
|
|---|
| [539] | 92 |
|
|---|
| [3528] | 93 | _samplingRate = settings.value("rnxSampl").toInt();
|
|---|
| [73] | 94 | }
|
|---|
| 95 |
|
|---|
| 96 | // Destructor
|
|---|
| 97 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 98 | bncRinex::~bncRinex() {
|
|---|
| [1535] | 99 | bncSettings settings;
|
|---|
| [4483] | 100 | if ((_header._version >= 3.0) && ( Qt::CheckState(settings.value("rnxAppend").toInt()) != Qt::Checked) ) {
|
|---|
| [843] | 101 | _out << "> 4 1" << endl;
|
|---|
| [698] | 102 | _out << "END OF FILE" << endl;
|
|---|
| 103 | }
|
|---|
| [77] | 104 | _out.close();
|
|---|
| [73] | 105 | }
|
|---|
| 106 |
|
|---|
| [420] | 107 | // Download Skeleton Header File
|
|---|
| 108 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 109 | t_irc bncRinex::downloadSkeleton() {
|
|---|
| 110 |
|
|---|
| 111 | t_irc irc = failure;
|
|---|
| 112 |
|
|---|
| 113 | QStringList table;
|
|---|
| [3335] | 114 | bncTableDlg::getFullTable(_ntripVersion, _mountPoint.host(),
|
|---|
| [4481] | 115 | _mountPoint.port(), table, true);
|
|---|
| [420] | 116 | QString net;
|
|---|
| 117 | QStringListIterator it(table);
|
|---|
| 118 | while (it.hasNext()) {
|
|---|
| 119 | QString line = it.next();
|
|---|
| 120 | if (line.indexOf("STR") == 0) {
|
|---|
| 121 | QStringList tags = line.split(";");
|
|---|
| [1495] | 122 | if (tags.size() > 7) {
|
|---|
| 123 | if (tags.at(1) == _mountPoint.path().mid(1).toAscii()) {
|
|---|
| 124 | net = tags.at(7);
|
|---|
| 125 | break;
|
|---|
| 126 | }
|
|---|
| [420] | 127 | }
|
|---|
| 128 | }
|
|---|
| 129 | }
|
|---|
| 130 | QString sklDir;
|
|---|
| [1495] | 131 | if (!net.isEmpty()) {
|
|---|
| 132 | it.toFront();
|
|---|
| 133 | while (it.hasNext()) {
|
|---|
| 134 | QString line = it.next();
|
|---|
| 135 | if (line.indexOf("NET") == 0) {
|
|---|
| 136 | QStringList tags = line.split(";");
|
|---|
| 137 | if (tags.size() > 6) {
|
|---|
| 138 | if (tags.at(1) == net) {
|
|---|
| 139 | sklDir = tags.at(6).trimmed();
|
|---|
| 140 | break;
|
|---|
| 141 | }
|
|---|
| 142 | }
|
|---|
| 143 | }
|
|---|
| [420] | 144 | }
|
|---|
| 145 | }
|
|---|
| 146 | if (!sklDir.isEmpty() && sklDir != "none") {
|
|---|
| 147 | QUrl url(sklDir + "/" + _mountPoint.path().mid(1,4).toLower() + ".skl");
|
|---|
| 148 | if (url.port() == -1) {
|
|---|
| 149 | url.setPort(80);
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| [3337] | 152 | bncNetQuery* query;
|
|---|
| 153 | if (_ntripVersion == "2s") {
|
|---|
| 154 | query = new bncNetQueryV2(true);
|
|---|
| 155 | }
|
|---|
| 156 | else if (_ntripVersion == "2") {
|
|---|
| 157 | query = new bncNetQueryV2(false);
|
|---|
| 158 | }
|
|---|
| 159 | else {
|
|---|
| 160 | query = new bncNetQueryV1;
|
|---|
| 161 | }
|
|---|
| 162 |
|
|---|
| [1386] | 163 | QByteArray outData;
|
|---|
| [3337] | 164 | query->waitForRequestResult(url, outData);
|
|---|
| 165 | if (query->status() == bncNetQuery::finished) {
|
|---|
| [4481] | 166 | irc = success;
|
|---|
| [6120] | 167 | _header._obsTypes.clear();
|
|---|
| [1386] | 168 | QTextStream in(outData);
|
|---|
| [4481] | 169 | _header.read(&in);
|
|---|
| [420] | 170 | }
|
|---|
| [4481] | 171 |
|
|---|
| [3337] | 172 | delete query;
|
|---|
| 173 | }
|
|---|
| [1386] | 174 |
|
|---|
| [420] | 175 | return irc;
|
|---|
| 176 | }
|
|---|
| 177 |
|
|---|
| [82] | 178 | // Read Skeleton Header File
|
|---|
| 179 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| [4532] | 180 | bool bncRinex::readSkeleton() {
|
|---|
| [82] | 181 |
|
|---|
| [4532] | 182 | bool readDone = false;
|
|---|
| 183 |
|
|---|
| [420] | 184 | // Read the local file
|
|---|
| 185 | // -------------------
|
|---|
| [276] | 186 | QFile skl(_sklName);
|
|---|
| [82] | 187 | if ( skl.exists() && skl.open(QIODevice::ReadOnly) ) {
|
|---|
| [4532] | 188 | readDone = true;
|
|---|
| [6120] | 189 | _header._obsTypes.clear();
|
|---|
| [82] | 190 | QTextStream in(&skl);
|
|---|
| [4481] | 191 | _header.read(&in);
|
|---|
| [82] | 192 | }
|
|---|
| [298] | 193 |
|
|---|
| [420] | 194 | // Read downloaded file
|
|---|
| 195 | // --------------------
|
|---|
| [2376] | 196 | else if ( _ntripVersion != "N" && _ntripVersion != "UN" &&
|
|---|
| 197 | _ntripVersion != "S" ) {
|
|---|
| [1154] | 198 | QDate currDate = currentDateAndTimeGPS().date();
|
|---|
| [420] | 199 | if ( !_skeletonDate.isValid() || _skeletonDate != currDate ) {
|
|---|
| [4532] | 200 | if (downloadSkeleton() == success) {
|
|---|
| 201 | readDone = true;
|
|---|
| 202 | }
|
|---|
| [4481] | 203 | _skeletonDate = currDate;
|
|---|
| [298] | 204 | }
|
|---|
| 205 | }
|
|---|
| [4532] | 206 |
|
|---|
| 207 | return readDone;
|
|---|
| [82] | 208 | }
|
|---|
| 209 |
|
|---|
| [647] | 210 | // Next File Epoch (static)
|
|---|
| [82] | 211 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| [647] | 212 | QString bncRinex::nextEpochStr(const QDateTime& datTim,
|
|---|
| 213 | const QString& intStr, QDateTime* nextEpoch) {
|
|---|
| [82] | 214 |
|
|---|
| [647] | 215 | QString epoStr;
|
|---|
| [82] | 216 |
|
|---|
| [129] | 217 | QTime nextTime;
|
|---|
| 218 | QDate nextDate;
|
|---|
| 219 |
|
|---|
| [204] | 220 | int indHlp = intStr.indexOf("min");
|
|---|
| 221 |
|
|---|
| 222 | if ( indHlp != -1) {
|
|---|
| 223 | int step = intStr.left(indHlp-1).toInt();
|
|---|
| [127] | 224 | char ch = 'A' + datTim.time().hour();
|
|---|
| [647] | 225 | epoStr = ch;
|
|---|
| [204] | 226 | if (datTim.time().minute() >= 60-step) {
|
|---|
| [647] | 227 | epoStr += QString("%1").arg(60-step, 2, 10, QChar('0'));
|
|---|
| [199] | 228 | if (datTim.time().hour() < 23) {
|
|---|
| 229 | nextTime.setHMS(datTim.time().hour() + 1 , 0, 0);
|
|---|
| 230 | nextDate = datTim.date();
|
|---|
| 231 | }
|
|---|
| 232 | else {
|
|---|
| 233 | nextTime.setHMS(0, 0, 0);
|
|---|
| 234 | nextDate = datTim.date().addDays(1);
|
|---|
| 235 | }
|
|---|
| 236 | }
|
|---|
| 237 | else {
|
|---|
| [204] | 238 | for (int limit = step; limit <= 60-step; limit += step) {
|
|---|
| 239 | if (datTim.time().minute() < limit) {
|
|---|
| [647] | 240 | epoStr += QString("%1").arg(limit-step, 2, 10, QChar('0'));
|
|---|
| [204] | 241 | nextTime.setHMS(datTim.time().hour(), limit, 0);
|
|---|
| 242 | nextDate = datTim.date();
|
|---|
| 243 | break;
|
|---|
| 244 | }
|
|---|
| [199] | 245 | }
|
|---|
| 246 | }
|
|---|
| 247 | }
|
|---|
| [127] | 248 | else if (intStr == "1 hour") {
|
|---|
| 249 | char ch = 'A' + datTim.time().hour();
|
|---|
| [647] | 250 | epoStr = ch;
|
|---|
| [129] | 251 | if (datTim.time().hour() < 23) {
|
|---|
| 252 | nextTime.setHMS(datTim.time().hour() + 1 , 0, 0);
|
|---|
| 253 | nextDate = datTim.date();
|
|---|
| 254 | }
|
|---|
| 255 | else {
|
|---|
| 256 | nextTime.setHMS(0, 0, 0);
|
|---|
| 257 | nextDate = datTim.date().addDays(1);
|
|---|
| 258 | }
|
|---|
| [127] | 259 | }
|
|---|
| 260 | else {
|
|---|
| [647] | 261 | epoStr = "0";
|
|---|
| [129] | 262 | nextTime.setHMS(0, 0, 0);
|
|---|
| 263 | nextDate = datTim.date().addDays(1);
|
|---|
| [127] | 264 | }
|
|---|
| [82] | 265 |
|
|---|
| [647] | 266 | if (nextEpoch) {
|
|---|
| 267 | *nextEpoch = QDateTime(nextDate, nextTime);
|
|---|
| 268 | }
|
|---|
| 269 |
|
|---|
| 270 | return epoStr;
|
|---|
| 271 | }
|
|---|
| 272 |
|
|---|
| 273 | // File Name according to RINEX Standards
|
|---|
| 274 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 275 | void bncRinex::resolveFileName(const QDateTime& datTim) {
|
|---|
| 276 |
|
|---|
| [1535] | 277 | bncSettings settings;
|
|---|
| [647] | 278 | QString path = settings.value("rnxPath").toString();
|
|---|
| 279 | expandEnvVar(path);
|
|---|
| 280 |
|
|---|
| 281 | if ( path.length() > 0 && path[path.length()-1] != QDir::separator() ) {
|
|---|
| 282 | path += QDir::separator();
|
|---|
| 283 | }
|
|---|
| 284 |
|
|---|
| 285 | QString hlpStr = nextEpochStr(datTim, settings.value("rnxIntr").toString(),
|
|---|
| 286 | &_nextCloseEpoch);
|
|---|
| 287 |
|
|---|
| [183] | 288 | QString ID4 = _statID.left(4);
|
|---|
| 289 |
|
|---|
| 290 | // Check name conflict
|
|---|
| 291 | // -------------------
|
|---|
| 292 | QString distStr;
|
|---|
| 293 | int num = 0;
|
|---|
| 294 | QListIterator<QString> it(settings.value("mountPoints").toStringList());
|
|---|
| 295 | while (it.hasNext()) {
|
|---|
| 296 | QString mp = it.next();
|
|---|
| 297 | if (mp.indexOf(ID4) != -1) {
|
|---|
| 298 | ++num;
|
|---|
| 299 | }
|
|---|
| 300 | }
|
|---|
| 301 | if (num > 1) {
|
|---|
| 302 | distStr = "_" + _statID.mid(4);
|
|---|
| 303 | }
|
|---|
| 304 |
|
|---|
| [276] | 305 | QString sklExt = settings.value("rnxSkel").toString();
|
|---|
| 306 | if (!sklExt.isEmpty()) {
|
|---|
| 307 | _sklName = path + ID4 + distStr + "." + sklExt;
|
|---|
| 308 | }
|
|---|
| 309 |
|
|---|
| [183] | 310 | path += ID4 +
|
|---|
| [127] | 311 | QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
|
|---|
| [276] | 312 | hlpStr + distStr + datTim.toString(".yyO");
|
|---|
| [82] | 313 |
|
|---|
| 314 | _fName = path.toAscii();
|
|---|
| 315 | }
|
|---|
| 316 |
|
|---|
| [77] | 317 | // Write RINEX Header
|
|---|
| 318 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| [4489] | 319 | void bncRinex::writeHeader(const QByteArray& format,
|
|---|
| [267] | 320 | const QDateTime& datTimNom) {
|
|---|
| [77] | 321 |
|
|---|
| [1535] | 322 | bncSettings settings;
|
|---|
| [356] | 323 |
|
|---|
| [77] | 324 | // Open the Output File
|
|---|
| 325 | // --------------------
|
|---|
| [267] | 326 | resolveFileName(datTimNom);
|
|---|
| [260] | 327 |
|
|---|
| 328 | // Append to existing file and return
|
|---|
| 329 | // ----------------------------------
|
|---|
| [5530] | 330 | if ( QFile::exists(_fName) &&
|
|---|
| 331 | (_reconnectFlag || Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) ) {
|
|---|
| 332 | _out.open(_fName.data(), ios::app);
|
|---|
| 333 | _out.setf(ios::showpoint | ios::fixed);
|
|---|
| 334 | _headerWritten = true;
|
|---|
| 335 | _reconnectFlag = false;
|
|---|
| [260] | 336 | }
|
|---|
| [5530] | 337 | else {
|
|---|
| 338 | _out.open(_fName.data());
|
|---|
| 339 | }
|
|---|
| [260] | 340 |
|
|---|
| [85] | 341 | _out.setf(ios::showpoint | ios::fixed);
|
|---|
| [77] | 342 |
|
|---|
| [4502] | 343 | // Read Skeleton Header
|
|---|
| [82] | 344 | // --------------------
|
|---|
| [4532] | 345 | bool skelRead = readSkeleton();
|
|---|
| [4502] | 346 |
|
|---|
| 347 | // Set RINEX Version
|
|---|
| 348 | // -----------------
|
|---|
| 349 | if ( Qt::CheckState(settings.value("rnxV3").toInt()) == Qt::Checked) {
|
|---|
| [5376] | 350 | _header._version = t_rnxObsHeader::defaultRnxObsVersion3;
|
|---|
| [4502] | 351 | }
|
|---|
| 352 | else {
|
|---|
| [5376] | 353 | _header._version = t_rnxObsHeader::defaultRnxObsVersion2;
|
|---|
| [4502] | 354 | }
|
|---|
| 355 |
|
|---|
| [4503] | 356 | // A Few Additional Comments
|
|---|
| 357 | // -------------------------
|
|---|
| [4532] | 358 | if (skelRead || _addComments.size() == 0) {
|
|---|
| 359 | _addComments.clear();
|
|---|
| 360 | _addComments << format.left(6) + " "
|
|---|
| 361 | + _mountPoint.host() + _mountPoint.path();
|
|---|
| [6120] | 362 | if (_header._obsTypes.size() == 0) {
|
|---|
| [4533] | 363 | _addComments << "Default set of observation types used";
|
|---|
| 364 | }
|
|---|
| [4532] | 365 | if (_nmea == "yes") {
|
|---|
| 366 | _addComments << "NMEA LAT=" + _latitude + " " + "LONG=" + _longitude;
|
|---|
| 367 | }
|
|---|
| [4503] | 368 | }
|
|---|
| 369 |
|
|---|
| [4502] | 370 | // Set Marker Name
|
|---|
| 371 | // ---------------
|
|---|
| [4495] | 372 | if (_header._markerName.isEmpty()) {
|
|---|
| 373 | _header._markerName = _statID;
|
|---|
| 374 | }
|
|---|
| [78] | 375 |
|
|---|
| [6120] | 376 | // Set Default Observation Types
|
|---|
| 377 | // -----------------------------
|
|---|
| 378 | if (_header._obsTypes.size() == 0) {
|
|---|
| 379 | if (_header._version < 3.0) {
|
|---|
| 380 | _header._obsTypes['G'] << "C1" << "P1" << "L1" << "S1"
|
|---|
| 381 | << "C2" << "P2" << "L2" << "S2";
|
|---|
| 382 | _header._obsTypes['R'] = _header._obsTypes['G'];
|
|---|
| 383 | _header._obsTypes['E'] = _header._obsTypes['G'];
|
|---|
| 384 | _header._obsTypes['J'] = _header._obsTypes['G'];
|
|---|
| 385 | _header._obsTypes['S'] = _header._obsTypes['G'];
|
|---|
| 386 | _header._obsTypes['C'] = _header._obsTypes['G'];
|
|---|
| 387 | }
|
|---|
| 388 | else {
|
|---|
| 389 | _header._obsTypes['G'] << "C1C" << "L1C" << "D1C" << "S1C"
|
|---|
| [4502] | 390 | << "C1P" << "L1P" << "D1P" << "S1P"
|
|---|
| 391 | << "C2C" << "L2C" << "D2C" << "S2C"
|
|---|
| 392 | << "C2P" << "L2P" << "D2P" << "S2P"
|
|---|
| 393 | << "C5" << "D5" << "L5" << "S5";
|
|---|
| [6120] | 394 |
|
|---|
| 395 | _header._obsTypes['R'] << "C1C" << "L1C" << "D1C" << "S1C"
|
|---|
| [4502] | 396 | << "C1P" << "L1P" << "D1P" << "S1P"
|
|---|
| 397 | << "C2C" << "L2C" << "D2C" << "S2C"
|
|---|
| 398 | << "C2P" << "L2P" << "D2P" << "S2P";
|
|---|
| [6120] | 399 |
|
|---|
| 400 | _header._obsTypes['E'] << "C1" << "L1" << "D1" << "S1"
|
|---|
| [4502] | 401 | << "C5" << "L5" << "D5" << "S5"
|
|---|
| 402 | << "C6" << "L6" << "D6" << "S6"
|
|---|
| 403 | << "C7" << "L7" << "D7" << "S7"
|
|---|
| 404 | << "C8" << "L8" << "D8" << "S8";
|
|---|
| [6120] | 405 |
|
|---|
| 406 | _header._obsTypes['J'] << "C1" << "L1" << "D1" << "S1"
|
|---|
| [4502] | 407 | << "C2" << "L2" << "D2" << "S2"
|
|---|
| 408 | << "C5" << "L5" << "D5" << "S5"
|
|---|
| 409 | << "C6" << "D6" << "L6" << "S6";
|
|---|
| [6120] | 410 |
|
|---|
| 411 | _header._obsTypes['S'] << "C1" << "L1" << "D1" << "S1"
|
|---|
| [4502] | 412 | << "C5" << "L5" << "D5" << "S5";
|
|---|
| [6120] | 413 |
|
|---|
| 414 | _header._obsTypes['C'] << "C1" << "L1" << "D1" << "S1"
|
|---|
| [4502] | 415 | << "C6" << "L6" << "D6" << "S6"
|
|---|
| 416 | << "C7" << "L7" << "D7" << "S7";
|
|---|
| [6120] | 417 | }
|
|---|
| [4502] | 418 | }
|
|---|
| 419 |
|
|---|
| [4503] | 420 | // Write the Header
|
|---|
| 421 | // ----------------
|
|---|
| 422 | QByteArray headerLines;
|
|---|
| 423 | QTextStream outHlp(&headerLines);
|
|---|
| 424 |
|
|---|
| [4495] | 425 | QMap<QString, QString> txtMap;
|
|---|
| [4532] | 426 | txtMap["COMMENT"] = _addComments.join("\\n");
|
|---|
| [4495] | 427 |
|
|---|
| 428 | _header.write(&outHlp, &txtMap);
|
|---|
| [4503] | 429 |
|
|---|
| [4481] | 430 | outHlp.flush();
|
|---|
| [4406] | 431 |
|
|---|
| [5530] | 432 | if (!_headerWritten) {
|
|---|
| 433 | _out << headerLines.data();
|
|---|
| 434 | }
|
|---|
| 435 |
|
|---|
| [77] | 436 | _headerWritten = true;
|
|---|
| 437 | }
|
|---|
| 438 |
|
|---|
| [73] | 439 | // Stores Observation into Internal Array
|
|---|
| 440 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| [2711] | 441 | void bncRinex::deepCopy(t_obs obs) {
|
|---|
| 442 | _obs.push_back(obs);
|
|---|
| [73] | 443 | }
|
|---|
| 444 |
|
|---|
| 445 | // Write One Epoch into the RINEX File
|
|---|
| 446 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| [3525] | 447 | void bncRinex::dumpEpoch(const QByteArray& format, long maxTime) {
|
|---|
| [73] | 448 |
|
|---|
| [160] | 449 | // Select observations older than maxTime
|
|---|
| 450 | // --------------------------------------
|
|---|
| [2711] | 451 | QList<t_obs> dumpList;
|
|---|
| 452 | QMutableListIterator<t_obs> mIt(_obs);
|
|---|
| [160] | 453 | while (mIt.hasNext()) {
|
|---|
| [2711] | 454 | t_obs obs = mIt.next();
|
|---|
| 455 | if (obs.GPSWeek * 7*24*3600 + obs.GPSWeeks < maxTime - 0.05) {
|
|---|
| [622] | 456 | dumpList.push_back(obs);
|
|---|
| [160] | 457 | mIt.remove();
|
|---|
| 458 | }
|
|---|
| 459 | }
|
|---|
| 460 |
|
|---|
| [75] | 461 | // Easy Return
|
|---|
| 462 | // -----------
|
|---|
| [160] | 463 | if (dumpList.isEmpty()) {
|
|---|
| [75] | 464 | return;
|
|---|
| 465 | }
|
|---|
| 466 |
|
|---|
| 467 | // Time of Epoch
|
|---|
| 468 | // -------------
|
|---|
| [2711] | 469 | const t_obs& fObs = dumpList.first();
|
|---|
| 470 | QDateTime datTim = dateAndTimeFromGPSweek(fObs.GPSWeek, fObs.GPSWeeks);
|
|---|
| 471 | QDateTime datTimNom = dateAndTimeFromGPSweek(fObs.GPSWeek,
|
|---|
| 472 | floor(fObs.GPSWeeks+0.5));
|
|---|
| [75] | 473 |
|
|---|
| [130] | 474 | // Close the file
|
|---|
| 475 | // --------------
|
|---|
| [267] | 476 | if (_nextCloseEpoch.isValid() && datTimNom >= _nextCloseEpoch) {
|
|---|
| [130] | 477 | closeFile();
|
|---|
| 478 | _headerWritten = false;
|
|---|
| 479 | }
|
|---|
| 480 |
|
|---|
| [78] | 481 | // Write RINEX Header
|
|---|
| 482 | // ------------------
|
|---|
| 483 | if (!_headerWritten) {
|
|---|
| [4489] | 484 | _header._startTime.set(fObs.GPSWeek, fObs.GPSWeeks);
|
|---|
| 485 | writeHeader(format, datTimNom);
|
|---|
| [78] | 486 | }
|
|---|
| 487 |
|
|---|
| [5328] | 488 | // Check whether observation types available
|
|---|
| 489 | // -----------------------------------------
|
|---|
| 490 | QMutableListIterator<t_obs> mItDump(dumpList);
|
|---|
| 491 | while (mItDump.hasNext()) {
|
|---|
| 492 | t_obs& obs = mItDump.next();
|
|---|
| [6120] | 493 | if (!_header._obsTypes.contains(obs.satSys) && !_header._obsTypes.contains(obs.satSys)) {
|
|---|
| [5328] | 494 | mItDump.remove();
|
|---|
| 495 | }
|
|---|
| 496 | }
|
|---|
| 497 | if (dumpList.isEmpty()) {
|
|---|
| 498 | return;
|
|---|
| 499 | }
|
|---|
| 500 |
|
|---|
| [2711] | 501 | double sec = double(datTim.time().second()) + fmod(fObs.GPSWeeks,1.0);
|
|---|
| [75] | 502 |
|
|---|
| [1044] | 503 | // Epoch header line: RINEX Version 3
|
|---|
| 504 | // ----------------------------------
|
|---|
| [4483] | 505 | if (_header._version >= 3.0) {
|
|---|
| [540] | 506 | _out << datTim.toString("> yyyy MM dd hh mm ").toAscii().data()
|
|---|
| 507 | << setw(10) << setprecision(7) << sec
|
|---|
| 508 | << " " << 0 << setw(3) << dumpList.size() << endl;
|
|---|
| [74] | 509 | }
|
|---|
| [1044] | 510 | // Epoch header line: RINEX Version 2
|
|---|
| 511 | // ----------------------------------
|
|---|
| [540] | 512 | else {
|
|---|
| 513 | _out << datTim.toString(" yy MM dd hh mm ").toAscii().data()
|
|---|
| 514 | << setw(10) << setprecision(7) << sec
|
|---|
| 515 | << " " << 0 << setw(3) << dumpList.size();
|
|---|
| [1044] | 516 |
|
|---|
| [2711] | 517 | QListIterator<t_obs> it(dumpList); int iSat = 0;
|
|---|
| [540] | 518 | while (it.hasNext()) {
|
|---|
| 519 | iSat++;
|
|---|
| [2711] | 520 | const t_obs& obs = it.next();
|
|---|
| 521 | _out << obs.satSys << setw(2) << obs.satNum;
|
|---|
| [540] | 522 | if (iSat == 12 && it.hasNext()) {
|
|---|
| 523 | _out << endl << " ";
|
|---|
| 524 | iSat = 0;
|
|---|
| 525 | }
|
|---|
| 526 | }
|
|---|
| [77] | 527 | _out << endl;
|
|---|
| [1044] | 528 | }
|
|---|
| 529 |
|
|---|
| [2711] | 530 | QListIterator<t_obs> it(dumpList);
|
|---|
| [1044] | 531 | while (it.hasNext()) {
|
|---|
| [2711] | 532 | const t_obs& obs = it.next();
|
|---|
| [1044] | 533 |
|
|---|
| 534 | // Cycle slips detection
|
|---|
| 535 | // ---------------------
|
|---|
| [2711] | 536 | QString prn = QString("%1%2").arg(obs.satSys)
|
|---|
| 537 | .arg(obs.satNum, 2, 10, QChar('0'));
|
|---|
| [1044] | 538 |
|
|---|
| 539 | char lli1 = ' ';
|
|---|
| 540 | char lli2 = ' ';
|
|---|
| [2688] | 541 | char lli5 = ' ';
|
|---|
| [2711] | 542 | if ( obs.slip_cnt_L1 >= 0 ) {
|
|---|
| [1044] | 543 | if ( _slip_cnt_L1.find(prn) != _slip_cnt_L1.end() &&
|
|---|
| [2711] | 544 | _slip_cnt_L1.find(prn).value() != obs.slip_cnt_L1 ) {
|
|---|
| [2682] | 545 | lli1 = '1';
|
|---|
| [1044] | 546 | }
|
|---|
| 547 | }
|
|---|
| 548 |
|
|---|
| [2711] | 549 | if ( obs.slip_cnt_L2 >= 0 ) {
|
|---|
| [1044] | 550 | if ( _slip_cnt_L2.find(prn) != _slip_cnt_L2.end() &&
|
|---|
| [2711] | 551 | _slip_cnt_L2.find(prn).value() != obs.slip_cnt_L2 ) {
|
|---|
| [2682] | 552 | lli2 = '1';
|
|---|
| [1044] | 553 | }
|
|---|
| 554 | }
|
|---|
| 555 |
|
|---|
| [2711] | 556 | if ( obs.slip_cnt_L5 >= 0 ) {
|
|---|
| [2688] | 557 | if ( _slip_cnt_L5.find(prn) != _slip_cnt_L5.end() &&
|
|---|
| [2711] | 558 | _slip_cnt_L5.find(prn).value() != obs.slip_cnt_L5 ) {
|
|---|
| [2688] | 559 | lli5 = '1';
|
|---|
| 560 | }
|
|---|
| 561 | }
|
|---|
| 562 |
|
|---|
| [2711] | 563 | _slip_cnt_L1[prn] = obs.slip_cnt_L1;
|
|---|
| 564 | _slip_cnt_L2[prn] = obs.slip_cnt_L2;
|
|---|
| 565 | _slip_cnt_L5[prn] = obs.slip_cnt_L5;
|
|---|
| [1044] | 566 |
|
|---|
| [4486] | 567 | // Write the data
|
|---|
| 568 | // --------------
|
|---|
| 569 | _out << rinexSatLine(obs, lli1, lli2, lli5) << endl;
|
|---|
| [75] | 570 | }
|
|---|
| 571 |
|
|---|
| [77] | 572 | _out.flush();
|
|---|
| [73] | 573 | }
|
|---|
| 574 |
|
|---|
| [130] | 575 | // Close the Old RINEX File
|
|---|
| 576 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 577 | void bncRinex::closeFile() {
|
|---|
| [4483] | 578 | if (_header._version == 3) {
|
|---|
| [843] | 579 | _out << "> 4 1" << endl;
|
|---|
| [698] | 580 | _out << "END OF FILE" << endl;
|
|---|
| 581 | }
|
|---|
| [130] | 582 | _out.close();
|
|---|
| [132] | 583 | if (!_rnxScriptName.isEmpty()) {
|
|---|
| [1523] | 584 | qApp->thread()->wait(100);
|
|---|
| [435] | 585 | #ifdef WIN32
|
|---|
| 586 | QProcess::startDetached(_rnxScriptName, QStringList() << _fName) ;
|
|---|
| 587 | #else
|
|---|
| [475] | 588 | QProcess::startDetached("nohup", QStringList() << _rnxScriptName << _fName) ;
|
|---|
| [435] | 589 | #endif
|
|---|
| [436] | 590 |
|
|---|
| [132] | 591 | }
|
|---|
| [130] | 592 | }
|
|---|
| [2695] | 593 |
|
|---|
| [4488] | 594 | // One Line in RINEX v2 or v3
|
|---|
| [2695] | 595 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| [3341] | 596 | string bncRinex::rinexSatLine(const t_obs& obs, char lli1, char lli2,
|
|---|
| 597 | char lli5) {
|
|---|
| [2695] | 598 | ostringstream str;
|
|---|
| 599 | str.setf(ios::showpoint | ios::fixed);
|
|---|
| 600 |
|
|---|
| [4486] | 601 | if (_header._version >= 3.0) {
|
|---|
| 602 | str << obs.satSys
|
|---|
| 603 | << setw(2) << setfill('0') << obs.satNum << setfill(' ');
|
|---|
| 604 | }
|
|---|
| [4384] | 605 |
|
|---|
| [6120] | 606 | const QVector<QString>& types = _header._obsTypes[obs.satSys];
|
|---|
| [4391] | 607 | for (int ii = 0; ii < types.size(); ii++) {
|
|---|
| [4749] | 608 | if (_header._version < 3.0 && ii > 0 && ii % 5 == 0) {
|
|---|
| 609 | str << endl;
|
|---|
| 610 | }
|
|---|
| [4483] | 611 | double value = obs.measdata(types[ii], _header._version);
|
|---|
| [4408] | 612 | str << setw(14) << setprecision(3) << value;
|
|---|
| 613 | if (value != 0.0 && types[ii].indexOf("L1") == 0) {
|
|---|
| 614 | str << lli1 << ' ';
|
|---|
| [4407] | 615 | }
|
|---|
| [4408] | 616 | else if (value != 0.0 && types[ii].indexOf("L2") == 0) {
|
|---|
| 617 | str << lli2 << ' ';
|
|---|
| [4407] | 618 | }
|
|---|
| [4408] | 619 | else if (value != 0.0 && types[ii].indexOf("L5") == 0) {
|
|---|
| 620 | str << lli5 << ' ';
|
|---|
| [4407] | 621 | }
|
|---|
| 622 | else {
|
|---|
| [4408] | 623 | str << " ";
|
|---|
| [4407] | 624 | }
|
|---|
| [2695] | 625 | }
|
|---|
| [4389] | 626 |
|
|---|
| [2695] | 627 | return str.str();
|
|---|
| 628 | }
|
|---|
| [3324] | 629 |
|
|---|
| [3344] | 630 | //
|
|---|
| 631 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 632 | string bncRinex::obsToStr(double val, int width, int precision) {
|
|---|
| [3326] | 633 | if (val != 0.0) {
|
|---|
| 634 | ostringstream str;
|
|---|
| 635 | str.setf(ios::showpoint | ios::fixed);
|
|---|
| [3344] | 636 | str << setw(width) << setprecision(precision) << val;
|
|---|
| [3326] | 637 | return str.str();
|
|---|
| 638 | }
|
|---|
| 639 | else {
|
|---|
| 640 | return "0.0";
|
|---|
| 641 | }
|
|---|
| 642 | }
|
|---|
| 643 |
|
|---|
| [3324] | 644 | // One Line in ASCII (Internal) Format
|
|---|
| 645 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 646 | string bncRinex::asciiSatLine(const t_obs& obs) {
|
|---|
| 647 |
|
|---|
| 648 | ostringstream str;
|
|---|
| 649 | str.setf(ios::showpoint | ios::fixed);
|
|---|
| 650 |
|
|---|
| [3325] | 651 | str << obs.satSys << setw(2) << setfill('0') << obs.satNum << setfill(' ');
|
|---|
| 652 |
|
|---|
| [3344] | 653 | if (obs.satSys == 'R') { // Glonass
|
|---|
| [4987] | 654 | str << ' ' << setw(2) << obs.slotNum << ' ';
|
|---|
| [3344] | 655 | }
|
|---|
| 656 | else {
|
|---|
| [4987] | 657 | str << " ";
|
|---|
| [3344] | 658 | }
|
|---|
| 659 |
|
|---|
| [4403] | 660 | float rnxVers = 3.0;
|
|---|
| 661 |
|
|---|
| [4987] | 662 | for (int ie = 0; ie < GNSSENTRY_NUMBER; ie++) {
|
|---|
| 663 | QString rnxStr = obs.rnxStr(ie);
|
|---|
| [4988] | 664 | if (rnxStr.length() >= 2) {
|
|---|
| 665 | double data = obs.measdata(rnxStr, rnxVers);
|
|---|
| [4989] | 666 | if (data != 0.0) {
|
|---|
| [4988] | 667 | int width = (rnxStr[0] == 'S') ? 8 : 14;
|
|---|
| 668 | int prec = 3;
|
|---|
| 669 | str << ' ' << rnxStr.toAscii().data()
|
|---|
| 670 | << ' ' << obsToStr(data, width, prec);
|
|---|
| [4987] | 671 | if (rnxStr[0] == 'L') {
|
|---|
| 672 | int slipCnt = 0;
|
|---|
| 673 | if (rnxStr[1] == '1') {
|
|---|
| 674 | slipCnt = obs.slip_cnt_L1;
|
|---|
| 675 | }
|
|---|
| 676 | else if (rnxStr[1] == '2') {
|
|---|
| 677 | slipCnt = obs.slip_cnt_L2;
|
|---|
| 678 | }
|
|---|
| 679 | else if (rnxStr[1] == '5') {
|
|---|
| 680 | slipCnt = obs.slip_cnt_L5;
|
|---|
| 681 | }
|
|---|
| [5523] | 682 | str << ' ' << setw(3) << slipCnt;
|
|---|
| [4987] | 683 | }
|
|---|
| 684 | }
|
|---|
| [4886] | 685 | }
|
|---|
| [3324] | 686 | }
|
|---|
| [4389] | 687 |
|
|---|
| [3324] | 688 | return str.str();
|
|---|
| 689 | }
|
|---|