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