source: ntrip/trunk/BNC/src/bncephuser.cpp@ 4984

Last change on this file since 4984 was 4904, checked in by mervart, 12 years ago
File size: 9.7 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: bncEphUser
30 *
31 * Purpose: Base for Classes that use Ephemerides
32 *
33 * Author: L. Mervart
34 *
35 * Created: 27-Jan-2011
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <iostream>
42
43#include "bncephuser.h"
44#include "bncapp.h"
45
46using namespace std;
47
48// Constructor
49////////////////////////////////////////////////////////////////////////////
50bncEphUser::bncEphUser(bool connectSlots) {
51
52 if (connectSlots) {
53 connect(((bncApp*)qApp), SIGNAL(newEphGPS(gpsephemeris)),
54 this, SLOT(slotNewEphGPS(gpsephemeris)), Qt::DirectConnection);
55
56 connect(((bncApp*)qApp), SIGNAL(newEphGlonass(glonassephemeris)),
57 this, SLOT(slotNewEphGlonass(glonassephemeris)), Qt::DirectConnection);
58
59 connect(((bncApp*)qApp), SIGNAL(newEphGalileo(galileoephemeris)),
60 this, SLOT(slotNewEphGalileo(galileoephemeris)), Qt::DirectConnection);
61 }
62}
63
64// Destructor
65////////////////////////////////////////////////////////////////////////////
66bncEphUser::~bncEphUser() {
67 QMapIterator<QString, t_ephPair*> it(_eph);
68 while (it.hasNext()) {
69 it.next();
70 delete it.value();
71 }
72}
73
74//
75////////////////////////////////////////////////////////////////////////////
76void bncEphUser::slotNewEphGPS(gpsephemeris gpseph) {
77 QMutexLocker locker(&_mutex);
78
79 QString prn = QString("G%1").arg(gpseph.satellite, 2, 10, QChar('0'));
80
81 if (_eph.contains(prn)) {
82 t_ephGPS* eLast = static_cast<t_ephGPS*>(_eph.value(prn)->last);
83 bncTime toc(gpseph.GPSweek, gpseph.TOC);
84 if (eLast->TOC() < toc) {
85 delete static_cast<t_ephGPS*>(_eph.value(prn)->prev);
86 _eph.value(prn)->prev = _eph.value(prn)->last;
87 _eph.value(prn)->last = new t_ephGPS();
88 static_cast<t_ephGPS*>(_eph.value(prn)->last)->set(&gpseph);
89 }
90 }
91 else {
92 t_ephGPS* eLast = new t_ephGPS();
93 eLast->set(&gpseph);
94 _eph.insert(prn, new t_ephPair(eLast));
95 }
96 ephBufferChanged();
97}
98
99//
100////////////////////////////////////////////////////////////////////////////
101void bncEphUser::slotNewEphGlonass(glonassephemeris gloeph) {
102 QMutexLocker locker(&_mutex);
103
104 QString prn = QString("R%1").arg(gloeph.almanac_number, 2, 10, QChar('0'));
105
106 if (_eph.contains(prn)) {
107 int ww = gloeph.GPSWeek;
108 int tow = gloeph.GPSTOW;
109 updatetime(&ww, &tow, gloeph.tb*1000, 0); // Moscow -> GPS
110 t_ephGlo* eLast = static_cast<t_ephGlo*>(_eph.value(prn)->last);
111 bncTime toc(ww, tow);
112 if (eLast->TOC() < toc) {
113 t_ephGlo* ephGlo = new t_ephGlo();
114 bool timeChanged;
115 ephGlo->set(&gloeph, timeChanged);
116 if (timeChanged) {
117 delete ephGlo;
118 }
119 else {
120 delete static_cast<t_ephGlo*>(_eph.value(prn)->prev);
121 _eph.value(prn)->prev = _eph.value(prn)->last;
122 _eph.value(prn)->last = ephGlo;
123 }
124 }
125 }
126 else {
127 t_ephGlo* eLast = new t_ephGlo();
128 bool timeChanged;
129 eLast->set(&gloeph, timeChanged);
130 if (timeChanged) {
131 delete eLast;
132 }
133 else {
134 _eph.insert(prn, new t_ephPair(eLast));
135 }
136 }
137 ephBufferChanged();
138}
139
140//
141////////////////////////////////////////////////////////////////////////////
142void bncEphUser::slotNewEphGalileo(galileoephemeris galeph) {
143 QMutexLocker locker(&_mutex);
144
145 QString prn = QString("E%1").arg(galeph.satellite, 2, 10, QChar('0'));
146
147 if (_eph.contains(prn)) {
148 t_ephGal* eLast = static_cast<t_ephGal*>(_eph.value(prn)->last);
149 bncTime toc(galeph.Week, galeph.TOC);
150 if (eLast->TOC() < toc) {
151 delete static_cast<t_ephGal*>(_eph.value(prn)->prev);
152 _eph.value(prn)->prev = _eph.value(prn)->last;
153 _eph.value(prn)->last = new t_ephGal();
154 static_cast<t_ephGal*>(_eph.value(prn)->last)->set(&galeph);
155 }
156 }
157 else {
158 t_ephGal* eLast = new t_ephGal();
159 eLast->set(&galeph);
160 _eph.insert(prn, new t_ephPair(eLast));
161 }
162 ephBufferChanged();
163}
164
165//
166////////////////////////////////////////////////////////////////////////////
167t_irc bncEphUser::putNewEph(t_eph* newEph) {
168
169 QMutexLocker locker(&_mutex);
170
171 if (!newEph) {
172 return failure;
173 }
174
175 QString prn = newEph->prn();
176
177 t_irc irc = failure;
178
179 if (_eph.contains(prn)) {
180 t_eph* eLast = _eph.value(prn)->last;
181 if (newEph->isNewerThan(eLast)) {
182 delete _eph.value(prn)->prev;
183 _eph.value(prn)->prev = _eph.value(prn)->last;
184 _eph.value(prn)->last = newEph;
185 irc = success;
186 }
187 }
188 else {
189 _eph.insert(prn, new t_ephPair(newEph));
190 irc = success;
191 }
192
193 if (irc == success) {
194 ephBufferChanged();
195 }
196
197 return irc;
198}
199
200//
201////////////////////////////////////////////////////////////////////////////
202t_irc t_corr::readLine(const QString& line) {
203
204 if (line[0] == '!') {
205 return failure;
206 }
207
208 QTextStream in(line.toAscii());
209
210 in >> messageType;
211
212 if (!relevantMessageType(messageType)) {
213 return failure;
214 }
215
216 int updateInterval;
217 int GPSweek;
218 double GPSweeks;
219 in >> updateInterval >> GPSweek >> GPSweeks >> prn;
220
221 if ( messageType == COTYPE_GPSCOMBINED ||
222 messageType == COTYPE_GLONASSCOMBINED ) {
223 rao.ReSize(3); rao = 0.0;
224 dotRao.ReSize(3); dotRao = 0.0;
225 dotDotRao.ReSize(3); dotDotRao = 0.0;
226 dClk = 0.0;
227 dotDClk = 0.0;
228 dotDotDClk = 0.0;
229 in >> iod
230 >> dClk >> rao[0] >> rao[1] >> rao[2]
231 >> dotDClk >> dotRao[0] >> dotRao[1] >> dotRao[2]
232 >> dotDotDClk >> dotDotRao[0] >> dotDotRao[1] >> dotDotRao[2];
233 dClk /= t_CST::c;
234 dotDClk /= t_CST::c;
235 dotDotDClk /= t_CST::c;
236
237 tClk.set(GPSweek, GPSweeks);
238 tRao.set(GPSweek, GPSweeks);
239 }
240 else if ( messageType == COTYPE_GPSORBIT ||
241 messageType == COTYPE_GLONASSORBIT ) {
242 rao.ReSize(3); rao = 0.0;
243 dotRao.ReSize(3); dotRao = 0.0;
244 dotDotRao.ReSize(3); dotDotRao = 0.0;
245 in >> iod
246 >> rao[0] >> rao[1] >> rao[2]
247 >> dotRao[0] >> dotRao[1] >> dotRao[2]
248 >> dotDotRao[0] >> dotDotRao[1] >> dotDotRao[2];
249
250 tRao.set(GPSweek, GPSweeks);
251
252 if (tClk != tRao) {
253 dClk = 0.0;
254 dotDClk = 0.0;
255 dotDotDClk = 0.0;
256 tClk.reset();
257 }
258 }
259 else if ( messageType == COTYPE_GPSCLOCK ||
260 messageType == COTYPE_GLONASSCLOCK ) {
261 int dummyIOD;
262 dClk = 0.0;
263 dotDClk = 0.0;
264 dotDotDClk = 0.0;
265 in >> dummyIOD >> dClk >> dotDClk >> dotDotDClk;
266 dClk /= t_CST::c;
267 dotDClk /= t_CST::c;
268 dotDotDClk /= t_CST::c;
269
270 tClk.set(GPSweek, GPSweeks);
271 }
272 else if ( messageType == COTYPE_GPSHR ||
273 messageType == COTYPE_GLONASSHR ) {
274 if (tRao.valid() && tClk.valid()) {
275 int dummyIOD;
276 in >> dummyIOD >> hrClk;
277 hrClk /= t_CST::c;
278 }
279 }
280
281 return success;
282}
283
284//
285////////////////////////////////////////////////////////////////////////////
286t_irc t_bias::readLine(const QString& line) {
287
288 if (line[0] == '!') {
289 return failure;
290 }
291
292 QTextStream in(line.toAscii());
293
294 int messageType;
295 in >> messageType;
296
297 if (messageType != BTYPE_GPS && messageType != BTYPE_GLONASS) {
298 return failure;
299 }
300
301 int updateInterval;
302 int GPSweek;
303 double GPSweeks;
304 int numBiases;
305 in >> updateInterval >> GPSweek >> GPSweeks >> _prn >> numBiases;
306
307 _time.set(GPSweek, GPSweeks);
308
309 for (int ii = 0; ii < numBiases; ii++) {
310 int bType;
311 double bValue;
312 in >> bType >> bValue;
313 if (bType == CODETYPEGPS_L1_CA) {
314 _value["1C"] = bValue;
315 }
316 else if (bType == CODETYPEGPS_L1_P) {
317 _value["1P"] = bValue;
318 }
319 else if (bType == CODETYPEGPS_L1_Z) {
320 _value["1W"] = bValue;
321 }
322 else if (bType == CODETYPEGPS_L2_CA) {
323 _value["2C"] = bValue;
324 }
325 else if (bType == CODETYPEGPS_SEMI_CODELESS) {
326 _value["2N"] = bValue;
327 }
328 else if (bType == CODETYPEGPS_L2_CM) {
329 _value["2M"] = bValue;
330 }
331 else if (bType == CODETYPEGPS_L2_CL) {
332 _value["2L"] = bValue;
333 }
334 else if (bType == CODETYPEGPS_L2_CML) {
335 _value["2X"] = bValue;
336 }
337 else if (bType == CODETYPEGPS_L2_P) {
338 _value["2P"] = bValue;
339 }
340 else if (bType == CODETYPEGPS_L2_Z) {
341 _value["2W"] = bValue;
342 }
343 else if (bType == CODETYPEGPS_L5_I) {
344 _value["5I"] = bValue;
345 }
346 else if (bType == CODETYPEGPS_L5_Q) {
347 _value["5Q"] = bValue;
348 }
349 else if (bType == CODETYPEGLONASS_L1_CA) {
350 _value["1C"] = bValue;
351 }
352 else if (bType == CODETYPEGLONASS_L1_P) {
353 _value["1P"] = bValue;
354 }
355 else if (bType == CODETYPEGLONASS_L2_CA) {
356 _value["2C"] = bValue;
357 }
358 else if (bType == CODETYPEGLONASS_L2_P) {
359 _value["2P"] = bValue;
360 }
361 }
362
363 return success;
364}
Note: See TracBrowser for help on using the repository browser.