[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>
|
---|
[75] | 45 |
|
---|
[300] | 46 | #include <QtCore>
|
---|
| 47 | #include <QUrl>
|
---|
| 48 | #include <QString>
|
---|
| 49 |
|
---|
[73] | 50 | #include "bncrinex.h"
|
---|
[157] | 51 | #include "bncapp.h"
|
---|
[82] | 52 | #include "bncutils.h"
|
---|
[126] | 53 | #include "bncconst.h"
|
---|
[298] | 54 | #include "bnctabledlg.h"
|
---|
[301] | 55 | #include "bncgetthread.h"
|
---|
[223] | 56 | #include "RTCM3/rtcm3torinex.h"
|
---|
[75] | 57 |
|
---|
| 58 | using namespace std;
|
---|
| 59 |
|
---|
[73] | 60 | // Constructor
|
---|
| 61 | ////////////////////////////////////////////////////////////////////////////
|
---|
[408] | 62 | bncRinex::bncRinex(const QByteArray& statID, const QUrl& mountPoint,
|
---|
[366] | 63 | const QByteArray& format, const QByteArray& latitude,
|
---|
| 64 | const QByteArray& longitude, const QByteArray& nmea) {
|
---|
[408] | 65 | _statID = statID;
|
---|
[336] | 66 | _mountPoint = mountPoint;
|
---|
[337] | 67 | _format = format.left(6);
|
---|
[366] | 68 | _latitude = latitude;
|
---|
| 69 | _longitude = longitude;
|
---|
| 70 | _nmea = nmea;
|
---|
[77] | 71 | _headerWritten = false;
|
---|
[369] | 72 | _reconnectFlag = false;
|
---|
[132] | 73 |
|
---|
| 74 | QSettings settings;
|
---|
| 75 | _rnxScriptName = settings.value("rnxScript").toString();
|
---|
| 76 | expandEnvVar(_rnxScriptName);
|
---|
[153] | 77 |
|
---|
[157] | 78 | _pgmName = ((bncApp*)qApp)->bncVersion().leftJustified(20, ' ', true);
|
---|
[319] | 79 | #ifdef WIN32
|
---|
| 80 | _userName = QString("${USERNAME}");
|
---|
| 81 | #else
|
---|
[158] | 82 | _userName = QString("${USER}");
|
---|
[319] | 83 | #endif
|
---|
[157] | 84 | expandEnvVar(_userName);
|
---|
[158] | 85 | _userName = _userName.leftJustified(20, ' ', true);
|
---|
[539] | 86 |
|
---|
| 87 | if ( Qt::CheckState(settings.value("rnxV3").toInt()) == Qt::Checked) {
|
---|
| 88 | _rinexVers = 3;
|
---|
| 89 | }
|
---|
| 90 | else {
|
---|
| 91 | _rinexVers = 2;
|
---|
| 92 | }
|
---|
[73] | 93 | }
|
---|
| 94 |
|
---|
| 95 | // Destructor
|
---|
| 96 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 97 | bncRinex::~bncRinex() {
|
---|
[77] | 98 | _out.close();
|
---|
[73] | 99 | }
|
---|
| 100 |
|
---|
[420] | 101 | // Download Skeleton Header File
|
---|
| 102 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 103 | t_irc bncRinex::downloadSkeleton() {
|
---|
| 104 |
|
---|
| 105 | t_irc irc = failure;
|
---|
| 106 |
|
---|
| 107 | QStringList table;
|
---|
| 108 | bncTableDlg::getFullTable(_mountPoint.host(), _mountPoint.port(),
|
---|
| 109 | table, false);
|
---|
| 110 | QString net;
|
---|
| 111 | QStringListIterator it(table);
|
---|
| 112 | while (it.hasNext()) {
|
---|
| 113 | QString line = it.next();
|
---|
| 114 | if (line.indexOf("STR") == 0) {
|
---|
| 115 | QStringList tags = line.split(";");
|
---|
| 116 | if (tags.at(1) == _mountPoint.path().mid(1).toAscii()) {
|
---|
| 117 | net = tags.at(7);
|
---|
| 118 | break;
|
---|
| 119 | }
|
---|
| 120 | }
|
---|
| 121 | }
|
---|
| 122 | QString sklDir;
|
---|
| 123 | it.toFront();
|
---|
| 124 | while (it.hasNext()) {
|
---|
| 125 | QString line = it.next();
|
---|
| 126 | if (line.indexOf("NET") == 0) {
|
---|
| 127 | QStringList tags = line.split(";");
|
---|
| 128 | if (tags.at(1) == net) {
|
---|
| 129 | sklDir = tags.at(6).trimmed();
|
---|
| 130 | break;
|
---|
| 131 | }
|
---|
| 132 | }
|
---|
| 133 | }
|
---|
| 134 | if (!sklDir.isEmpty() && sklDir != "none") {
|
---|
| 135 | QUrl url(sklDir + "/" + _mountPoint.path().mid(1,4).toLower() + ".skl");
|
---|
| 136 | if (url.port() == -1) {
|
---|
| 137 | url.setPort(80);
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | const int timeOut = 10*1000;
|
---|
| 141 | QString msg;
|
---|
| 142 | QByteArray _latitude;
|
---|
| 143 | QByteArray _longitude;
|
---|
| 144 | QByteArray _nmea;
|
---|
| 145 | QTcpSocket* socket = bncGetThread::request(url, _latitude, _longitude, _nmea, timeOut, msg);
|
---|
| 146 |
|
---|
| 147 | if (socket) {
|
---|
[421] | 148 | _headerLines.clear();
|
---|
| 149 | bool firstLineRead = false;
|
---|
[420] | 150 | while (true) {
|
---|
| 151 | if (socket->canReadLine()) {
|
---|
| 152 | irc = success;
|
---|
[421] | 153 | QString line = socket->readLine();
|
---|
| 154 | line.chop(1);
|
---|
| 155 | if (line.indexOf("RINEX VERSION") != -1) {
|
---|
[545] | 156 | if (_rinexVers == 3) {
|
---|
| 157 | _headerLines.append(" 3.00 OBSERVATION DATA"
|
---|
| 158 | " M (MIXED)"
|
---|
| 159 | " RINEX VERSION / TYPE");
|
---|
| 160 | }
|
---|
| 161 | else {
|
---|
| 162 | _headerLines.append(" 2.11 OBSERVATION DATA"
|
---|
| 163 | " M (MIXED)"
|
---|
| 164 | " RINEX VERSION / TYPE");
|
---|
| 165 | }
|
---|
[421] | 166 | _headerLines.append("PGM / RUN BY / DATE");
|
---|
| 167 | firstLineRead = true;
|
---|
| 168 | }
|
---|
| 169 | else if (firstLineRead) {
|
---|
| 170 | if (line.indexOf("END OF HEADER") != -1) {
|
---|
| 171 | _headerLines.append("# / TYPES OF OBSERV");
|
---|
[546] | 172 | if (_rinexVers == 2) {
|
---|
| 173 | _headerLines.append(
|
---|
| 174 | QString(" 1 1").leftJustified(60, ' ', true) +
|
---|
| 175 | "WAVELENGTH FACT L1/2");
|
---|
| 176 | }
|
---|
[421] | 177 | _headerLines.append("TIME OF FIRST OBS");
|
---|
| 178 | _headerLines.append( line );
|
---|
| 179 | break;
|
---|
| 180 | }
|
---|
| 181 | else {
|
---|
| 182 | _headerLines.append( line );
|
---|
| 183 | }
|
---|
| 184 | }
|
---|
[420] | 185 | }
|
---|
| 186 | else {
|
---|
| 187 | socket->waitForReadyRead(timeOut);
|
---|
| 188 | if (socket->bytesAvailable() > 0) {
|
---|
| 189 | continue;
|
---|
| 190 | }
|
---|
| 191 | else {
|
---|
| 192 | break;
|
---|
| 193 | }
|
---|
| 194 | }
|
---|
| 195 | }
|
---|
| 196 | delete socket;
|
---|
| 197 | }
|
---|
| 198 | }
|
---|
| 199 | return irc;
|
---|
| 200 | }
|
---|
| 201 |
|
---|
[82] | 202 | // Read Skeleton Header File
|
---|
| 203 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 204 | void bncRinex::readSkeleton() {
|
---|
| 205 |
|
---|
[420] | 206 | // Read the local file
|
---|
| 207 | // -------------------
|
---|
[276] | 208 | QFile skl(_sklName);
|
---|
[82] | 209 | if ( skl.exists() && skl.open(QIODevice::ReadOnly) ) {
|
---|
[422] | 210 | _headerLines.clear();
|
---|
[82] | 211 | QTextStream in(&skl);
|
---|
| 212 | while ( !in.atEnd() ) {
|
---|
| 213 | _headerLines.append( in.readLine() );
|
---|
| 214 | if (_headerLines.last().indexOf("END OF HEADER") != -1) {
|
---|
| 215 | break;
|
---|
| 216 | }
|
---|
| 217 | }
|
---|
| 218 | }
|
---|
[298] | 219 |
|
---|
[420] | 220 | // Read downloaded file
|
---|
| 221 | // --------------------
|
---|
[298] | 222 | else {
|
---|
[420] | 223 | QDate currDate = QDate::currentDate();
|
---|
| 224 | if ( !_skeletonDate.isValid() || _skeletonDate != currDate ) {
|
---|
| 225 | if ( downloadSkeleton() == success) {
|
---|
| 226 | _skeletonDate = currDate;
|
---|
[298] | 227 | }
|
---|
| 228 | }
|
---|
| 229 | }
|
---|
[82] | 230 | }
|
---|
| 231 |
|
---|
| 232 | // File Name according to RINEX Standards
|
---|
| 233 | ////////////////////////////////////////////////////////////////////////////
|
---|
[125] | 234 | void bncRinex::resolveFileName(const QDateTime& datTim) {
|
---|
[82] | 235 |
|
---|
| 236 | QSettings settings;
|
---|
| 237 | QString path = settings.value("rnxPath").toString();
|
---|
| 238 | expandEnvVar(path);
|
---|
| 239 |
|
---|
[391] | 240 | if ( path.length() > 0 && path[path.length()-1] != QDir::separator() ) {
|
---|
[82] | 241 | path += QDir::separator();
|
---|
| 242 | }
|
---|
| 243 |
|
---|
[127] | 244 | QString intStr = settings.value("rnxIntr").toString();
|
---|
| 245 | QString hlpStr;
|
---|
[129] | 246 |
|
---|
| 247 | QTime nextTime;
|
---|
| 248 | QDate nextDate;
|
---|
| 249 |
|
---|
[204] | 250 | int indHlp = intStr.indexOf("min");
|
---|
| 251 |
|
---|
| 252 | if ( indHlp != -1) {
|
---|
| 253 | int step = intStr.left(indHlp-1).toInt();
|
---|
[127] | 254 | char ch = 'A' + datTim.time().hour();
|
---|
| 255 | hlpStr = ch;
|
---|
[204] | 256 | if (datTim.time().minute() >= 60-step) {
|
---|
| 257 | hlpStr += QString("%1").arg(60-step, 2, 10, QChar('0'));
|
---|
[199] | 258 | if (datTim.time().hour() < 23) {
|
---|
| 259 | nextTime.setHMS(datTim.time().hour() + 1 , 0, 0);
|
---|
| 260 | nextDate = datTim.date();
|
---|
| 261 | }
|
---|
| 262 | else {
|
---|
| 263 | nextTime.setHMS(0, 0, 0);
|
---|
| 264 | nextDate = datTim.date().addDays(1);
|
---|
| 265 | }
|
---|
| 266 | }
|
---|
| 267 | else {
|
---|
[204] | 268 | for (int limit = step; limit <= 60-step; limit += step) {
|
---|
| 269 | if (datTim.time().minute() < limit) {
|
---|
| 270 | hlpStr += QString("%1").arg(limit-step, 2, 10, QChar('0'));
|
---|
| 271 | nextTime.setHMS(datTim.time().hour(), limit, 0);
|
---|
| 272 | nextDate = datTim.date();
|
---|
| 273 | break;
|
---|
| 274 | }
|
---|
[199] | 275 | }
|
---|
| 276 | }
|
---|
| 277 | }
|
---|
[127] | 278 | else if (intStr == "1 hour") {
|
---|
| 279 | char ch = 'A' + datTim.time().hour();
|
---|
| 280 | hlpStr = ch;
|
---|
[129] | 281 | if (datTim.time().hour() < 23) {
|
---|
| 282 | nextTime.setHMS(datTim.time().hour() + 1 , 0, 0);
|
---|
| 283 | nextDate = datTim.date();
|
---|
| 284 | }
|
---|
| 285 | else {
|
---|
| 286 | nextTime.setHMS(0, 0, 0);
|
---|
| 287 | nextDate = datTim.date().addDays(1);
|
---|
| 288 | }
|
---|
[127] | 289 | }
|
---|
| 290 | else {
|
---|
| 291 | hlpStr = "0";
|
---|
[129] | 292 | nextTime.setHMS(0, 0, 0);
|
---|
| 293 | nextDate = datTim.date().addDays(1);
|
---|
[127] | 294 | }
|
---|
[267] | 295 | _nextCloseEpoch = QDateTime(nextDate, nextTime);
|
---|
[82] | 296 |
|
---|
[183] | 297 | QString ID4 = _statID.left(4);
|
---|
| 298 |
|
---|
| 299 | // Check name conflict
|
---|
| 300 | // -------------------
|
---|
| 301 | QString distStr;
|
---|
| 302 | int num = 0;
|
---|
| 303 | QListIterator<QString> it(settings.value("mountPoints").toStringList());
|
---|
| 304 | while (it.hasNext()) {
|
---|
| 305 | QString mp = it.next();
|
---|
| 306 | if (mp.indexOf(ID4) != -1) {
|
---|
| 307 | ++num;
|
---|
| 308 | }
|
---|
| 309 | }
|
---|
| 310 | if (num > 1) {
|
---|
| 311 | distStr = "_" + _statID.mid(4);
|
---|
| 312 | }
|
---|
| 313 |
|
---|
[276] | 314 | QString sklExt = settings.value("rnxSkel").toString();
|
---|
| 315 | if (!sklExt.isEmpty()) {
|
---|
| 316 | _sklName = path + ID4 + distStr + "." + sklExt;
|
---|
| 317 | }
|
---|
| 318 |
|
---|
[183] | 319 | path += ID4 +
|
---|
[127] | 320 | QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
|
---|
[276] | 321 | hlpStr + distStr + datTim.toString(".yyO");
|
---|
[82] | 322 |
|
---|
| 323 | _fName = path.toAscii();
|
---|
| 324 | }
|
---|
| 325 |
|
---|
[77] | 326 | // Write RINEX Header
|
---|
| 327 | ////////////////////////////////////////////////////////////////////////////
|
---|
[267] | 328 | void bncRinex::writeHeader(const QDateTime& datTim,
|
---|
| 329 | const QDateTime& datTimNom) {
|
---|
[77] | 330 |
|
---|
[356] | 331 | QSettings settings;
|
---|
| 332 |
|
---|
[77] | 333 | // Open the Output File
|
---|
| 334 | // --------------------
|
---|
[267] | 335 | resolveFileName(datTimNom);
|
---|
[260] | 336 |
|
---|
| 337 | // Append to existing file and return
|
---|
| 338 | // ----------------------------------
|
---|
| 339 | if ( QFile::exists(_fName) ) {
|
---|
[369] | 340 | if (_reconnectFlag ||
|
---|
| 341 | Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
|
---|
[260] | 342 | _out.open(_fName.data(), ios::app);
|
---|
| 343 | _out.setf(ios::showpoint | ios::fixed);
|
---|
| 344 | _headerWritten = true;
|
---|
[369] | 345 | _reconnectFlag = false;
|
---|
[260] | 346 | return;
|
---|
| 347 | }
|
---|
| 348 | }
|
---|
| 349 |
|
---|
[82] | 350 | _out.open(_fName.data());
|
---|
[85] | 351 | _out.setf(ios::showpoint | ios::fixed);
|
---|
[77] | 352 |
|
---|
[82] | 353 | // Copy Skeleton Header
|
---|
| 354 | // --------------------
|
---|
[276] | 355 | readSkeleton();
|
---|
[82] | 356 | if (_headerLines.size() > 0) {
|
---|
| 357 | QStringListIterator it(_headerLines);
|
---|
| 358 | while (it.hasNext()) {
|
---|
| 359 | QString line = it.next();
|
---|
[157] | 360 | if (line.indexOf("PGM / RUN BY / DATE") != -1) {
|
---|
[159] | 361 | QString hlp = QDate::currentDate().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
|
---|
[157] | 362 | _out << _pgmName.toAscii().data() << _userName.toAscii().data()
|
---|
| 363 | << hlp.toAscii().data() << "PGM / RUN BY / DATE" << endl;
|
---|
| 364 | }
|
---|
| 365 | else if (line.indexOf("# / TYPES OF OBSERV") != -1) {
|
---|
[545] | 366 | if (_rinexVers == 3) {
|
---|
| 367 | _out << "G 6 C1C L1C S1C C2P L2P S2P SYS / # / OBS TYPES" << endl;
|
---|
| 368 | _out << "R 6 C1C L1C S1C C2P L2P S2P SYS / # / OBS TYPES" << endl;
|
---|
| 369 | }
|
---|
| 370 | else {
|
---|
| 371 | _out << " 8 C1 C2 P1 P2 L1 L2 S1 S2"
|
---|
| 372 | " # / TYPES OF OBSERV" << endl;
|
---|
| 373 | }
|
---|
[82] | 374 | }
|
---|
| 375 | else if (line.indexOf("TIME OF FIRST OBS") != -1) {
|
---|
[125] | 376 | _out << datTim.toString(" yyyy MM dd"
|
---|
| 377 | " hh mm ss.zzz0000").toAscii().data();
|
---|
| 378 | _out << " TIME OF FIRST OBS" << endl;
|
---|
[337] | 379 | QString hlp = (_format + QString(" %1").arg(_mountPoint.host() +
|
---|
| 380 | _mountPoint.path())).leftJustified(60, ' ', true);
|
---|
[156] | 381 | _out << hlp.toAscii().data() << "COMMENT" << endl;
|
---|
[82] | 382 | }
|
---|
| 383 | else {
|
---|
| 384 | _out << line.toAscii().data() << endl;
|
---|
| 385 | }
|
---|
| 386 | }
|
---|
| 387 | }
|
---|
[78] | 388 |
|
---|
[82] | 389 | // Write Dummy Header
|
---|
| 390 | // ------------------
|
---|
| 391 | else {
|
---|
| 392 | double approxPos[3]; approxPos[0] = approxPos[1] = approxPos[2] = 0.0;
|
---|
| 393 | double antennaNEU[3]; antennaNEU[0] = antennaNEU[1] = antennaNEU[2] = 0.0;
|
---|
| 394 |
|
---|
[545] | 395 | if (_rinexVers == 3) {
|
---|
| 396 | _out << " 3.00 OBSERVATION DATA M (MIXED) RINEX VERSION / TYPE" << endl;
|
---|
| 397 | }
|
---|
| 398 | else {
|
---|
| 399 | _out << " 2.11 OBSERVATION DATA M (MIXED) RINEX VERSION / TYPE" << endl;
|
---|
| 400 | }
|
---|
[159] | 401 | QString hlp = QDate::currentDate().toString("dd-MMM-yyyy").leftJustified(20, ' ', true);
|
---|
[157] | 402 | _out << _pgmName.toAscii().data() << _userName.toAscii().data()
|
---|
| 403 | << hlp.toAscii().data() << "PGM / RUN BY / DATE" << endl;
|
---|
[86] | 404 | _out.setf(ios::left);
|
---|
[82] | 405 | _out << setw(60) << _statID.data() << "MARKER NAME" << endl;
|
---|
[354] | 406 | _out << setw(60) << "unknown unknown" << "OBSERVER / AGENCY" << endl;
|
---|
[82] | 407 | _out << setw(20) << "unknown"
|
---|
| 408 | << setw(20) << "unknown"
|
---|
| 409 | << setw(20) << "unknown" << "REC # / TYPE / VERS" << endl;
|
---|
| 410 | _out << setw(20) << "unknown"
|
---|
| 411 | << setw(20) << "unknown"
|
---|
| 412 | << setw(20) << " " << "ANT # / TYPE" << endl;
|
---|
[86] | 413 | _out.unsetf(ios::left);
|
---|
[82] | 414 | _out << setw(14) << setprecision(4) << approxPos[0]
|
---|
| 415 | << setw(14) << setprecision(4) << approxPos[1]
|
---|
| 416 | << setw(14) << setprecision(4) << approxPos[2]
|
---|
| 417 | << " " << "APPROX POSITION XYZ" << endl;
|
---|
| 418 | _out << setw(14) << setprecision(4) << antennaNEU[0]
|
---|
| 419 | << setw(14) << setprecision(4) << antennaNEU[1]
|
---|
| 420 | << setw(14) << setprecision(4) << antennaNEU[2]
|
---|
| 421 | << " " << "ANTENNA: DELTA H/E/N" << endl;
|
---|
[544] | 422 | if (_rinexVers == 3) {
|
---|
| 423 | _out << "G 6 C1C L1C S1C C2P L2P S2P SYS / # / OBS TYPES" << endl;
|
---|
| 424 | _out << "R 6 C1C L1C S1C C2P L2P S2P SYS / # / OBS TYPES" << endl;
|
---|
| 425 |
|
---|
| 426 | }
|
---|
| 427 | else {
|
---|
| 428 | _out << " 1 1 WAVELENGTH FACT L1/2" << endl;
|
---|
| 429 | _out << " 8 C1 C2 P1 P2 L1 L2 S1 S2 # / TYPES OF OBSERV" << endl;
|
---|
| 430 | }
|
---|
| 431 | _out << datTim.toString(" yyyy MM dd"
|
---|
[125] | 432 | " hh mm ss.zzz0000").toAscii().data();
|
---|
| 433 | _out << " " << "TIME OF FIRST OBS" << endl;
|
---|
[337] | 434 | hlp = (_format + QString(" %1").arg(_mountPoint.host() +
|
---|
| 435 | _mountPoint.path())).leftJustified(60, ' ', true);
|
---|
[156] | 436 | _out << hlp.toAscii().data() << "COMMENT" << endl;
|
---|
[366] | 437 |
|
---|
[410] | 438 | if (_nmea == "yes") {
|
---|
| 439 | hlp = ("NMEA LAT=" + _latitude + " " + "LONG=" + _longitude).leftJustified(60, ' ',true);
|
---|
[366] | 440 | _out << hlp.toAscii().data() << "COMMENT" << endl; }
|
---|
| 441 |
|
---|
[82] | 442 | _out << " END OF HEADER" << endl;
|
---|
| 443 | }
|
---|
[78] | 444 |
|
---|
[77] | 445 | _headerWritten = true;
|
---|
| 446 | }
|
---|
| 447 |
|
---|
[73] | 448 | // Stores Observation into Internal Array
|
---|
| 449 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 450 | void bncRinex::deepCopy(const Observation* obs) {
|
---|
[74] | 451 | Observation* newObs = new Observation();
|
---|
| 452 | memcpy(newObs, obs, sizeof(*obs));
|
---|
| 453 | _obs.push_back(newObs);
|
---|
[73] | 454 | }
|
---|
| 455 |
|
---|
| 456 | // Write One Epoch into the RINEX File
|
---|
| 457 | ////////////////////////////////////////////////////////////////////////////
|
---|
[160] | 458 | void bncRinex::dumpEpoch(long maxTime) {
|
---|
[73] | 459 |
|
---|
[160] | 460 | // Select observations older than maxTime
|
---|
| 461 | // --------------------------------------
|
---|
| 462 | QList<Observation*> dumpList;
|
---|
| 463 | QMutableListIterator<Observation*> mIt(_obs);
|
---|
| 464 | while (mIt.hasNext()) {
|
---|
| 465 | Observation* ob = mIt.next();
|
---|
[238] | 466 | if (ob->GPSWeek * 7*24*3600 + ob->GPSWeeks < maxTime - 0.05) {
|
---|
[160] | 467 | dumpList.push_back(ob);
|
---|
| 468 | mIt.remove();
|
---|
| 469 | }
|
---|
| 470 | }
|
---|
| 471 |
|
---|
[75] | 472 | // Easy Return
|
---|
| 473 | // -----------
|
---|
[160] | 474 | if (dumpList.isEmpty()) {
|
---|
[75] | 475 | return;
|
---|
| 476 | }
|
---|
| 477 |
|
---|
| 478 | // Time of Epoch
|
---|
| 479 | // -------------
|
---|
[222] | 480 | Observation* fObs = *dumpList.begin();
|
---|
[267] | 481 | QDateTime datTim = dateAndTimeFromGPSweek(fObs->GPSWeek, fObs->GPSWeeks);
|
---|
| 482 | QDateTime datTimNom = dateAndTimeFromGPSweek(fObs->GPSWeek,
|
---|
| 483 | floor(fObs->GPSWeeks+0.5));
|
---|
[75] | 484 |
|
---|
[130] | 485 | // Close the file
|
---|
| 486 | // --------------
|
---|
[267] | 487 | if (_nextCloseEpoch.isValid() && datTimNom >= _nextCloseEpoch) {
|
---|
[130] | 488 | closeFile();
|
---|
| 489 | _headerWritten = false;
|
---|
| 490 | }
|
---|
| 491 |
|
---|
[78] | 492 | // Write RINEX Header
|
---|
| 493 | // ------------------
|
---|
| 494 | if (!_headerWritten) {
|
---|
[267] | 495 | writeHeader(datTim, datTimNom);
|
---|
[78] | 496 | }
|
---|
| 497 |
|
---|
[353] | 498 | double sec = double(datTim.time().second()) + fmod(fObs->GPSWeeks,1.0);
|
---|
[75] | 499 |
|
---|
[540] | 500 | // RINEX Version 3
|
---|
| 501 | // ---------------
|
---|
| 502 | if (_rinexVers == 3) {
|
---|
| 503 | _out << datTim.toString("> yyyy MM dd hh mm ").toAscii().data()
|
---|
| 504 | << setw(10) << setprecision(7) << sec
|
---|
| 505 | << " " << 0 << setw(3) << dumpList.size() << endl;
|
---|
[539] | 506 |
|
---|
[540] | 507 | QListIterator<Observation*> it(dumpList);
|
---|
| 508 | while (it.hasNext()) {
|
---|
| 509 | Observation* ob = it.next();
|
---|
[543] | 510 | _out << ob->satSys
|
---|
| 511 | << setw(2) << setfill('0') << ob->satNum << setfill(' ')
|
---|
[541] | 512 | << setw(14) << setprecision(3) << ob->C1 << " "
|
---|
[542] | 513 | << setw(14) << setprecision(3) << ob->L1 << " "
|
---|
| 514 | << setw(1) << ob->SNR1
|
---|
[541] | 515 | << setw(14) << setprecision(3) << ob->S1 << " "
|
---|
| 516 | << setw(14) << setprecision(3) << ob->P2 << " "
|
---|
[542] | 517 | << setw(14) << setprecision(3) << ob->L2 << " "
|
---|
| 518 | << setw(1) << ob->SNR2
|
---|
[540] | 519 | << setw(14) << setprecision(3) << ob->S2
|
---|
| 520 | << endl;
|
---|
| 521 | delete ob;
|
---|
[75] | 522 | }
|
---|
[74] | 523 | }
|
---|
[75] | 524 |
|
---|
[540] | 525 | // RINEX Version 2
|
---|
| 526 | // ---------------
|
---|
| 527 | else {
|
---|
| 528 | _out << datTim.toString(" yy MM dd hh mm ").toAscii().data()
|
---|
| 529 | << setw(10) << setprecision(7) << sec
|
---|
| 530 | << " " << 0 << setw(3) << dumpList.size();
|
---|
| 531 |
|
---|
| 532 | QListIterator<Observation*> it(dumpList); int iSat = 0;
|
---|
| 533 | while (it.hasNext()) {
|
---|
| 534 | iSat++;
|
---|
| 535 | Observation* ob = it.next();
|
---|
| 536 | _out << ob->satSys << setw(2) << ob->satNum;
|
---|
| 537 | if (iSat == 12 && it.hasNext()) {
|
---|
| 538 | _out << endl << " ";
|
---|
| 539 | iSat = 0;
|
---|
| 540 | }
|
---|
| 541 | }
|
---|
[77] | 542 | _out << endl;
|
---|
[540] | 543 |
|
---|
| 544 | it.toFront();
|
---|
| 545 | while (it.hasNext()) {
|
---|
| 546 | Observation* ob = it.next();
|
---|
| 547 |
|
---|
| 548 | char lli = ' ';
|
---|
| 549 | char snr = ' ';
|
---|
| 550 | _out << setw(14) << setprecision(3) << ob->C1 << lli << snr;
|
---|
| 551 | _out << setw(14) << setprecision(3) << ob->C2 << lli << snr;
|
---|
| 552 | _out << setw(14) << setprecision(3) << ob->P1 << lli << snr;
|
---|
| 553 | _out << setw(14) << setprecision(3) << ob->P2 << lli << snr;
|
---|
| 554 | _out << setw(14) << setprecision(3) << ob->L1 << lli
|
---|
| 555 | << setw(1) << ob->SNR1 << endl;
|
---|
| 556 | _out << setw(14) << setprecision(3) << ob->L2 << lli
|
---|
| 557 | << setw(1) << ob->SNR2;
|
---|
| 558 | _out << setw(14) << setprecision(3) << ob->S1 ;
|
---|
| 559 | _out << setw(16) << setprecision(3) << ob->S2 ;
|
---|
| 560 | _out << endl;
|
---|
| 561 |
|
---|
| 562 | delete ob;
|
---|
| 563 | }
|
---|
[75] | 564 | }
|
---|
| 565 |
|
---|
[77] | 566 | _out.flush();
|
---|
[73] | 567 | }
|
---|
| 568 |
|
---|
[130] | 569 | // Close the Old RINEX File
|
---|
| 570 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 571 | void bncRinex::closeFile() {
|
---|
[436] | 572 | QMutexLocker locker(&_mutex);
|
---|
[130] | 573 | _out.close();
|
---|
[132] | 574 | if (!_rnxScriptName.isEmpty()) {
|
---|
[436] | 575 |
|
---|
[435] | 576 | #ifdef WIN32
|
---|
| 577 | QProcess::startDetached(_rnxScriptName, QStringList() << _fName) ;
|
---|
| 578 | #else
|
---|
[475] | 579 | QProcess::startDetached("nohup", QStringList() << _rnxScriptName << _fName) ;
|
---|
[435] | 580 | #endif
|
---|
[436] | 581 |
|
---|
[132] | 582 | }
|
---|
[130] | 583 | }
|
---|