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