[280] | 1 | // Part of BNC, a utility for retrieving decoding and
|
---|
[464] | 2 | // converting GNSS data streams from NTRIP broadcasters.
|
---|
[280] | 3 | //
|
---|
[464] | 4 | // Copyright (C) 2007
|
---|
[280] | 5 | // German Federal Agency for Cartography and Geodesy (BKG)
|
---|
| 6 | // http://www.bkg.bund.de
|
---|
[464] | 7 | // Czech Technical University Prague, Department of Geodesy
|
---|
[280] | 8 | // http://www.fsv.cvut.cz
|
---|
| 9 | //
|
---|
| 10 | // Email: euref-ip@bkg.bund.de
|
---|
| 11 | //
|
---|
| 12 | // This program is free software; you can redistribute it and/or
|
---|
| 13 | // modify it under the terms of the GNU General Public License
|
---|
| 14 | // as published by the Free Software Foundation, version 2.
|
---|
| 15 | //
|
---|
| 16 | // This program is distributed in the hope that it will be useful,
|
---|
| 17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 19 | // GNU General Public License for more details.
|
---|
| 20 | //
|
---|
| 21 | // You should have received a copy of the GNU General Public License
|
---|
| 22 | // along with this program; if not, write to the Free Software
|
---|
| 23 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
---|
[73] | 24 |
|
---|
| 25 | /* -------------------------------------------------------------------------
|
---|
[93] | 26 | * BKG NTRIP Client
|
---|
[73] | 27 | * -------------------------------------------------------------------------
|
---|
| 28 | *
|
---|
| 29 | * Class: bncRinex
|
---|
| 30 | *
|
---|
| 31 | * Purpose: writes RINEX files
|
---|
| 32 | *
|
---|
| 33 | * Author: L. Mervart
|
---|
| 34 | *
|
---|
| 35 | * Created: 27-Aug-2006
|
---|
| 36 | *
|
---|
| 37 | * Changes:
|
---|
| 38 | *
|
---|
| 39 | * -----------------------------------------------------------------------*/
|
---|
| 40 |
|
---|
[292] | 41 | #include <stdlib.h>
|
---|
[300] | 42 | #include <iostream>
|
---|
[75] | 43 | #include <iomanip>
|
---|
[221] | 44 | #include <math.h>
|
---|
[2695] | 45 | #include <sstream>
|
---|
[75] | 46 |
|
---|
[300] | 47 | #include <QtCore>
|
---|
| 48 | #include <QUrl>
|
---|
| 49 | #include <QString>
|
---|
| 50 |
|
---|
[73] | 51 | #include "bncrinex.h"
|
---|
[157] | 52 | #include "bncapp.h"
|
---|
[82] | 53 | #include "bncutils.h"
|
---|
[126] | 54 | #include "bncconst.h"
|
---|
[298] | 55 | #include "bnctabledlg.h"
|
---|
[301] | 56 | #include "bncgetthread.h"
|
---|
[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();
|
---|
[4390] | 94 |
|
---|
[4484] | 95 | // Initialize RINEX v2 Types
|
---|
| 96 | // -------------------------
|
---|
| 97 | _header._obsTypesV2 << "C1" << "P1" << "L1" << "S1"
|
---|
| 98 | << "C2" << "P2" << "L2" << "S2";
|
---|
| 99 |
|
---|
[4390] | 100 | // Initialize RINEX v3 Types
|
---|
| 101 | // -------------------------
|
---|
[4482] | 102 | _header._obsTypesV3['G'] << "C1C" << "L1C" << "D1C" << "S1C"
|
---|
| 103 | << "C1P" << "L1P" << "D1P" << "S1P"
|
---|
| 104 | << "C2C" << "L2C" << "D2C" << "S2C"
|
---|
| 105 | << "C2P" << "L2P" << "D2P" << "S2P"
|
---|
| 106 | << "C5" << "D5" << "L5" << "S5";
|
---|
[4390] | 107 |
|
---|
[4482] | 108 | _header._obsTypesV3['R'] << "C1C" << "L1C" << "D1C" << "S1C"
|
---|
| 109 | << "C1P" << "L1P" << "D1P" << "S1P"
|
---|
| 110 | << "C2C" << "L2C" << "D2C" << "S2C"
|
---|
| 111 | << "C2P" << "L2P" << "D2P" << "S2P";
|
---|
[4390] | 112 |
|
---|
[4482] | 113 | _header._obsTypesV3['E'] << "C1" << "L1" << "D1" << "S1"
|
---|
| 114 | << "C5" << "L5" << "D5" << "S5"
|
---|
| 115 | << "C6" << "L6" << "D6" << "S6"
|
---|
| 116 | << "C7" << "L7" << "D7" << "S7"
|
---|
| 117 | << "C8" << "L8" << "D8" << "S8";
|
---|
[4390] | 118 |
|
---|
[4482] | 119 | _header._obsTypesV3['J'] << "C1" << "L1" << "D1" << "S1"
|
---|
| 120 | << "C2" << "L2" << "D2" << "S2"
|
---|
| 121 | << "C5" << "L5" << "D5" << "S5"
|
---|
| 122 | << "C6" << "D6" << "L6" << "S6";
|
---|
[4402] | 123 |
|
---|
[4482] | 124 | _header._obsTypesV3['S'] << "C1" << "L1" << "D1" << "S1"
|
---|
| 125 | << "C5" << "L5" << "D5" << "S5";
|
---|
[4390] | 126 |
|
---|
[4482] | 127 | _header._obsTypesV3['C'] << "C2" << "L2" << "D2" << "S2"
|
---|
| 128 | << "C6" << "L6" << "D6" << "S6"
|
---|
| 129 | << "C7" << "L7" << "D7" << "S7";
|
---|
[73] | 130 | }
|
---|
| 131 |
|
---|
| 132 | // Destructor
|
---|
| 133 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 134 | bncRinex::~bncRinex() {
|
---|
[1535] | 135 | bncSettings settings;
|
---|
[4483] | 136 | if ((_header._version >= 3.0) && ( Qt::CheckState(settings.value("rnxAppend").toInt()) != Qt::Checked) ) {
|
---|
[843] | 137 | _out << "> 4 1" << endl;
|
---|
[698] | 138 | _out << "END OF FILE" << endl;
|
---|
| 139 | }
|
---|
[77] | 140 | _out.close();
|
---|
[73] | 141 | }
|
---|
| 142 |
|
---|
[420] | 143 | // Download Skeleton Header File
|
---|
| 144 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 145 | t_irc bncRinex::downloadSkeleton() {
|
---|
| 146 |
|
---|
| 147 | t_irc irc = failure;
|
---|
| 148 |
|
---|
| 149 | QStringList table;
|
---|
[3335] | 150 | bncTableDlg::getFullTable(_ntripVersion, _mountPoint.host(),
|
---|
[4481] | 151 | _mountPoint.port(), table, true);
|
---|
[420] | 152 | QString net;
|
---|
| 153 | QStringListIterator it(table);
|
---|
| 154 | while (it.hasNext()) {
|
---|
| 155 | QString line = it.next();
|
---|
| 156 | if (line.indexOf("STR") == 0) {
|
---|
| 157 | QStringList tags = line.split(";");
|
---|
[1495] | 158 | if (tags.size() > 7) {
|
---|
| 159 | if (tags.at(1) == _mountPoint.path().mid(1).toAscii()) {
|
---|
| 160 | net = tags.at(7);
|
---|
| 161 | break;
|
---|
| 162 | }
|
---|
[420] | 163 | }
|
---|
| 164 | }
|
---|
| 165 | }
|
---|
| 166 | QString sklDir;
|
---|
[1495] | 167 | if (!net.isEmpty()) {
|
---|
| 168 | it.toFront();
|
---|
| 169 | while (it.hasNext()) {
|
---|
| 170 | QString line = it.next();
|
---|
| 171 | if (line.indexOf("NET") == 0) {
|
---|
| 172 | QStringList tags = line.split(";");
|
---|
| 173 | if (tags.size() > 6) {
|
---|
| 174 | if (tags.at(1) == net) {
|
---|
| 175 | sklDir = tags.at(6).trimmed();
|
---|
| 176 | break;
|
---|
| 177 | }
|
---|
| 178 | }
|
---|
| 179 | }
|
---|
[420] | 180 | }
|
---|
| 181 | }
|
---|
| 182 | if (!sklDir.isEmpty() && sklDir != "none") {
|
---|
| 183 | QUrl url(sklDir + "/" + _mountPoint.path().mid(1,4).toLower() + ".skl");
|
---|
| 184 | if (url.port() == -1) {
|
---|
| 185 | url.setPort(80);
|
---|
| 186 | }
|
---|
| 187 |
|
---|
[3337] | 188 | bncNetQuery* query;
|
---|
| 189 | if (_ntripVersion == "2s") {
|
---|
| 190 | query = new bncNetQueryV2(true);
|
---|
| 191 | }
|
---|
| 192 | else if (_ntripVersion == "2") {
|
---|
| 193 | query = new bncNetQueryV2(false);
|
---|
| 194 | }
|
---|
| 195 | else {
|
---|
| 196 | query = new bncNetQueryV1;
|
---|
| 197 | }
|
---|
| 198 |
|
---|
[1386] | 199 | QByteArray outData;
|
---|
[3337] | 200 | query->waitForRequestResult(url, outData);
|
---|
| 201 | if (query->status() == bncNetQuery::finished) {
|
---|
[4481] | 202 | irc = success;
|
---|
[1386] | 203 | QTextStream in(outData);
|
---|
[4481] | 204 | _header.read(&in);
|
---|
[420] | 205 | }
|
---|
[4481] | 206 |
|
---|
[3337] | 207 | delete query;
|
---|
| 208 | }
|
---|
[1386] | 209 |
|
---|
[420] | 210 | return irc;
|
---|
| 211 | }
|
---|
| 212 |
|
---|
[82] | 213 | // Read Skeleton Header File
|
---|
| 214 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 215 | void bncRinex::readSkeleton() {
|
---|
| 216 |
|
---|
[420] | 217 | // Read the local file
|
---|
| 218 | // -------------------
|
---|
[276] | 219 | QFile skl(_sklName);
|
---|
[82] | 220 | if ( skl.exists() && skl.open(QIODevice::ReadOnly) ) {
|
---|
| 221 | QTextStream in(&skl);
|
---|
[4481] | 222 | _header.read(&in);
|
---|
[82] | 223 | }
|
---|
[298] | 224 |
|
---|
[420] | 225 | // Read downloaded file
|
---|
| 226 | // --------------------
|
---|
[2376] | 227 | else if ( _ntripVersion != "N" && _ntripVersion != "UN" &&
|
---|
| 228 | _ntripVersion != "S" ) {
|
---|
[1154] | 229 | QDate currDate = currentDateAndTimeGPS().date();
|
---|
[420] | 230 | if ( !_skeletonDate.isValid() || _skeletonDate != currDate ) {
|
---|
[4481] | 231 | downloadSkeleton();
|
---|
| 232 | _skeletonDate = currDate;
|
---|
[298] | 233 | }
|
---|
| 234 | }
|
---|
[4483] | 235 |
|
---|
| 236 | bncSettings settings;
|
---|
| 237 | if ( Qt::CheckState(settings.value("rnxV3").toInt()) == Qt::Checked) {
|
---|
| 238 | _header._version = 3.01;
|
---|
| 239 | }
|
---|
| 240 | else {
|
---|
| 241 | _header._version = 2.12;
|
---|
| 242 | }
|
---|
[82] | 243 | }
|
---|
| 244 |
|
---|
[647] | 245 | // Next File Epoch (static)
|
---|
[82] | 246 | ////////////////////////////////////////////////////////////////////////////
|
---|
[647] | 247 | QString bncRinex::nextEpochStr(const QDateTime& datTim,
|
---|
| 248 | const QString& intStr, QDateTime* nextEpoch) {
|
---|
[82] | 249 |
|
---|
[647] | 250 | QString epoStr;
|
---|
[82] | 251 |
|
---|
[129] | 252 | QTime nextTime;
|
---|
| 253 | QDate nextDate;
|
---|
| 254 |
|
---|
[204] | 255 | int indHlp = intStr.indexOf("min");
|
---|
| 256 |
|
---|
| 257 | if ( indHlp != -1) {
|
---|
| 258 | int step = intStr.left(indHlp-1).toInt();
|
---|
[127] | 259 | char ch = 'A' + datTim.time().hour();
|
---|
[647] | 260 | epoStr = ch;
|
---|
[204] | 261 | if (datTim.time().minute() >= 60-step) {
|
---|
[647] | 262 | epoStr += QString("%1").arg(60-step, 2, 10, QChar('0'));
|
---|
[199] | 263 | if (datTim.time().hour() < 23) {
|
---|
| 264 | nextTime.setHMS(datTim.time().hour() + 1 , 0, 0);
|
---|
| 265 | nextDate = datTim.date();
|
---|
| 266 | }
|
---|
| 267 | else {
|
---|
| 268 | nextTime.setHMS(0, 0, 0);
|
---|
| 269 | nextDate = datTim.date().addDays(1);
|
---|
| 270 | }
|
---|
| 271 | }
|
---|
| 272 | else {
|
---|
[204] | 273 | for (int limit = step; limit <= 60-step; limit += step) {
|
---|
| 274 | if (datTim.time().minute() < limit) {
|
---|
[647] | 275 | epoStr += QString("%1").arg(limit-step, 2, 10, QChar('0'));
|
---|
[204] | 276 | nextTime.setHMS(datTim.time().hour(), limit, 0);
|
---|
| 277 | nextDate = datTim.date();
|
---|
| 278 | break;
|
---|
| 279 | }
|
---|
[199] | 280 | }
|
---|
| 281 | }
|
---|
| 282 | }
|
---|
[127] | 283 | else if (intStr == "1 hour") {
|
---|
| 284 | char ch = 'A' + datTim.time().hour();
|
---|
[647] | 285 | epoStr = ch;
|
---|
[129] | 286 | if (datTim.time().hour() < 23) {
|
---|
| 287 | nextTime.setHMS(datTim.time().hour() + 1 , 0, 0);
|
---|
| 288 | nextDate = datTim.date();
|
---|
| 289 | }
|
---|
| 290 | else {
|
---|
| 291 | nextTime.setHMS(0, 0, 0);
|
---|
| 292 | nextDate = datTim.date().addDays(1);
|
---|
| 293 | }
|
---|
[127] | 294 | }
|
---|
| 295 | else {
|
---|
[647] | 296 | epoStr = "0";
|
---|
[129] | 297 | nextTime.setHMS(0, 0, 0);
|
---|
| 298 | nextDate = datTim.date().addDays(1);
|
---|
[127] | 299 | }
|
---|
[82] | 300 |
|
---|
[647] | 301 | if (nextEpoch) {
|
---|
| 302 | *nextEpoch = QDateTime(nextDate, nextTime);
|
---|
| 303 | }
|
---|
| 304 |
|
---|
| 305 | return epoStr;
|
---|
| 306 | }
|
---|
| 307 |
|
---|
| 308 | // File Name according to RINEX Standards
|
---|
| 309 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 310 | void bncRinex::resolveFileName(const QDateTime& datTim) {
|
---|
| 311 |
|
---|
[1535] | 312 | bncSettings settings;
|
---|
[647] | 313 | QString path = settings.value("rnxPath").toString();
|
---|
| 314 | expandEnvVar(path);
|
---|
| 315 |
|
---|
| 316 | if ( path.length() > 0 && path[path.length()-1] != QDir::separator() ) {
|
---|
| 317 | path += QDir::separator();
|
---|
| 318 | }
|
---|
| 319 |
|
---|
| 320 | QString hlpStr = nextEpochStr(datTim, settings.value("rnxIntr").toString(),
|
---|
| 321 | &_nextCloseEpoch);
|
---|
| 322 |
|
---|
[183] | 323 | QString ID4 = _statID.left(4);
|
---|
| 324 |
|
---|
| 325 | // Check name conflict
|
---|
| 326 | // -------------------
|
---|
| 327 | QString distStr;
|
---|
| 328 | int num = 0;
|
---|
| 329 | QListIterator<QString> it(settings.value("mountPoints").toStringList());
|
---|
| 330 | while (it.hasNext()) {
|
---|
| 331 | QString mp = it.next();
|
---|
| 332 | if (mp.indexOf(ID4) != -1) {
|
---|
| 333 | ++num;
|
---|
| 334 | }
|
---|
| 335 | }
|
---|
| 336 | if (num > 1) {
|
---|
| 337 | distStr = "_" + _statID.mid(4);
|
---|
| 338 | }
|
---|
| 339 |
|
---|
[276] | 340 | QString sklExt = settings.value("rnxSkel").toString();
|
---|
| 341 | if (!sklExt.isEmpty()) {
|
---|
| 342 | _sklName = path + ID4 + distStr + "." + sklExt;
|
---|
| 343 | }
|
---|
| 344 |
|
---|
[183] | 345 | path += ID4 +
|
---|
[127] | 346 | QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
|
---|
[276] | 347 | hlpStr + distStr + datTim.toString(".yyO");
|
---|
[82] | 348 |
|
---|
| 349 | _fName = path.toAscii();
|
---|
| 350 | }
|
---|
| 351 |
|
---|
[77] | 352 | // Write RINEX Header
|
---|
| 353 | ////////////////////////////////////////////////////////////////////////////
|
---|
[4489] | 354 | void bncRinex::writeHeader(const QByteArray& format,
|
---|
[267] | 355 | const QDateTime& datTimNom) {
|
---|
[77] | 356 |
|
---|
[1535] | 357 | bncSettings settings;
|
---|
[356] | 358 |
|
---|
[77] | 359 | // Open the Output File
|
---|
| 360 | // --------------------
|
---|
[267] | 361 | resolveFileName(datTimNom);
|
---|
[260] | 362 |
|
---|
| 363 | // Append to existing file and return
|
---|
| 364 | // ----------------------------------
|
---|
| 365 | if ( QFile::exists(_fName) ) {
|
---|
[369] | 366 | if (_reconnectFlag ||
|
---|
| 367 | Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
|
---|
[260] | 368 | _out.open(_fName.data(), ios::app);
|
---|
| 369 | _out.setf(ios::showpoint | ios::fixed);
|
---|
| 370 | _headerWritten = true;
|
---|
[369] | 371 | _reconnectFlag = false;
|
---|
[260] | 372 | return;
|
---|
| 373 | }
|
---|
| 374 | }
|
---|
| 375 |
|
---|
[82] | 376 | _out.open(_fName.data());
|
---|
[85] | 377 | _out.setf(ios::showpoint | ios::fixed);
|
---|
[77] | 378 |
|
---|
[82] | 379 | // Copy Skeleton Header
|
---|
| 380 | // --------------------
|
---|
[276] | 381 | readSkeleton();
|
---|
[4495] | 382 | if (_header._markerName.isEmpty()) {
|
---|
| 383 | _header._markerName = _statID;
|
---|
| 384 | }
|
---|
[78] | 385 |
|
---|
[4495] | 386 | // A few additional comments
|
---|
| 387 | // -------------------------
|
---|
| 388 | QMap<QString, QString> txtMap;
|
---|
| 389 | QStringList addComments;
|
---|
| 390 |
|
---|
| 391 | addComments << format.left(6) + " " + _mountPoint.host() + _mountPoint.path();
|
---|
| 392 |
|
---|
| 393 | if (_nmea == "yes") {
|
---|
| 394 | addComments << "NMEA LAT=" + _latitude + " " + "LONG=" + _longitude;
|
---|
| 395 | }
|
---|
| 396 |
|
---|
| 397 | txtMap["COMMENT"] = addComments.join("\\n");
|
---|
| 398 |
|
---|
[4481] | 399 | QByteArray headerLines;
|
---|
| 400 | QTextStream outHlp(&headerLines);
|
---|
[4495] | 401 | _header.write(&outHlp, &txtMap);
|
---|
[4481] | 402 | outHlp.flush();
|
---|
| 403 | _out << headerLines.data();
|
---|
[4406] | 404 |
|
---|
[77] | 405 | _headerWritten = true;
|
---|
| 406 | }
|
---|
| 407 |
|
---|
[73] | 408 | // Stores Observation into Internal Array
|
---|
| 409 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2711] | 410 | void bncRinex::deepCopy(t_obs obs) {
|
---|
| 411 | _obs.push_back(obs);
|
---|
[73] | 412 | }
|
---|
| 413 |
|
---|
| 414 | // Write One Epoch into the RINEX File
|
---|
| 415 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3525] | 416 | void bncRinex::dumpEpoch(const QByteArray& format, long maxTime) {
|
---|
[73] | 417 |
|
---|
[160] | 418 | // Select observations older than maxTime
|
---|
| 419 | // --------------------------------------
|
---|
[2711] | 420 | QList<t_obs> dumpList;
|
---|
| 421 | QMutableListIterator<t_obs> mIt(_obs);
|
---|
[160] | 422 | while (mIt.hasNext()) {
|
---|
[2711] | 423 | t_obs obs = mIt.next();
|
---|
| 424 | if (obs.GPSWeek * 7*24*3600 + obs.GPSWeeks < maxTime - 0.05) {
|
---|
[622] | 425 | dumpList.push_back(obs);
|
---|
[160] | 426 | mIt.remove();
|
---|
| 427 | }
|
---|
| 428 | }
|
---|
| 429 |
|
---|
[75] | 430 | // Easy Return
|
---|
| 431 | // -----------
|
---|
[160] | 432 | if (dumpList.isEmpty()) {
|
---|
[75] | 433 | return;
|
---|
| 434 | }
|
---|
| 435 |
|
---|
| 436 | // Time of Epoch
|
---|
| 437 | // -------------
|
---|
[2711] | 438 | const t_obs& fObs = dumpList.first();
|
---|
| 439 | QDateTime datTim = dateAndTimeFromGPSweek(fObs.GPSWeek, fObs.GPSWeeks);
|
---|
| 440 | QDateTime datTimNom = dateAndTimeFromGPSweek(fObs.GPSWeek,
|
---|
| 441 | floor(fObs.GPSWeeks+0.5));
|
---|
[75] | 442 |
|
---|
[130] | 443 | // Close the file
|
---|
| 444 | // --------------
|
---|
[267] | 445 | if (_nextCloseEpoch.isValid() && datTimNom >= _nextCloseEpoch) {
|
---|
[130] | 446 | closeFile();
|
---|
| 447 | _headerWritten = false;
|
---|
| 448 | }
|
---|
| 449 |
|
---|
[78] | 450 | // Write RINEX Header
|
---|
| 451 | // ------------------
|
---|
| 452 | if (!_headerWritten) {
|
---|
[4489] | 453 | _header._startTime.set(fObs.GPSWeek, fObs.GPSWeeks);
|
---|
| 454 | writeHeader(format, datTimNom);
|
---|
[78] | 455 | }
|
---|
| 456 |
|
---|
[2711] | 457 | double sec = double(datTim.time().second()) + fmod(fObs.GPSWeeks,1.0);
|
---|
[75] | 458 |
|
---|
[1044] | 459 | // Epoch header line: RINEX Version 3
|
---|
| 460 | // ----------------------------------
|
---|
[4483] | 461 | if (_header._version >= 3.0) {
|
---|
[540] | 462 | _out << datTim.toString("> yyyy MM dd hh mm ").toAscii().data()
|
---|
| 463 | << setw(10) << setprecision(7) << sec
|
---|
| 464 | << " " << 0 << setw(3) << dumpList.size() << endl;
|
---|
[74] | 465 | }
|
---|
[1044] | 466 | // Epoch header line: RINEX Version 2
|
---|
| 467 | // ----------------------------------
|
---|
[540] | 468 | else {
|
---|
| 469 | _out << datTim.toString(" yy MM dd hh mm ").toAscii().data()
|
---|
| 470 | << setw(10) << setprecision(7) << sec
|
---|
| 471 | << " " << 0 << setw(3) << dumpList.size();
|
---|
[1044] | 472 |
|
---|
[2711] | 473 | QListIterator<t_obs> it(dumpList); int iSat = 0;
|
---|
[540] | 474 | while (it.hasNext()) {
|
---|
| 475 | iSat++;
|
---|
[2711] | 476 | const t_obs& obs = it.next();
|
---|
| 477 | _out << obs.satSys << setw(2) << obs.satNum;
|
---|
[540] | 478 | if (iSat == 12 && it.hasNext()) {
|
---|
| 479 | _out << endl << " ";
|
---|
| 480 | iSat = 0;
|
---|
| 481 | }
|
---|
| 482 | }
|
---|
[77] | 483 | _out << endl;
|
---|
[1044] | 484 | }
|
---|
| 485 |
|
---|
[2711] | 486 | QListIterator<t_obs> it(dumpList);
|
---|
[1044] | 487 | while (it.hasNext()) {
|
---|
[2711] | 488 | const t_obs& obs = it.next();
|
---|
[1044] | 489 |
|
---|
| 490 | // Cycle slips detection
|
---|
| 491 | // ---------------------
|
---|
[2711] | 492 | QString prn = QString("%1%2").arg(obs.satSys)
|
---|
| 493 | .arg(obs.satNum, 2, 10, QChar('0'));
|
---|
[1044] | 494 |
|
---|
| 495 | char lli1 = ' ';
|
---|
| 496 | char lli2 = ' ';
|
---|
[2688] | 497 | char lli5 = ' ';
|
---|
[2711] | 498 | if ( obs.slip_cnt_L1 >= 0 ) {
|
---|
[1044] | 499 | if ( _slip_cnt_L1.find(prn) != _slip_cnt_L1.end() &&
|
---|
[2711] | 500 | _slip_cnt_L1.find(prn).value() != obs.slip_cnt_L1 ) {
|
---|
[2682] | 501 | lli1 = '1';
|
---|
[1044] | 502 | }
|
---|
| 503 | }
|
---|
| 504 |
|
---|
[2711] | 505 | if ( obs.slip_cnt_L2 >= 0 ) {
|
---|
[1044] | 506 | if ( _slip_cnt_L2.find(prn) != _slip_cnt_L2.end() &&
|
---|
[2711] | 507 | _slip_cnt_L2.find(prn).value() != obs.slip_cnt_L2 ) {
|
---|
[2682] | 508 | lli2 = '1';
|
---|
[1044] | 509 | }
|
---|
| 510 | }
|
---|
| 511 |
|
---|
[2711] | 512 | if ( obs.slip_cnt_L5 >= 0 ) {
|
---|
[2688] | 513 | if ( _slip_cnt_L5.find(prn) != _slip_cnt_L5.end() &&
|
---|
[2711] | 514 | _slip_cnt_L5.find(prn).value() != obs.slip_cnt_L5 ) {
|
---|
[2688] | 515 | lli5 = '1';
|
---|
| 516 | }
|
---|
| 517 | }
|
---|
| 518 |
|
---|
[2711] | 519 | _slip_cnt_L1[prn] = obs.slip_cnt_L1;
|
---|
| 520 | _slip_cnt_L2[prn] = obs.slip_cnt_L2;
|
---|
| 521 | _slip_cnt_L5[prn] = obs.slip_cnt_L5;
|
---|
[1044] | 522 |
|
---|
[4486] | 523 | // Write the data
|
---|
| 524 | // --------------
|
---|
| 525 | _out << rinexSatLine(obs, lli1, lli2, lli5) << endl;
|
---|
[75] | 526 | }
|
---|
| 527 |
|
---|
[77] | 528 | _out.flush();
|
---|
[73] | 529 | }
|
---|
| 530 |
|
---|
[130] | 531 | // Close the Old RINEX File
|
---|
| 532 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 533 | void bncRinex::closeFile() {
|
---|
[4483] | 534 | if (_header._version == 3) {
|
---|
[843] | 535 | _out << "> 4 1" << endl;
|
---|
[698] | 536 | _out << "END OF FILE" << endl;
|
---|
| 537 | }
|
---|
[130] | 538 | _out.close();
|
---|
[132] | 539 | if (!_rnxScriptName.isEmpty()) {
|
---|
[1523] | 540 | qApp->thread()->wait(100);
|
---|
[435] | 541 | #ifdef WIN32
|
---|
| 542 | QProcess::startDetached(_rnxScriptName, QStringList() << _fName) ;
|
---|
| 543 | #else
|
---|
[475] | 544 | QProcess::startDetached("nohup", QStringList() << _rnxScriptName << _fName) ;
|
---|
[435] | 545 | #endif
|
---|
[436] | 546 |
|
---|
[132] | 547 | }
|
---|
[130] | 548 | }
|
---|
[2695] | 549 |
|
---|
[4488] | 550 | // One Line in RINEX v2 or v3
|
---|
[2695] | 551 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3341] | 552 | string bncRinex::rinexSatLine(const t_obs& obs, char lli1, char lli2,
|
---|
| 553 | char lli5) {
|
---|
[2695] | 554 | ostringstream str;
|
---|
| 555 | str.setf(ios::showpoint | ios::fixed);
|
---|
| 556 |
|
---|
[4486] | 557 | if (_header._version >= 3.0) {
|
---|
| 558 | str << obs.satSys
|
---|
| 559 | << setw(2) << setfill('0') << obs.satNum << setfill(' ');
|
---|
| 560 | }
|
---|
[4384] | 561 |
|
---|
[4486] | 562 | const QVector<QString>& types = (_header._version > 3.0) ?
|
---|
| 563 | _header._obsTypesV3[obs.satSys] : _header._obsTypesV2;
|
---|
[4391] | 564 | for (int ii = 0; ii < types.size(); ii++) {
|
---|
[4483] | 565 | double value = obs.measdata(types[ii], _header._version);
|
---|
[4408] | 566 | str << setw(14) << setprecision(3) << value;
|
---|
| 567 | if (value != 0.0 && types[ii].indexOf("L1") == 0) {
|
---|
| 568 | str << lli1 << ' ';
|
---|
[4407] | 569 | }
|
---|
[4408] | 570 | else if (value != 0.0 && types[ii].indexOf("L2") == 0) {
|
---|
| 571 | str << lli2 << ' ';
|
---|
[4407] | 572 | }
|
---|
[4408] | 573 | else if (value != 0.0 && types[ii].indexOf("L5") == 0) {
|
---|
| 574 | str << lli5 << ' ';
|
---|
[4407] | 575 | }
|
---|
| 576 | else {
|
---|
[4408] | 577 | str << " ";
|
---|
[4407] | 578 | }
|
---|
[2695] | 579 | }
|
---|
[4389] | 580 |
|
---|
[2695] | 581 | return str.str();
|
---|
| 582 | }
|
---|
[3324] | 583 |
|
---|
[3344] | 584 | //
|
---|
| 585 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 586 | string bncRinex::obsToStr(double val, int width, int precision) {
|
---|
[3326] | 587 | if (val != 0.0) {
|
---|
| 588 | ostringstream str;
|
---|
| 589 | str.setf(ios::showpoint | ios::fixed);
|
---|
[3344] | 590 | str << setw(width) << setprecision(precision) << val;
|
---|
[3326] | 591 | return str.str();
|
---|
| 592 | }
|
---|
| 593 | else {
|
---|
| 594 | return "0.0";
|
---|
| 595 | }
|
---|
| 596 | }
|
---|
| 597 |
|
---|
[3324] | 598 | // One Line in ASCII (Internal) Format
|
---|
| 599 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 600 | string bncRinex::asciiSatLine(const t_obs& obs) {
|
---|
| 601 |
|
---|
| 602 | ostringstream str;
|
---|
| 603 | str.setf(ios::showpoint | ios::fixed);
|
---|
| 604 |
|
---|
[3325] | 605 | str << obs.satSys << setw(2) << setfill('0') << obs.satNum << setfill(' ');
|
---|
| 606 |
|
---|
[3344] | 607 | if (obs.satSys == 'R') { // Glonass
|
---|
| 608 | str << ' ' << setw(2) << obs.slotNum;
|
---|
| 609 | }
|
---|
| 610 | else {
|
---|
| 611 | str << " ";
|
---|
| 612 | }
|
---|
| 613 |
|
---|
[4403] | 614 | float rnxVers = 3.0;
|
---|
| 615 |
|
---|
[4391] | 616 | if (obs.satSys == 'G') { // GPS
|
---|
| 617 | str << " 1C "
|
---|
[4403] | 618 | << obsToStr(obs.measdata("C1C", rnxVers)) << ' '
|
---|
| 619 | << obsToStr(obs.measdata("L1C", rnxVers)) << ' '
|
---|
| 620 | << obsToStr(obs.measdata("D1C", rnxVers)) << ' '
|
---|
| 621 | << obsToStr(obs.measdata("S1C", rnxVers), 8, 3) << ' '
|
---|
[4391] | 622 | << setw(2) << obs.slip_cnt_L1;
|
---|
[4403] | 623 | str << " 1P "
|
---|
| 624 | << obsToStr(obs.measdata("C1P", rnxVers)) << ' '
|
---|
| 625 | << obsToStr(obs.measdata("L1P", rnxVers)) << ' '
|
---|
| 626 | << obsToStr(obs.measdata("D1P", rnxVers)) << ' '
|
---|
| 627 | << obsToStr(obs.measdata("S1P", rnxVers), 8, 3) << ' '
|
---|
[4391] | 628 | << setw(2) << obs.slip_cnt_L1;
|
---|
| 629 | str << " 2P "
|
---|
[4403] | 630 | << obsToStr(obs.measdata("C2P", rnxVers)) << ' '
|
---|
| 631 | << obsToStr(obs.measdata("L2P", rnxVers)) << ' '
|
---|
| 632 | << obsToStr(obs.measdata("D2P", rnxVers)) << ' '
|
---|
| 633 | << obsToStr(obs.measdata("S2P", rnxVers), 8, 3) << ' '
|
---|
[4391] | 634 | << setw(2) << obs.slip_cnt_L2;
|
---|
| 635 | str << " 5C "
|
---|
[4403] | 636 | << obsToStr(obs.measdata("C5", rnxVers)) << ' '
|
---|
| 637 | << obsToStr(obs.measdata("L5", rnxVers)) << ' '
|
---|
| 638 | << obsToStr(obs.measdata("D5", rnxVers)) << ' '
|
---|
| 639 | << obsToStr(obs.measdata("S5", rnxVers), 8, 3) << ' '
|
---|
[4391] | 640 | << setw(2) << obs.slip_cnt_L5;
|
---|
[3324] | 641 | }
|
---|
[4391] | 642 | else if (obs.satSys == 'R') { // Glonass
|
---|
| 643 | str << " 1C "
|
---|
[4403] | 644 | << obsToStr(obs.measdata("C1C", rnxVers)) << ' '
|
---|
| 645 | << obsToStr(obs.measdata("L1C", rnxVers)) << ' '
|
---|
| 646 | << obsToStr(obs.measdata("D1C", rnxVers)) << ' '
|
---|
| 647 | << obsToStr(obs.measdata("S1C", rnxVers), 8, 3) << ' '
|
---|
[4391] | 648 | << setw(2) << obs.slip_cnt_L1;
|
---|
| 649 | str << " 1P "
|
---|
[4403] | 650 | << obsToStr(obs.measdata("C1P", rnxVers)) << ' '
|
---|
| 651 | << obsToStr(obs.measdata("L1P", rnxVers)) << ' '
|
---|
| 652 | << obsToStr(obs.measdata("D1P", rnxVers)) << ' '
|
---|
| 653 | << obsToStr(obs.measdata("S1P", rnxVers), 8, 3) << ' '
|
---|
[4391] | 654 | << setw(2) << obs.slip_cnt_L1;
|
---|
| 655 | str << " 2P "
|
---|
[4403] | 656 | << obsToStr(obs.measdata("C2P", rnxVers)) << ' '
|
---|
| 657 | << obsToStr(obs.measdata("L2P", rnxVers)) << ' '
|
---|
| 658 | << obsToStr(obs.measdata("D2P", rnxVers)) << ' '
|
---|
| 659 | << obsToStr(obs.measdata("S2P", rnxVers), 8, 3) << ' '
|
---|
[4391] | 660 | << setw(2) << obs.slip_cnt_L2;
|
---|
| 661 | str << " 2C "
|
---|
[4403] | 662 | << obsToStr(obs.measdata("C2C", rnxVers)) << ' '
|
---|
| 663 | << obsToStr(obs.measdata("L2C", rnxVers)) << ' '
|
---|
| 664 | << obsToStr(obs.measdata("D2C", rnxVers)) << ' '
|
---|
| 665 | << obsToStr(obs.measdata("S2C", rnxVers), 8, 3) << ' '
|
---|
[4391] | 666 | << setw(2) << obs.slip_cnt_L2;
|
---|
| 667 | }
|
---|
| 668 | else if (obs.satSys == 'E') { // Galileo
|
---|
| 669 | str << " 1C "
|
---|
[4403] | 670 | << obsToStr(obs.measdata("C1", rnxVers)) << ' '
|
---|
| 671 | << obsToStr(obs.measdata("L1", rnxVers)) << ' '
|
---|
| 672 | << obsToStr(obs.measdata("D1", rnxVers)) << ' '
|
---|
| 673 | << obsToStr(obs.measdata("S1", rnxVers), 8, 3) << ' '
|
---|
[4391] | 674 | << setw(2) << obs.slip_cnt_L1;
|
---|
[4389] | 675 |
|
---|
[4391] | 676 | str << " 5C "
|
---|
[4403] | 677 | << obsToStr(obs.measdata("C5", rnxVers)) << ' '
|
---|
| 678 | << obsToStr(obs.measdata("L5", rnxVers)) << ' '
|
---|
| 679 | << obsToStr(obs.measdata("D5", rnxVers)) << ' '
|
---|
| 680 | << obsToStr(obs.measdata("S5", rnxVers), 8, 3) << ' '
|
---|
[4391] | 681 | << setw(2) << obs.slip_cnt_L5;
|
---|
| 682 | }
|
---|
[3324] | 683 | return str.str();
|
---|
| 684 | }
|
---|