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