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

Last change on this file since 6393 was 6393, checked in by mervart, 9 years ago
File size: 5.8 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 connect(BNC_CORE, SIGNAL(newEphSBAS(sbasephemeris)),
63 this, SLOT(slotNewEphSBAS(sbasephemeris)), Qt::DirectConnection);
64 }
65}
66
67// Destructor
68////////////////////////////////////////////////////////////////////////////
69bncEphUser::~bncEphUser() {
70 QMapIterator<QString, t_ephPair*> it(_eph);
71 while (it.hasNext()) {
72 it.next();
73 delete it.value();
74 }
75}
76
77//
78////////////////////////////////////////////////////////////////////////////
79void bncEphUser::slotNewEphGPS(gpsephemeris gpseph) {
80 QMutexLocker locker(&_mutex);
81
82 t_ephGPS* eNew = new t_ephGPS(); eNew->set(&gpseph);
83
84 QString prn(eNew->prn().toString().c_str());
85
86 if (_eph.contains(prn)) {
87 t_ephGPS* eLast = static_cast<t_ephGPS*>(_eph.value(prn)->last);
88 if (eNew->isNewerThan(eLast)) {
89 delete _eph.value(prn)->prev;
90 _eph.value(prn)->prev = _eph.value(prn)->last;
91 _eph.value(prn)->last = eNew;
92 ephBufferChanged();
93 }
94 else {
95 delete eNew;
96 }
97 }
98 else {
99 _eph.insert(prn, new t_ephPair(eNew));
100 ephBufferChanged();
101 }
102}
103
104//
105////////////////////////////////////////////////////////////////////////////
106void bncEphUser::slotNewEphGlonass(glonassephemeris gloeph) {
107 QMutexLocker locker(&_mutex);
108
109 t_ephGlo* eNew = new t_ephGlo(); eNew->set(&gloeph);
110
111 QString prn(eNew->prn().toString().c_str());
112
113 if (_eph.contains(prn)) {
114 t_ephGlo* eLast = static_cast<t_ephGlo*>(_eph.value(prn)->last);
115 if (eNew->isNewerThan(eLast)) {
116 delete _eph.value(prn)->prev;
117 _eph.value(prn)->prev = _eph.value(prn)->last;
118 _eph.value(prn)->last = eNew;
119 ephBufferChanged();
120 }
121 else {
122 delete eNew;
123 }
124 }
125 else {
126 _eph.insert(prn, new t_ephPair(eNew));
127 ephBufferChanged();
128 }
129}
130
131//
132////////////////////////////////////////////////////////////////////////////
133void bncEphUser::slotNewEphGalileo(galileoephemeris galeph) {
134 QMutexLocker locker(&_mutex);
135
136 QString prn = QString("E%1").arg(galeph.satellite, 2, 10, QChar('0'));
137
138 if (_eph.contains(prn)) {
139 t_ephGal* eLast = static_cast<t_ephGal*>(_eph.value(prn)->last);
140 bncTime toc(galeph.Week, galeph.TOC);
141 if (eLast->TOC() < toc) {
142 delete static_cast<t_ephGal*>(_eph.value(prn)->prev);
143 _eph.value(prn)->prev = _eph.value(prn)->last;
144 _eph.value(prn)->last = new t_ephGal();
145 static_cast<t_ephGal*>(_eph.value(prn)->last)->set(&galeph);
146 }
147 }
148 else {
149 t_ephGal* eLast = new t_ephGal();
150 eLast->set(&galeph);
151 _eph.insert(prn, new t_ephPair(eLast));
152 }
153 ephBufferChanged();
154}
155
156//
157////////////////////////////////////////////////////////////////////////////
158t_irc bncEphUser::putNewEph(t_eph* newEph) {
159
160 QMutexLocker locker(&_mutex);
161
162 if (!newEph) {
163 return failure;
164 }
165
166 QString prn(newEph->prn().toString().c_str());
167
168 t_irc irc = failure;
169
170 if (_eph.contains(prn)) {
171 t_eph* eLast = _eph.value(prn)->last;
172 if (newEph->isNewerThan(eLast)) {
173 delete _eph.value(prn)->prev;
174 _eph.value(prn)->prev = _eph.value(prn)->last;
175 _eph.value(prn)->last = newEph;
176 irc = success;
177 }
178 }
179 else {
180 _eph.insert(prn, new t_ephPair(newEph));
181 irc = success;
182 }
183
184 if (irc == success) {
185 ephBufferChanged();
186 }
187
188 return irc;
189}
190
191//
192////////////////////////////////////////////////////////////////////////////
193void bncEphUser::slotNewEphSBAS(sbasephemeris sbaseph) {
194 QMutexLocker locker(&_mutex);
195
196 t_ephSBAS* eNew = new t_ephSBAS(); eNew->set(&sbaseph);
197 QString prn = QString(eNew->prn().toString().c_str());
198
199 if (_eph.contains(prn)) {
200 if (eNew->isNewerThan(_eph.value(prn)->last)) {
201 delete _eph.value(prn)->prev;
202 _eph.value(prn)->prev = _eph.value(prn)->last;
203 _eph.value(prn)->last = eNew;
204 }
205 else {
206 delete eNew;
207 return;
208 }
209 }
210 else {
211 _eph.insert(prn, new t_ephPair(eNew));
212 }
213 ephBufferChanged();
214}
215
Note: See TracBrowser for help on using the repository browser.