source: ntrip/trunk/BNC/src/PPP/pppRunRealTime.cpp@ 5860

Last change on this file since 5860 was 5860, checked in by mervart, 10 years ago
File size: 9.8 KB
Line 
1
2// Part of BNC, a utility for retrieving decoding and
3// converting GNSS data streams from NTRIP broadcasters.
4//
5// Copyright (C) 2007
6// German Federal Agency for Cartography and Geodesy (BKG)
7// http://www.bkg.bund.de
8// Czech Technical University Prague, Department of Geodesy
9// http://www.fsv.cvut.cz
10//
11// Email: euref-ip@bkg.bund.de
12//
13// This program is free software; you can redistribute it and/or
14// modify it under the terms of the GNU General Public License
15// as published by the Free Software Foundation, version 2.
16//
17// This program is distributed in the hope that it will be useful,
18// but WITHOUT ANY WARRANTY; without even the implied warranty of
19// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20// GNU General Public License for more details.
21//
22// You should have received a copy of the GNU General Public License
23// along with this program; if not, write to the Free Software
24// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
26/* -------------------------------------------------------------------------
27 * BKG NTRIP Client
28 * -------------------------------------------------------------------------
29 *
30 * Class: t_pppRunRealTime
31 *
32 * Purpose: Single Real-Time PPP Client
33 *
34 * Author: L. Mervart
35 *
36 * Created: 29-Jul-2014
37 *
38 * Changes:
39 *
40 * -----------------------------------------------------------------------*/
41
42
43#include <iostream>
44#include <iomanip>
45#include <string.h>
46#include <map>
47
48#include "pppRunRealTime.h"
49#include "bnccore.h"
50#include "bncephuser.h"
51
52using namespace BNC_PPP;
53using namespace std;
54
55// Constructor
56////////////////////////////////////////////////////////////////////////////
57t_pppRunRealTime::t_pppRunRealTime(const t_pppOptions* opt) {
58 _opt = opt;
59 connect(this, SIGNAL(newMessage(QByteArray,bool)),
60 BNC_CORE, SLOT(slotMessage(const QByteArray,bool)));
61 if (_opt->_realTime) {
62 connect(BNC_CORE->caster(), SIGNAL(newObs(QByteArray, QList<t_obs>)),
63 this, SLOT(slotNewObs(QByteArray, QList<t_obs>)));
64
65 connect(BNC_CORE, SIGNAL(newEphGPS(gpsephemeris)),
66 this, SLOT(slotNewEphGPS(gpsephemeris)));
67
68 connect(BNC_CORE, SIGNAL(newEphGlonass(glonassephemeris)),
69 this, SLOT(slotNewEphGlonass(glonassephemeris)));
70
71 connect(BNC_CORE, SIGNAL(newEphGalileo(galileoephemeris)),
72 this, SLOT(slotNewEphGalileo(galileoephemeris)));
73
74 connect(BNC_CORE, SIGNAL(newCorrections(QStringList)),
75 this, SLOT(slotNewCorrections(QStringList)));
76
77 for (unsigned iPrn = 0; iPrn <= t_prn::MAXPRN; iPrn++) {
78 _lastOrbCorrIOD[iPrn] = -1;
79 _lastClkCorrValue[iPrn] = 0.0;
80 }
81
82 _pppClient = new t_pppClient(_opt);
83 }
84 else {
85 throw t_except("t_pppRunRealTime: post-processing not yet implemented");
86 }
87}
88
89// Destructor
90////////////////////////////////////////////////////////////////////////////
91t_pppRunRealTime::~t_pppRunRealTime() {
92}
93
94//
95////////////////////////////////////////////////////////////////////////////
96void t_pppRunRealTime::slotNewEphGPS(gpsephemeris gpseph) {
97 QMutexLocker locker(&_mutex);
98 t_ephGPS eph;
99 eph.set(&gpseph);
100 _pppClient->putEphemeris(&eph);
101}
102
103//
104////////////////////////////////////////////////////////////////////////////
105void t_pppRunRealTime::slotNewEphGlonass(glonassephemeris gloeph) {
106 QMutexLocker locker(&_mutex);
107 t_ephGlo eph;
108 eph.set(&gloeph);
109 _pppClient->putEphemeris(&eph);
110}
111
112//
113////////////////////////////////////////////////////////////////////////////
114void t_pppRunRealTime::slotNewEphGalileo(galileoephemeris galeph) {
115 QMutexLocker locker(&_mutex);
116 t_ephGal eph;
117 eph.set(&galeph);
118 _pppClient->putEphemeris(&eph);
119}
120
121//
122////////////////////////////////////////////////////////////////////////////
123void t_pppRunRealTime::slotNewObs(QByteArray staID, QList<t_obs> obsList) {
124 QMutexLocker locker(&_mutex);
125
126 if (string(staID.data()) != _opt->_roverName) {
127 return;
128 }
129
130 // Loop over all obsevations (possible different epochs)
131 // -----------------------------------------------------
132 QListIterator<t_obs> it(obsList);
133 while (it.hasNext()) {
134 const t_obs& oldObs = it.next();
135 t_satObs* newObs = new t_satObs;
136
137 newObs->_prn.set(oldObs.satSys, oldObs.satNum);
138 newObs->_time.set(oldObs.GPSWeek, oldObs.GPSWeeks);
139
140 // Find the corresponding data epoch or create a new one
141 // -----------------------------------------------------
142 t_epoData* epoch = 0;
143 deque<t_epoData*>::const_iterator it;
144 for (it = _epoData.begin(); it != _epoData.end(); it++) {
145 if (newObs->_time == (*it)->_time) {
146 epoch = *it;
147 break;
148 }
149 }
150 if (epoch == 0) {
151 if (_epoData.empty() || newObs->_time > _epoData.back()->_time) {
152 epoch = new t_epoData;
153 epoch->_time = newObs->_time;
154 _epoData.push_back(epoch);
155 }
156 }
157
158 // Fill the new observation and add it to the corresponding epoch
159 // --------------------------------------------------------------
160 if (epoch != 0) {
161 epoch->_satObs.push_back(newObs);
162 map<string, t_frqObs*> frqObsMap;
163 for (unsigned iEntry = 0; iEntry < GNSSENTRY_NUMBER; iEntry++) {
164 string hlp(oldObs.rnxStr(iEntry).toAscii().data());
165 if (hlp.length() == 3) {
166 char obsType = hlp[0];
167 string rnxType2ch = hlp.substr(1);
168 if (obsType == 'C' || obsType == 'L') {
169 t_frqObs* frqObs = 0;
170 if (frqObsMap.find(rnxType2ch) == frqObsMap.end()) {
171 frqObs = new t_frqObs();
172 frqObsMap[rnxType2ch] = frqObs;
173 frqObs->_rnxType2ch = rnxType2ch;
174 newObs->_obs.push_back(frqObs);
175 }
176 else {
177 frqObs = frqObsMap[rnxType2ch];
178 }
179 if (obsType == 'C') {
180 frqObs->_code = oldObs._measdata[iEntry];
181 frqObs->_codeValid = true;
182 }
183 else if (obsType == 'L') {
184 frqObs->_phase = oldObs._measdata[iEntry];
185 frqObs->_phaseValid = true;
186 }
187 }
188 }
189 }
190 }
191 }
192
193 // Process the oldest epochs
194 // ------------------------
195 while (_epoData.size() && _epoData.front()->_time < _lastClkCorrTime + 10.0) {
196
197 const vector<t_satObs*>& satObs = _epoData.front()->_satObs;
198
199 t_output output;
200 _pppClient->processEpoch(satObs, &output);
201
202 delete _epoData.front(); _epoData.pop_front();
203
204 //// beg test
205 cout << output._log << endl; cout.flush();
206 //// end test
207
208 emit newMessage(QByteArray(output._log.c_str()), true);
209 }
210}
211
212//
213////////////////////////////////////////////////////////////////////////////
214void t_pppRunRealTime::slotNewCorrections(QStringList corrList) {
215 QMutexLocker locker(&_mutex);
216
217 if (_opt->_corrMount.empty()) {
218 return;
219 }
220
221 // Check the Mountpoint (source of corrections)
222 // --------------------------------------------
223 QMutableListIterator<QString> itm(corrList);
224 while (itm.hasNext()) {
225 QStringList hlp = itm.next().split(" ");
226 if (hlp.size() > 0) {
227 QString mountpoint = hlp[hlp.size()-1];
228 if (mountpoint != QString(_opt->_corrMount.c_str())) {
229 itm.remove();
230 }
231 }
232 }
233
234 if (corrList.size() == 0) {
235 return;
236 }
237
238 vector<t_orbCorr*> orbCorr;
239 vector<t_clkCorr*> clkCorr;
240 vector<t_satBias*> satBias;
241
242 QListIterator<QString> it(corrList);
243 while (it.hasNext()) {
244 QString line = it.next();
245
246 QTextStream in(&line);
247 int messageType;
248 int updateInterval;
249 int GPSweek;
250 double GPSweeks;
251 QString prn;
252 in >> messageType >> updateInterval >> GPSweek >> GPSweeks >> prn;
253
254 if ( t_corr::relevantMessageType(messageType) ) {
255 t_corr corr;
256 corr.readLine(line);
257 if (messageType == COTYPE_GPSCOMBINED || messageType == COTYPE_GLONASSCOMBINED ||
258 messageType == COTYPE_GPSORBIT || messageType == COTYPE_GLONASSORBIT ) {
259 t_orbCorr* cc = new t_orbCorr();
260 cc->_prn.set(corr.prn.toAscii().data());
261 cc->_iod = corr.iod;
262 cc->_time = corr.tRao;
263 cc->_system = 'R';
264 cc->_xr[0] = corr.rao[0];
265 cc->_xr[1] = corr.rao[1];
266 cc->_xr[2] = corr.rao[2];
267 cc->_dotXr[0] = corr.dotRao[0];
268 cc->_dotXr[0] = corr.dotRao[1];
269 cc->_dotXr[0] = corr.dotRao[2];
270 orbCorr.push_back(cc);
271
272 _lastOrbCorrIOD[cc->_prn.toInt()] = cc->_iod;
273 }
274 else if (messageType == COTYPE_GPSCOMBINED || messageType == COTYPE_GLONASSCOMBINED ||
275 messageType == COTYPE_GPSCLOCK || messageType == COTYPE_GLONASSCLOCK ) {
276 t_clkCorr* cc = new t_clkCorr();
277 cc->_prn.set(corr.prn.toAscii().data());
278 cc->_iod = corr.iod;
279 cc->_time = corr.tClk;
280 cc->_dClk = corr.dClk;
281 cc->_dotDClk = corr.dotDClk;
282 cc->_dotDotDClk = corr.dotDotDClk;
283 cc->_clkPartial = 0.0;
284 if (messageType == COTYPE_GPSCLOCK || messageType == COTYPE_GLONASSCLOCK) {
285 int lastIOD = _lastOrbCorrIOD[cc->_prn.toInt()];
286 if (lastIOD != -1) {
287 cc->_iod = lastIOD;
288 }
289 else {
290 delete cc;
291 cc = 0;
292 }
293 }
294 if (cc) {
295 clkCorr.push_back(cc);
296 if (_lastClkCorrTime.undef() || cc->_time > _lastClkCorrTime) {
297 _lastClkCorrTime = cc->_time;
298 }
299 }
300 }
301 }
302 else if ( messageType == BTYPE_GPS || messageType == BTYPE_GLONASS ) {
303 t_bias bias;
304 bias.readLine(line);
305 }
306 }
307
308 _pppClient->putOrbCorrections(orbCorr);
309 _pppClient->putClkCorrections(clkCorr);
310 _pppClient->putBiases(satBias);
311
312 for (unsigned ii = 0; ii < orbCorr.size(); ii++) {
313 delete orbCorr[ii];
314 }
315 for (unsigned ii = 0; ii < clkCorr.size(); ii++) {
316 delete clkCorr[ii];
317 }
318 for (unsigned ii = 0; ii < satBias.size(); ii++) {
319 delete satBias[ii];
320 }
321}
Note: See TracBrowser for help on using the repository browser.