[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 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3999] | 88 | t_rnxNavFile::t_rnxNavFile(const QString& fileName, e_inpOut inpOut) {
|
---|
| 89 | _inpOut = inpOut;
|
---|
| 90 | _stream = 0;
|
---|
| 91 | _file = 0;
|
---|
| 92 | if (_inpOut == input) {
|
---|
| 93 | openRead(fileName);
|
---|
| 94 | }
|
---|
| 95 | else {
|
---|
| 96 | openWrite(fileName);
|
---|
| 97 | }
|
---|
[3657] | 98 | }
|
---|
| 99 |
|
---|
[3999] | 100 | // Open for input
|
---|
| 101 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 102 | void t_rnxNavFile::openRead(const QString& fileName) {
|
---|
| 103 |
|
---|
| 104 | _fileName = fileName; expandEnvVar(_fileName);
|
---|
| 105 | _file = new QFile(_fileName);
|
---|
| 106 | _file->open(QIODevice::ReadOnly | QIODevice::Text);
|
---|
| 107 | _stream = new QTextStream();
|
---|
| 108 | _stream->setDevice(_file);
|
---|
| 109 |
|
---|
| 110 | _header.read(_stream);
|
---|
| 111 | this->read(_stream);
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | // Open for output
|
---|
| 115 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 116 | void t_rnxNavFile::openWrite(const QString& fileName) {
|
---|
| 117 |
|
---|
| 118 | _fileName = fileName; expandEnvVar(_fileName);
|
---|
| 119 | _file = new QFile(_fileName);
|
---|
| 120 | _file->open(QIODevice::WriteOnly | QIODevice::Text);
|
---|
| 121 | _stream = new QTextStream();
|
---|
| 122 | _stream->setDevice(_file);
|
---|
| 123 | }
|
---|
| 124 |
|
---|
[3657] | 125 | // Destructor
|
---|
| 126 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3645] | 127 | t_rnxNavFile::~t_rnxNavFile() {
|
---|
[3999] | 128 | close();
|
---|
[3758] | 129 | for (unsigned ii = 0; ii < _ephs.size(); ii++) {
|
---|
| 130 | delete _ephs[ii];
|
---|
[3999] | 131 | }
|
---|
[3645] | 132 | }
|
---|
| 133 |
|
---|
[3999] | 134 | // Close
|
---|
| 135 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 136 | void t_rnxNavFile::close() {
|
---|
| 137 | delete _stream; _stream = 0;
|
---|
| 138 | delete _file; _file = 0;
|
---|
| 139 | }
|
---|
| 140 |
|
---|
[3746] | 141 | // Read File Content
|
---|
[3659] | 142 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3746] | 143 | void t_rnxNavFile::read(QTextStream* stream) {
|
---|
[3659] | 144 |
|
---|
[3746] | 145 | while (stream->status() == QTextStream::Ok && !stream->atEnd()) {
|
---|
| 146 | QString line = stream->readLine();
|
---|
[3659] | 147 | if (line.isEmpty()) {
|
---|
| 148 | continue;
|
---|
| 149 | }
|
---|
| 150 | QStringList hlp = line.split(QRegExp("\\s+"), QString::SkipEmptyParts);
|
---|
| 151 | QString prn;
|
---|
| 152 | if (version() >= 3.0) {
|
---|
| 153 | prn = hlp.at(0);
|
---|
| 154 | }
|
---|
| 155 | else {
|
---|
| 156 | if (glonass()) {
|
---|
[3669] | 157 | prn = QString("R%1").arg(hlp.at(0).toInt(), 2, 10, QChar('0'));
|
---|
[3659] | 158 | }
|
---|
| 159 | else {
|
---|
[3669] | 160 | prn = QString("G%1").arg(hlp.at(0).toInt(), 2, 10, QChar('0'));
|
---|
[3659] | 161 | }
|
---|
| 162 | }
|
---|
[3746] | 163 | t_eph* eph = 0;
|
---|
[3659] | 164 | QStringList lines; lines << line;
|
---|
| 165 | if (prn[0] == 'G') {
|
---|
| 166 | for (int ii = 1; ii < 8; ii++) {
|
---|
[3746] | 167 | lines << stream->readLine();
|
---|
[3659] | 168 | }
|
---|
| 169 | eph = new t_ephGPS(version(), lines);
|
---|
| 170 | }
|
---|
| 171 | else if (prn[0] == 'R') {
|
---|
| 172 | for (int ii = 1; ii < 4; ii++) {
|
---|
[3746] | 173 | lines << stream->readLine();
|
---|
[3659] | 174 | }
|
---|
| 175 | eph = new t_ephGlo(version(), lines);
|
---|
| 176 | }
|
---|
| 177 | else if (prn[0] == 'E') {
|
---|
| 178 | for (int ii = 1; ii < 8; ii++) {
|
---|
[3746] | 179 | lines << stream->readLine();
|
---|
[3659] | 180 | }
|
---|
| 181 | eph = new t_ephGal(version(), lines);
|
---|
| 182 | }
|
---|
[3662] | 183 | if (eph && eph->ok()) {
|
---|
[3758] | 184 | _ephs.push_back(eph);
|
---|
[3659] | 185 | }
|
---|
[3746] | 186 | else {
|
---|
| 187 | delete eph;
|
---|
| 188 | }
|
---|
[3659] | 189 | }
|
---|
[3746] | 190 | }
|
---|
[3659] | 191 |
|
---|
[3746] | 192 | // Read Next Ephemeris
|
---|
| 193 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3757] | 194 | t_eph* t_rnxNavFile::getNextEph(const bncTime& tt,
|
---|
| 195 | const QMap<QString, int>* corrIODs) {
|
---|
[3758] | 196 |
|
---|
[3764] | 197 | // Get Ephemeris according to IOD
|
---|
| 198 | // ------------------------------
|
---|
[3758] | 199 | if (corrIODs) {
|
---|
| 200 | QMapIterator<QString, int> itIOD(*corrIODs);
|
---|
| 201 | while (itIOD.hasNext()) {
|
---|
| 202 | itIOD.next();
|
---|
| 203 | QString prn = itIOD.key();
|
---|
| 204 | int iod = itIOD.value();
|
---|
| 205 | vector<t_eph*>::iterator it = _ephs.begin();
|
---|
| 206 | while (it != _ephs.end()) {
|
---|
| 207 | t_eph* eph = *it;
|
---|
| 208 | if (eph->prn() == prn && eph->IOD() == iod) {
|
---|
| 209 | it = _ephs.erase(it);
|
---|
| 210 | return eph;
|
---|
| 211 | }
|
---|
| 212 | ++it;
|
---|
| 213 | }
|
---|
[3748] | 214 | }
|
---|
[3746] | 215 | }
|
---|
[3758] | 216 |
|
---|
[3764] | 217 | // Get Ephemeris according to time
|
---|
| 218 | // -------------------------------
|
---|
| 219 | else {
|
---|
| 220 | vector<t_eph*>::iterator it = _ephs.begin();
|
---|
| 221 | while (it != _ephs.end()) {
|
---|
| 222 | t_eph* eph = *it;
|
---|
[3758] | 223 |
|
---|
[3764] | 224 | bncTime ephTime(eph->GPSweek(), eph->GPSweeks());
|
---|
| 225 | double dt = ephTime - tt;
|
---|
| 226 |
|
---|
| 227 | if (dt < 2*3600.0) {
|
---|
| 228 | it = _ephs.erase(it);
|
---|
| 229 | return eph;
|
---|
| 230 | }
|
---|
| 231 | ++it;
|
---|
| 232 | }
|
---|
| 233 | }
|
---|
| 234 |
|
---|
[3683] | 235 | return 0;
|
---|
[3659] | 236 | }
|
---|