source: ntrip/trunk/BNC/src/RTCM/GPSDecoder.cpp@ 5734

Last change on this file since 5734 was 5551, checked in by stoecker, 11 years ago

proper RINEX 2 output for Lx and Sx

File size: 6.9 KB
Line 
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: GPSDecoder
30 *
31 * Purpose: Decoder Base Class
32 *
33 * Author: L. Mervart
34 *
35 * Created: 16-Dec-2011
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <iomanip>
42#include <cmath>
43
44#include "GPSDecoder.h"
45#include "bncsettings.h"
46
47extern "C" {
48#include "rtcm3torinex.h"
49}
50
51using namespace std;
52
53// Constructor
54//////////////////////////////////////////////////////////////////////////////
55GPSDecoder::GPSDecoder() {
56 _rnx = 0;
57}
58
59// Initialize RINEX Writer
60//////////////////////////////////////////////////////////////////////////////
61void GPSDecoder::initRinex(const QByteArray& staID, const QUrl& mountPoint,
62 const QByteArray& latitude,
63 const QByteArray& longitude, const QByteArray& nmea,
64 const QByteArray& ntripVersion) {
65 if (_rnx) {
66 return;
67 }
68 bncSettings settings;
69 if ( !settings.value("rnxPath").toString().isEmpty() ) {
70 _rnx = new bncRinex(staID, mountPoint, latitude, longitude,
71 nmea, ntripVersion);
72 }
73}
74
75// Write RINEX Epoch
76//////////////////////////////////////////////////////////////////////////////
77void GPSDecoder::dumpRinexEpoch(const t_obs& obs, const QByteArray& format) {
78 if (_rnx) {
79 long iSec = long(floor(obs.GPSWeeks+0.5));
80 long obsTime = obs.GPSWeek * 7*24*3600 + iSec;
81 if (_rnx->samplingRate() == 0 || iSec % _rnx->samplingRate() == 0) {
82 _rnx->deepCopy(obs);
83 }
84 _rnx->dumpEpoch(format, obsTime);
85 }
86}
87
88// Set RINEX Reconnect Flag
89//////////////////////////////////////////////////////////////////////////////
90void GPSDecoder::setRinexReconnectFlag(bool flag) {
91 if (_rnx) {
92 _rnx->setReconnectFlag(flag);
93 }
94}
95
96//
97//////////////////////////////////////////////////////////////////////////////
98void t_obs::setMeasdata(QString rnxStr, float rnxVers, double value) {
99 int ie = iEntry(rnxStr, rnxVers);
100
101 if (ie != -1) {
102 _codetype[ie] = rnxStr.mid(1);
103 _measdata[ie] = value;
104 }
105}
106
107//
108//////////////////////////////////////////////////////////////////////////////
109double t_obs::measdata(QString rnxStr, float rnxVers) const {
110 int ie = iEntry(rnxStr, rnxVers);
111
112 if (ie != -1) {
113 return _measdata[ie];
114 }
115
116 return 0.0;
117}
118
119//
120//////////////////////////////////////////////////////////////////////////////
121QString t_obs::rnxStr(int iEntry) const {
122 QString str(1,' ');
123 switch(iEntry & 3) {
124 case GNSSENTRY_CODE: str[0] = 'C'; break;
125 case GNSSENTRY_PHASE: str[0] = 'L'; break;
126 case GNSSENTRY_DOPPLER: str[0] = 'D'; break;
127 case GNSSENTRY_SNR: str[0] = 'S'; break;
128 }
129 str += _codetype[iEntry];
130 return str.trimmed();
131}
132
133//
134//////////////////////////////////////////////////////////////////////////////
135int t_obs::iEntry(QString rnxStr, float rnxVers, bool cmode) const {
136
137 int res = 0;
138 bool tryagain = false;
139 QString rnxStrOrig = rnxStr;
140
141 if (rnxVers < 3.0) {
142 if (rnxStr == "C1") rnxStr = "C1C";
143 else if (rnxStr == "P1") rnxStr = "C1P";
144 else if (rnxStr == "C2") rnxStr = "C2C";
145 else if (rnxStr == "P2") rnxStr = "C2P";
146 if(cmode)
147 {
148 if (rnxStr == "S1") rnxStr = "S1C";
149 else if (rnxStr == "L1") rnxStr = "L1C";
150 else if (rnxStr == "S2") rnxStr = "S2C";
151 else if (rnxStr == "L2") rnxStr = "L2C";
152 }
153 else
154 {
155 if (rnxStr == "S1") {rnxStr = "S1P"; tryagain = true; }
156 else if (rnxStr == "L1") {rnxStr = "L1P"; tryagain = true; }
157 else if (rnxStr == "S2") {rnxStr = "S2P"; tryagain = true; }
158 else if (rnxStr == "L2") {rnxStr = "L2P"; tryagain = true; }
159 }
160 }
161
162 // Observation Type (Code, Phase, Doppler, SNR)
163 // --------------------------------------------
164 if (rnxStr[0] == 'C') {
165 res += GNSSENTRY_CODE;
166 }
167 else if (rnxStr[0] == 'L') {
168 res += GNSSENTRY_PHASE;
169 }
170 else if (rnxStr[0] == 'D') {
171 res += GNSSENTRY_DOPPLER;
172 }
173 else if (rnxStr[0] == 'S') {
174 res += GNSSENTRY_SNR;
175 }
176 else {
177 return -1;
178 }
179
180 // Frequency
181 // ---------
182 if (rnxStr[1] == '1') {
183 if (rnxStr.length() < 3) {
184 res += GNSSENTRY_TYPEC1;
185 }
186 else if (QString("ABCIQ").indexOf(rnxStr[2]) != -1) {
187 res += GNSSENTRY_TYPEC1;
188 }
189 else if (QString("SL").indexOf(rnxStr[2]) != -1) {
190 res += GNSSENTRY_TYPEC1N;
191 }
192 else if (QString("PWY").indexOf(rnxStr[2]) != -1) {
193 res += GNSSENTRY_TYPEP1;
194 }
195 else if (rnxStr[2] == 'Z') {
196 res += GNSSENTRY_TYPECSAIF;
197 }
198 else if (rnxStr[2] == 'X') {
199 if (satSys == 'C' || satSys == 'E') {
200 res += GNSSENTRY_TYPEC1;
201 }
202 else {
203 res += GNSSENTRY_TYPEC1N;
204 }
205 }
206 else {
207 return -1;
208 }
209 }
210 else if (rnxStr[1] == '2') {
211 if (rnxStr.length() < 3) {
212 res += GNSSENTRY_TYPEC2;
213 }
214 else if (QString("PWY").indexOf(rnxStr[2]) != -1) {
215 res += GNSSENTRY_TYPEP2;
216 }
217 else if (QString("CSLX").indexOf(rnxStr[2]) != -1) {
218 res += GNSSENTRY_TYPEC2;
219 }
220 else if (rnxStr[2] == 'I') {
221 if (satSys == 'C') {
222 res += GNSSENTRY_TYPEC1; // Compass: RINEX 3.01 "2I" corresponds to "1I" RINEX 3.02
223 }
224 else {
225 res += GNSSENTRY_TYPEC2;
226 }
227 }
228 else if (rnxStr[2] == 'Q') {
229 res += GNSSENTRY_TYPEC2;
230 }
231 else {
232 return -1;
233 }
234 }
235 else if (rnxStr[1] == '5') {
236 res += GNSSENTRY_TYPEC5;
237 }
238 else if (rnxStr[1] == '6') {
239 res += GNSSENTRY_TYPEC6;
240 }
241 else if (rnxStr[1] == '7') {
242 res += GNSSENTRY_TYPEC5B;
243 }
244 else if (rnxStr[1] == '8') {
245 res += GNSSENTRY_TYPEC5AB;
246 }
247 else {
248 return -1;
249 }
250
251 /* Note: We prefer P over C for Lx or Sx (i.e. we first try for P values) */
252 if(_codetype[res].isEmpty() && tryagain)
253 res = iEntry(rnxStrOrig, rnxVers, true);
254
255 return res;
256}
Note: See TracBrowser for help on using the repository browser.