[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"
|
---|
[4010] | 44 | #include "bncapp.h"
|
---|
[3657] | 45 | #include "bncutils.h"
|
---|
[3659] | 46 | #include "RTCM3/ephemeris.h"
|
---|
[3645] | 47 |
|
---|
| 48 | using namespace std;
|
---|
| 49 |
|
---|
| 50 | // Constructor
|
---|
| 51 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3657] | 52 | t_rnxNavFile::t_rnxNavHeader::t_rnxNavHeader() {
|
---|
| 53 | _version = 0.0;
|
---|
[3659] | 54 | _glonass = false;
|
---|
[3645] | 55 | }
|
---|
| 56 |
|
---|
| 57 | // Destructor
|
---|
| 58 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3657] | 59 | t_rnxNavFile::t_rnxNavHeader::~t_rnxNavHeader() {
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | // Read Header
|
---|
| 63 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 64 | t_irc t_rnxNavFile::t_rnxNavHeader::read(QTextStream* stream) {
|
---|
| 65 | while (stream->status() == QTextStream::Ok && !stream->atEnd()) {
|
---|
| 66 | QString line = stream->readLine();
|
---|
| 67 | if (line.isEmpty()) {
|
---|
| 68 | continue;
|
---|
| 69 | }
|
---|
| 70 | QString value = line.left(60).trimmed();
|
---|
| 71 | QString key = line.mid(60).trimmed();
|
---|
| 72 | if (key == "END OF HEADER") {
|
---|
| 73 | break;
|
---|
| 74 | }
|
---|
| 75 | else if (key == "RINEX VERSION / TYPE") {
|
---|
| 76 | QTextStream in(value.toAscii(), QIODevice::ReadOnly);
|
---|
| 77 | in >> _version;
|
---|
[3659] | 78 | if (value.indexOf("GLONASS") != -1) {
|
---|
| 79 | _glonass = true;
|
---|
| 80 | }
|
---|
[3657] | 81 | }
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | return success;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | // Constructor
|
---|
| 88 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3999] | 89 | t_rnxNavFile::t_rnxNavFile(const QString& fileName, e_inpOut inpOut) {
|
---|
| 90 | _inpOut = inpOut;
|
---|
| 91 | _stream = 0;
|
---|
| 92 | _file = 0;
|
---|
| 93 | if (_inpOut == input) {
|
---|
| 94 | openRead(fileName);
|
---|
| 95 | }
|
---|
| 96 | else {
|
---|
| 97 | openWrite(fileName);
|
---|
| 98 | }
|
---|
[3657] | 99 | }
|
---|
| 100 |
|
---|
[3999] | 101 | // Open for input
|
---|
| 102 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 103 | void t_rnxNavFile::openRead(const QString& fileName) {
|
---|
| 104 |
|
---|
| 105 | _fileName = fileName; expandEnvVar(_fileName);
|
---|
| 106 | _file = new QFile(_fileName);
|
---|
| 107 | _file->open(QIODevice::ReadOnly | QIODevice::Text);
|
---|
| 108 | _stream = new QTextStream();
|
---|
| 109 | _stream->setDevice(_file);
|
---|
| 110 |
|
---|
| 111 | _header.read(_stream);
|
---|
| 112 | this->read(_stream);
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | // Open for output
|
---|
| 116 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 117 | void t_rnxNavFile::openWrite(const QString& fileName) {
|
---|
| 118 |
|
---|
| 119 | _fileName = fileName; expandEnvVar(_fileName);
|
---|
| 120 | _file = new QFile(_fileName);
|
---|
| 121 | _file->open(QIODevice::WriteOnly | QIODevice::Text);
|
---|
| 122 | _stream = new QTextStream();
|
---|
| 123 | _stream->setDevice(_file);
|
---|
| 124 | }
|
---|
| 125 |
|
---|
[3657] | 126 | // Destructor
|
---|
| 127 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3645] | 128 | t_rnxNavFile::~t_rnxNavFile() {
|
---|
[3999] | 129 | close();
|
---|
[3758] | 130 | for (unsigned ii = 0; ii < _ephs.size(); ii++) {
|
---|
| 131 | delete _ephs[ii];
|
---|
[3999] | 132 | }
|
---|
[3645] | 133 | }
|
---|
| 134 |
|
---|
[3999] | 135 | // Close
|
---|
| 136 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 137 | void t_rnxNavFile::close() {
|
---|
| 138 | delete _stream; _stream = 0;
|
---|
| 139 | delete _file; _file = 0;
|
---|
| 140 | }
|
---|
| 141 |
|
---|
[3746] | 142 | // Read File Content
|
---|
[3659] | 143 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3746] | 144 | void t_rnxNavFile::read(QTextStream* stream) {
|
---|
[3659] | 145 |
|
---|
[3746] | 146 | while (stream->status() == QTextStream::Ok && !stream->atEnd()) {
|
---|
| 147 | QString line = stream->readLine();
|
---|
[3659] | 148 | if (line.isEmpty()) {
|
---|
| 149 | continue;
|
---|
| 150 | }
|
---|
| 151 | QStringList hlp = line.split(QRegExp("\\s+"), QString::SkipEmptyParts);
|
---|
| 152 | QString prn;
|
---|
| 153 | if (version() >= 3.0) {
|
---|
| 154 | prn = hlp.at(0);
|
---|
| 155 | }
|
---|
| 156 | else {
|
---|
| 157 | if (glonass()) {
|
---|
[3669] | 158 | prn = QString("R%1").arg(hlp.at(0).toInt(), 2, 10, QChar('0'));
|
---|
[3659] | 159 | }
|
---|
| 160 | else {
|
---|
[3669] | 161 | prn = QString("G%1").arg(hlp.at(0).toInt(), 2, 10, QChar('0'));
|
---|
[3659] | 162 | }
|
---|
| 163 | }
|
---|
[3746] | 164 | t_eph* eph = 0;
|
---|
[3659] | 165 | QStringList lines; lines << line;
|
---|
| 166 | if (prn[0] == 'G') {
|
---|
| 167 | for (int ii = 1; ii < 8; ii++) {
|
---|
[3746] | 168 | lines << stream->readLine();
|
---|
[3659] | 169 | }
|
---|
| 170 | eph = new t_ephGPS(version(), lines);
|
---|
| 171 | }
|
---|
| 172 | else if (prn[0] == 'R') {
|
---|
| 173 | for (int ii = 1; ii < 4; ii++) {
|
---|
[3746] | 174 | lines << stream->readLine();
|
---|
[3659] | 175 | }
|
---|
| 176 | eph = new t_ephGlo(version(), lines);
|
---|
| 177 | }
|
---|
| 178 | else if (prn[0] == 'E') {
|
---|
| 179 | for (int ii = 1; ii < 8; ii++) {
|
---|
[3746] | 180 | lines << stream->readLine();
|
---|
[3659] | 181 | }
|
---|
| 182 | eph = new t_ephGal(version(), lines);
|
---|
| 183 | }
|
---|
[3662] | 184 | if (eph && eph->ok()) {
|
---|
[3758] | 185 | _ephs.push_back(eph);
|
---|
[3659] | 186 | }
|
---|
[3746] | 187 | else {
|
---|
| 188 | delete eph;
|
---|
| 189 | }
|
---|
[3659] | 190 | }
|
---|
[3746] | 191 | }
|
---|
[3659] | 192 |
|
---|
[3746] | 193 | // Read Next Ephemeris
|
---|
| 194 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3757] | 195 | t_eph* t_rnxNavFile::getNextEph(const bncTime& tt,
|
---|
| 196 | const QMap<QString, int>* corrIODs) {
|
---|
[3758] | 197 |
|
---|
[3764] | 198 | // Get Ephemeris according to IOD
|
---|
| 199 | // ------------------------------
|
---|
[3758] | 200 | if (corrIODs) {
|
---|
| 201 | QMapIterator<QString, int> itIOD(*corrIODs);
|
---|
| 202 | while (itIOD.hasNext()) {
|
---|
| 203 | itIOD.next();
|
---|
| 204 | QString prn = itIOD.key();
|
---|
| 205 | int iod = itIOD.value();
|
---|
| 206 | vector<t_eph*>::iterator it = _ephs.begin();
|
---|
| 207 | while (it != _ephs.end()) {
|
---|
| 208 | t_eph* eph = *it;
|
---|
| 209 | if (eph->prn() == prn && eph->IOD() == iod) {
|
---|
| 210 | it = _ephs.erase(it);
|
---|
| 211 | return eph;
|
---|
| 212 | }
|
---|
| 213 | ++it;
|
---|
| 214 | }
|
---|
[3748] | 215 | }
|
---|
[3746] | 216 | }
|
---|
[3758] | 217 |
|
---|
[3764] | 218 | // Get Ephemeris according to time
|
---|
| 219 | // -------------------------------
|
---|
| 220 | else {
|
---|
| 221 | vector<t_eph*>::iterator it = _ephs.begin();
|
---|
| 222 | while (it != _ephs.end()) {
|
---|
| 223 | t_eph* eph = *it;
|
---|
[3758] | 224 |
|
---|
[4018] | 225 | double dt = eph->TOC() - tt;
|
---|
[3764] | 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 | }
|
---|
[4004] | 237 |
|
---|
| 238 | //
|
---|
| 239 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 240 | void t_rnxNavFile::writeHeader() {
|
---|
[4010] | 241 |
|
---|
| 242 | bncApp* app = (bncApp*) qApp;
|
---|
| 243 |
|
---|
| 244 | if (version() < 3.0) {
|
---|
| 245 | *_stream << QString("%1 Navigation data")
|
---|
| 246 | .arg(_header._version, 9, 'f', 2)
|
---|
| 247 | .leftJustified(60)
|
---|
| 248 | << "RINEX VERSION / TYPE\n";
|
---|
| 249 | }
|
---|
| 250 | else {
|
---|
| 251 | *_stream << QString("%1 Navigation data Mixed")
|
---|
| 252 | .arg(_header._version, 9, 'f', 2)
|
---|
| 253 | .leftJustified(60)
|
---|
| 254 | << "RINEX VERSION / TYPE\n";
|
---|
| 255 | }
|
---|
| 256 |
|
---|
| 257 | *_stream << QString("%1%2%3")
|
---|
| 258 | .arg(app->pgmName(), -20)
|
---|
| 259 | .arg(app->userName(), -20)
|
---|
| 260 | .arg(currentDateAndTimeGPS().date().toString("dd-MMM-yyyy"), -20)
|
---|
| 261 | .leftJustified(60)
|
---|
| 262 | << "PGM / RUN BY / DATE\n";
|
---|
| 263 |
|
---|
| 264 | *_stream << QString()
|
---|
| 265 | .leftJustified(60)
|
---|
| 266 | << "END OF HEADER\n";
|
---|
[4004] | 267 | }
|
---|
| 268 |
|
---|
| 269 | //
|
---|
| 270 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 271 | void t_rnxNavFile::writeEph(const t_eph* eph) {
|
---|
[4013] | 272 | *_stream << eph->toString(version());
|
---|
[4004] | 273 | }
|
---|