source: ntrip/trunk/BNC/src/GPSDecoder.cpp@ 5807

Last change on this file since 5807 was 5738, checked in by mervart, 10 years ago
File size: 6.9 KB
RevLine 
[3528]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
[4439]47extern "C" {
[4440]48#include "rtcm3torinex.h"
[4439]49}
[4422]50
[3528]51using namespace std;
52
53// Constructor
54//////////////////////////////////////////////////////////////////////////////
55GPSDecoder::GPSDecoder() {
[3529]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 }
[3528]68 bncSettings settings;
[3529]69 if ( !settings.value("rnxPath").toString().isEmpty() ) {
70 _rnx = new bncRinex(staID, mountPoint, latitude, longitude,
71 nmea, ntripVersion);
[3528]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}
[4392]95
96//
97//////////////////////////////////////////////////////////////////////////////
[5367]98void t_obs::setMeasdata(QString rnxStr, float rnxVers, double value) {
[5551]99 int ie = iEntry(rnxStr, rnxVers);
[5367]100
[5368]101 if (ie != -1) {
102 _codetype[ie] = rnxStr.mid(1);
103 _measdata[ie] = value;
[5367]104 }
[4393]105}
[4392]106
107//
108//////////////////////////////////////////////////////////////////////////////
[5550]109double t_obs::measdata(QString rnxStr, float rnxVers) const {
[5551]110 int ie = iEntry(rnxStr, rnxVers);
[5549]111
112 if (ie != -1) {
113 return _measdata[ie];
[4403]114 }
[5549]115
[5529]116 return 0.0;
[4403]117}
[4392]118
[4403]119//
120//////////////////////////////////////////////////////////////////////////////
[5370]121QString t_obs::rnxStr(int iEntry) const {
[5380]122 QString str(1,' ');
[5370]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//////////////////////////////////////////////////////////////////////////////
[5551]135int t_obs::iEntry(QString rnxStr, float rnxVers, bool cmode) const {
[5370]136
[5368]137 int res = 0;
[5551]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 }
[5370]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 {
[5368]177 return -1;
178 }
[5370]179
180 // Frequency
181 // ---------
182 if (rnxStr[1] == '1') {
183 if (rnxStr.length() < 3) {
184 res += GNSSENTRY_TYPEC1;
[5355]185 }
[5374]186 else if (QString("ABCIQ").indexOf(rnxStr[2]) != -1) {
[5370]187 res += GNSSENTRY_TYPEC1;
188 }
[5374]189 else if (QString("SL").indexOf(rnxStr[2]) != -1) {
190 res += GNSSENTRY_TYPEC1N;
191 }
[5370]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 }
[5374]198 else if (rnxStr[2] == 'X') {
[5375]199 if (satSys == 'C' || satSys == 'E') {
[5374]200 res += GNSSENTRY_TYPEC1;
201 }
202 else {
203 res += GNSSENTRY_TYPEC1N;
204 }
205 }
[5370]206 else {
207 return -1;
208 }
209 }
210 else if (rnxStr[1] == '2') {
211 if (rnxStr.length() < 3) {
[5549]212 res += GNSSENTRY_TYPEC2;
[5370]213 }
[5371]214 else if (QString("PWY").indexOf(rnxStr[2]) != -1) {
[5370]215 res += GNSSENTRY_TYPEP2;
216 }
[5371]217 else if (QString("CSLX").indexOf(rnxStr[2]) != -1) {
[5370]218 res += GNSSENTRY_TYPEC2;
219 }
[5375]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') {
[5374]229 res += GNSSENTRY_TYPEC2;
[5368]230 }
[5370]231 else {
232 return -1;
233 }
234 }
235 else if (rnxStr[1] == '5') {
[5368]236 res += GNSSENTRY_TYPEC5;
[5370]237 }
238 else if (rnxStr[1] == '6') {
[5368]239 res += GNSSENTRY_TYPEC6;
[5370]240 }
241 else if (rnxStr[1] == '7') {
[5368]242 res += GNSSENTRY_TYPEC5B;
[5370]243 }
244 else if (rnxStr[1] == '8') {
[5368]245 res += GNSSENTRY_TYPEC5AB;
[5355]246 }
[5370]247 else {
248 return -1;
249 }
250
[5551]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
[5368]255 return res;
[4392]256}
Note: See TracBrowser for help on using the repository browser.