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

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