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

Last change on this file since 5550 was 5550, checked in by mervart, 10 years ago
File size: 6.3 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
100 if (rnxVers < 3.0) {
101 if (rnxStr == "C1") rnxStr = "C1C";
102 else if (rnxStr == "P1") rnxStr = "C1P";
103 else if (rnxStr == "C2") rnxStr = "C2C";
104 else if (rnxStr == "P2") rnxStr = "C2P";
105 }
106
107 int ie = iEntry(rnxStr);
108
109 if (ie != -1) {
110 _codetype[ie] = rnxStr.mid(1);
111 _measdata[ie] = value;
112 }
113}
114
115//
116//////////////////////////////////////////////////////////////////////////////
117double t_obs::measdata(QString rnxStr, float rnxVers) const {
118
119 if (rnxVers < 3.0) {
120 if (rnxStr == "C1") rnxStr = "C1C";
121 else if (rnxStr == "P1") rnxStr = "C1P";
122 else if (rnxStr == "C2") rnxStr = "C2C";
123 else if (rnxStr == "P2") rnxStr = "C2P";
124 }
125
126 int ie = iEntry(rnxStr);
127
128 if (ie != -1) {
129 return _measdata[ie];
130 }
131
132 return 0.0;
133}
134
135//
136//////////////////////////////////////////////////////////////////////////////
137QString t_obs::rnxStr(int iEntry) const {
138 QString str(1,' ');
139 switch(iEntry & 3) {
140 case GNSSENTRY_CODE: str[0] = 'C'; break;
141 case GNSSENTRY_PHASE: str[0] = 'L'; break;
142 case GNSSENTRY_DOPPLER: str[0] = 'D'; break;
143 case GNSSENTRY_SNR: str[0] = 'S'; break;
144 }
145 str += _codetype[iEntry];
146 return str.trimmed();
147}
148
149//
150//////////////////////////////////////////////////////////////////////////////
151int t_obs::iEntry(QString rnxStr) const {
152
153 int res = 0;
154
155 // Observation Type (Code, Phase, Doppler, SNR)
156 // --------------------------------------------
157 if (rnxStr[0] == 'C') {
158 res += GNSSENTRY_CODE;
159 }
160 else if (rnxStr[0] == 'L') {
161 res += GNSSENTRY_PHASE;
162 }
163 else if (rnxStr[0] == 'D') {
164 res += GNSSENTRY_DOPPLER;
165 }
166 else if (rnxStr[0] == 'S') {
167 res += GNSSENTRY_SNR;
168 }
169 else {
170 return -1;
171 }
172
173 // Frequency
174 // ---------
175 if (rnxStr[1] == '1') {
176 if (rnxStr.length() < 3) {
177 res += GNSSENTRY_TYPEC1;
178 }
179 else if (QString("ABCIQ").indexOf(rnxStr[2]) != -1) {
180 res += GNSSENTRY_TYPEC1;
181 }
182 else if (QString("SL").indexOf(rnxStr[2]) != -1) {
183 res += GNSSENTRY_TYPEC1N;
184 }
185 else if (QString("PWY").indexOf(rnxStr[2]) != -1) {
186 res += GNSSENTRY_TYPEP1;
187 }
188 else if (rnxStr[2] == 'Z') {
189 res += GNSSENTRY_TYPECSAIF;
190 }
191 else if (rnxStr[2] == 'X') {
192 if (satSys == 'C' || satSys == 'E') {
193 res += GNSSENTRY_TYPEC1;
194 }
195 else {
196 res += GNSSENTRY_TYPEC1N;
197 }
198 }
199 else {
200 return -1;
201 }
202 }
203 else if (rnxStr[1] == '2') {
204 if (rnxStr.length() < 3) {
205 res += GNSSENTRY_TYPEC2;
206 }
207 else if (QString("PWY").indexOf(rnxStr[2]) != -1) {
208 res += GNSSENTRY_TYPEP2;
209 }
210 else if (QString("CSLX").indexOf(rnxStr[2]) != -1) {
211 res += GNSSENTRY_TYPEC2;
212 }
213 else if (rnxStr[2] == 'I') {
214 if (satSys == 'C') {
215 res += GNSSENTRY_TYPEC1; // Compass: RINEX 3.01 "2I" corresponds to "1I" RINEX 3.02
216 }
217 else {
218 res += GNSSENTRY_TYPEC2;
219 }
220 }
221 else if (rnxStr[2] == 'Q') {
222 res += GNSSENTRY_TYPEC2;
223 }
224 else {
225 return -1;
226 }
227 }
228 else if (rnxStr[1] == '5') {
229 res += GNSSENTRY_TYPEC5;
230 }
231 else if (rnxStr[1] == '6') {
232 res += GNSSENTRY_TYPEC6;
233 }
234 else if (rnxStr[1] == '7') {
235 res += GNSSENTRY_TYPEC5B;
236 }
237 else if (rnxStr[1] == '8') {
238 res += GNSSENTRY_TYPEC5AB;
239 }
240 else {
241 return -1;
242 }
243
244 return res;
245}
Note: See TracBrowser for help on using the repository browser.