[3645] | 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: t_rnxNavFile
|
---|
| 30 | *
|
---|
| 31 | * Purpose: Reads RINEX Navigation File
|
---|
| 32 | *
|
---|
| 33 | * Author: L. Mervart
|
---|
| 34 | *
|
---|
| 35 | * Created: 24-Jan-2012
|
---|
| 36 | *
|
---|
| 37 | * Changes:
|
---|
| 38 | *
|
---|
| 39 | * -----------------------------------------------------------------------*/
|
---|
| 40 |
|
---|
| 41 | #include <iostream>
|
---|
[3666] | 42 | #include <newmatio.h>
|
---|
[3645] | 43 | #include "rnxnavfile.h"
|
---|
[3657] | 44 | #include "bncutils.h"
|
---|
[3659] | 45 | #include "RTCM3/ephemeris.h"
|
---|
[3645] | 46 |
|
---|
| 47 | using namespace std;
|
---|
| 48 |
|
---|
| 49 | // Constructor
|
---|
| 50 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3657] | 51 | t_rnxNavFile::t_rnxNavHeader::t_rnxNavHeader() {
|
---|
| 52 | _version = 0.0;
|
---|
[3659] | 53 | _glonass = false;
|
---|
[3645] | 54 | }
|
---|
| 55 |
|
---|
| 56 | // Destructor
|
---|
| 57 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3657] | 58 | t_rnxNavFile::t_rnxNavHeader::~t_rnxNavHeader() {
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | // Read Header
|
---|
| 62 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 63 | t_irc t_rnxNavFile::t_rnxNavHeader::read(QTextStream* stream) {
|
---|
| 64 | while (stream->status() == QTextStream::Ok && !stream->atEnd()) {
|
---|
| 65 | QString line = stream->readLine();
|
---|
| 66 | if (line.isEmpty()) {
|
---|
| 67 | continue;
|
---|
| 68 | }
|
---|
| 69 | QString value = line.left(60).trimmed();
|
---|
| 70 | QString key = line.mid(60).trimmed();
|
---|
| 71 | if (key == "END OF HEADER") {
|
---|
| 72 | break;
|
---|
| 73 | }
|
---|
| 74 | else if (key == "RINEX VERSION / TYPE") {
|
---|
| 75 | QTextStream in(value.toAscii(), QIODevice::ReadOnly);
|
---|
| 76 | in >> _version;
|
---|
[3659] | 77 | if (value.indexOf("GLONASS") != -1) {
|
---|
| 78 | _glonass = true;
|
---|
| 79 | }
|
---|
[3657] | 80 | }
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | return success;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | // Constructor
|
---|
| 87 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3658] | 88 | t_rnxNavFile::t_rnxNavFile(QString fileName) {
|
---|
[3657] | 89 | expandEnvVar(fileName);
|
---|
[3746] | 90 | QFile* file = new QFile(fileName);
|
---|
| 91 | file->open(QIODevice::ReadOnly | QIODevice::Text);
|
---|
| 92 | QTextStream* stream = new QTextStream();
|
---|
| 93 | stream->setDevice(file);
|
---|
| 94 | _header.read(stream);
|
---|
| 95 | this->read(stream);
|
---|
| 96 | delete stream;
|
---|
| 97 | delete file;
|
---|
[3657] | 98 | }
|
---|
| 99 |
|
---|
| 100 | // Destructor
|
---|
| 101 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3645] | 102 | t_rnxNavFile::~t_rnxNavFile() {
|
---|
[3747] | 103 | while (!_ephs.empty()) {
|
---|
| 104 | t_eph* eph = _ephs.front();
|
---|
| 105 | _ephs.pop();
|
---|
| 106 | delete eph;
|
---|
| 107 | }
|
---|
[3645] | 108 | }
|
---|
| 109 |
|
---|
[3746] | 110 | // Read File Content
|
---|
[3659] | 111 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3746] | 112 | void t_rnxNavFile::read(QTextStream* stream) {
|
---|
[3659] | 113 |
|
---|
[3746] | 114 | while (stream->status() == QTextStream::Ok && !stream->atEnd()) {
|
---|
| 115 | QString line = stream->readLine();
|
---|
[3659] | 116 | if (line.isEmpty()) {
|
---|
| 117 | continue;
|
---|
| 118 | }
|
---|
| 119 | QStringList hlp = line.split(QRegExp("\\s+"), QString::SkipEmptyParts);
|
---|
| 120 | QString prn;
|
---|
| 121 | if (version() >= 3.0) {
|
---|
| 122 | prn = hlp.at(0);
|
---|
| 123 | }
|
---|
| 124 | else {
|
---|
| 125 | if (glonass()) {
|
---|
[3669] | 126 | prn = QString("R%1").arg(hlp.at(0).toInt(), 2, 10, QChar('0'));
|
---|
[3659] | 127 | }
|
---|
| 128 | else {
|
---|
[3669] | 129 | prn = QString("G%1").arg(hlp.at(0).toInt(), 2, 10, QChar('0'));
|
---|
[3659] | 130 | }
|
---|
| 131 | }
|
---|
[3746] | 132 | t_eph* eph = 0;
|
---|
[3659] | 133 | QStringList lines; lines << line;
|
---|
| 134 | if (prn[0] == 'G') {
|
---|
| 135 | for (int ii = 1; ii < 8; ii++) {
|
---|
[3746] | 136 | lines << stream->readLine();
|
---|
[3659] | 137 | }
|
---|
| 138 | eph = new t_ephGPS(version(), lines);
|
---|
| 139 | }
|
---|
| 140 | else if (prn[0] == 'R') {
|
---|
| 141 | for (int ii = 1; ii < 4; ii++) {
|
---|
[3746] | 142 | lines << stream->readLine();
|
---|
[3659] | 143 | }
|
---|
| 144 | eph = new t_ephGlo(version(), lines);
|
---|
| 145 | }
|
---|
| 146 | else if (prn[0] == 'E') {
|
---|
| 147 | for (int ii = 1; ii < 8; ii++) {
|
---|
[3746] | 148 | lines << stream->readLine();
|
---|
[3659] | 149 | }
|
---|
| 150 | eph = new t_ephGal(version(), lines);
|
---|
| 151 | }
|
---|
[3662] | 152 | if (eph && eph->ok()) {
|
---|
[3746] | 153 | _ephs.push(eph);
|
---|
[3659] | 154 | }
|
---|
[3746] | 155 | else {
|
---|
| 156 | delete eph;
|
---|
| 157 | }
|
---|
[3659] | 158 | }
|
---|
[3746] | 159 | }
|
---|
[3659] | 160 |
|
---|
[3746] | 161 | // Read Next Ephemeris
|
---|
| 162 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3748] | 163 | t_eph* t_rnxNavFile::getNextEph(const bncTime& tt) {
|
---|
| 164 | while (!_ephs.empty()) {
|
---|
[3746] | 165 | t_eph* eph = _ephs.front();
|
---|
[3748] | 166 | bncTime ephTime(eph->GPSweek(), eph->GPSweeks());
|
---|
| 167 | double dt = ephTime - tt;
|
---|
| 168 | if (dt < 4*3600.0) {
|
---|
| 169 | _ephs.pop();
|
---|
| 170 | return eph;
|
---|
| 171 | }
|
---|
| 172 | else {
|
---|
| 173 | return 0;
|
---|
| 174 | }
|
---|
[3746] | 175 | }
|
---|
[3683] | 176 | return 0;
|
---|
[3659] | 177 | }
|
---|