1 | /* -------------------------------------------------------------------------
|
---|
2 | * BKG NTRIP Client
|
---|
3 | * -------------------------------------------------------------------------
|
---|
4 | *
|
---|
5 | * Class: bncComb
|
---|
6 | *
|
---|
7 | * Purpose: Combinations of Orbit/Clock Corrections
|
---|
8 | *
|
---|
9 | * Author: L. Mervart
|
---|
10 | *
|
---|
11 | * Created: 22-Jan-2011
|
---|
12 | *
|
---|
13 | * Changes:
|
---|
14 | *
|
---|
15 | * -----------------------------------------------------------------------*/
|
---|
16 |
|
---|
17 | #include <newmatio.h>
|
---|
18 | #include <iomanip>
|
---|
19 | #include <sstream>
|
---|
20 |
|
---|
21 | #include "bnccomb.h"
|
---|
22 | #include "bnccore.h"
|
---|
23 | #include "upload/bncrtnetdecoder.h"
|
---|
24 | #include "bncsettings.h"
|
---|
25 | #include "bncutils.h"
|
---|
26 | #include "bncsp3.h"
|
---|
27 | #include "bncantex.h"
|
---|
28 | #include "t_prn.h"
|
---|
29 |
|
---|
30 | const double sig0_offAC = 1000.0;
|
---|
31 | const double sig0_offACSat = 100.0;
|
---|
32 | const double sigP_offACSat = 0.01;
|
---|
33 | const double sig0_clkSat = 100.0;
|
---|
34 |
|
---|
35 | const double sigObs = 0.05;
|
---|
36 |
|
---|
37 | using namespace std;
|
---|
38 |
|
---|
39 | // Constructor
|
---|
40 | ////////////////////////////////////////////////////////////////////////////
|
---|
41 | bncComb::cmbParam::cmbParam(parType type_, int index_, const QString& ac_, const QString& prn_) {
|
---|
42 |
|
---|
43 | type = type_;
|
---|
44 | index = index_;
|
---|
45 | AC = ac_;
|
---|
46 | prn = prn_;
|
---|
47 | xx = 0.0;
|
---|
48 | eph = 0;
|
---|
49 |
|
---|
50 | if (type == offACgnss) {
|
---|
51 | epoSpec = true;
|
---|
52 | sig0 = sig0_offAC;
|
---|
53 | sigP = sig0;
|
---|
54 | }
|
---|
55 | else if (type == offACSat) {
|
---|
56 | epoSpec = false;
|
---|
57 | sig0 = sig0_offACSat;
|
---|
58 | sigP = sigP_offACSat;
|
---|
59 | }
|
---|
60 | else if (type == clkSat) {
|
---|
61 | epoSpec = true;
|
---|
62 | sig0 = sig0_clkSat;
|
---|
63 | sigP = sig0;
|
---|
64 | }
|
---|
65 | }
|
---|
66 |
|
---|
67 | // Destructor
|
---|
68 | ////////////////////////////////////////////////////////////////////////////
|
---|
69 | bncComb::cmbParam::~cmbParam() {
|
---|
70 | }
|
---|
71 |
|
---|
72 | // Partial
|
---|
73 | ////////////////////////////////////////////////////////////////////////////
|
---|
74 | double bncComb::cmbParam::partial(char sys, const QString& AC_, const QString& prn_) {
|
---|
75 |
|
---|
76 | if (type == offACgnss) {
|
---|
77 | if (AC == AC_ && prn_[0].toLatin1() == sys) {
|
---|
78 | return 1.0;
|
---|
79 | }
|
---|
80 | }
|
---|
81 | else if (type == offACSat) {
|
---|
82 | if (AC == AC_ && prn == prn_) {
|
---|
83 | return 1.0;
|
---|
84 | }
|
---|
85 | }
|
---|
86 | else if (type == clkSat) {
|
---|
87 | if (prn == prn_) {
|
---|
88 | return 1.0;
|
---|
89 | }
|
---|
90 | }
|
---|
91 |
|
---|
92 | return 0.0;
|
---|
93 | }
|
---|
94 |
|
---|
95 | //
|
---|
96 | ////////////////////////////////////////////////////////////////////////////
|
---|
97 | QString bncComb::cmbParam::toString(char sys) const {
|
---|
98 |
|
---|
99 | QString outStr;
|
---|
100 |
|
---|
101 | if (type == offACgnss) {
|
---|
102 | outStr = "AC Offset " + AC + " " + sys + " ";
|
---|
103 | }
|
---|
104 | else if (type == offACSat) {
|
---|
105 | outStr = "Sat Offset " + AC + " " + prn.mid(0,3);
|
---|
106 | }
|
---|
107 | else if (type == clkSat) {
|
---|
108 | outStr = "Clk Corr " + prn.mid(0,3);
|
---|
109 | }
|
---|
110 |
|
---|
111 | return outStr;
|
---|
112 | }
|
---|
113 |
|
---|
114 | // Singleton
|
---|
115 | ////////////////////////////////////////////////////////////////////////////
|
---|
116 | bncComb* bncComb::instance() {
|
---|
117 | static bncComb _bncComb;
|
---|
118 | return &_bncComb;
|
---|
119 | }
|
---|
120 |
|
---|
121 | // Constructor
|
---|
122 | ////////////////////////////////////////////////////////////////////////////
|
---|
123 | bncComb::bncComb() : _ephUser(true) {
|
---|
124 |
|
---|
125 | bncSettings settings;
|
---|
126 |
|
---|
127 | QStringList cmbStreams = settings.value("cmbStreams").toStringList();
|
---|
128 |
|
---|
129 | _cmbSampl = settings.value("cmbSampl").toInt();
|
---|
130 | if (_cmbSampl <= 0) {
|
---|
131 | _cmbSampl = 10;
|
---|
132 | }
|
---|
133 | _useGps = (Qt::CheckState(settings.value("cmbGps").toInt()) == Qt::Checked) ? true : false;
|
---|
134 | if (_useGps) {
|
---|
135 | _cmbSysPrn['G'] = t_prn::MAXPRN_GPS;
|
---|
136 | _masterMissingEpochs['G'] = 0;
|
---|
137 | }
|
---|
138 | _useGlo = (Qt::CheckState(settings.value("cmbGlo").toInt()) == Qt::Checked) ? true : false;
|
---|
139 | if (_useGlo) {
|
---|
140 | _cmbSysPrn['R'] = t_prn::MAXPRN_GLONASS;
|
---|
141 | _masterMissingEpochs['R'] = 0;
|
---|
142 | }
|
---|
143 | _useGal = (Qt::CheckState(settings.value("cmbGal").toInt()) == Qt::Checked) ? true : false;
|
---|
144 | if (_useGal) {
|
---|
145 | _cmbSysPrn['E'] = t_prn::MAXPRN_GALILEO;
|
---|
146 | _masterMissingEpochs['E'] = 0;
|
---|
147 | }
|
---|
148 | _useBds = (Qt::CheckState(settings.value("cmbBds").toInt()) == Qt::Checked) ? true : false;
|
---|
149 | if (_useBds) {
|
---|
150 | _cmbSysPrn['C'] = t_prn::MAXPRN_BDS;
|
---|
151 | _masterMissingEpochs['C'] = 0;
|
---|
152 | }
|
---|
153 | _useQzss = (Qt::CheckState(settings.value("cmbQzss").toInt()) == Qt::Checked) ? true : false;
|
---|
154 | if (_useQzss) {
|
---|
155 | _cmbSysPrn['J'] = t_prn::MAXPRN_QZSS;
|
---|
156 | _masterMissingEpochs['J'] = 0;
|
---|
157 | }
|
---|
158 | _useSbas = (Qt::CheckState(settings.value("cmbSbas").toInt()) == Qt::Checked) ? true : false;
|
---|
159 | if (_useSbas) {
|
---|
160 | _cmbSysPrn['S'] = t_prn::MAXPRN_SBAS;
|
---|
161 | _masterMissingEpochs['S'] = 0;
|
---|
162 | }
|
---|
163 | _useIrnss = (Qt::CheckState(settings.value("cmbIrnss").toInt()) == Qt::Checked) ? true : false;
|
---|
164 | if (_useIrnss) {
|
---|
165 | _cmbSysPrn['I'] = t_prn::MAXPRN_IRNSS;
|
---|
166 | _masterMissingEpochs['I'] = 0;
|
---|
167 | }
|
---|
168 |
|
---|
169 | if (cmbStreams.size() >= 1 && !cmbStreams[0].isEmpty()) {
|
---|
170 | QListIterator<QString> it(cmbStreams);
|
---|
171 | while (it.hasNext()) {
|
---|
172 | QStringList hlp = it.next().split(" ");
|
---|
173 | cmbAC* newAC = new cmbAC();
|
---|
174 | newAC->mountPoint = hlp[0];
|
---|
175 | newAC->name = hlp[1];
|
---|
176 | newAC->weight = hlp[2].toDouble();
|
---|
177 | QMapIterator<char, unsigned> itSys(_cmbSysPrn);
|
---|
178 | // init
|
---|
179 | while (itSys.hasNext()) {
|
---|
180 | itSys.next();
|
---|
181 | char sys = itSys.key();
|
---|
182 | if (_masterOrbitAC.isEmpty()) {
|
---|
183 | _masterOrbitAC[sys] = newAC->name;
|
---|
184 | }
|
---|
185 | }
|
---|
186 | _ACs.append(newAC);
|
---|
187 | }
|
---|
188 | }
|
---|
189 |
|
---|
190 | QString ssrFormat;
|
---|
191 | _ssrCorr = 0;
|
---|
192 | QListIterator<QString> it(settings.value("uploadMountpointsOut").toStringList());
|
---|
193 | while (it.hasNext()) {
|
---|
194 | QStringList hlp = it.next().split(",");
|
---|
195 | if (hlp.size() > 7) {
|
---|
196 | ssrFormat = hlp[7];
|
---|
197 | }
|
---|
198 | }
|
---|
199 | if (ssrFormat == "IGS-SSR") {
|
---|
200 | _ssrCorr = new SsrCorrIgs();
|
---|
201 | }
|
---|
202 | else if (ssrFormat == "RTCM-SSR") {
|
---|
203 | _ssrCorr = new SsrCorrRtcm();
|
---|
204 | }
|
---|
205 | else { // default
|
---|
206 | _ssrCorr = new SsrCorrIgs();
|
---|
207 | }
|
---|
208 |
|
---|
209 | _rtnetDecoder = 0;
|
---|
210 |
|
---|
211 | connect(this, SIGNAL(newMessage(QByteArray,bool)),
|
---|
212 | BNC_CORE, SLOT(slotMessage(const QByteArray,bool)));
|
---|
213 |
|
---|
214 | connect(BNC_CORE, SIGNAL(providerIDChanged(QString)),
|
---|
215 | this, SLOT(slotProviderIDChanged(QString)));
|
---|
216 |
|
---|
217 | connect(BNC_CORE, SIGNAL(newOrbCorrections(QList<t_orbCorr>)),
|
---|
218 | this, SLOT(slotNewOrbCorrections(QList<t_orbCorr>)));
|
---|
219 |
|
---|
220 | connect(BNC_CORE, SIGNAL(newClkCorrections(QList<t_clkCorr>)),
|
---|
221 | this, SLOT(slotNewClkCorrections(QList<t_clkCorr>)));
|
---|
222 |
|
---|
223 | // Combination Method
|
---|
224 | // ------------------
|
---|
225 | if (settings.value("cmbMethod").toString() == "Single-Epoch") {
|
---|
226 | _method = singleEpoch;
|
---|
227 | }
|
---|
228 | else {
|
---|
229 | _method = filter;
|
---|
230 | }
|
---|
231 |
|
---|
232 | // Initialize Parameters (model: Clk_Corr = AC_Offset + Sat_Offset + Clk)
|
---|
233 | // ----------------------------------------------------------------------
|
---|
234 | if (_method == filter) {
|
---|
235 | // SYSTEM
|
---|
236 | QMapIterator<char, unsigned> itSys(_cmbSysPrn);
|
---|
237 | while (itSys.hasNext()) {
|
---|
238 | itSys.next();
|
---|
239 | int nextPar = 0;
|
---|
240 | char sys = itSys.key();
|
---|
241 | unsigned maxPrn = itSys.value();
|
---|
242 | unsigned flag = 0;
|
---|
243 | if (sys == 'E') {
|
---|
244 | flag = 1;
|
---|
245 | }
|
---|
246 | // AC
|
---|
247 | QListIterator<cmbAC*> itAc(_ACs);
|
---|
248 | while (itAc.hasNext()) {
|
---|
249 | cmbAC* AC = itAc.next();
|
---|
250 | _params[sys].push_back(new cmbParam(cmbParam::offACgnss, ++nextPar, AC->name, ""));
|
---|
251 | for (unsigned iGnss = 1; iGnss <= maxPrn; iGnss++) {
|
---|
252 | QString prn = QString("%1%2_%3").arg(sys).arg(iGnss, 2, 10, QChar('0')).arg(flag);
|
---|
253 | _params[sys].push_back(new cmbParam(cmbParam::offACSat, ++nextPar, AC->name, prn));
|
---|
254 | }
|
---|
255 | }
|
---|
256 | for (unsigned iGnss = 1; iGnss <= maxPrn; iGnss++) {
|
---|
257 | QString prn = QString("%1%2_%3").arg(sys).arg(iGnss, 2, 10, QChar('0')).arg(flag);
|
---|
258 | _params[sys].push_back(new cmbParam(cmbParam::clkSat, ++nextPar, "", prn));
|
---|
259 | }
|
---|
260 | // Initialize Variance-Covariance Matrix
|
---|
261 | // -------------------------------------
|
---|
262 | _QQ[sys].ReSize(_params[sys].size());
|
---|
263 | _QQ[sys] = 0.0;
|
---|
264 | for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
|
---|
265 | cmbParam* pp = _params[sys][iPar-1];
|
---|
266 | _QQ[sys](iPar,iPar) = pp->sig0 * pp->sig0;
|
---|
267 | }
|
---|
268 | }
|
---|
269 | }
|
---|
270 |
|
---|
271 | // ANTEX File
|
---|
272 | // ----------
|
---|
273 | _antex = 0;
|
---|
274 | QString antexFileName = settings.value("uploadAntexFile").toString();
|
---|
275 | if (!antexFileName.isEmpty()) {
|
---|
276 | _antex = new bncAntex();
|
---|
277 | if (_antex->readFile(antexFileName) != success) {
|
---|
278 | emit newMessage("wrong ANTEX file", true);
|
---|
279 | delete _antex;
|
---|
280 | _antex = 0;
|
---|
281 | }
|
---|
282 | }
|
---|
283 |
|
---|
284 | // Maximal Residuum
|
---|
285 | // ----------------
|
---|
286 | _MAXRES = settings.value("cmbMaxres").toDouble();
|
---|
287 | if (_MAXRES <= 0.0) {
|
---|
288 | _MAXRES = 999.0;
|
---|
289 | }
|
---|
290 | }
|
---|
291 |
|
---|
292 | // Destructor
|
---|
293 | ////////////////////////////////////////////////////////////////////////////
|
---|
294 | bncComb::~bncComb() {
|
---|
295 | QListIterator<cmbAC*> icAC(_ACs);
|
---|
296 | while (icAC.hasNext()) {
|
---|
297 | delete icAC.next();
|
---|
298 | }
|
---|
299 | delete _rtnetDecoder;
|
---|
300 | if (_ssrCorr) {
|
---|
301 | delete _ssrCorr;
|
---|
302 | }
|
---|
303 | delete _antex;
|
---|
304 | QMapIterator<char, unsigned> itSys(_cmbSysPrn);
|
---|
305 | while (itSys.hasNext()) {
|
---|
306 | itSys.next();
|
---|
307 | char sys = itSys.key();
|
---|
308 | for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
|
---|
309 | delete _params[sys][iPar-1];
|
---|
310 | }
|
---|
311 | QListIterator<bncTime> itTime(_buffer[sys].keys());
|
---|
312 | while (itTime.hasNext()) {
|
---|
313 | bncTime epoTime = itTime.next();
|
---|
314 | _buffer[sys].remove(epoTime);
|
---|
315 | }
|
---|
316 | }
|
---|
317 |
|
---|
318 | }
|
---|
319 |
|
---|
320 | // Remember orbit corrections
|
---|
321 | ////////////////////////////////////////////////////////////////////////////
|
---|
322 | void bncComb::slotNewOrbCorrections(QList<t_orbCorr> orbCorrections) {
|
---|
323 | QMutexLocker locker(&_mutex);
|
---|
324 |
|
---|
325 | for (int ii = 0; ii < orbCorrections.size(); ii++) {
|
---|
326 | t_orbCorr& orbCorr = orbCorrections[ii];
|
---|
327 | QString staID(orbCorr._staID.c_str());
|
---|
328 | QString prn(orbCorr._prn.toInternalString().c_str());
|
---|
329 | char sys = orbCorr._prn.system();
|
---|
330 |
|
---|
331 | if (!_cmbSysPrn.contains(sys)){
|
---|
332 | continue;
|
---|
333 | }
|
---|
334 |
|
---|
335 | // Find/Check the AC Name
|
---|
336 | // ----------------------
|
---|
337 | QString acName;
|
---|
338 | QListIterator<cmbAC*> icAC(_ACs);
|
---|
339 | while (icAC.hasNext()) {
|
---|
340 | cmbAC* AC = icAC.next();
|
---|
341 | if (AC->mountPoint == staID) {
|
---|
342 | acName = AC->name;
|
---|
343 | break;
|
---|
344 | }
|
---|
345 | }
|
---|
346 | if (acName.isEmpty()) {
|
---|
347 | continue;
|
---|
348 | }
|
---|
349 |
|
---|
350 | // Store the correction
|
---|
351 | // --------------------
|
---|
352 | QMap<t_prn, t_orbCorr>& storage = _orbCorrections[acName];
|
---|
353 | storage[orbCorr._prn] = orbCorr;
|
---|
354 | }
|
---|
355 | }
|
---|
356 |
|
---|
357 | // Process clock corrections
|
---|
358 | ////////////////////////////////////////////////////////////////////////////
|
---|
359 | void bncComb::slotNewClkCorrections(QList<t_clkCorr> clkCorrections) {
|
---|
360 | QMutexLocker locker(&_mutex);
|
---|
361 |
|
---|
362 | bncTime lastTime;
|
---|
363 |
|
---|
364 | for (int ii = 0; ii < clkCorrections.size(); ii++) {
|
---|
365 | t_clkCorr& clkCorr = clkCorrections[ii];
|
---|
366 | QString staID(clkCorr._staID.c_str());
|
---|
367 | QString prn(clkCorr._prn.toInternalString().c_str());
|
---|
368 | char sys = clkCorr._prn.system();
|
---|
369 |
|
---|
370 | if (!_cmbSysPrn.contains(sys)){
|
---|
371 | continue;
|
---|
372 | }
|
---|
373 |
|
---|
374 | // Set the last time
|
---|
375 | // -----------------
|
---|
376 | if (lastTime.undef() || clkCorr._time > lastTime) {
|
---|
377 | lastTime = clkCorr._time;
|
---|
378 | }
|
---|
379 |
|
---|
380 | // Find/Check the AC Name
|
---|
381 | // ----------------------
|
---|
382 | QString acName;
|
---|
383 | QListIterator<cmbAC*> icAC(_ACs);
|
---|
384 | while (icAC.hasNext()) {
|
---|
385 | cmbAC* AC = icAC.next();
|
---|
386 | if (AC->mountPoint == staID) {
|
---|
387 | acName = AC->name;
|
---|
388 | break;
|
---|
389 | }
|
---|
390 | }
|
---|
391 | if (acName.isEmpty()) {
|
---|
392 | continue;
|
---|
393 | }
|
---|
394 |
|
---|
395 | // Check Modulo Time
|
---|
396 | // -----------------
|
---|
397 | int sec = int(nint(clkCorr._time.gpssec()*10));
|
---|
398 | if (sec % (_cmbSampl*10) != 0.0) {
|
---|
399 | continue;
|
---|
400 | }
|
---|
401 |
|
---|
402 | // Check Correction Age
|
---|
403 | // --------------------
|
---|
404 | if (_resTime.valid() && clkCorr._time <= _resTime) {
|
---|
405 | emit newMessage("bncComb: old correction: " + acName.toLatin1() + " " + prn.mid(0,3).toLatin1(), true);
|
---|
406 | continue;
|
---|
407 | }
|
---|
408 |
|
---|
409 | // Create new correction
|
---|
410 | // ---------------------
|
---|
411 | cmbCorr* newCorr = new cmbCorr();
|
---|
412 | newCorr->_prn = prn;
|
---|
413 | newCorr->_time = clkCorr._time;
|
---|
414 | newCorr->_iod = clkCorr._iod;
|
---|
415 | newCorr->_acName = acName;
|
---|
416 | newCorr->_clkCorr = clkCorr;
|
---|
417 |
|
---|
418 | // Check orbit correction
|
---|
419 | // ----------------------
|
---|
420 | if (!_orbCorrections.contains(acName)) {
|
---|
421 | delete newCorr;
|
---|
422 | continue;
|
---|
423 | }
|
---|
424 | else {
|
---|
425 | QMap<t_prn, t_orbCorr>& storage = _orbCorrections[acName];
|
---|
426 | if (!storage.contains(clkCorr._prn) ||
|
---|
427 | storage[clkCorr._prn]._iod != newCorr->_iod) {
|
---|
428 | delete newCorr;
|
---|
429 | continue;
|
---|
430 | }
|
---|
431 | else {
|
---|
432 | newCorr->_orbCorr = storage[clkCorr._prn];
|
---|
433 | }
|
---|
434 | }
|
---|
435 |
|
---|
436 | // Check the Ephemeris
|
---|
437 | //--------------------
|
---|
438 | t_eph* ephLast = _ephUser.ephLast(prn);
|
---|
439 | t_eph* ephPrev = _ephUser.ephPrev(prn);
|
---|
440 | if (ephLast == 0) {
|
---|
441 | emit newMessage("bncComb: eph not found for " + prn.mid(0,3).toLatin1(), true);
|
---|
442 | delete newCorr;
|
---|
443 | continue;
|
---|
444 | }
|
---|
445 | else if (ephLast->checkState() == t_eph::bad ||
|
---|
446 | ephLast->checkState() == t_eph::outdated ||
|
---|
447 | ephLast->checkState() == t_eph::unhealthy) {
|
---|
448 | emit newMessage("bncComb: ephLast not ok for " + prn.mid(0,3).toLatin1(), true);
|
---|
449 | delete newCorr;
|
---|
450 | continue;
|
---|
451 | }
|
---|
452 | else {
|
---|
453 | if (ephLast->IOD() == newCorr->_iod) {
|
---|
454 | newCorr->_eph = ephLast;
|
---|
455 | }
|
---|
456 | else if (ephPrev && ephPrev->checkState() == t_eph::ok &&
|
---|
457 | ephPrev->IOD() == newCorr->_iod) {
|
---|
458 | newCorr->_eph = ephPrev;
|
---|
459 | switchToLastEph(ephLast, newCorr);
|
---|
460 | }
|
---|
461 | else {
|
---|
462 | emit newMessage("bncComb: eph not found for " + prn.mid(0,3).toLatin1() +
|
---|
463 | QString(" with IOD %1").arg(newCorr->_iod).toLatin1(), true);
|
---|
464 | delete newCorr;
|
---|
465 | continue;
|
---|
466 | }
|
---|
467 | }
|
---|
468 |
|
---|
469 | // Store correction into the buffer
|
---|
470 | // --------------------------------
|
---|
471 | QVector<cmbCorr*>& corrs = _buffer[sys][newCorr->_time].corrs;
|
---|
472 | corrs.push_back(newCorr);
|
---|
473 | }
|
---|
474 |
|
---|
475 | // Process previous Epoch(s)
|
---|
476 | // -------------------------
|
---|
477 | const double outWait = 1.0 * _cmbSampl;
|
---|
478 | QMapIterator<char, unsigned> itSys(_cmbSysPrn);
|
---|
479 | while (itSys.hasNext()) {
|
---|
480 | itSys.next();
|
---|
481 | char sys = itSys.key();
|
---|
482 | QListIterator<bncTime> itTime(_buffer[sys].keys());
|
---|
483 | while (itTime.hasNext()) {
|
---|
484 | bncTime epoTime = itTime.next();
|
---|
485 | if (epoTime < lastTime - outWait) {
|
---|
486 | _resTime = epoTime;
|
---|
487 | processEpoch(sys);
|
---|
488 | }
|
---|
489 | }
|
---|
490 | }
|
---|
491 | }
|
---|
492 |
|
---|
493 | // Change the correction so that it refers to last received ephemeris
|
---|
494 | ////////////////////////////////////////////////////////////////////////////
|
---|
495 | void bncComb::switchToLastEph(t_eph* lastEph, cmbCorr* corr) {
|
---|
496 |
|
---|
497 | if (corr->_eph == lastEph) {
|
---|
498 | return;
|
---|
499 | }
|
---|
500 |
|
---|
501 | ColumnVector oldXC(6);
|
---|
502 | ColumnVector oldVV(3);
|
---|
503 | if (corr->_eph->getCrd(corr->_time, oldXC, oldVV, false) != success) {
|
---|
504 | return;
|
---|
505 | }
|
---|
506 |
|
---|
507 | ColumnVector newXC(6);
|
---|
508 | ColumnVector newVV(3);
|
---|
509 | if (lastEph->getCrd(corr->_time, newXC, newVV, false) != success) {
|
---|
510 | return;
|
---|
511 | }
|
---|
512 |
|
---|
513 | ColumnVector dX = newXC.Rows(1,3) - oldXC.Rows(1,3);
|
---|
514 | ColumnVector dV = newVV - oldVV;
|
---|
515 | double dC = newXC(4) - oldXC(4);
|
---|
516 |
|
---|
517 | ColumnVector dRAO(3);
|
---|
518 | XYZ_to_RSW(newXC.Rows(1,3), newVV, dX, dRAO);
|
---|
519 |
|
---|
520 | ColumnVector dDotRAO(3);
|
---|
521 | XYZ_to_RSW(newXC.Rows(1,3), newVV, dV, dDotRAO);
|
---|
522 |
|
---|
523 | QString msg = "switch corr " + corr->_prn.mid(0,3)
|
---|
524 | + QString(" %1 -> %2 %3").arg(corr->_iod,3).arg(lastEph->IOD(),3).arg(dC*t_CST::c, 8, 'f', 4);
|
---|
525 |
|
---|
526 | emit newMessage(msg.toLatin1(), false);
|
---|
527 |
|
---|
528 | corr->_iod = lastEph->IOD();
|
---|
529 | corr->_eph = lastEph;
|
---|
530 |
|
---|
531 | corr->_orbCorr._xr += dRAO;
|
---|
532 | corr->_orbCorr._dotXr += dDotRAO;
|
---|
533 | corr->_clkCorr._dClk -= dC;
|
---|
534 | }
|
---|
535 |
|
---|
536 | // Process Epoch
|
---|
537 | ////////////////////////////////////////////////////////////////////////////
|
---|
538 | void bncComb::processEpoch(char sys) {
|
---|
539 |
|
---|
540 | _log.clear();
|
---|
541 |
|
---|
542 | QTextStream out(&_log, QIODevice::WriteOnly);
|
---|
543 |
|
---|
544 | out << endl << "Combination: " << sys << endl
|
---|
545 | << "--------------------------------" << endl;
|
---|
546 |
|
---|
547 | // Observation Statistics
|
---|
548 | // ----------------------
|
---|
549 | bool masterPresent = false;
|
---|
550 | QListIterator<cmbAC*> icAC(_ACs);
|
---|
551 | while (icAC.hasNext()) {
|
---|
552 | cmbAC* AC = icAC.next();
|
---|
553 | AC->numObs[sys] = 0;
|
---|
554 | QVectorIterator<cmbCorr*> itCorr(corrs(sys));
|
---|
555 | while (itCorr.hasNext()) {
|
---|
556 | cmbCorr* corr = itCorr.next();
|
---|
557 | if (corr->_acName == AC->name) {
|
---|
558 | AC->numObs[sys] += 1;
|
---|
559 | if (AC->name == _masterOrbitAC[sys]) {
|
---|
560 | masterPresent = true;
|
---|
561 | }
|
---|
562 | }
|
---|
563 | }
|
---|
564 | out << AC->name.toLatin1().data() << ": " << AC->numObs[sys] << endl;
|
---|
565 | }
|
---|
566 |
|
---|
567 | // If Master not present, switch to another one
|
---|
568 | // --------------------------------------------
|
---|
569 | const unsigned switchMasterAfterGap = 1;
|
---|
570 | if (masterPresent) {
|
---|
571 | _masterMissingEpochs[sys] = 0;
|
---|
572 | }
|
---|
573 | else {
|
---|
574 | ++_masterMissingEpochs[sys];
|
---|
575 | if (_masterMissingEpochs[sys] < switchMasterAfterGap) {
|
---|
576 | out << "Missing Master, Epoch skipped" << endl;
|
---|
577 | _buffer[sys].remove(_resTime);
|
---|
578 | emit newMessage(_log, false);
|
---|
579 | return;
|
---|
580 | }
|
---|
581 | else {
|
---|
582 | _masterMissingEpochs[sys] = 0;
|
---|
583 | QListIterator<cmbAC*> icAC(_ACs);
|
---|
584 | while (icAC.hasNext()) {
|
---|
585 | cmbAC* AC = icAC.next();
|
---|
586 | if (AC->numObs[sys] > 0) {
|
---|
587 | out << "Switching Master AC "
|
---|
588 | << _masterOrbitAC[sys].toLatin1().data() << " --> "
|
---|
589 | << AC->name.toLatin1().data() << " "
|
---|
590 | << _resTime.datestr().c_str() << " "
|
---|
591 | << _resTime.timestr().c_str() << endl;
|
---|
592 | _masterOrbitAC[sys] = AC->name;
|
---|
593 | break;
|
---|
594 | }
|
---|
595 | }
|
---|
596 | }
|
---|
597 | }
|
---|
598 |
|
---|
599 | QMap<QString, cmbCorr*> resCorr;
|
---|
600 |
|
---|
601 | // Perform the actual Combination using selected Method
|
---|
602 | // ----------------------------------------------------
|
---|
603 | t_irc irc;
|
---|
604 | ColumnVector dx;
|
---|
605 | if (_method == filter) {
|
---|
606 | irc = processEpoch_filter(sys, out, resCorr, dx);
|
---|
607 | }
|
---|
608 | else {
|
---|
609 | irc = processEpoch_singleEpoch(sys, out, resCorr, dx);
|
---|
610 | }
|
---|
611 |
|
---|
612 | // Update Parameter Values, Print Results
|
---|
613 | // --------------------------------------
|
---|
614 | if (irc == success) {
|
---|
615 | for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
|
---|
616 | cmbParam* pp = _params[sys][iPar-1];
|
---|
617 | pp->xx += dx(iPar);
|
---|
618 | if (pp->type == cmbParam::clkSat) {
|
---|
619 | if (resCorr.find(pp->prn) != resCorr.end()) {
|
---|
620 | resCorr[pp->prn]->_dClkResult = pp->xx / t_CST::c;
|
---|
621 | }
|
---|
622 | }
|
---|
623 | out << _resTime.datestr().c_str() << " "
|
---|
624 | << _resTime.timestr().c_str() << " ";
|
---|
625 | out.setRealNumberNotation(QTextStream::FixedNotation);
|
---|
626 | out.setFieldWidth(8);
|
---|
627 | out.setRealNumberPrecision(4);
|
---|
628 | out << pp->toString(sys) << " "
|
---|
629 | << pp->xx << " +- " << sqrt(_QQ[sys](pp->index,pp->index)) << endl;
|
---|
630 | out.setFieldWidth(0);
|
---|
631 | }
|
---|
632 | printResults(out, resCorr);
|
---|
633 | dumpResults(resCorr);
|
---|
634 | }
|
---|
635 |
|
---|
636 | // Delete Data, emit Message
|
---|
637 | // -------------------------
|
---|
638 | _buffer[sys].remove(_resTime);
|
---|
639 | emit newMessage(_log, false);
|
---|
640 | }
|
---|
641 |
|
---|
642 | // Process Epoch - Filter Method
|
---|
643 | ////////////////////////////////////////////////////////////////////////////
|
---|
644 | t_irc bncComb::processEpoch_filter(char sys, QTextStream& out,
|
---|
645 | QMap<QString, cmbCorr*>& resCorr,
|
---|
646 | ColumnVector& dx) {
|
---|
647 |
|
---|
648 | // Prediction Step
|
---|
649 | // ---------------
|
---|
650 | int nPar = _params[sys].size();
|
---|
651 | ColumnVector x0(nPar);
|
---|
652 | for (int iPar = 1; iPar <= nPar; iPar++) {
|
---|
653 | cmbParam* pp = _params[sys][iPar-1];
|
---|
654 | if (pp->epoSpec) {
|
---|
655 | pp->xx = 0.0;
|
---|
656 | _QQ[sys].Row(iPar) = 0.0;
|
---|
657 | _QQ[sys].Column(iPar) = 0.0;
|
---|
658 | _QQ[sys](iPar,iPar) = pp->sig0 * pp->sig0;
|
---|
659 | }
|
---|
660 | else {
|
---|
661 | _QQ[sys](iPar,iPar) += pp->sigP * pp->sigP;
|
---|
662 | }
|
---|
663 | x0(iPar) = pp->xx;
|
---|
664 | }
|
---|
665 |
|
---|
666 | // Check Satellite Positions for Outliers
|
---|
667 | // --------------------------------------
|
---|
668 | if (checkOrbits(sys, out) != success) {
|
---|
669 | return failure;
|
---|
670 | }
|
---|
671 |
|
---|
672 | // Update and outlier detection loop
|
---|
673 | // ---------------------------------
|
---|
674 | SymmetricMatrix QQ_sav = _QQ[sys];
|
---|
675 | while (true) {
|
---|
676 |
|
---|
677 | Matrix AA;
|
---|
678 | ColumnVector ll;
|
---|
679 | DiagonalMatrix PP;
|
---|
680 |
|
---|
681 | if (createAmat(sys, AA, ll, PP, x0, resCorr) != success) {
|
---|
682 | return failure;
|
---|
683 | }
|
---|
684 |
|
---|
685 | dx.ReSize(nPar); dx = 0.0;
|
---|
686 | kalman(AA, ll, PP, _QQ[sys], dx);
|
---|
687 |
|
---|
688 | ColumnVector vv = ll - AA * dx;
|
---|
689 |
|
---|
690 | int maxResIndex;
|
---|
691 | double maxRes = vv.maximum_absolute_value1(maxResIndex);
|
---|
692 | out.setRealNumberNotation(QTextStream::FixedNotation);
|
---|
693 | out.setRealNumberPrecision(3);
|
---|
694 | out << _resTime.datestr().c_str() << " " << _resTime.timestr().c_str()
|
---|
695 | << " Maximum Residuum " << maxRes << ' '
|
---|
696 | << corrs(sys)[maxResIndex-1]->_acName << ' ' << corrs(sys)[maxResIndex-1]->_prn.mid(0,3);
|
---|
697 | if (maxRes > _MAXRES) {
|
---|
698 | for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
|
---|
699 | cmbParam* pp = _params[sys][iPar-1];
|
---|
700 | if (pp->type == cmbParam::offACSat &&
|
---|
701 | pp->AC == corrs(sys)[maxResIndex-1]->_acName &&
|
---|
702 | pp->prn == corrs(sys)[maxResIndex-1]->_prn.mid(0,3)) {
|
---|
703 | QQ_sav.Row(iPar) = 0.0;
|
---|
704 | QQ_sav.Column(iPar) = 0.0;
|
---|
705 | QQ_sav(iPar,iPar) = pp->sig0 * pp->sig0;
|
---|
706 | }
|
---|
707 | }
|
---|
708 |
|
---|
709 | out << " Outlier" << endl;
|
---|
710 | _QQ[sys] = QQ_sav;
|
---|
711 | corrs(sys).remove(maxResIndex-1);
|
---|
712 | }
|
---|
713 | else {
|
---|
714 | out << " OK" << endl;
|
---|
715 | out.setRealNumberNotation(QTextStream::FixedNotation);
|
---|
716 | out.setRealNumberPrecision(4);
|
---|
717 | for (int ii = 0; ii < corrs(sys).size(); ii++) {
|
---|
718 | const cmbCorr* corr = corrs(sys)[ii];
|
---|
719 | out << _resTime.datestr().c_str() << ' '
|
---|
720 | << _resTime.timestr().c_str() << " "
|
---|
721 | << corr->_acName << ' ' << corr->_prn.mid(0,3);
|
---|
722 | out.setFieldWidth(10);
|
---|
723 | out << " res = " << vv[ii] << endl;
|
---|
724 | out.setFieldWidth(0);
|
---|
725 | }
|
---|
726 | break;
|
---|
727 | }
|
---|
728 | }
|
---|
729 |
|
---|
730 | return success;
|
---|
731 | }
|
---|
732 |
|
---|
733 | // Print results
|
---|
734 | ////////////////////////////////////////////////////////////////////////////
|
---|
735 | void bncComb::printResults(QTextStream& out,
|
---|
736 | const QMap<QString, cmbCorr*>& resCorr) {
|
---|
737 |
|
---|
738 | QMapIterator<QString, cmbCorr*> it(resCorr);
|
---|
739 | while (it.hasNext()) {
|
---|
740 | it.next();
|
---|
741 | cmbCorr* corr = it.value();
|
---|
742 | const t_eph* eph = corr->_eph;
|
---|
743 | if (eph) {
|
---|
744 | ColumnVector xc(6);
|
---|
745 | ColumnVector vv(3);
|
---|
746 | if (eph->getCrd(_resTime, xc, vv, false) != success) {
|
---|
747 | continue;
|
---|
748 | }
|
---|
749 | out << _resTime.datestr().c_str() << " "
|
---|
750 | << _resTime.timestr().c_str() << " ";
|
---|
751 | out.setFieldWidth(3);
|
---|
752 | out << "Full Clock " << corr->_prn.mid(0,3) << " " << corr->_iod << " ";
|
---|
753 | out.setFieldWidth(14);
|
---|
754 | out << (xc(4) + corr->_dClkResult) * t_CST::c << endl;
|
---|
755 | out.setFieldWidth(0);
|
---|
756 | }
|
---|
757 | else {
|
---|
758 | out << "bncComb::printResuls bug" << endl;
|
---|
759 | }
|
---|
760 | }
|
---|
761 | }
|
---|
762 |
|
---|
763 | // Send results to RTNet Decoder and directly to PPP Client
|
---|
764 | ////////////////////////////////////////////////////////////////////////////
|
---|
765 | void bncComb::dumpResults(const QMap<QString, cmbCorr*>& resCorr) {
|
---|
766 |
|
---|
767 | QList<t_orbCorr> orbCorrections;
|
---|
768 | QList<t_clkCorr> clkCorrections;
|
---|
769 |
|
---|
770 | QString outLines;
|
---|
771 | unsigned year, month, day, hour, minute;
|
---|
772 | double sec;
|
---|
773 | _resTime.civil_date(year, month, day);
|
---|
774 | _resTime.civil_time(hour, minute, sec);
|
---|
775 |
|
---|
776 | outLines.sprintf("* %4d %2d %2d %d %d %12.8f\n",
|
---|
777 | year, month, day, hour, minute, sec);
|
---|
778 |
|
---|
779 | QMapIterator<QString, cmbCorr*> it(resCorr);
|
---|
780 | while (it.hasNext()) {
|
---|
781 | it.next();
|
---|
782 | cmbCorr* corr = it.value();
|
---|
783 |
|
---|
784 | t_orbCorr orbCorr(corr->_orbCorr);
|
---|
785 | orbCorr._staID = "INTERNAL";
|
---|
786 | orbCorrections.push_back(orbCorr);
|
---|
787 |
|
---|
788 | t_clkCorr clkCorr(corr->_clkCorr);
|
---|
789 | clkCorr._staID = "INTERNAL";
|
---|
790 | clkCorr._dClk = corr->_dClkResult;
|
---|
791 | clkCorr._dotDClk = 0.0;
|
---|
792 | clkCorr._dotDotDClk = 0.0;
|
---|
793 | clkCorrections.push_back(clkCorr);
|
---|
794 |
|
---|
795 | ColumnVector xc(6);
|
---|
796 | ColumnVector vv(3);
|
---|
797 | corr->_eph->setClkCorr(dynamic_cast<const t_clkCorr*>(&clkCorr));
|
---|
798 | corr->_eph->setOrbCorr(dynamic_cast<const t_orbCorr*>(&orbCorr));
|
---|
799 | if (corr->_eph->getCrd(_resTime, xc, vv, true) != success) {
|
---|
800 | delete corr;
|
---|
801 | continue;
|
---|
802 | }
|
---|
803 |
|
---|
804 | // Correction Phase Center --> CoM
|
---|
805 | // -------------------------------
|
---|
806 | ColumnVector dx(3); dx = 0.0;
|
---|
807 | if (_antex) {
|
---|
808 | double Mjd = _resTime.mjd() + _resTime.daysec()/86400.0;
|
---|
809 | if (_antex->satCoMcorrection(corr->_prn, Mjd, xc.Rows(1,3), dx) != success) {
|
---|
810 | dx = 0;
|
---|
811 | _log += "antenna not found " + corr->_prn.mid(0,3).toLatin1() + '\n';
|
---|
812 | }
|
---|
813 | }
|
---|
814 |
|
---|
815 | outLines += corr->_prn.mid(0,3);
|
---|
816 | QString hlp;
|
---|
817 | hlp.sprintf(" APC 3 %15.4f %15.4f %15.4f"
|
---|
818 | " Clk 1 %15.4f"
|
---|
819 | " Vel 3 %15.4f %15.4f %15.4f"
|
---|
820 | " CoM 3 %15.4f %15.4f %15.4f\n",
|
---|
821 | xc(1), xc(2), xc(3),
|
---|
822 | xc(4) * t_CST::c,
|
---|
823 | vv(1), vv(2), vv(3),
|
---|
824 | xc(1)-dx(1), xc(2)-dx(2), xc(3)-dx(3));
|
---|
825 | outLines += hlp;
|
---|
826 |
|
---|
827 | QString line;
|
---|
828 | int messageType = _ssrCorr->COTYPE_GPSCOMBINED;
|
---|
829 | int updateInt = 0;
|
---|
830 | line.sprintf("%d %d %d %.1f %s"
|
---|
831 | " %lu"
|
---|
832 | " %8.3f %8.3f %8.3f %8.3f"
|
---|
833 | " %10.5f %10.5f %10.5f %10.5f"
|
---|
834 | " %10.5f INTERNAL",
|
---|
835 | messageType, updateInt, _resTime.gpsw(), _resTime.gpssec(),
|
---|
836 | corr->_prn.mid(0,3).toLatin1().data(),
|
---|
837 | corr->_iod,
|
---|
838 | corr->_dClkResult * t_CST::c,
|
---|
839 | corr->_orbCorr._xr[0],
|
---|
840 | corr->_orbCorr._xr[1],
|
---|
841 | corr->_orbCorr._xr[2],
|
---|
842 | 0.0,
|
---|
843 | corr->_orbCorr._dotXr[0],
|
---|
844 | corr->_orbCorr._dotXr[1],
|
---|
845 | corr->_orbCorr._dotXr[2],
|
---|
846 | 0.0);
|
---|
847 |
|
---|
848 | delete corr;
|
---|
849 | }
|
---|
850 |
|
---|
851 | outLines += "EOE\n"; // End Of Epoch flag
|
---|
852 |
|
---|
853 | if (!_rtnetDecoder) {
|
---|
854 | _rtnetDecoder = new bncRtnetDecoder();
|
---|
855 | }
|
---|
856 |
|
---|
857 | vector<string> errmsg;
|
---|
858 | _rtnetDecoder->Decode(outLines.toLatin1().data(), outLines.length(), errmsg);
|
---|
859 |
|
---|
860 | // Send new Corrections to PPP etc.
|
---|
861 | // --------------------------------
|
---|
862 | if (orbCorrections.size() > 0 && clkCorrections.size() > 0) {
|
---|
863 | emit newOrbCorrections(orbCorrections);
|
---|
864 | emit newClkCorrections(clkCorrections);
|
---|
865 | }
|
---|
866 | }
|
---|
867 |
|
---|
868 | // Create First Design Matrix and Vector of Measurements
|
---|
869 | ////////////////////////////////////////////////////////////////////////////
|
---|
870 | t_irc bncComb::createAmat(char sys, Matrix& AA, ColumnVector& ll, DiagonalMatrix& PP,
|
---|
871 | const ColumnVector& x0, QMap<QString, cmbCorr*>& resCorr) {
|
---|
872 |
|
---|
873 | unsigned nPar = _params[sys].size();
|
---|
874 | unsigned nObs = corrs(sys).size();
|
---|
875 |
|
---|
876 | if (nObs == 0) {
|
---|
877 | return failure;
|
---|
878 | }
|
---|
879 |
|
---|
880 | int maxSat = _cmbSysPrn[sys];
|
---|
881 |
|
---|
882 | const int nCon = (_method == filter) ? 1 + maxSat : 0;
|
---|
883 |
|
---|
884 | AA.ReSize(nObs+nCon, nPar); AA = 0.0;
|
---|
885 | ll.ReSize(nObs+nCon); ll = 0.0;
|
---|
886 | PP.ReSize(nObs+nCon); PP = 1.0 / (sigObs * sigObs);
|
---|
887 |
|
---|
888 | int iObs = 0;
|
---|
889 | QVectorIterator<cmbCorr*> itCorr(corrs(sys));
|
---|
890 | while (itCorr.hasNext()) {
|
---|
891 | cmbCorr* corr = itCorr.next();
|
---|
892 | QString prn = corr->_prn;
|
---|
893 |
|
---|
894 | ++iObs;
|
---|
895 |
|
---|
896 | if (corr->_acName == _masterOrbitAC[sys] && resCorr.find(prn) == resCorr.end()) {
|
---|
897 | resCorr[prn] = new cmbCorr(*corr);
|
---|
898 | }
|
---|
899 |
|
---|
900 | for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
|
---|
901 | cmbParam* pp = _params[sys][iPar-1];
|
---|
902 | AA(iObs, iPar) = pp->partial(sys, corr->_acName, prn);
|
---|
903 | }
|
---|
904 |
|
---|
905 | ll(iObs) = corr->_clkCorr._dClk * t_CST::c - DotProduct(AA.Row(iObs), x0);
|
---|
906 | }
|
---|
907 |
|
---|
908 | // Regularization
|
---|
909 | // --------------
|
---|
910 | if (_method == filter) {
|
---|
911 | const double Ph = 1.e6;
|
---|
912 | PP(nObs+1) = Ph;
|
---|
913 | for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
|
---|
914 | cmbParam* pp = _params[sys][iPar-1];
|
---|
915 | if ( AA.Column(iPar).maximum_absolute_value() > 0.0 &&
|
---|
916 | pp->type == cmbParam::clkSat ) {
|
---|
917 | AA(nObs+1, iPar) = 1.0;
|
---|
918 | }
|
---|
919 | }
|
---|
920 | unsigned flag = 0;
|
---|
921 | if (sys == 'E') {
|
---|
922 | flag = 1;
|
---|
923 | }
|
---|
924 | if (sys == 'R') {
|
---|
925 | return success;
|
---|
926 | }
|
---|
927 | int iCond = 1;
|
---|
928 | // GNSS
|
---|
929 | for (unsigned iGnss = 1; iGnss <= _cmbSysPrn[sys]; iGnss++) {
|
---|
930 | QString prn = QString("%1%2_%3").arg(sys).arg(iGnss, 2, 10, QChar('0')).arg(flag);
|
---|
931 | ++iCond;
|
---|
932 | PP(nObs+iCond) = Ph;
|
---|
933 | for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
|
---|
934 | cmbParam* pp = _params[sys][iPar-1];
|
---|
935 | if ( pp &&
|
---|
936 | AA.Column(iPar).maximum_absolute_value() > 0.0 &&
|
---|
937 | pp->type == cmbParam::offACSat &&
|
---|
938 | pp->prn == prn) {
|
---|
939 | AA(nObs+iCond, iPar) = 1.0;
|
---|
940 | }
|
---|
941 | }
|
---|
942 | }
|
---|
943 | }
|
---|
944 |
|
---|
945 | return success;
|
---|
946 | }
|
---|
947 |
|
---|
948 | // Process Epoch - Single-Epoch Method
|
---|
949 | ////////////////////////////////////////////////////////////////////////////
|
---|
950 | t_irc bncComb::processEpoch_singleEpoch(char sys, QTextStream& out,
|
---|
951 | QMap<QString, cmbCorr*>& resCorr,
|
---|
952 | ColumnVector& dx) {
|
---|
953 |
|
---|
954 | // Check Satellite Positions for Outliers
|
---|
955 | // --------------------------------------
|
---|
956 | if (checkOrbits(sys, out) != success) {
|
---|
957 | return failure;
|
---|
958 | }
|
---|
959 |
|
---|
960 | // Outlier Detection Loop
|
---|
961 | // ----------------------
|
---|
962 | while (true) {
|
---|
963 |
|
---|
964 | // Remove Satellites that are not in Master
|
---|
965 | // ----------------------------------------
|
---|
966 | QMutableVectorIterator<cmbCorr*> it(corrs(sys));
|
---|
967 | while (it.hasNext()) {
|
---|
968 | cmbCorr* corr = it.next();
|
---|
969 | QString prn = corr->_prn;
|
---|
970 | bool foundMaster = false;
|
---|
971 | QVectorIterator<cmbCorr*> itHlp(corrs(sys));
|
---|
972 | while (itHlp.hasNext()) {
|
---|
973 | cmbCorr* corrHlp = itHlp.next();
|
---|
974 | QString prnHlp = corrHlp->_prn;
|
---|
975 | QString ACHlp = corrHlp->_acName;
|
---|
976 | if (ACHlp == _masterOrbitAC[sys] && prn == prnHlp) {
|
---|
977 | foundMaster = true;
|
---|
978 | break;
|
---|
979 | }
|
---|
980 | }
|
---|
981 | if (!foundMaster) {
|
---|
982 | delete corr;
|
---|
983 | it.remove();
|
---|
984 | }
|
---|
985 | }
|
---|
986 |
|
---|
987 | // Count Number of Observations per Satellite and per AC
|
---|
988 | // -----------------------------------------------------
|
---|
989 | QMap<QString, int> numObsPrn;
|
---|
990 | QMap<QString, int> numObsAC;
|
---|
991 | QVectorIterator<cmbCorr*> itCorr(corrs(sys));
|
---|
992 | while (itCorr.hasNext()) {
|
---|
993 | cmbCorr* corr = itCorr.next();
|
---|
994 | QString prn = corr->_prn;
|
---|
995 | QString AC = corr->_acName;
|
---|
996 | if (numObsPrn.find(prn) == numObsPrn.end()) {
|
---|
997 | numObsPrn[prn] = 1;
|
---|
998 | }
|
---|
999 | else {
|
---|
1000 | numObsPrn[prn] += 1;
|
---|
1001 | }
|
---|
1002 | if (numObsAC.find(AC) == numObsAC.end()) {
|
---|
1003 | numObsAC[AC] = 1;
|
---|
1004 | }
|
---|
1005 | else {
|
---|
1006 | numObsAC[AC] += 1;
|
---|
1007 | }
|
---|
1008 | }
|
---|
1009 |
|
---|
1010 | // Clean-Up the Parameters
|
---|
1011 | // -----------------------
|
---|
1012 | for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
|
---|
1013 | delete _params[sys][iPar-1];
|
---|
1014 | }
|
---|
1015 | _params[sys].clear();
|
---|
1016 |
|
---|
1017 | // Set new Parameters
|
---|
1018 | // ------------------
|
---|
1019 | int nextPar = 0;
|
---|
1020 |
|
---|
1021 | QMapIterator<QString, int> itAC(numObsAC);
|
---|
1022 | while (itAC.hasNext()) {
|
---|
1023 | itAC.next();
|
---|
1024 | const QString& AC = itAC.key();
|
---|
1025 | int numObs = itAC.value();
|
---|
1026 | if (AC != _masterOrbitAC[sys] && numObs > 0) {
|
---|
1027 | _params[sys].push_back(new cmbParam(cmbParam::offACgnss, ++nextPar, AC, ""));
|
---|
1028 | }
|
---|
1029 | }
|
---|
1030 |
|
---|
1031 | QMapIterator<QString, int> itPrn(numObsPrn);
|
---|
1032 | while (itPrn.hasNext()) {
|
---|
1033 | itPrn.next();
|
---|
1034 | const QString& prn = itPrn.key();
|
---|
1035 | int numObs = itPrn.value();
|
---|
1036 | if (numObs > 0) {
|
---|
1037 | _params[sys].push_back(new cmbParam(cmbParam::clkSat, ++nextPar, "", prn));
|
---|
1038 | }
|
---|
1039 | }
|
---|
1040 |
|
---|
1041 | int nPar = _params[sys].size();
|
---|
1042 | ColumnVector x0(nPar);
|
---|
1043 | x0 = 0.0;
|
---|
1044 |
|
---|
1045 | // Create First-Design Matrix
|
---|
1046 | // --------------------------
|
---|
1047 | Matrix AA;
|
---|
1048 | ColumnVector ll;
|
---|
1049 | DiagonalMatrix PP;
|
---|
1050 | if (createAmat(sys, AA, ll, PP, x0, resCorr) != success) {
|
---|
1051 | return failure;
|
---|
1052 | }
|
---|
1053 |
|
---|
1054 | ColumnVector vv;
|
---|
1055 | try {
|
---|
1056 | Matrix ATP = AA.t() * PP;
|
---|
1057 | SymmetricMatrix NN; NN << ATP * AA;
|
---|
1058 | ColumnVector bb = ATP * ll;
|
---|
1059 | _QQ[sys] = NN.i();
|
---|
1060 | dx = _QQ[sys] * bb;
|
---|
1061 | vv = ll - AA * dx;
|
---|
1062 | }
|
---|
1063 | catch (Exception& exc) {
|
---|
1064 | out << exc.what() << endl;
|
---|
1065 | return failure;
|
---|
1066 | }
|
---|
1067 |
|
---|
1068 | int maxResIndex;
|
---|
1069 | double maxRes = vv.maximum_absolute_value1(maxResIndex);
|
---|
1070 | out.setRealNumberNotation(QTextStream::FixedNotation);
|
---|
1071 | out.setRealNumberPrecision(3);
|
---|
1072 | out << _resTime.datestr().c_str() << " " << _resTime.timestr().c_str()
|
---|
1073 | << " Maximum Residuum " << maxRes << ' '
|
---|
1074 | << corrs(sys)[maxResIndex-1]->_acName << ' ' << corrs(sys)[maxResIndex-1]->_prn.mid(0,3);
|
---|
1075 |
|
---|
1076 | if (maxRes > _MAXRES) {
|
---|
1077 | out << " Outlier" << endl;
|
---|
1078 | delete corrs(sys)[maxResIndex-1];
|
---|
1079 | corrs(sys).remove(maxResIndex-1);
|
---|
1080 | }
|
---|
1081 | else {
|
---|
1082 | out << " OK" << endl;
|
---|
1083 | out.setRealNumberNotation(QTextStream::FixedNotation);
|
---|
1084 | out.setRealNumberPrecision(3);
|
---|
1085 | for (int ii = 0; ii < vv.Nrows(); ii++) {
|
---|
1086 | const cmbCorr* corr = corrs(sys)[ii];
|
---|
1087 | out << _resTime.datestr().c_str() << ' '
|
---|
1088 | << _resTime.timestr().c_str() << " "
|
---|
1089 | << corr->_acName << ' ' << corr->_prn.mid(0,3);
|
---|
1090 | out.setFieldWidth(6);
|
---|
1091 | out << " res = " << vv[ii] << endl;
|
---|
1092 | out.setFieldWidth(0);
|
---|
1093 | }
|
---|
1094 | return success;
|
---|
1095 | }
|
---|
1096 |
|
---|
1097 | }
|
---|
1098 |
|
---|
1099 | return failure;
|
---|
1100 | }
|
---|
1101 |
|
---|
1102 | // Check Satellite Positions for Outliers
|
---|
1103 | ////////////////////////////////////////////////////////////////////////////
|
---|
1104 | t_irc bncComb::checkOrbits(char sys, QTextStream& out) {
|
---|
1105 |
|
---|
1106 | const double MAX_DISPLACEMENT = 0.20;
|
---|
1107 |
|
---|
1108 | // Switch to last ephemeris (if possible)
|
---|
1109 | // --------------------------------------
|
---|
1110 | QMutableVectorIterator<cmbCorr*> im(corrs(sys));
|
---|
1111 | while (im.hasNext()) {
|
---|
1112 | cmbCorr* corr = im.next();
|
---|
1113 | QString prn = corr->_prn;
|
---|
1114 |
|
---|
1115 | t_eph* ephLast = _ephUser.ephLast(prn);
|
---|
1116 | t_eph* ephPrev = _ephUser.ephPrev(prn);
|
---|
1117 |
|
---|
1118 | if (ephLast == 0) {
|
---|
1119 | out << "checkOrbit: missing eph (not found) " << corr->_prn.mid(0,3) << endl;
|
---|
1120 | delete corr;
|
---|
1121 | im.remove();
|
---|
1122 | }
|
---|
1123 | else if (corr->_eph == 0) {
|
---|
1124 | out << "checkOrbit: missing eph (zero) " << corr->_prn.mid(0,3) << endl;
|
---|
1125 | delete corr;
|
---|
1126 | im.remove();
|
---|
1127 | }
|
---|
1128 | else {
|
---|
1129 | if ( corr->_eph == ephLast || corr->_eph == ephPrev ) {
|
---|
1130 | switchToLastEph(ephLast, corr);
|
---|
1131 | }
|
---|
1132 | else {
|
---|
1133 | out << "checkOrbit: missing eph (deleted) " << corr->_prn.mid(0,3) << endl;
|
---|
1134 | delete corr;
|
---|
1135 | im.remove();
|
---|
1136 | }
|
---|
1137 | }
|
---|
1138 | }
|
---|
1139 |
|
---|
1140 | while (true) {
|
---|
1141 |
|
---|
1142 | // Compute Mean Corrections for all Satellites
|
---|
1143 | // -------------------------------------------
|
---|
1144 | QMap<QString, int> numCorr;
|
---|
1145 | QMap<QString, ColumnVector> meanRao;
|
---|
1146 | QVectorIterator<cmbCorr*> it(corrs(sys));
|
---|
1147 | while (it.hasNext()) {
|
---|
1148 | cmbCorr* corr = it.next();
|
---|
1149 | QString prn = corr->_prn;
|
---|
1150 | if (meanRao.find(prn) == meanRao.end()) {
|
---|
1151 | meanRao[prn].ReSize(4);
|
---|
1152 | meanRao[prn].Rows(1,3) = corr->_orbCorr._xr;
|
---|
1153 | meanRao[prn](4) = 1;
|
---|
1154 | }
|
---|
1155 | else {
|
---|
1156 | meanRao[prn].Rows(1,3) += corr->_orbCorr._xr;
|
---|
1157 | meanRao[prn](4) += 1;
|
---|
1158 | }
|
---|
1159 | if (numCorr.find(prn) == numCorr.end()) {
|
---|
1160 | numCorr[prn] = 1;
|
---|
1161 | }
|
---|
1162 | else {
|
---|
1163 | numCorr[prn] += 1;
|
---|
1164 | }
|
---|
1165 | }
|
---|
1166 |
|
---|
1167 | // Compute Differences wrt. Mean, find Maximum
|
---|
1168 | // -------------------------------------------
|
---|
1169 | QMap<QString, cmbCorr*> maxDiff;
|
---|
1170 | it.toFront();
|
---|
1171 | while (it.hasNext()) {
|
---|
1172 | cmbCorr* corr = it.next();
|
---|
1173 | QString prn = corr->_prn;
|
---|
1174 | if (meanRao[prn](4) != 0) {
|
---|
1175 | meanRao[prn] /= meanRao[prn](4);
|
---|
1176 | meanRao[prn](4) = 0;
|
---|
1177 | }
|
---|
1178 | corr->_diffRao = corr->_orbCorr._xr - meanRao[prn].Rows(1,3);
|
---|
1179 | if (maxDiff.find(prn) == maxDiff.end()) {
|
---|
1180 | maxDiff[prn] = corr;
|
---|
1181 | }
|
---|
1182 | else {
|
---|
1183 | double normMax = maxDiff[prn]->_diffRao.NormFrobenius();
|
---|
1184 | double norm = corr->_diffRao.NormFrobenius();
|
---|
1185 | if (norm > normMax) {
|
---|
1186 | maxDiff[prn] = corr;
|
---|
1187 | }
|
---|
1188 | }
|
---|
1189 | }
|
---|
1190 |
|
---|
1191 | if (_ACs.size() == 1) {
|
---|
1192 | break;
|
---|
1193 | }
|
---|
1194 |
|
---|
1195 | // Remove Outliers
|
---|
1196 | // ---------------
|
---|
1197 | bool removed = false;
|
---|
1198 | QMutableVectorIterator<cmbCorr*> im(corrs(sys));
|
---|
1199 | while (im.hasNext()) {
|
---|
1200 | cmbCorr* corr = im.next();
|
---|
1201 | QString prn = corr->_prn;
|
---|
1202 | if (numCorr[prn] < 2) {
|
---|
1203 | delete corr;
|
---|
1204 | im.remove();
|
---|
1205 | }
|
---|
1206 | else if (corr == maxDiff[prn]) {
|
---|
1207 | double norm = corr->_diffRao.NormFrobenius();
|
---|
1208 | if (norm > MAX_DISPLACEMENT) {
|
---|
1209 | out << _resTime.datestr().c_str() << " "
|
---|
1210 | << _resTime.timestr().c_str() << " "
|
---|
1211 | << "Orbit Outlier: "
|
---|
1212 | << corr->_acName.toLatin1().data() << " "
|
---|
1213 | << prn.mid(0,3).toLatin1().data() << " "
|
---|
1214 | << corr->_iod << " "
|
---|
1215 | << norm << endl;
|
---|
1216 | delete corr;
|
---|
1217 | im.remove();
|
---|
1218 | removed = true;
|
---|
1219 | }
|
---|
1220 | }
|
---|
1221 | }
|
---|
1222 |
|
---|
1223 | if (!removed) {
|
---|
1224 | break;
|
---|
1225 | }
|
---|
1226 | }
|
---|
1227 |
|
---|
1228 | return success;
|
---|
1229 | }
|
---|
1230 |
|
---|
1231 | //
|
---|
1232 | ////////////////////////////////////////////////////////////////////////////
|
---|
1233 | void bncComb::slotProviderIDChanged(QString mountPoint) {
|
---|
1234 | QMutexLocker locker(&_mutex);
|
---|
1235 |
|
---|
1236 | QTextStream out(&_log, QIODevice::WriteOnly);
|
---|
1237 |
|
---|
1238 | // Find the AC Name
|
---|
1239 | // ----------------
|
---|
1240 | QString acName;
|
---|
1241 | QListIterator<cmbAC*> icAC(_ACs);
|
---|
1242 | while (icAC.hasNext()) {
|
---|
1243 | cmbAC* AC = icAC.next();
|
---|
1244 | if (AC->mountPoint == mountPoint) {
|
---|
1245 | acName = AC->name;
|
---|
1246 | out << "Provider ID changed: AC " << AC->name.toLatin1().data() << " "
|
---|
1247 | << _resTime.datestr().c_str() << " "
|
---|
1248 | << _resTime.timestr().c_str() << endl;
|
---|
1249 | break;
|
---|
1250 | }
|
---|
1251 | }
|
---|
1252 | if (acName.isEmpty()) {
|
---|
1253 | return;
|
---|
1254 | }
|
---|
1255 | QMapIterator<char, unsigned> itSys(_cmbSysPrn);
|
---|
1256 | while (itSys.hasNext()) {
|
---|
1257 | itSys.next();
|
---|
1258 | char sys = itSys.key();
|
---|
1259 | // Remove all corrections of the corresponding AC
|
---|
1260 | // ----------------------------------------------
|
---|
1261 | QListIterator<bncTime> itTime(_buffer[sys].keys());
|
---|
1262 | while (itTime.hasNext()) {
|
---|
1263 | bncTime epoTime = itTime.next();
|
---|
1264 | QVector<cmbCorr*>& corrVec = _buffer[sys][epoTime].corrs;
|
---|
1265 | QMutableVectorIterator<cmbCorr*> it(corrVec);
|
---|
1266 | while (it.hasNext()) {
|
---|
1267 | cmbCorr* corr = it.next();
|
---|
1268 | if (acName == corr->_acName) {
|
---|
1269 | delete corr;
|
---|
1270 | it.remove();
|
---|
1271 | }
|
---|
1272 | }
|
---|
1273 | }
|
---|
1274 |
|
---|
1275 | // Reset Satellite Offsets
|
---|
1276 | // -----------------------
|
---|
1277 | if (_method == filter) {
|
---|
1278 | for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
|
---|
1279 | cmbParam* pp = _params[sys][iPar-1];
|
---|
1280 | if (pp->AC == acName && pp->type == cmbParam::offACSat) {
|
---|
1281 | pp->xx = 0.0;
|
---|
1282 | _QQ[sys].Row(iPar) = 0.0;
|
---|
1283 | _QQ[sys].Column(iPar) = 0.0;
|
---|
1284 | _QQ[sys](iPar,iPar) = pp->sig0 * pp->sig0;
|
---|
1285 | }
|
---|
1286 | }
|
---|
1287 | }
|
---|
1288 | }
|
---|
1289 | }
|
---|