[866] | 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: RTCM3coDecoder
|
---|
| 30 | *
|
---|
| 31 | * Purpose: RTCM3 Clock Orbit Decoder
|
---|
| 32 | *
|
---|
| 33 | * Author: L. Mervart
|
---|
| 34 | *
|
---|
| 35 | * Created: 05-May-2008
|
---|
| 36 | *
|
---|
| 37 | * Changes:
|
---|
| 38 | *
|
---|
| 39 | * -----------------------------------------------------------------------*/
|
---|
| 40 |
|
---|
[868] | 41 | #include <stdio.h>
|
---|
[920] | 42 | #include <math.h>
|
---|
[868] | 43 |
|
---|
[866] | 44 | #include "RTCM3coDecoder.h"
|
---|
[918] | 45 | #include "bncutils.h"
|
---|
[934] | 46 | #include "bncrinex.h"
|
---|
[936] | 47 | #include "bncapp.h"
|
---|
[866] | 48 |
|
---|
| 49 | using namespace std;
|
---|
| 50 |
|
---|
| 51 | // Constructor
|
---|
| 52 | ////////////////////////////////////////////////////////////////////////////
|
---|
[934] | 53 | RTCM3coDecoder::RTCM3coDecoder(const QString& fileName) {
|
---|
| 54 |
|
---|
| 55 | // File Output
|
---|
| 56 | // -----------
|
---|
| 57 | QSettings settings;
|
---|
| 58 | QString path = settings.value("corrPath").toString();
|
---|
| 59 | if (!path.isEmpty()) {
|
---|
| 60 | expandEnvVar(path);
|
---|
| 61 | if ( path.length() > 0 && path[path.length()-1] != QDir::separator() ) {
|
---|
| 62 | path += QDir::separator();
|
---|
| 63 | }
|
---|
| 64 | _fileNameSkl = path + fileName;
|
---|
| 65 | }
|
---|
| 66 | _out = 0;
|
---|
| 67 |
|
---|
[936] | 68 | connect(this, SIGNAL(newCorrLine(QString)),
|
---|
| 69 | (bncApp*) qApp, SLOT(slotNewCorrLine(QString)));
|
---|
[866] | 70 | }
|
---|
| 71 |
|
---|
| 72 | // Destructor
|
---|
| 73 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 74 | RTCM3coDecoder::~RTCM3coDecoder() {
|
---|
[935] | 75 | delete _out;
|
---|
[866] | 76 | }
|
---|
| 77 |
|
---|
[934] | 78 | // Reopen Output File
|
---|
| 79 | ////////////////////////////////////////////////////////////////////////
|
---|
| 80 | void RTCM3coDecoder::reopen() {
|
---|
| 81 |
|
---|
| 82 | if (!_fileNameSkl.isEmpty()) {
|
---|
| 83 |
|
---|
| 84 | QSettings settings;
|
---|
| 85 |
|
---|
| 86 | QDateTime datTim = QDateTime::currentDateTime().toUTC();
|
---|
| 87 |
|
---|
| 88 | QString hlpStr = bncRinex::nextEpochStr(datTim,
|
---|
| 89 | settings.value("corrIntr").toString());
|
---|
| 90 |
|
---|
| 91 | QString fileName = _fileNameSkl
|
---|
| 92 | + QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0'))
|
---|
[938] | 93 | + hlpStr + datTim.toString(".yyC");
|
---|
[934] | 94 |
|
---|
| 95 | if (_fileName == fileName) {
|
---|
| 96 | return;
|
---|
| 97 | }
|
---|
| 98 | else {
|
---|
| 99 | _fileName = fileName;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | delete _out;
|
---|
| 103 | _out = new ofstream( _fileName.toAscii().data() );
|
---|
| 104 | }
|
---|
| 105 | }
|
---|
| 106 |
|
---|
[866] | 107 | //
|
---|
| 108 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 109 | t_irc RTCM3coDecoder::Decode(char* buffer, int bufLen) {
|
---|
[868] | 110 |
|
---|
[869] | 111 | _buffer.append(buffer, bufLen);
|
---|
[868] | 112 |
|
---|
[869] | 113 | while (true) {
|
---|
[908] | 114 |
|
---|
| 115 | memset(&_co, 0, sizeof(_co));
|
---|
[906] | 116 |
|
---|
[879] | 117 | int bytesused = 0;
|
---|
| 118 | GCOB_RETURN irc = GetClockOrbitBias(&_co, &_bias, _buffer.data(),
|
---|
| 119 | _buffer.size(), &bytesused);
|
---|
| 120 |
|
---|
[906] | 121 | // Not enough Data
|
---|
| 122 | // ---------------
|
---|
[879] | 123 | if (irc == GCOBR_SHORTBUFFER ||
|
---|
[906] | 124 | irc == GCOBR_MESSAGEEXCEEDSBUFFER) {
|
---|
[869] | 125 | return failure;
|
---|
| 126 | }
|
---|
[879] | 127 |
|
---|
[906] | 128 | // Message correctly decoded
|
---|
| 129 | // -------------------------
|
---|
[908] | 130 | else if ( (irc == GCOBR_OK || irc == GCOBR_MESSAGEFOLLOWS) &&
|
---|
| 131 | bytesused > 0) {
|
---|
[881] | 132 | reopen();
|
---|
[918] | 133 |
|
---|
| 134 | int GPSweek;
|
---|
| 135 | double GPSweeks;
|
---|
| 136 | currentGPSWeeks(GPSweek, GPSweeks);
|
---|
[919] | 137 |
|
---|
| 138 | if (_co.NumberOfGPSSat > 0) {
|
---|
| 139 | if (GPSweeks > _co.GPSEpochTime + 86400.0) {
|
---|
| 140 | GPSweek += 1;
|
---|
| 141 | }
|
---|
| 142 | else if (GPSweeks < _co.GPSEpochTime - 86400.0) {
|
---|
| 143 | GPSweek -= 1;
|
---|
| 144 | }
|
---|
| 145 | GPSweeks = _co.GPSEpochTime;
|
---|
[918] | 146 | }
|
---|
[919] | 147 | else {
|
---|
| 148 | double GPSdaysec = fmod(GPSweeks, 86400.0);
|
---|
| 149 | int weekDay = int((GPSweeks - GPSdaysec) / 86400.0);
|
---|
| 150 | if (GPSdaysec > _co.GLONASSEpochTime + 3600.0) {
|
---|
| 151 | weekDay += 1;
|
---|
| 152 | if (weekDay > 6) {
|
---|
| 153 | weekDay = 0;
|
---|
| 154 | GPSweek += 1;
|
---|
| 155 | }
|
---|
| 156 | }
|
---|
| 157 | else if (GPSdaysec < _co.GLONASSEpochTime - 3600.0) {
|
---|
| 158 | weekDay -= 1;
|
---|
| 159 | if (weekDay < 0) {
|
---|
| 160 | weekDay = 6;
|
---|
| 161 | GPSweek -= 1;
|
---|
| 162 | }
|
---|
| 163 | }
|
---|
| 164 | GPSweeks = weekDay * 86400.0 + _co.GLONASSEpochTime;
|
---|
[918] | 165 | }
|
---|
| 166 |
|
---|
[869] | 167 | for(int ii = 0; ii < _co.NumberOfGPSSat; ++ii) {
|
---|
[875] | 168 | QString line;
|
---|
[919] | 169 | line.sprintf("%d %.1f G%2.2d %3d %8.3f %8.3f %8.3f %8.3f\n",
|
---|
[918] | 170 | GPSweek, GPSweeks, _co.Sat[ii].ID, _co.Sat[ii].IOD,
|
---|
| 171 | _co.Sat[ii].Clock.DeltaA0,
|
---|
| 172 | _co.Sat[ii].Orbit.DeltaRadial,
|
---|
| 173 | _co.Sat[ii].Orbit.DeltaAlongTrack,
|
---|
[869] | 174 | _co.Sat[ii].Orbit.DeltaCrossTrack);
|
---|
[934] | 175 | printLine(line);
|
---|
[869] | 176 | }
|
---|
[903] | 177 | for(int ii = CLOCKORBIT_NUMGPS;
|
---|
| 178 | ii < CLOCKORBIT_NUMGPS + _co.NumberOfGLONASSSat; ++ii) {
|
---|
| 179 | QString line;
|
---|
[919] | 180 | line.sprintf("%d %.1f R%2.2d %3d %8.3f %8.3f %8.3f %8.3f\n",
|
---|
[918] | 181 | GPSweek, GPSweeks, _co.Sat[ii].ID, _co.Sat[ii].IOD,
|
---|
| 182 | _co.Sat[ii].Clock.DeltaA0,
|
---|
| 183 | _co.Sat[ii].Orbit.DeltaRadial,
|
---|
| 184 | _co.Sat[ii].Orbit.DeltaAlongTrack,
|
---|
[903] | 185 | _co.Sat[ii].Orbit.DeltaCrossTrack);
|
---|
[934] | 186 | printLine(line);
|
---|
[903] | 187 | }
|
---|
[879] | 188 | _buffer = _buffer.substr(bytesused);
|
---|
[869] | 189 | return success;
|
---|
| 190 | }
|
---|
[879] | 191 |
|
---|
[906] | 192 | // All other Cases
|
---|
| 193 | // ---------------
|
---|
[869] | 194 | else {
|
---|
[879] | 195 | _buffer = _buffer.substr(1);
|
---|
[869] | 196 | }
|
---|
[868] | 197 | }
|
---|
[866] | 198 | }
|
---|
[934] | 199 |
|
---|
| 200 | //
|
---|
| 201 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 202 | void RTCM3coDecoder::printLine(const QString& line) {
|
---|
| 203 | if (_out) {
|
---|
| 204 | *_out << line.toAscii().data();
|
---|
| 205 | _out->flush();
|
---|
| 206 | }
|
---|
| 207 |
|
---|
[936] | 208 | emit newCorrLine(line);
|
---|
[934] | 209 | }
|
---|