[297] | 1 | // Part of BNC, a utility for retrieving decoding and
|
---|
[464] | 2 | // converting GNSS data streams from NTRIP broadcasters.
|
---|
[297] | 3 | //
|
---|
[464] | 4 | // Copyright (C) 2007
|
---|
[297] | 5 | // German Federal Agency for Cartography and Geodesy (BKG)
|
---|
| 6 | // http://www.bkg.bund.de
|
---|
[464] | 7 | // Czech Technical University Prague, Department of Geodesy
|
---|
[297] | 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.
|
---|
[296] | 24 |
|
---|
| 25 | /* -------------------------------------------------------------------------
|
---|
| 26 | * BKG NTRIP Client
|
---|
| 27 | * -------------------------------------------------------------------------
|
---|
| 28 | *
|
---|
| 29 | * Class: RTCM3Decoder
|
---|
| 30 | *
|
---|
| 31 | * Purpose: RTCM3 Decoder
|
---|
| 32 | *
|
---|
| 33 | * Author: L. Mervart
|
---|
| 34 | *
|
---|
| 35 | * Created: 24-Aug-2006
|
---|
| 36 | *
|
---|
| 37 | * Changes:
|
---|
| 38 | *
|
---|
| 39 | * -----------------------------------------------------------------------*/
|
---|
| 40 |
|
---|
| 41 | #include <iostream>
|
---|
| 42 | #include <math.h>
|
---|
[585] | 43 | #include <string.h>
|
---|
[296] | 44 |
|
---|
| 45 | #include "RTCM3Decoder.h"
|
---|
| 46 | #include "bncconst.h"
|
---|
[511] | 47 | #include "bncapp.h"
|
---|
[296] | 48 |
|
---|
| 49 | using namespace std;
|
---|
| 50 |
|
---|
| 51 | #ifndef isinf
|
---|
| 52 | # define isinf(x) 0
|
---|
| 53 | #endif
|
---|
| 54 |
|
---|
[511] | 55 | //
|
---|
| 56 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 57 | ephSender::ephSender() {
|
---|
| 58 | connect(this, SIGNAL(newGPSEph(gpsephemeris*)),
|
---|
| 59 | (bncApp*) qApp, SLOT(slotNewGPSEph(gpsephemeris*)));
|
---|
| 60 | connect(this, SIGNAL(newGlonassEph(glonassephemeris*)),
|
---|
| 61 | (bncApp*) qApp, SLOT(slotNewGlonassEph(glonassephemeris*)));
|
---|
| 62 | }
|
---|
| 63 |
|
---|
[320] | 64 | // Error Handling
|
---|
| 65 | ////////////////////////////////////////////////////////////////////////////
|
---|
[504] | 66 | void RTCM3Error(const char*, ...) {
|
---|
[505] | 67 | }
|
---|
[320] | 68 |
|
---|
[296] | 69 | // Constructor
|
---|
| 70 | ////////////////////////////////////////////////////////////////////////////
|
---|
[511] | 71 | RTCM3Decoder::RTCM3Decoder() : GPSDecoder() {
|
---|
[505] | 72 |
|
---|
| 73 | const int LEAPSECONDS = 14; /* only needed for approx. time */
|
---|
| 74 |
|
---|
[296] | 75 | time_t tim;
|
---|
| 76 | tim = time(0) - ((10*365+2+5)*24*60*60 + LEAPSECONDS);
|
---|
[505] | 77 |
|
---|
| 78 | memset(&_Parser, 0, sizeof(_Parser));
|
---|
[296] | 79 | _Parser.GPSWeek = tim/(7*24*60*60);
|
---|
| 80 | _Parser.GPSTOW = tim%(7*24*60*60);
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | // Destructor
|
---|
| 84 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 85 | RTCM3Decoder::~RTCM3Decoder() {
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | //
|
---|
| 89 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 90 | void RTCM3Decoder::Decode(char* buffer, int bufLen) {
|
---|
[508] | 91 |
|
---|
[296] | 92 | for (int ii = 0; ii < bufLen; ii++) {
|
---|
[505] | 93 |
|
---|
[296] | 94 | _Parser.Message[_Parser.MessageSize++] = buffer[ii];
|
---|
| 95 | if (_Parser.MessageSize >= _Parser.NeedBytes) {
|
---|
| 96 |
|
---|
| 97 | while(int rr = RTCM3Parser(&_Parser)) {
|
---|
| 98 |
|
---|
[511] | 99 | // GNSS Observations
|
---|
| 100 | // -----------------
|
---|
| 101 | if (rr == 1 || rr == 2) {
|
---|
[296] | 102 |
|
---|
[511] | 103 | if (!_Parser.init) {
|
---|
| 104 | HandleHeader(&_Parser);
|
---|
| 105 | _Parser.init = 1;
|
---|
| 106 | }
|
---|
| 107 |
|
---|
| 108 | if (rr == 2) {
|
---|
| 109 | std::cerr << "No valid RINEX! All values are modulo 299792.458!\n";
|
---|
| 110 | }
|
---|
| 111 |
|
---|
| 112 | for (int ii = 0; ii < _Parser.Data.numsats; ii++) {
|
---|
| 113 | Observation* obs = new Observation();
|
---|
[554] | 114 | if (_Parser.Data.satellites[ii] <= PRN_GPS_END) {
|
---|
[511] | 115 | obs->satSys = 'G';
|
---|
| 116 | obs->satNum = _Parser.Data.satellites[ii];
|
---|
| 117 | }
|
---|
[554] | 118 | else if (_Parser.Data.satellites[ii] <= PRN_GLONASS_END) {
|
---|
[511] | 119 | obs->satSys = 'R';
|
---|
| 120 | obs->satNum = _Parser.Data.satellites[ii] - PRN_GLONASS_START + 1;
|
---|
| 121 | }
|
---|
[554] | 122 | else {
|
---|
| 123 | obs->satSys = 'S';
|
---|
| 124 | obs->satNum = _Parser.Data.satellites[ii] - PRN_WAAS_START + 20;
|
---|
| 125 | }
|
---|
[511] | 126 | obs->GPSWeek = _Parser.Data.week;
|
---|
| 127 | obs->GPSWeeks = _Parser.Data.timeofweek / 1000.0;
|
---|
| 128 |
|
---|
| 129 | for (int jj = 0; jj < _Parser.numdatatypesGPS; jj++) {
|
---|
| 130 | int v = 0;
|
---|
| 131 | int df = _Parser.dataflag[jj];
|
---|
| 132 | int pos = _Parser.datapos[jj];
|
---|
[366] | 133 | if ( (_Parser.Data.dataflags[ii] & df)
|
---|
| 134 | && !isnan(_Parser.Data.measdata[ii][pos])
|
---|
| 135 | && !isinf(_Parser.Data.measdata[ii][pos])) {
|
---|
[511] | 136 | v = 1;
|
---|
[366] | 137 | }
|
---|
[511] | 138 | else {
|
---|
| 139 | df = _Parser.dataflagGPS[jj];
|
---|
| 140 | pos = _Parser.dataposGPS[jj];
|
---|
| 141 | if ( (_Parser.Data.dataflags[ii] & df)
|
---|
| 142 | && !isnan(_Parser.Data.measdata[ii][pos])
|
---|
| 143 | && !isinf(_Parser.Data.measdata[ii][pos])) {
|
---|
| 144 | v = 1;
|
---|
| 145 | }
|
---|
| 146 | }
|
---|
| 147 | if(!v)
|
---|
| 148 | { continue; }
|
---|
| 149 | else
|
---|
| 150 | {
|
---|
| 151 | if (_Parser.dataflag[jj] & GNSSDF_C1DATA) {
|
---|
| 152 | obs->C1 = _Parser.Data.measdata[ii][_Parser.datapos[jj]];
|
---|
| 153 | }
|
---|
| 154 | else if (_Parser.dataflag[jj] & GNSSDF_C2DATA) {
|
---|
| 155 | obs->C2 = _Parser.Data.measdata[ii][_Parser.datapos[jj]];
|
---|
| 156 | }
|
---|
| 157 | else if (_Parser.dataflag[jj] & GNSSDF_P1DATA) {
|
---|
| 158 | obs->P1 = _Parser.Data.measdata[ii][_Parser.datapos[jj]];
|
---|
| 159 | }
|
---|
| 160 | else if (_Parser.dataflag[jj] & GNSSDF_P2DATA) {
|
---|
| 161 | obs->P2 = _Parser.Data.measdata[ii][_Parser.datapos[jj]];
|
---|
| 162 | }
|
---|
| 163 | else if (df & (GNSSDF_L1CDATA|GNSSDF_L1PDATA)) {
|
---|
| 164 | obs->L1 = _Parser.Data.measdata[ii][pos];
|
---|
| 165 | obs->SNR1 = _Parser.Data.snrL1[ii];
|
---|
| 166 | }
|
---|
| 167 | else if (df & (GNSSDF_L2CDATA|GNSSDF_L2PDATA)) {
|
---|
| 168 | obs->L2 = _Parser.Data.measdata[ii][pos];
|
---|
| 169 | obs->SNR2 = _Parser.Data.snrL2[ii];
|
---|
| 170 | }
|
---|
| 171 | else if (df & (GNSSDF_S1CDATA|GNSSDF_S1PDATA)) {
|
---|
| 172 | obs->S1 = _Parser.Data.measdata[ii][pos];
|
---|
| 173 | }
|
---|
| 174 | else if (df & (GNSSDF_S2CDATA|GNSSDF_S2PDATA)) {
|
---|
| 175 | obs->S2 = _Parser.Data.measdata[ii][pos];
|
---|
| 176 | }
|
---|
[366] | 177 | }
|
---|
[296] | 178 | }
|
---|
[511] | 179 | _obsList.push_back(obs);
|
---|
[296] | 180 | }
|
---|
| 181 | }
|
---|
[511] | 182 |
|
---|
| 183 | // GPS Ephemeris
|
---|
| 184 | // -------------
|
---|
| 185 | else if (rr == 1019) {
|
---|
| 186 | gpsephemeris* ep = new gpsephemeris(_Parser.ephemerisGPS);
|
---|
| 187 | emit _ephSender.newGPSEph(ep);
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | // GLONASS Ephemeris
|
---|
| 191 | // -----------------
|
---|
| 192 | else if (rr == 1020) {
|
---|
| 193 | glonassephemeris* ep = new glonassephemeris(_Parser.ephemerisGLONASS);
|
---|
| 194 | emit _ephSender.newGlonassEph(ep);
|
---|
| 195 | }
|
---|
[296] | 196 | }
|
---|
| 197 | }
|
---|
| 198 | }
|
---|
| 199 | }
|
---|