source: ntrip/trunk/BNC/src/combination/bnccomb.cpp@ 10903

Last change on this file since 10903 was 10890, checked in by stuerze, 3 weeks ago

minor changes

File size: 53.2 KB
Line 
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#include <map>
21
22#include "bnccomb.h"
23#include <combination/bncbiassnx.h>
24#include "bnccore.h"
25#include "upload/bncrtnetdecoder.h"
26#include "bncsettings.h"
27#include "bncutils.h"
28#include "bncantex.h"
29#include "t_prn.h"
30
31const double sig0_offAC = 1000.0;
32const double sigP_offAC = 1000.0;
33
34const double sig0_offACSat = 1000.0;
35const double sigP_offACSat = 0.01;
36
37const double sig0_clkSat = 100.0;
38const double sigP_clkSat = 100.0; //*) White noise may be set to something between a few centimeters and tens of meters.
39 // A large value results in a combination that is equivalent to a single-epoch combination algorithm.
40
41const double sigObs = 0.05;
42
43using namespace std;
44
45// Constructor
46////////////////////////////////////////////////////////////////////////////
47bncComb::cmbParam::cmbParam(parType type_, int index_, const QString& ac_, const QString& prn_) {
48
49 type = type_;
50 index = index_;
51 AC = ac_;
52 prn = prn_;
53 xx = 0.0;
54 eph = 0;
55
56 if (type == offACgnss) {
57 epoSpec = true;
58 sig0 = sig0_offAC; // 1000.0
59 sigP = sig0; // 1000.0
60 }
61 else if (type == offACSat) {
62 epoSpec = false;
63 sig0 = sig0_offACSat; // 100.0
64 sigP = sigP_offACSat; // 0.01
65 }
66 // combined clock
67 else if (type == clkSat) {
68 epoSpec = true;
69 sig0 = sig0_clkSat; // 100.0
70 sigP = sigP_clkSat; // 10.0
71
72 }
73
74}
75
76// Destructor
77////////////////////////////////////////////////////////////////////////////
78bncComb::cmbParam::~cmbParam() {
79}
80
81// Partial
82////////////////////////////////////////////////////////////////////////////
83double bncComb::cmbParam::partial(char sys, const QString& AC_, const QString& prn_) {
84
85 if (type == offACgnss) {
86 if (AC == AC_ && prn_[0].toLatin1() == sys) {
87 return 1.0;
88 }
89 }
90 else if (type == offACSat) {
91 if (AC == AC_ && prn == prn_) {
92 return 1.0;
93 }
94 }
95 else if (type == clkSat) {
96 if (prn == prn_) {
97 return 1.0;
98 }
99 }
100
101 return 0.0;
102}
103
104//
105////////////////////////////////////////////////////////////////////////////
106QString bncComb::cmbParam::toString(char sys) const {
107
108 QString outStr;
109
110 if (type == offACgnss) {
111 outStr = "AC Offset " + AC + " " + sys + " ";
112 }
113 else if (type == offACSat) {
114 outStr = "Sat Offset " + AC + " " + prn.mid(0,3);
115 }
116 else if (type == clkSat) {
117 outStr = "Clk Corr " + prn.mid(0,3);
118 }
119
120 return outStr;
121}
122
123// Singleton: definition class variable
124////////////////////////////////////////////////////////////////////////////
125bncComb* bncComb::instance = nullptr;
126
127
128// Constructor
129////////////////////////////////////////////////////////////////////////////
130bncComb::bncComb() : _ephUser(true) {
131
132 bncSettings settings;
133
134 _running = true;
135
136 QStringList cmbStreams = settings.value("cmbStreams").toStringList();
137
138 _cmbSampl = settings.value("cmbSampl").toString().split("sec").first().toInt();
139 if (_cmbSampl <= 0) {
140 _cmbSampl = 5;
141 }
142 _useGps = (Qt::CheckState(settings.value("cmbGps").toInt()) == Qt::Checked) ? true : false;
143 if (_useGps) {
144 _cmbSysPrn['G'] = t_prn::MAXPRN_GPS;
145 _masterMissingEpochs['G'] = 0;
146 }
147 _useGlo = (Qt::CheckState(settings.value("cmbGlo").toInt()) == Qt::Checked) ? true : false;
148 if (_useGlo) {
149 _cmbSysPrn['R'] = t_prn::MAXPRN_GLONASS;
150 _masterMissingEpochs['R'] = 0;
151 }
152 _useGal = (Qt::CheckState(settings.value("cmbGal").toInt()) == Qt::Checked) ? true : false;
153 if (_useGal) {
154 _cmbSysPrn['E'] = t_prn::MAXPRN_GALILEO;
155 _masterMissingEpochs['E'] = 0;
156 }
157 _useBds = (Qt::CheckState(settings.value("cmbBds").toInt()) == Qt::Checked) ? true : false;
158 if (_useBds) {
159 _cmbSysPrn['C'] = t_prn::MAXPRN_BDS;
160 _masterMissingEpochs['C'] = 0;
161 }
162 _useQzss = (Qt::CheckState(settings.value("cmbQzss").toInt()) == Qt::Checked) ? true : false;
163 if (_useQzss) {
164 _cmbSysPrn['J'] = t_prn::MAXPRN_QZSS;
165 _masterMissingEpochs['J'] = 0;
166 }
167 _useSbas = (Qt::CheckState(settings.value("cmbSbas").toInt()) == Qt::Checked) ? true : false;
168 if (_useSbas) {
169 _cmbSysPrn['S'] = t_prn::MAXPRN_SBAS;
170 _masterMissingEpochs['S'] = 0;
171 }
172 _useNavic = (Qt::CheckState(settings.value("cmbNavic").toInt()) == Qt::Checked) ? true : false;
173 if (_useNavic) {
174 _cmbSysPrn['I'] = t_prn::MAXPRN_NavIC;
175 _masterMissingEpochs['I'] = 0;
176 }
177
178 if (cmbStreams.size() >= 1 && !cmbStreams[0].isEmpty()) {
179 QListIterator<QString> it(cmbStreams);
180 while (it.hasNext()) {
181 QStringList hlp = it.next().split(" ");
182 cmbAC* newAC = new cmbAC();
183 newAC->mountPoint = hlp[0];
184 newAC->name = hlp[1];
185 newAC->weightFactor = hlp[2].toDouble();
186 newAC->excludeSats = hlp[3].split(QRegExp("[ ,]"), Qt::SkipEmptyParts);
187 newAC->isAPC = bool(newAC->mountPoint.mid(0,4) == "SSRA");
188 QMapIterator<char, unsigned> itSys(_cmbSysPrn);
189 // init
190 while (itSys.hasNext()) {
191 itSys.next();
192 char sys = itSys.key();
193 if (!_masterOrbitAC.contains(sys) &&
194 !newAC->excludeSats.contains(QString(sys), Qt::CaseSensitive)) {
195 _masterOrbitAC[sys] = newAC->name;
196 _masterIsAPC[sys] = newAC->isAPC;
197 }
198 }
199 _ACs.append(newAC);
200 }
201 }
202
203 QString ssrFormat;
204 _ssrCorr = 0;
205 QListIterator<QString> it(settings.value("uploadMountpointsOut").toStringList());
206 while (it.hasNext()) {
207 QStringList hlp = it.next().split(",");
208 if (hlp.size() > 7) {
209 ssrFormat = hlp[7];
210 }
211 }
212 if (ssrFormat == "IGS-SSR") {
213 _ssrCorr = new SsrCorrIgs();
214 }
215 else if (ssrFormat == "RTCM-SSR") {
216 _ssrCorr = new SsrCorrRtcm();
217 }
218 else if (ssrFormat == "RTCM-NEW-SSR") {
219 _ssrCorr = new SsrCorrRtcmNew();
220 }
221 else { // default
222 _ssrCorr = new SsrCorrIgs();
223 }
224
225 _rtnetDecoder = new bncRtnetDecoder();
226
227 connect(this, SIGNAL(newMessage(QByteArray,bool)), BNC_CORE, SLOT(slotMessage(const QByteArray,bool)));
228 connect(BNC_CORE, SIGNAL(providerIDChanged(QString)), this, SLOT(slotProviderIDChanged(QString)));
229 connect(BNC_CORE, SIGNAL(newOrbCorrections(QList<t_orbCorr>)), this, SLOT(slotNewOrbCorrections(QList<t_orbCorr>)));
230 connect(BNC_CORE, SIGNAL(newClkCorrections(QList<t_clkCorr>)), this, SLOT(slotNewClkCorrections(QList<t_clkCorr>)));
231 connect(BNC_CORE, SIGNAL(newCodeBiases(QList<t_satCodeBias>)), this, SLOT(slotNewCodeBiases(QList<t_satCodeBias>)));
232 connect(BNC_CORE, SIGNAL(newPhaseBiases(QList<t_satPhaseBias>)), this, SLOT(slotNewPhaseBiases(QList<t_satPhaseBias>)));
233
234 // Combination Method
235 // ------------------
236 if (settings.value("cmbMethod").toString() == "Single-Epoch") {
237 _method = singleEpoch;
238 }
239 else {
240 _method = filter;
241 }
242
243 // Initialize Parameters (model: Clk_Corr = AC_Offset + Sat_Offset + Clk)
244 // ----------------------------------------------------------------------
245 if (_method == filter) {
246 // SYSTEM
247 QMapIterator<char, unsigned> itSys(_cmbSysPrn);
248 while (itSys.hasNext()) {
249 itSys.next();
250 int nextPar = 0;
251 char sys = itSys.key();
252 int maxPrn = itSys.value();
253 // AC
254 QListIterator<cmbAC*> itAc(_ACs);
255 while (itAc.hasNext()) {
256 cmbAC* AC = itAc.next();
257 _params[sys].push_back(new cmbParam(cmbParam::offACgnss, ++nextPar, AC->name, ""));
258 for (int iGnss = 1; iGnss <= maxPrn; iGnss++) {
259 int flag = t_corrSSR::getSsrNavTypeFlag(sys, iGnss);
260 QString prn = QString("%1%2_%3").arg(sys).arg(iGnss, 2, 10, QChar('0')).arg(flag);
261 _params[sys].push_back(new cmbParam(cmbParam::offACSat, ++nextPar, AC->name, prn));
262 }
263 }
264 for (int iGnss = 1; iGnss <= maxPrn; iGnss++) {
265 int flag = t_corrSSR::getSsrNavTypeFlag(sys, iGnss);
266 QString prn = QString("%1%2_%3").arg(sys).arg(iGnss, 2, 10, QChar('0')).arg(flag);
267 _params[sys].push_back(new cmbParam(cmbParam::clkSat, ++nextPar, "", prn));
268 }
269 // Initialize Variance-Covariance Matrix
270 // -------------------------------------
271 _QQ[sys].ReSize(_params[sys].size());
272 _QQ[sys] = 0.0;
273 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
274 cmbParam* pp = _params[sys][iPar-1];
275 _QQ[sys](iPar,iPar) = pp->sig0 * pp->sig0;
276 }
277 }
278 }
279
280 // ANTEX File
281 // ----------
282 _antex = 0;
283 QString antexFileName = settings.value("uploadAntexFile").toString();
284 if (!antexFileName.isEmpty()) {
285 _antex = new bncAntex();
286 if (_antex->readFile(antexFileName) != success) {
287 emit newMessage("bncComb: wrong ANTEX file", true);
288 delete _antex;
289 _antex = 0;
290 }
291 }
292
293
294 // Bias SINEX File
295 // ---------------
296 _bsx = 0;
297 QString bsxFileName = settings.value("cmbBsxFile").toString();
298 if (!bsxFileName.isEmpty()) {
299 _bsx = new bncBiasSnx();
300 if (_bsx->readFile(bsxFileName) != success) {
301 emit newMessage("bncComb: wrong Bias SINEX file", true);
302 delete _bsx;
303 _bsx = 0;
304 }
305 }
306 if (_bsx) {
307 _ms = 3.0 * 3600 * 1000.0;
308 QTimer::singleShot(_ms, this, SLOT(slotReadBiasSnxFile()));
309 }
310
311 // Maximal Residuum
312 // ----------------
313 _MAX_RES = settings.value("cmbMaxres").toDouble();
314 if (_MAX_RES <= 0.0) {
315 _MAX_RES = 999.0;
316 }
317
318 // Maximal Displacement
319 // --------------------
320 _MAX_DISPLACEMENT = settings.value("cmbMaxdisplacement").toDouble();
321 if (_MAX_DISPLACEMENT <= 0.0) {
322 _MAX_DISPLACEMENT = 2.0;
323 }
324
325 // Logfile
326 // -------
327 QString intr = "1 day";
328 QString logFileCmb = settings.value("cmbLogpath").toString();
329 int l = logFileCmb.length();
330 if (logFileCmb.isEmpty()) {
331 _logFile = 0;
332 }
333 else {
334 if (l && logFileCmb[l-1] != QDir::separator() ) {
335 logFileCmb += QDir::separator();
336 }
337
338 logFileCmb = logFileCmb + "COMB00BNC" + "${V3PROD}" + ".CMB";
339
340 _logFile = new bncoutf(logFileCmb, intr, _cmbSampl);
341 }
342
343 _newCorr = 0;
344}
345
346// Destructor
347////////////////////////////////////////////////////////////////////////////
348bncComb::~bncComb() {
349
350 _running = false;
351#ifndef WIN32
352 sleep(2);
353#else
354 Sleep(2000);
355#endif
356
357 QListIterator<cmbAC*> icAC(_ACs);
358 while (icAC.hasNext()) {
359 delete icAC.next();
360 }
361 _ACs.clear();
362
363 delete _rtnetDecoder;
364
365 if (_ssrCorr) {
366 delete _ssrCorr;
367 }
368
369 if (_newCorr) {
370 delete _newCorr;
371 }
372
373 delete _antex;
374 delete _bsx;
375 delete _logFile;
376
377 QMapIterator<char, unsigned> itSys(_cmbSysPrn);
378 while (itSys.hasNext()) {
379 itSys.next();
380 char sys = itSys.key();
381 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
382 delete _params[sys][iPar-1];
383 }
384 _buffer.remove(sys);
385 }
386 _params.clear();
387 _buffer.clear();
388 _cmbSysPrn.clear();
389
390 while (!_epoClkData.empty()) {
391 delete _epoClkData.front();
392 _epoClkData.pop_front();
393 }
394}
395
396void bncComb::slotReadBiasSnxFile() {
397 bncSettings settings;
398 QString bsxFileName = settings.value("cmbBsxFile").toString();
399
400 if (bsxFileName.isEmpty()) {
401 emit newMessage("bncComb: no Bias SINEX file specified", true);
402 return;
403 }
404 if (!_bsx) {
405 _bsx = new bncBiasSnx();
406 }
407 if (_bsx->readFile(bsxFileName) != success) {
408 emit newMessage("bncComb: wrong Bias SINEX file", true);
409 delete _bsx;
410 _bsx = 0;
411 }
412 else {
413 emit newMessage("bncComb: successfully read Bias SINEX file", true);
414 }
415
416 QTimer::singleShot(_ms, this, SLOT(slotReadBiasSnxFile()));
417}
418
419
420// Remember orbit corrections
421////////////////////////////////////////////////////////////////////////////
422void bncComb::slotNewOrbCorrections(QList<t_orbCorr> orbCorrections) {
423 QMutexLocker locker(&_mutex);
424 for (int ii = 0; ii < orbCorrections.size(); ii++) {
425 t_orbCorr& orbCorr = orbCorrections[ii];
426 QString staID(orbCorr._staID.c_str());
427 char sys = orbCorr._prn.system();
428
429 if (!_cmbSysPrn.contains(sys)){
430 continue;
431 }
432
433 // Find/Check the AC Name
434 // ----------------------
435 QString acName;
436 QStringList excludeSats;
437 QListIterator<cmbAC*> icAC(_ACs);
438 while (icAC.hasNext()) {
439 cmbAC* AC = icAC.next();
440 if (AC->mountPoint == staID) {
441 acName = AC->name;
442 excludeSats = AC->excludeSats;
443 break;
444 }
445 }
446 if (acName.isEmpty() || excludeSat(orbCorr._prn, excludeSats)) {
447 continue;
448 }
449
450 // Store the correction
451 // --------------------
452 QMap<t_prn, t_orbCorr>& storage = _orbCorrections[acName];
453 storage[orbCorr._prn] = orbCorr;
454 }
455}
456
457// Remember Satellite Code Biases
458////////////////////////////////////////////////////////////////////////////
459void bncComb::slotNewCodeBiases(QList<t_satCodeBias> satCodeBiases) {
460 QMutexLocker locker(&_mutex);
461
462 for (int ii = 0; ii < satCodeBiases.size(); ii++) {
463 t_satCodeBias& satCodeBias = satCodeBiases[ii];
464 QString staID(satCodeBias._staID.c_str());
465 char sys = satCodeBias._prn.system();
466
467 if (!_cmbSysPrn.contains(sys)){
468 continue;
469 }
470
471 // Find/Check the AC Name
472 // ----------------------
473 QString acName;
474 QStringList excludeSats;
475 QListIterator<cmbAC*> icAC(_ACs);
476 while (icAC.hasNext()) {
477 cmbAC* AC = icAC.next();
478 if (AC->mountPoint == staID) {
479 acName = AC->name;
480 excludeSats = AC->excludeSats;
481 break;
482 }
483 }
484 if (acName.isEmpty() || excludeSat(satCodeBias._prn, excludeSats)) {
485 continue;
486 }
487
488 // Store the correction
489 // --------------------
490 QMap<t_prn, t_satCodeBias>& storage = _satCodeBiases[acName];
491 storage[satCodeBias._prn] = satCodeBias;
492 }
493 return;
494}
495
496// Remember Satellite Phase Biases
497////////////////////////////////////////////////////////////////////////////
498void bncComb::slotNewPhaseBiases(QList<t_satPhaseBias> satPhaseBiases) {
499 QMutexLocker locker(&_mutex);
500
501 for (int ii = 0; ii < satPhaseBiases.size(); ii++) {
502 t_satPhaseBias& satPhaseBias = satPhaseBiases[ii];
503 QString staID(satPhaseBias._staID.c_str());
504 char sys = satPhaseBias._prn.system();
505
506 if (!_cmbSysPrn.contains(sys)){
507 continue;
508 }
509
510 // Find/Check the AC Name
511 // ----------------------
512 QString acName;
513 QStringList excludeSats;
514 QListIterator<cmbAC*> icAC(_ACs);
515 while (icAC.hasNext()) {
516 cmbAC* AC = icAC.next();
517 if (AC->mountPoint == staID) {
518 acName = AC->name;
519 excludeSats = AC->excludeSats;
520 break;
521 }
522 }
523 if (acName.isEmpty() || excludeSat(satPhaseBias._prn, excludeSats)) {
524 continue;
525 }
526
527 // Store the correction
528 // --------------------
529 QMap<t_prn, t_satPhaseBias>& storage = _satPhaseBiases[acName];
530 storage[satPhaseBias._prn] = satPhaseBias;
531 }
532 return;
533}
534
535
536// Process clock corrections
537////////////////////////////////////////////////////////////////////////////
538void bncComb::slotNewClkCorrections(QList<t_clkCorr> clkCorrections) {
539 QMutexLocker locker(&_mutex);
540 const double outWait = 1.0 * _cmbSampl;
541 int currentWeek = 0;
542 double currentSec = 0.0;
543 currentGPSWeeks(currentWeek, currentSec);
544 bncTime currentTime(currentWeek, currentSec);
545
546 // Loop over all observations (possible different epochs)
547 // -----------------------------------------------------
548 for (int ii = 0; ii < clkCorrections.size(); ii++) {
549 t_clkCorr& newClk = clkCorrections[ii];
550 char sys = newClk._prn.system();
551 if (!_cmbSysPrn.contains(sys)){
552 continue;
553 }
554
555 // Check Modulo Time
556 // -----------------
557 int sec = int(nint(newClk._time.gpssec()*10));
558 if (sec % (_cmbSampl*10) != 0.0) {
559 continue;
560 }
561
562 // Find/Check the AC Name
563 // ----------------------
564 QString acName;
565 QStringList excludeSats;
566 bool isAPC;
567 QString staID(newClk._staID.c_str());
568 QListIterator<cmbAC*> icAC(_ACs);
569 while (icAC.hasNext()) {
570 cmbAC* AC = icAC.next();
571 if (AC->mountPoint == staID) {
572 acName = AC->name;
573 excludeSats = AC->excludeSats;
574 isAPC = AC->isAPC;
575 break;
576 }
577 }
578 if (acName.isEmpty() ||
579 isAPC != _masterIsAPC[sys] ||
580 excludeSat(newClk._prn, excludeSats)) {
581 continue;
582 }
583
584 // Check regarding current time
585 // ----------------------------
586 if (BNC_CORE->mode() != t_bncCore::batchPostProcessing) {
587 if (fabs(currentTime - newClk._time) > 60.0) { // future or very old data sets
588 #ifdef BNC_DEBUG_CMB
589 emit newMessage("bncComb: future or very old data sets: " + acName.toLatin1() + " " + newClk._prn.toString().c_str() +
590 QString(" %1 ").arg(newClk._time.timestr().c_str()).toLatin1() + "vs. current time" +
591 QString(" %1 ").arg(currentTime.timestr().c_str()).toLatin1(), true);
592 #endif
593 continue;
594 }
595 }
596
597 // Check Correction Age
598 // --------------------
599 if (_resTime.valid() && newClk._time <= _resTime) {
600#ifdef BNC_DEBUG_CMB
601 emit newMessage("bncComb: old correction: " + acName.toLatin1() + " " + newClk._prn.toString().c_str() +
602 QString(" %1 ").arg(newClk._time.timestr().c_str()).toLatin1() + "vs. last processing Epoch" +
603 QString(" %1 ").arg(_resTime.timestr().c_str()).toLatin1(), true);
604#endif
605 continue;
606 }
607
608 // Set the last time
609 // -----------------
610 if (_lastClkCorrTime.undef() || newClk._time > _lastClkCorrTime) {
611 _lastClkCorrTime = newClk._time;
612 }
613
614 // Find the corresponding data epoch or create a new one
615 // -----------------------------------------------------
616 epoClkData* epoch = 0;
617 deque<epoClkData*>::const_iterator it;
618 for (it = _epoClkData.begin(); it != _epoClkData.end(); it++) {
619 if (newClk._time == (*it)->_time) {
620 epoch = *it;
621 break;
622 }
623 }
624 if (epoch == 0) {
625 if (_epoClkData.empty() || newClk._time > _epoClkData.back()->_time) {
626 epoch = new epoClkData;
627 epoch->_time = newClk._time;
628 _epoClkData.push_back(epoch);
629 }
630 }
631
632 // Put data into the epoch
633 // -----------------------
634 if (epoch != 0) {
635 epoch->_clkCorr.push_back(newClk);
636 }
637 }
638
639 // Make sure the buffer does not grow beyond any limit
640 // ---------------------------------------------------
641 const unsigned MAX_EPODATA_SIZE = 60.0 / _cmbSampl;
642 if (_epoClkData.size() > MAX_EPODATA_SIZE) {
643 delete _epoClkData.front();
644 _epoClkData.pop_front();
645 }
646
647 // Process the oldest epochs
648 // ------------------------
649 while (_epoClkData.size()) {
650
651 if (!_lastClkCorrTime.valid()) {
652 return;
653 }
654
655 const vector<t_clkCorr>& clkCorrVec = _epoClkData.front()->_clkCorr;
656
657 bncTime epoTime = _epoClkData.front()->_time;
658
659 if (BNC_CORE->mode() != t_bncCore::batchPostProcessing) {
660 if ((currentTime - epoTime) > 60.0) {
661 delete _epoClkData.front();
662 _epoClkData.pop_front();
663 continue;
664 }
665 }
666 // Process the front epoch
667 // -----------------------
668 if (epoTime < (_lastClkCorrTime - outWait)) {
669 _resTime = epoTime;
670 processEpoch(_resTime, clkCorrVec);
671 delete _epoClkData.front();
672 _epoClkData.pop_front();
673 }
674 else {
675 return;
676 }
677 }
678}
679
680// Change the correction so that it refers to last received ephemeris
681////////////////////////////////////////////////////////////////////////////
682void bncComb::switchToLastEph(t_eph* lastEph, cmbCorr* corr) {
683
684 if (corr->_eph == lastEph) {
685 return;
686 }
687
688 ColumnVector oldXC(6);
689 ColumnVector oldVV(3);
690 if (corr->_eph->getCrd(corr->_time, oldXC, oldVV, false) != success) {
691 return;
692 }
693
694 ColumnVector newXC(6);
695 ColumnVector newVV(3);
696 if (lastEph->getCrd(corr->_time, newXC, newVV, false) != success) {
697 return;
698 }
699
700 ColumnVector dX = newXC.Rows(1,3) - oldXC.Rows(1,3);
701 ColumnVector dV = newVV - oldVV;
702 double dC = newXC(4) - oldXC(4);
703
704 ColumnVector dRAO(3);
705 XYZ_to_RSW(newXC.Rows(1,3), newVV, dX, dRAO);
706
707 ColumnVector dDotRAO(3);
708 XYZ_to_RSW(newXC.Rows(1,3), newVV, dV, dDotRAO);
709
710 QString msg = "bncComb: switch corr " + corr->_prn.mid(0,3)
711 + QString(" %1 -> %2 %3").arg(corr->_iod,3).arg(lastEph->IOD(),3).arg(dC*t_CST::c, 8, 'f', 4);
712
713 emit newMessage(msg.toLatin1(), false);
714
715 corr->_iod = lastEph->IOD();
716 corr->_eph = lastEph;
717
718 corr->_orbCorr._xr += dRAO;
719 corr->_orbCorr._dotXr += dDotRAO;
720 corr->_clkCorr._dClk -= dC;
721}
722
723// Process Epoch
724////////////////////////////////////////////////////////////////////////////
725void bncComb::processEpoch(bncTime epoTime, const vector<t_clkCorr>& clkCorrVec) {
726 QDateTime now = currentDateAndTimeGPS();
727 bncTime currentTime(now.toString(Qt::ISODate).toStdString());
728 for (unsigned ii = 0; ii < clkCorrVec.size(); ii++) {
729 const t_clkCorr& clkCorr = clkCorrVec[ii];
730 QString staID(clkCorr._staID.c_str());
731 QString prnStr(clkCorr._prn.toInternalString().c_str());
732 char sys = clkCorr._prn.system();
733
734 // Find/Check the AC Name
735 // ----------------------
736 QString acName;
737 double weigthFactor;
738 QListIterator<cmbAC*> icAC(_ACs);
739 while (icAC.hasNext()) {
740 cmbAC* AC = icAC.next();
741 if (AC->mountPoint == staID) {
742 acName = AC->name;
743 weigthFactor = AC->weightFactor;
744 break;
745 }
746 }
747
748 // Create new correction
749 // ---------------------
750 _newCorr = new cmbCorr();
751 _newCorr->_prn = prnStr;
752 _newCorr->_time = clkCorr._time;
753 _newCorr->_iod = clkCorr._iod;
754 _newCorr->_acName = acName;
755 _newCorr->_weightFactor = weigthFactor;
756 _newCorr->_clkCorr = clkCorr;
757
758 // Check orbit correction
759 // ----------------------
760 if (!_orbCorrections.contains(acName)) {
761 delete _newCorr; _newCorr = 0;
762 continue;
763 }
764 else {
765 QMap<t_prn, t_orbCorr>& storage = _orbCorrections[acName];
766 if (!storage.contains(clkCorr._prn) ||
767 storage[clkCorr._prn]._iod != _newCorr->_iod) {
768 delete _newCorr; _newCorr = 0;
769 continue;
770 }
771 else {
772 _newCorr->_orbCorr = storage[clkCorr._prn];
773 }
774 }
775
776 // Check the Ephemeris
777 //--------------------
778 t_eph* ephLast = _ephUser.ephLast(prnStr);
779 t_eph* ephPrev = _ephUser.ephPrev(prnStr);
780 if (ephLast == 0) {
781#ifdef BNC_DEBUG_CMB
782 emit newMessage("bncComb: eph not found for " + prnStr.mid(0,3).toLatin1(), true);
783#endif
784 delete _newCorr; _newCorr = 0;
785 continue;
786 }
787 else if (outDatedBcep(ephLast, currentTime) ||
788 ephLast->checkState() == t_eph::bad ||
789 ephLast->checkState() == t_eph::outdated ||
790 ephLast->checkState() == t_eph::unhealthy) {
791#ifdef BNC_DEBUG_CMB
792 emit newMessage("bncComb: ephLast not ok (checkState: " + ephLast->checkStateToString().toLatin1() + ") for " + prnStr.mid(0,3).toLatin1(), true);
793#endif
794 delete _newCorr; _newCorr = 0;
795 continue;
796 }
797 else {
798 if (ephLast->IOD() == _newCorr->_iod) {
799 _newCorr->_eph = ephLast;
800 }
801 else if (ephPrev &&
802 !outDatedBcep(ephPrev, currentTime) && // if not updated in storage
803 ephPrev->checkState() == t_eph::ok && // received
804 ephPrev->IOD() == _newCorr->_iod) {
805 _newCorr->_eph = ephPrev;
806 switchToLastEph(ephLast, _newCorr);
807 }
808 else {
809#ifdef BNC_DEBUG_CMB
810 emit newMessage("bncComb: eph not found for " + prnStr.mid(0,3).toLatin1() +
811 QString(" with IOD %1").arg(_newCorr->_iod).toLatin1(), true);
812#endif
813 delete _newCorr; _newCorr = 0;
814 continue;
815 }
816 }
817
818 // Check satellite code biases
819 // ----------------------------
820 if (_satCodeBiases.contains(acName)) {
821 QMap<t_prn, t_satCodeBias>& storage = _satCodeBiases[acName];
822 if (storage.contains(clkCorr._prn)) {
823 _newCorr->_satCodeBias = storage[clkCorr._prn];
824 QMap<t_frequency::type, double> codeBiasesRefSig;
825 for (unsigned ii = 1; ii < cmbRefSig::cIF; ii++) {
826 t_frequency::type frqType = cmbRefSig::toFreq(sys, static_cast<cmbRefSig::type>(ii));
827 char frqNum = t_frequency::toString(frqType)[1];
828 char attrib = cmbRefSig::toAttrib(sys, static_cast<cmbRefSig::type>(ii));
829 QString rnxType2ch = QString("%1%2").arg(frqNum).arg(attrib);
830 for (unsigned ii = 0; ii < _newCorr->_satCodeBias._bias.size(); ii++) {
831 const t_frqCodeBias& bias = _newCorr->_satCodeBias._bias[ii];
832 if (rnxType2ch.toStdString() == bias._rnxType2ch) {
833 codeBiasesRefSig[frqType] = bias._value;
834 }
835 }
836 }
837 map<t_frequency::type, double> codeCoeff;
838 double channel = double(_newCorr->_eph->slotNum());
839 cmbRefSig::coeff(sys, cmbRefSig::cIF, channel, codeCoeff);
840 map<t_frequency::type, double>::const_iterator it;
841 for (it = codeCoeff.begin(); it != codeCoeff.end(); it++) {
842 t_frequency::type frqType = it->first;
843 double codeCoeff = it->second;
844 _newCorr->_satCodeBiasIF += codeCoeff * codeBiasesRefSig[frqType];
845 }
846 _newCorr->_satCodeBias._bias.clear();
847 }
848 }
849
850 // Check satellite phase biases
851 // ----------------------------
852 if (_satPhaseBiases.contains(acName)) {
853 QMap<t_prn, t_satPhaseBias>& storage = _satPhaseBiases[acName];
854 if (storage.contains(clkCorr._prn)) {
855 // Yaw angle
856 t_satPhaseBias& pb = storage[clkCorr._prn];
857 double dt = _newCorr->_time - pb._time;
858 if (pb._updateInt) {
859 dt -= (0.5 * ssrUpdateInt[pb._updateInt]);
860 }
861 _newCorr->_satYawAngle = pb._yaw + pb._yawRate * dt;
862
863 // _lambdaIF
864 map<t_frequency::type, double> codeCoeff;
865 double channel = double(_newCorr->_eph->slotNum());
866 cmbRefSig::coeff(sys, cmbRefSig::cIF, channel, codeCoeff);
867 map<t_frequency::type, double>::const_iterator it;
868 for (it = codeCoeff.begin(); it != codeCoeff.end(); it++) {
869 t_frequency::type frqType = it->first;
870 double codeCoeff = it->second;
871 _newCorr->_lambdaIF += codeCoeff * t_CST::c / t_CST::freq(frqType, channel);
872 }
873 }
874 }
875
876 // Store correction into the buffer
877 // --------------------------------
878 QVector<cmbCorr*>& corrs = _buffer[sys].corrs;
879 QVectorIterator<cmbCorr*> itCorr(corrs);
880 bool available = false;
881 while (itCorr.hasNext()) {
882 cmbCorr* corr = itCorr.next();
883 QString prnStr = corr->_prn;
884 QString acName = corr->_acName;
885 if (_newCorr->_acName == acName &&
886 _newCorr->_prn == prnStr) {
887 available = true;
888 }
889 }
890
891 if (!available) {
892 corrs.push_back(_newCorr); _newCorr = 0;
893 }
894 else {
895 delete _newCorr; _newCorr = 0;
896 continue;
897 }
898 }
899
900 // Process Systems of this Epoch
901 // ------------------------------
902 QMapIterator<char, unsigned> itSys(_cmbSysPrn);
903 while (itSys.hasNext()) {
904 itSys.next();
905 char sys = itSys.key();
906 _log.clear();
907 QTextStream out(&_log, QIODevice::WriteOnly);
908 processSystem(epoTime, sys, out);
909 _buffer.remove(sys);
910 if (_logFile) {
911 _logFile->write(epoTime.gpsw(),epoTime.gpssec(), QString(_log));
912 }
913 }
914}
915
916void bncComb::processSystem(bncTime epoTime, char sys, QTextStream& out) {
917
918 out << "\n"
919 << epoTime.datestr().c_str() << " "
920 << epoTime.timestr().c_str() << " "
921 << "Combination: " << sys << "\n"
922 << "--------------------------------------" << "\n";
923
924 // Observation Statistics
925 // ----------------------
926 bool masterPresent = false;
927 QListIterator<cmbAC*> icAC(_ACs);
928 while (icAC.hasNext()) {
929 cmbAC* AC = icAC.next();
930 AC->numObs[sys] = 0;
931 QVectorIterator<cmbCorr*> itCorr(corrs(sys));
932 while (itCorr.hasNext()) {
933 cmbCorr* corr = itCorr.next();
934 if (corr->_acName == AC->name) {
935 AC->numObs[sys] += 1;
936 if (AC->name == _masterOrbitAC[sys]) {
937 masterPresent = true;
938 }
939 }
940 }
941 out << epoTime.datestr().c_str() << " "
942 << epoTime.timestr().c_str() << " "
943 << "Sat Num " << sys << " "
944 << AC->name.toLatin1().data() << ": " << AC->numObs[sys] << "\n";
945 }
946
947 // If Master not present, switch to another one
948 // --------------------------------------------
949 const unsigned switchMasterAfterGap = 1;
950 if (masterPresent) {
951 _masterMissingEpochs[sys] = 0;
952 }
953 else {
954 ++_masterMissingEpochs[sys];
955 if (_masterMissingEpochs[sys] < switchMasterAfterGap) {
956 out << "Missing Master, Epoch skipped" << "\n";
957 _buffer.remove(sys);
958 emit newMessage(_log, false);
959 return;
960 }
961 else {
962 _masterMissingEpochs[sys] = 0;
963 QListIterator<cmbAC*> icAC(_ACs);
964 while (icAC.hasNext()) {
965 cmbAC* AC = icAC.next();
966 if (AC->numObs[sys] > 0) {
967 out << epoTime.datestr().c_str() << " "
968 << epoTime.timestr().c_str() << " "
969 << "Switching Master " << sys << " "
970 << _masterOrbitAC[sys].toLatin1().data() << " --> "
971 << AC->name.toLatin1().data() << "\n";
972 _masterOrbitAC[sys] = AC->name;
973 _masterIsAPC[sys] = AC->isAPC;
974 break;
975 }
976 }
977 }
978 }
979
980 QMap<QString, cmbCorr*> masterCorr;
981
982 // Perform the actual Combination using selected Method
983 // ----------------------------------------------------
984 t_irc irc;
985 ColumnVector dx;
986 if (_method == filter) {
987 irc = processEpoch_filter(epoTime, sys, out, masterCorr, dx);
988 }
989 else {
990 irc = processEpoch_singleEpoch(epoTime, sys, out, masterCorr, dx);
991 }
992
993 // Update Parameter Values, Print Results
994 // --------------------------------------
995 if (irc == success) {
996 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
997 cmbParam* pp = _params[sys][iPar-1];
998 pp->xx += dx(iPar);
999 if (pp->type == cmbParam::clkSat) {
1000 if (masterCorr.find(pp->prn) != masterCorr.end()) {
1001 // set clock result
1002 masterCorr[pp->prn]->_dClkResult = pp->xx / t_CST::c;
1003 // Add Code Biases from SINEX File
1004 if (_bsx) {
1005 map<t_frequency::type, double> codeCoeff;
1006 double channel = double(masterCorr[pp->prn]->_eph->slotNum());
1007 cmbRefSig::coeff(sys, cmbRefSig::cIF, channel, codeCoeff);
1008 t_frequency::type fType1 = cmbRefSig::toFreq(sys, cmbRefSig::c1);
1009 t_frequency::type fType2 = cmbRefSig::toFreq(sys, cmbRefSig::c2);
1010 _bsx->determineSsrSatCodeBiases(pp->prn.mid(0,3), codeCoeff[fType1], codeCoeff[fType2], masterCorr[pp->prn]->_satCodeBias);
1011 }
1012 }
1013 }
1014 out << epoTime.datestr().c_str() << " "
1015 << epoTime.timestr().c_str() << " ";
1016 out.setRealNumberNotation(QTextStream::FixedNotation);
1017 out.setFieldWidth(8);
1018 out.setRealNumberPrecision(4);
1019 out << pp->toString(sys) << " "
1020 << pp->xx << " +- " << sqrt(_QQ[sys](pp->index,pp->index)) << "\n";
1021 out.setFieldWidth(0);
1022 out.flush();
1023 }
1024 printResults(epoTime, out, masterCorr);
1025 dumpResults(epoTime, masterCorr);
1026 }
1027}
1028
1029// Process Epoch - Filter Method
1030////////////////////////////////////////////////////////////////////////////
1031t_irc bncComb::processEpoch_filter(bncTime epoTime, char sys, QTextStream& out,
1032 QMap<QString, cmbCorr*>& masterCorr,
1033 ColumnVector& dx) {
1034
1035 // Prediction Step
1036 // ---------------
1037 int nPar = _params[sys].size();
1038 ColumnVector x0(nPar);
1039 for (int iPar = 1; iPar <= nPar; iPar++) {
1040 cmbParam* pp = _params[sys][iPar-1];
1041 if (pp->epoSpec) {
1042 pp->xx = 0.0;
1043 _QQ[sys].Row(iPar) = 0.0;
1044 _QQ[sys].Column(iPar) = 0.0;
1045 _QQ[sys](iPar,iPar) = pp->sig0 * pp->sig0;
1046 }
1047 else {
1048 _QQ[sys](iPar,iPar) += pp->sigP * pp->sigP;
1049 }
1050 x0(iPar) = pp->xx;
1051 }
1052
1053 // Check Satellite Positions for Outliers
1054 // --------------------------------------
1055 if (checkOrbits(epoTime, sys, out, masterCorr) != success) {
1056 return failure;
1057 }
1058
1059 // Update and outlier detection loop
1060 // ---------------------------------
1061 SymmetricMatrix QQ_sav = _QQ[sys];
1062 while (_running) {
1063
1064 Matrix AA;
1065 ColumnVector ll;
1066 DiagonalMatrix PP;
1067
1068 if (createAmat(sys, AA, ll, PP, x0, masterCorr) != success) {
1069 return failure;
1070 }
1071
1072 dx.ReSize(nPar); dx = 0.0;
1073 kalman(AA, ll, PP, _QQ[sys], dx);
1074
1075 ColumnVector vv = ll - AA * dx;
1076
1077 int maxResIndex;
1078 double maxRes = vv.maximum_absolute_value1(maxResIndex);
1079 out.setRealNumberNotation(QTextStream::FixedNotation);
1080 out.setRealNumberPrecision(3);
1081 out << epoTime.datestr().c_str() << " " << epoTime.timestr().c_str()
1082 << " Maximum Residuum " << maxRes << ' '
1083 << corrs(sys)[maxResIndex-1]->_acName << ' ' << corrs(sys)[maxResIndex-1]->_prn.mid(0,3);
1084 if (maxRes > _MAX_RES) {
1085 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
1086 cmbParam* pp = _params[sys][iPar-1];
1087 if (pp->type == cmbParam::offACSat &&
1088 pp->AC == corrs(sys)[maxResIndex-1]->_acName &&
1089 pp->prn == corrs(sys)[maxResIndex-1]->_prn.mid(0,3)) {
1090 QQ_sav.Row(iPar) = 0.0;
1091 QQ_sav.Column(iPar) = 0.0;
1092 QQ_sav(iPar,iPar) = pp->sig0 * pp->sig0;
1093 }
1094 }
1095
1096 out << " Outlier" << "\n";
1097 _QQ[sys] = QQ_sav;
1098 delete corrs(sys)[maxResIndex-1];
1099 corrs(sys).remove(maxResIndex-1);
1100 }
1101 else {
1102 out << " OK" << "\n";
1103 out.setRealNumberNotation(QTextStream::FixedNotation);
1104 out.setRealNumberPrecision(4);
1105 for (int ii = 0; ii < corrs(sys).size(); ii++) {
1106 const cmbCorr* corr = corrs(sys)[ii];
1107 out << epoTime.datestr().c_str() << ' '
1108 << epoTime.timestr().c_str() << " "
1109 << corr->_acName << ' ' << corr->_prn.mid(0,3);
1110 out.setFieldWidth(10);
1111 out << " res = " << vv[ii] << "\n";
1112 out.setFieldWidth(0);
1113 }
1114 break;
1115 }
1116 }
1117
1118 return success;
1119}
1120
1121// Print results
1122////////////////////////////////////////////////////////////////////////////
1123void bncComb::printResults(bncTime epoTime, QTextStream& out,
1124 const QMap<QString, cmbCorr*>& masterCorr) {
1125
1126 QMapIterator<QString, cmbCorr*> it(masterCorr);
1127 while (it.hasNext()) {
1128 it.next();
1129 cmbCorr* corr = it.value();
1130 const t_eph* eph = corr->_eph;
1131 if (eph) {
1132 ColumnVector xc(6);
1133 ColumnVector vv(3);
1134 if (eph->getCrd(epoTime, xc, vv, false) != success) {
1135 continue;
1136 }
1137 out << epoTime.datestr().c_str() << " "
1138 << epoTime.timestr().c_str() << " ";
1139 out.setFieldWidth(3);
1140 out << "Full Clock " << corr->_prn.mid(0,3) << " " << corr->_iod << " ";
1141 out.setFieldWidth(14);
1142 out << (xc(4) + corr->_dClkResult) * t_CST::c << "\n";
1143 out.setFieldWidth(0);
1144 out.flush();
1145 }
1146 else {
1147 out << "bncComb::printResults bug" << "\n";
1148 }
1149 }
1150}
1151
1152// Send results to RTNet Decoder and directly to PPP Client
1153////////////////////////////////////////////////////////////////////////////
1154void bncComb::dumpResults(bncTime epoTime, QMap<QString, cmbCorr*>& masterCorr) {
1155
1156 QList<t_orbCorr> orbCorrections;
1157 QList<t_clkCorr> clkCorrections;
1158 QList<t_satCodeBias> satCodeBiasList;
1159 QList<t_satPhaseBias> satPhaseBiasList;
1160
1161 unsigned year, month, day, hour, minute;
1162 double sec;
1163 epoTime.civil_date(year, month, day);
1164 epoTime.civil_time(hour, minute, sec);
1165
1166 QString outLines = QString().asprintf("* %4d %2d %2d %d %d %12.8f\n",
1167 year, month, day, hour, minute, sec);
1168
1169 QMutableMapIterator<QString, cmbCorr*> it(masterCorr);
1170 while (it.hasNext()) {
1171 it.next();
1172 cmbCorr* corr = it.value();
1173
1174 // ORBIT
1175 t_orbCorr orbCorr(corr->_orbCorr);
1176 orbCorr._staID = "INTERNAL";
1177 orbCorrections.push_back(orbCorr);
1178
1179 // CLOCK
1180 t_clkCorr clkCorr(corr->_clkCorr);
1181 clkCorr._staID = "INTERNAL";
1182 clkCorr._dClk = corr->_dClkResult;
1183 clkCorr._dotDClk = 0.0;
1184 clkCorr._dotDotDClk = 0.0;
1185 clkCorrections.push_back(clkCorr);
1186
1187 ColumnVector xc(6);
1188 ColumnVector vv(3);
1189 corr->_eph->setClkCorr(dynamic_cast<const t_clkCorr*>(&clkCorr));
1190 corr->_eph->setOrbCorr(dynamic_cast<const t_orbCorr*>(&orbCorr));
1191 if (corr->_eph->getCrd(epoTime, xc, vv, true) != success) {
1192 delete corr;
1193 it.remove();
1194 continue;
1195 }
1196
1197 // Correction Phase Center --> CoM
1198 // -------------------------------
1199 ColumnVector dx(3); dx = 0.0;
1200 ColumnVector apc(3); apc = 0.0;
1201 ColumnVector com(3); com = 0.0;
1202 bool masterIsAPC = true;
1203 if (_antex) {
1204 double Mjd = epoTime.mjd() + epoTime.daysec()/86400.0;
1205 char sys = corr->_eph->prn().system();
1206 masterIsAPC = _masterIsAPC[sys];
1207 if (_antex->satCoMcorrection(corr->_prn, Mjd, xc.Rows(1,3), dx) != success) {
1208 dx = 0;
1209 _log += "antenna not found " + corr->_prn.mid(0,3).toLatin1() + '\n';
1210 }
1211 }
1212 if (masterIsAPC) {
1213 apc(1) = xc(1);
1214 apc(2) = xc(2);
1215 apc(3) = xc(3);
1216 com(1) = xc(1)-dx(1);
1217 com(2) = xc(2)-dx(2);
1218 com(3) = xc(3)-dx(3);
1219 }
1220 else {
1221 com(1) = xc(1);
1222 com(2) = xc(2);
1223 com(3) = xc(3);
1224 apc(1) = xc(1)+dx(1);
1225 apc(2) = xc(2)+dx(2);
1226 apc(3) = xc(3)+dx(3);
1227 }
1228
1229 outLines += corr->_prn.mid(0,3);
1230 QString hlp = QString().asprintf(
1231 " APC 3 %15.4f %15.4f %15.4f"
1232 " Clk 1 %15.4f"
1233 " Vel 3 %15.4f %15.4f %15.4f"
1234 " CoM 3 %15.4f %15.4f %15.4f",
1235 apc(1), apc(2), apc(3),
1236 xc(4) * t_CST::c,
1237 vv(1), vv(2), vv(3),
1238 com(1), com(2), com(3));
1239 outLines += hlp;
1240 hlp.clear();
1241
1242 // CODE BIASES
1243 if (corr->_satCodeBias._bias.size()) {
1244 t_satCodeBias satCodeBias(corr->_satCodeBias);
1245 satCodeBias._staID = "INTERNAL";
1246 satCodeBiasList.push_back(satCodeBias);
1247 hlp = QString().asprintf(" CodeBias %2lu", satCodeBias._bias.size());
1248 outLines += hlp;
1249 hlp.clear();
1250 for (unsigned ii = 0; ii < satCodeBias._bias.size(); ii++) {
1251 const t_frqCodeBias& frqCodeBias = satCodeBias._bias[ii];
1252 if (!frqCodeBias._rnxType2ch.empty()) {
1253 hlp = QString().asprintf(" %s%12.6f",
1254 frqCodeBias._rnxType2ch.c_str(),
1255 frqCodeBias._value);
1256 outLines += hlp;
1257 hlp.clear();
1258 }
1259 }
1260 }
1261 // PHASE BIASES
1262 /* can be added as soon as yaw agles from the ACs have useful values
1263 t_satPhaseBias satPhaseBias(corr->_satPhaseBias);
1264 satPhaseBias._staID = "INTERNAL";
1265 satPhaseBias._yaw = corr->_satYawAngle;
1266 satPhaseBiasList.push_back(satPhaseBias);
1267 hlp = QString().asprintf(" YawAngle %1.4f", satPhaseBias._yaw);
1268 outLines += hlp;
1269 hlp.clear();
1270 hlp = QString().asprintf(" PhaseBias %2lu", satPhaseBias._bias.size());
1271 outLines += hlp;
1272 hlp.clear();
1273 for (unsigned ii = 0; ii < satPhaseBias._bias.size(); ii++) {
1274 const t_frqPhaseBias& frqPhaseBias = satPhaseBias._bias[ii];
1275 if (!frqPhaseBias._rnxType2ch.empty()) {
1276 hlp = QString().asprintf(" %s%10.6f%3d%3d%3d",
1277 frqPhaseBias._rnxType2ch.c_str(),
1278 frqPhaseBias._value,
1279 frqPhaseBias._fixIndicator,
1280 frqPhaseBias._fixWideLaneIndicator,
1281 frqPhaseBias._jumpCounter);
1282 outLines += hlp;
1283 hlp.clear();
1284 }
1285 }*/
1286 outLines += "\n";
1287 delete corr;
1288 it.remove();
1289 }
1290 outLines += "EOE\n"; // End Of Epoch flag
1291 //cout << outLines.toStdString();
1292
1293 vector<string> errmsg;
1294 _rtnetDecoder->Decode(outLines.toLatin1().data(), outLines.length(), errmsg);
1295
1296 // Send new Corrections to PPP etc.
1297 // --------------------------------
1298 if (orbCorrections.size() > 0 && clkCorrections.size() > 0) {
1299 emit newOrbCorrections(orbCorrections);
1300 emit newClkCorrections(clkCorrections);
1301 }
1302 if (satCodeBiasList.size()) {
1303 emit newCodeBiases(satCodeBiasList);
1304 }
1305}
1306
1307// Create First Design Matrix and Vector of Measurements
1308////////////////////////////////////////////////////////////////////////////
1309t_irc bncComb::createAmat(char sys, Matrix& AA, ColumnVector& ll, DiagonalMatrix& PP, const ColumnVector& x0, const QMap<QString, cmbCorr*>& masterCorr) {
1310
1311 unsigned nPar = _params[sys].size();
1312 unsigned nObs = corrs(sys).size();
1313
1314 if (nObs == 0) {
1315 return failure;
1316 }
1317
1318 int maxSat = _cmbSysPrn[sys];
1319
1320 const int nCon = (_method == filter) ? 1 + maxSat : 0;
1321
1322 AA.ReSize(nObs+nCon, nPar); AA = 0.0;
1323 ll.ReSize(nObs+nCon); ll = 0.0;
1324 PP.ReSize(nObs+nCon); PP = 1.0 / (sigObs * sigObs);
1325
1326 int iObs = 0;
1327 QVectorIterator<cmbCorr*> itCorr(corrs(sys));
1328 while (itCorr.hasNext()) {
1329 cmbCorr* corr = itCorr.next();
1330 QString prn = corr->_prn;
1331
1332 ++iObs;
1333
1334 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
1335 cmbParam* pp = _params[sys][iPar-1];
1336 AA(iObs, iPar) = pp->partial(sys, corr->_acName, prn);
1337 }
1338 // Consistency corrections to keep the combined clock consistent to masterOrbit
1339 // ----------------------------------------------------------------------------
1340 double dC_orb = DotProduct((corr->_satPos - masterCorr[prn]->_satPos), corr->_satPos);
1341 dC_orb /= masterCorr[prn]->_satPos.NormFrobenius();
1342 double dC_att = (corr->_satYawAngle - masterCorr[prn]->_satYawAngle) / (2 * M_PI);
1343 dC_att *= corr->_lambdaIF;
1344 double dC_apriori_corr = dC_orb;// + dC_att; can be added if useful values are provided by the ACs
1345
1346 ll(iObs) = ((corr->_clkCorr._dClk * t_CST::c) - dC_apriori_corr - corr->_satCodeBiasIF) - DotProduct(AA.Row(iObs), x0);
1347
1348 PP(iObs, iObs) *= 1.0 / (corr->_weightFactor * corr->_weightFactor);
1349 }
1350
1351 // Regularization
1352 // --------------
1353 if (_method == filter) {
1354 const double Ph = 1.e6;
1355 PP(nObs+1) = Ph;
1356 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
1357 cmbParam* pp = _params[sys][iPar-1];
1358 if ( AA.Column(iPar).maximum_absolute_value() > 0.0 &&
1359 pp->type == cmbParam::clkSat ) {
1360 AA(nObs+1, iPar) = 1.0;
1361 }
1362 }
1363
1364 int iCond = 1;
1365 // GNSS
1366 for (unsigned iGnss = 1; iGnss <= _cmbSysPrn[sys]; iGnss++) {
1367 int flag = t_corrSSR::getSsrNavTypeFlag(sys, iGnss);
1368 QString prn = QString("%1%2_%3").arg(sys).arg(iGnss, 2, 10, QChar('0')).arg(flag);
1369 ++iCond;
1370 PP(nObs+iCond) = Ph;
1371 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
1372 cmbParam* pp = _params[sys][iPar-1];
1373 if ( pp &&
1374 AA.Column(iPar).maximum_absolute_value() > 0.0 &&
1375 pp->type == cmbParam::offACSat &&
1376 pp->prn == prn) {
1377 AA(nObs+iCond, iPar) = 1.0;
1378 }
1379 }
1380 }
1381 }
1382
1383 return success;
1384}
1385
1386// Process Epoch - Single-Epoch Method
1387////////////////////////////////////////////////////////////////////////////
1388t_irc bncComb::processEpoch_singleEpoch(bncTime epoTime, char sys, QTextStream& out,
1389 QMap<QString, cmbCorr*>& masterCorr,
1390 ColumnVector& dx) {
1391
1392 // Check Satellite Positions for Outliers
1393 // --------------------------------------
1394 if (checkOrbits(epoTime, sys, out, masterCorr) != success) {
1395 return failure;
1396 }
1397
1398 // Outlier Detection Loop
1399 // ----------------------
1400 while (_running) {
1401 // Count Number of Observations per Satellite and per AC
1402 // -----------------------------------------------------
1403 QMap<QString, int> numObsPrn;
1404 QMap<QString, int> numObsAC;
1405 QVectorIterator<cmbCorr*> itCorr(corrs(sys));
1406 while (itCorr.hasNext()) {
1407 cmbCorr* corr = itCorr.next();
1408 QString prn = corr->_prn;
1409 QString AC = corr->_acName;
1410 if (numObsPrn.find(prn) == numObsPrn.end()) {
1411 numObsPrn[prn] = 1;
1412 }
1413 else {
1414 numObsPrn[prn] += 1;
1415 }
1416 if (numObsAC.find(AC) == numObsAC.end()) {
1417 numObsAC[AC] = 1;
1418 }
1419 else {
1420 numObsAC[AC] += 1;
1421 }
1422 }
1423
1424 // Clean-Up the Parameters
1425 // -----------------------
1426 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
1427 delete _params[sys][iPar-1];
1428 }
1429 _params[sys].clear();
1430
1431 // Set new Parameters
1432 // ------------------
1433 int nextPar = 0;
1434
1435 QMapIterator<QString, int> itAC(numObsAC);
1436 while (itAC.hasNext()) {
1437 itAC.next();
1438 const QString& AC = itAC.key();
1439 int numObs = itAC.value();
1440 if (AC != _masterOrbitAC[sys] && numObs > 0) {
1441 _params[sys].push_back(new cmbParam(cmbParam::offACgnss, ++nextPar, AC, ""));
1442 }
1443 }
1444
1445 QMapIterator<QString, int> itPrn(numObsPrn);
1446 while (itPrn.hasNext()) {
1447 itPrn.next();
1448 const QString& prn = itPrn.key();
1449 int numObs = itPrn.value();
1450 if (numObs > 0) {
1451 _params[sys].push_back(new cmbParam(cmbParam::clkSat, ++nextPar, "", prn));
1452 }
1453 }
1454
1455 int nPar = _params[sys].size();
1456 ColumnVector x0(nPar);
1457 x0 = 0.0;
1458
1459 // Create First-Design Matrix
1460 // --------------------------
1461 Matrix AA;
1462 ColumnVector ll;
1463 DiagonalMatrix PP;
1464 if (createAmat(sys, AA, ll, PP, x0, masterCorr) != success) {
1465 return failure;
1466 }
1467
1468 ColumnVector vv;
1469 try {
1470 Matrix ATP = AA.t() * PP;
1471 SymmetricMatrix NN; NN << ATP * AA;
1472 ColumnVector bb = ATP * ll;
1473 _QQ[sys] = NN.i();
1474 dx = _QQ[sys] * bb;
1475 vv = ll - AA * dx;
1476 }
1477 catch (Exception& exc) {
1478 out << exc.what() << "\n";
1479 return failure;
1480 }
1481
1482 int maxResIndex;
1483 double maxRes = vv.maximum_absolute_value1(maxResIndex);
1484 out.setRealNumberNotation(QTextStream::FixedNotation);
1485 out.setRealNumberPrecision(3);
1486 out << epoTime.datestr().c_str() << " " << epoTime.timestr().c_str()
1487 << " Maximum Residuum " << maxRes << ' '
1488 << corrs(sys)[maxResIndex-1]->_acName << ' ' << corrs(sys)[maxResIndex-1]->_prn.mid(0,3);
1489
1490 if (maxRes > _MAX_RES) {
1491 out << " Outlier" << "\n";
1492 delete corrs(sys)[maxResIndex-1];
1493 corrs(sys).remove(maxResIndex-1);
1494 }
1495 else {
1496 out << " OK" << "\n";
1497 out.setRealNumberNotation(QTextStream::FixedNotation);
1498 out.setRealNumberPrecision(3);
1499 for (int ii = 0; ii < vv.Nrows(); ii++) {
1500 const cmbCorr* corr = corrs(sys)[ii];
1501 out << epoTime.datestr().c_str() << ' '
1502 << epoTime.timestr().c_str() << " "
1503 << corr->_acName << ' ' << corr->_prn.mid(0,3);
1504 out.setFieldWidth(6);
1505 out << " res = " << vv[ii] << "\n";
1506 out.setFieldWidth(0);
1507 }
1508 return success;
1509 }
1510
1511 }
1512
1513 return failure;
1514}
1515
1516// Check Satellite Positions for Outliers
1517////////////////////////////////////////////////////////////////////////////
1518t_irc bncComb::checkOrbits(bncTime epoTime, char sys, QTextStream& out, QMap<QString, cmbCorr*>& masterCorr) {
1519
1520 // Switch to last ephemeris (if possible)
1521 // --------------------------------------
1522 QMutableVectorIterator<cmbCorr*> im(corrs(sys));
1523 while (im.hasNext()) {
1524 cmbCorr* corr = im.next();
1525 QString prn = corr->_prn;
1526
1527 t_eph* ephLast = _ephUser.ephLast(prn);
1528 t_eph* ephPrev = _ephUser.ephPrev(prn);
1529
1530 if (ephLast == 0) {
1531 out << "checkOrbit: missing eph (not found) " << corr->_prn.mid(0,3) << "\n";
1532 delete corr;
1533 im.remove();
1534 }
1535 else if (corr->_eph == 0) {
1536 out << "checkOrbit: missing eph (zero) " << corr->_prn.mid(0,3) << "\n";
1537 delete corr;
1538 im.remove();
1539 }
1540 else {
1541 if ( corr->_eph == ephLast ||
1542 corr->_eph == ephPrev ) {
1543 switchToLastEph(ephLast, corr);
1544
1545 ColumnVector xc(6);
1546 ColumnVector vv(3);
1547 if (corr->_eph->getCrd(corr->_time, xc, vv, false) != success) {
1548 delete corr;
1549 im.remove();
1550 }
1551 else {
1552 corr->_satPos = xc.Rows(1,3);
1553 }
1554 }
1555 else {
1556 out << "checkOrbit: missing eph (deleted) " << corr->_prn.mid(0,3) << "\n";
1557 delete corr;
1558 im.remove();
1559 }
1560 }
1561 }
1562
1563 while (_running) {
1564
1565 // Compute Mean Corrections for all Satellites
1566 // -------------------------------------------
1567 QMap<QString, int> numCorr;
1568 QMap<QString, ColumnVector> meanRao;
1569 QVectorIterator<cmbCorr*> it(corrs(sys));
1570 while (it.hasNext()) {
1571 cmbCorr* corr = it.next();
1572 QString prn = corr->_prn;
1573
1574 if (meanRao.find(prn) == meanRao.end()) {
1575 meanRao[prn].ReSize(4);
1576 meanRao[prn].Rows(1,3) = corr->_orbCorr._xr;
1577 meanRao[prn](4) = 1;
1578 }
1579 else {
1580 meanRao[prn].Rows(1,3) += corr->_orbCorr._xr;
1581 meanRao[prn](4) += 1;
1582 }
1583 if (numCorr.find(prn) == numCorr.end()) {
1584 numCorr[prn] = 1;
1585 }
1586 else {
1587 numCorr[prn] += 1;
1588 }
1589 }
1590
1591 // Compute Differences wrt. Mean, find Maximum
1592 // -------------------------------------------
1593 QMap<QString, cmbCorr*> maxDiff;
1594 it.toFront();
1595 while (it.hasNext()) {
1596 cmbCorr* corr = it.next();
1597 QString prn = corr->_prn;
1598 if (meanRao[prn](4) != 0) {
1599 meanRao[prn] /= meanRao[prn](4);
1600 meanRao[prn](4) = 0;
1601 }
1602 corr->_diffRao2Mean = corr->_orbCorr._xr - meanRao[prn].Rows(1,3);
1603
1604 if (maxDiff.find(prn) == maxDiff.end()) {
1605 maxDiff[prn] = corr;
1606 }
1607 else {
1608 double normMax = maxDiff[prn]->_diffRao2Mean.NormFrobenius();
1609 double norm = corr->_diffRao2Mean.NormFrobenius();
1610 if (norm > normMax) {
1611 maxDiff[prn] = corr;
1612 }
1613 }
1614 }
1615
1616 if (_ACs.size() == 1) {
1617 QVectorIterator<cmbCorr*> it(corrs(sys));
1618 while (it.hasNext()) {
1619 cmbCorr* corr = it.next();
1620 QString prn = corr->_prn;
1621 if (corr->_acName == _masterOrbitAC[sys] && masterCorr.find(prn) == masterCorr.end()) {
1622 masterCorr[prn] = new cmbCorr(*corr);
1623 }
1624 }
1625 break;
1626 }
1627
1628 // Remove Outliers
1629 // ---------------
1630 bool removed = false;
1631 QMutableVectorIterator<cmbCorr*> im(corrs(sys));
1632 while (im.hasNext()) {
1633 cmbCorr* corr = im.next();
1634 QString prn = corr->_prn;
1635 if (numCorr[prn] < 2) {
1636 delete corr;
1637 im.remove();
1638 }
1639 else if (corr == maxDiff[prn]) {
1640 double norm = corr->_diffRao2Mean.NormFrobenius();
1641 if (norm > _MAX_DISPLACEMENT) {
1642 out << epoTime.datestr().c_str() << " "
1643 << epoTime.timestr().c_str() << " "
1644 << "Orbit Outlier: "
1645 << corr->_acName.toLatin1().data() << " "
1646 << prn.mid(0,3).toLatin1().data() << " "
1647 << corr->_iod << " "
1648 << norm << "\n";
1649 delete corr;
1650 im.remove();
1651 removed = true;
1652 }
1653 }
1654 }
1655 // Set master orbit
1656 // -----------------------------------------
1657 if (!removed) {
1658 QVectorIterator<cmbCorr*> it(corrs(sys));
1659 while (it.hasNext()) {
1660 cmbCorr* corr = it.next();
1661 QString prn = corr->_prn;
1662 if (corr->_acName == _masterOrbitAC[sys] && masterCorr.find(prn) == masterCorr.end()) {
1663 masterCorr[prn] = new cmbCorr(*corr);
1664 }
1665 }
1666 // Remove satellites that are not in masterOrbit
1667 // and compute differences wrt. masterOrbit
1668 // ----------------------------------------------
1669 QMutableVectorIterator<cmbCorr*> im(corrs(sys));
1670 while (im.hasNext()) {
1671 cmbCorr* corr = im.next();
1672 QString prn = corr->_prn;
1673 if (masterCorr.find(prn) == masterCorr.end()) {
1674 delete corr;
1675 im.remove();
1676 }
1677 }
1678 break;
1679 }
1680 }
1681
1682 return success;
1683}
1684
1685//
1686////////////////////////////////////////////////////////////////////////////
1687void bncComb::slotProviderIDChanged(QString mountPoint) {
1688 QMutexLocker locker(&_mutex);
1689
1690 QTextStream out(&_log, QIODevice::WriteOnly);
1691
1692 // Find the AC Name
1693 // ----------------
1694 QString acName;
1695 QListIterator<cmbAC*> icAC(_ACs);
1696 while (icAC.hasNext()) {
1697 cmbAC *AC = icAC.next();
1698 if (AC->mountPoint == mountPoint) {
1699 acName = AC->name;
1700 out << "SSR Provider or Service changed: AC " << AC->name.toLatin1().data() << " "
1701 << _resTime.datestr().c_str() << " " << _resTime.timestr().c_str()
1702 << "\n";
1703 break;
1704 }
1705 }
1706 if (acName.isEmpty()) {
1707 return;
1708 }
1709 QMapIterator<char, unsigned> itSys(_cmbSysPrn);
1710 while (itSys.hasNext()) {
1711 itSys.next();
1712 char sys = itSys.key();
1713 // Remove all corrections of the corresponding AC
1714 // ----------------------------------------------
1715 QVector<cmbCorr*> &corrVec = _buffer[sys].corrs;
1716 QMutableVectorIterator<cmbCorr*> it(corrVec);
1717 while (it.hasNext()) {
1718 cmbCorr *corr = it.next();
1719 if (acName == corr->_acName) {
1720 delete corr;
1721 it.remove();
1722 }
1723 }
1724 // Reset Satellite Offsets
1725 // -----------------------
1726 if (_method == filter) {
1727 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
1728 cmbParam *pp = _params[sys][iPar - 1];
1729 if (pp->AC == acName && pp->type == cmbParam::offACSat) {
1730 pp->xx = 0.0;
1731 _QQ[sys].Row(iPar) = 0.0;
1732 _QQ[sys].Column(iPar) = 0.0;
1733 _QQ[sys](iPar, iPar) = pp->sig0 * pp->sig0;
1734 }
1735 }
1736 }
1737 }
1738}
1739
1740//
1741////////////////////////////////////////////////////////////////////////////
1742bool bncComb::excludeSat(const t_prn& prn, const QStringList excludeSats) const {
1743 QStringListIterator it(excludeSats);
1744 while (it.hasNext()) {
1745 string prnStr = it.next().toLatin1().data();
1746 if (prnStr == prn.toString() || // prn
1747 prnStr == prn.toString().substr(0,1)) { // sys
1748 return true;
1749 }
1750 }
1751 return false;
1752}
Note: See TracBrowser for help on using the repository browser.