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