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

Last change on this file since 10834 was 10823, checked in by stuerze, 4 months ago

minor changes

File size: 52.1 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// " YawAngle %1.4f",
1236 apc(1), apc(2), apc(3),
1237 xc(4) * t_CST::c,
1238 vv(1), vv(2), vv(3),
1239 com(1), com(2), com(3)
1240// corr->_satYawAngle
1241 );
1242 outLines += hlp;
1243 hlp.clear();
1244
1245 // CODE BIASES
1246 if (corr->_satCodeBias._bias.size()) {
1247 t_satCodeBias satCodeBias(corr->_satCodeBias);
1248 satCodeBias._staID = "INTERNAL";
1249 satCodeBiasList.push_back(satCodeBias);
1250 hlp = QString().asprintf(" CodeBias %2lu", satCodeBias._bias.size());
1251 outLines += hlp;
1252 hlp.clear();
1253 for (unsigned ii = 0; ii < satCodeBias._bias.size(); ii++) {
1254 const t_frqCodeBias& frqCodeBias = satCodeBias._bias[ii];
1255 if (!frqCodeBias._rnxType2ch.empty()) {
1256 hlp = QString().asprintf(" %s%10.6f", frqCodeBias._rnxType2ch.c_str(), frqCodeBias._value);
1257 outLines += hlp;
1258 hlp.clear();
1259 }
1260 }
1261 }
1262
1263 outLines += "\n";
1264 delete corr;
1265 it.remove();
1266 }
1267
1268 outLines += "EOE\n"; // End Of Epoch flag
1269 //cout << outLines.toStdString();
1270
1271 vector<string> errmsg;
1272 _rtnetDecoder->Decode(outLines.toLatin1().data(), outLines.length(), errmsg);
1273
1274 // Send new Corrections to PPP etc.
1275 // --------------------------------
1276 if (orbCorrections.size() > 0 && clkCorrections.size() > 0) {
1277 emit newOrbCorrections(orbCorrections);
1278 emit newClkCorrections(clkCorrections);
1279 }
1280 if (satCodeBiasList.size()) {
1281 emit newCodeBiases(satCodeBiasList);
1282 }
1283}
1284
1285// Create First Design Matrix and Vector of Measurements
1286////////////////////////////////////////////////////////////////////////////
1287t_irc bncComb::createAmat(char sys, Matrix& AA, ColumnVector& ll, DiagonalMatrix& PP, const ColumnVector& x0, const QMap<QString, cmbCorr*>& masterCorr) {
1288
1289 unsigned nPar = _params[sys].size();
1290 unsigned nObs = corrs(sys).size();
1291
1292 if (nObs == 0) {
1293 return failure;
1294 }
1295
1296 int maxSat = _cmbSysPrn[sys];
1297
1298 const int nCon = (_method == filter) ? 1 + maxSat : 0;
1299
1300 AA.ReSize(nObs+nCon, nPar); AA = 0.0;
1301 ll.ReSize(nObs+nCon); ll = 0.0;
1302 PP.ReSize(nObs+nCon); PP = 1.0 / (sigObs * sigObs);
1303
1304 int iObs = 0;
1305 QVectorIterator<cmbCorr*> itCorr(corrs(sys));
1306 while (itCorr.hasNext()) {
1307 cmbCorr* corr = itCorr.next();
1308 QString prn = corr->_prn;
1309
1310 ++iObs;
1311
1312 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
1313 cmbParam* pp = _params[sys][iPar-1];
1314 AA(iObs, iPar) = pp->partial(sys, corr->_acName, prn);
1315 }
1316 // Consistency corrections to keep the combined clock consistent to masterOrbit
1317 // ----------------------------------------------------------------------------
1318 double dC_orb = DotProduct((corr->_satPos - masterCorr[prn]->_satPos), corr->_satPos);
1319 dC_orb /= masterCorr[prn]->_satPos.NormFrobenius();
1320 double dC_att = (corr->_satYawAngle - masterCorr[prn]->_satYawAngle) / (2 * M_PI);
1321 dC_att *= corr->_lambdaIF;
1322 double dC_apriori_corr = dC_orb;// + dC_att;
1323
1324 ll(iObs) = ((corr->_clkCorr._dClk * t_CST::c) - dC_apriori_corr - corr->_satCodeBiasIF) - DotProduct(AA.Row(iObs), x0);
1325
1326 PP(iObs, iObs) *= 1.0 / (corr->_weightFactor * corr->_weightFactor);
1327 }
1328
1329 // Regularization
1330 // --------------
1331 if (_method == filter) {
1332 const double Ph = 1.e6;
1333 PP(nObs+1) = Ph;
1334 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
1335 cmbParam* pp = _params[sys][iPar-1];
1336 if ( AA.Column(iPar).maximum_absolute_value() > 0.0 &&
1337 pp->type == cmbParam::clkSat ) {
1338 AA(nObs+1, iPar) = 1.0;
1339 }
1340 }
1341// if (sys == 'R') {
1342// return success;
1343// }
1344 int iCond = 1;
1345 // GNSS
1346 for (unsigned iGnss = 1; iGnss <= _cmbSysPrn[sys]; iGnss++) {
1347 int flag = t_corrSSR::getSsrNavTypeFlag(sys, iGnss);
1348 QString prn = QString("%1%2_%3").arg(sys).arg(iGnss, 2, 10, QChar('0')).arg(flag);
1349 ++iCond;
1350 PP(nObs+iCond) = Ph;
1351 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
1352 cmbParam* pp = _params[sys][iPar-1];
1353 if ( pp &&
1354 AA.Column(iPar).maximum_absolute_value() > 0.0 &&
1355 pp->type == cmbParam::offACSat &&
1356 pp->prn == prn) {
1357 AA(nObs+iCond, iPar) = 1.0;
1358 }
1359 }
1360 }
1361 }
1362
1363 return success;
1364}
1365
1366// Process Epoch - Single-Epoch Method
1367////////////////////////////////////////////////////////////////////////////
1368t_irc bncComb::processEpoch_singleEpoch(bncTime epoTime, char sys, QTextStream& out,
1369 QMap<QString, cmbCorr*>& masterCorr,
1370 ColumnVector& dx) {
1371
1372 // Check Satellite Positions for Outliers
1373 // --------------------------------------
1374 if (checkOrbits(epoTime, sys, out, masterCorr) != success) {
1375 return failure;
1376 }
1377
1378 // Outlier Detection Loop
1379 // ----------------------
1380 while (_running) {
1381 // Count Number of Observations per Satellite and per AC
1382 // -----------------------------------------------------
1383 QMap<QString, int> numObsPrn;
1384 QMap<QString, int> numObsAC;
1385 QVectorIterator<cmbCorr*> itCorr(corrs(sys));
1386 while (itCorr.hasNext()) {
1387 cmbCorr* corr = itCorr.next();
1388 QString prn = corr->_prn;
1389 QString AC = corr->_acName;
1390 if (numObsPrn.find(prn) == numObsPrn.end()) {
1391 numObsPrn[prn] = 1;
1392 }
1393 else {
1394 numObsPrn[prn] += 1;
1395 }
1396 if (numObsAC.find(AC) == numObsAC.end()) {
1397 numObsAC[AC] = 1;
1398 }
1399 else {
1400 numObsAC[AC] += 1;
1401 }
1402 }
1403
1404 // Clean-Up the Parameters
1405 // -----------------------
1406 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
1407 delete _params[sys][iPar-1];
1408 }
1409 _params[sys].clear();
1410
1411 // Set new Parameters
1412 // ------------------
1413 int nextPar = 0;
1414
1415 QMapIterator<QString, int> itAC(numObsAC);
1416 while (itAC.hasNext()) {
1417 itAC.next();
1418 const QString& AC = itAC.key();
1419 int numObs = itAC.value();
1420 if (AC != _masterOrbitAC[sys] && numObs > 0) {
1421 _params[sys].push_back(new cmbParam(cmbParam::offACgnss, ++nextPar, AC, ""));
1422 }
1423 }
1424
1425 QMapIterator<QString, int> itPrn(numObsPrn);
1426 while (itPrn.hasNext()) {
1427 itPrn.next();
1428 const QString& prn = itPrn.key();
1429 int numObs = itPrn.value();
1430 if (numObs > 0) {
1431 _params[sys].push_back(new cmbParam(cmbParam::clkSat, ++nextPar, "", prn));
1432 }
1433 }
1434
1435 int nPar = _params[sys].size();
1436 ColumnVector x0(nPar);
1437 x0 = 0.0;
1438
1439 // Create First-Design Matrix
1440 // --------------------------
1441 Matrix AA;
1442 ColumnVector ll;
1443 DiagonalMatrix PP;
1444 if (createAmat(sys, AA, ll, PP, x0, masterCorr) != success) {
1445 return failure;
1446 }
1447
1448 ColumnVector vv;
1449 try {
1450 Matrix ATP = AA.t() * PP;
1451 SymmetricMatrix NN; NN << ATP * AA;
1452 ColumnVector bb = ATP * ll;
1453 _QQ[sys] = NN.i();
1454 dx = _QQ[sys] * bb;
1455 vv = ll - AA * dx;
1456 }
1457 catch (Exception& exc) {
1458 out << exc.what() << "\n";
1459 return failure;
1460 }
1461
1462 int maxResIndex;
1463 double maxRes = vv.maximum_absolute_value1(maxResIndex);
1464 out.setRealNumberNotation(QTextStream::FixedNotation);
1465 out.setRealNumberPrecision(3);
1466 out << epoTime.datestr().c_str() << " " << epoTime.timestr().c_str()
1467 << " Maximum Residuum " << maxRes << ' '
1468 << corrs(sys)[maxResIndex-1]->_acName << ' ' << corrs(sys)[maxResIndex-1]->_prn.mid(0,3);
1469
1470 if (maxRes > _MAX_RES) {
1471 out << " Outlier" << "\n";
1472 delete corrs(sys)[maxResIndex-1];
1473 corrs(sys).remove(maxResIndex-1);
1474 }
1475 else {
1476 out << " OK" << "\n";
1477 out.setRealNumberNotation(QTextStream::FixedNotation);
1478 out.setRealNumberPrecision(3);
1479 for (int ii = 0; ii < vv.Nrows(); ii++) {
1480 const cmbCorr* corr = corrs(sys)[ii];
1481 out << epoTime.datestr().c_str() << ' '
1482 << epoTime.timestr().c_str() << " "
1483 << corr->_acName << ' ' << corr->_prn.mid(0,3);
1484 out.setFieldWidth(6);
1485 out << " res = " << vv[ii] << "\n";
1486 out.setFieldWidth(0);
1487 }
1488 return success;
1489 }
1490
1491 }
1492
1493 return failure;
1494}
1495
1496// Check Satellite Positions for Outliers
1497////////////////////////////////////////////////////////////////////////////
1498t_irc bncComb::checkOrbits(bncTime epoTime, char sys, QTextStream& out, QMap<QString, cmbCorr*>& masterCorr) {
1499
1500 // Switch to last ephemeris (if possible)
1501 // --------------------------------------
1502 QMutableVectorIterator<cmbCorr*> im(corrs(sys));
1503 while (im.hasNext()) {
1504 cmbCorr* corr = im.next();
1505 QString prn = corr->_prn;
1506
1507 t_eph* ephLast = _ephUser.ephLast(prn);
1508 t_eph* ephPrev = _ephUser.ephPrev(prn);
1509
1510 if (ephLast == 0) {
1511 out << "checkOrbit: missing eph (not found) " << corr->_prn.mid(0,3) << "\n";
1512 delete corr;
1513 im.remove();
1514 }
1515 else if (corr->_eph == 0) {
1516 out << "checkOrbit: missing eph (zero) " << corr->_prn.mid(0,3) << "\n";
1517 delete corr;
1518 im.remove();
1519 }
1520 else {
1521 if ( corr->_eph == ephLast ||
1522 corr->_eph == ephPrev ) {
1523 switchToLastEph(ephLast, corr);
1524
1525 ColumnVector xc(6);
1526 ColumnVector vv(3);
1527 if (corr->_eph->getCrd(corr->_time, xc, vv, false) != success) {
1528 delete corr;
1529 im.remove();
1530 }
1531 else {
1532 corr->_satPos = xc.Rows(1,3);
1533 }
1534 }
1535 else {
1536 out << "checkOrbit: missing eph (deleted) " << corr->_prn.mid(0,3) << "\n";
1537 delete corr;
1538 im.remove();
1539 }
1540 }
1541 }
1542
1543 while (_running) {
1544
1545 // Compute Mean Corrections for all Satellites
1546 // -------------------------------------------
1547 QMap<QString, int> numCorr;
1548 QMap<QString, ColumnVector> meanRao;
1549 QVectorIterator<cmbCorr*> it(corrs(sys));
1550 while (it.hasNext()) {
1551 cmbCorr* corr = it.next();
1552 QString prn = corr->_prn;
1553
1554 if (meanRao.find(prn) == meanRao.end()) {
1555 meanRao[prn].ReSize(4);
1556 meanRao[prn].Rows(1,3) = corr->_orbCorr._xr;
1557 meanRao[prn](4) = 1;
1558 }
1559 else {
1560 meanRao[prn].Rows(1,3) += corr->_orbCorr._xr;
1561 meanRao[prn](4) += 1;
1562 }
1563 if (numCorr.find(prn) == numCorr.end()) {
1564 numCorr[prn] = 1;
1565 }
1566 else {
1567 numCorr[prn] += 1;
1568 }
1569 }
1570
1571 // Compute Differences wrt. Mean, find Maximum
1572 // -------------------------------------------
1573 QMap<QString, cmbCorr*> maxDiff;
1574 it.toFront();
1575 while (it.hasNext()) {
1576 cmbCorr* corr = it.next();
1577 QString prn = corr->_prn;
1578 if (meanRao[prn](4) != 0) {
1579 meanRao[prn] /= meanRao[prn](4);
1580 meanRao[prn](4) = 0;
1581 }
1582 corr->_diffRao2Mean = corr->_orbCorr._xr - meanRao[prn].Rows(1,3);
1583
1584 if (maxDiff.find(prn) == maxDiff.end()) {
1585 maxDiff[prn] = corr;
1586 }
1587 else {
1588 double normMax = maxDiff[prn]->_diffRao2Mean.NormFrobenius();
1589 double norm = corr->_diffRao2Mean.NormFrobenius();
1590 if (norm > normMax) {
1591 maxDiff[prn] = corr;
1592 }
1593 }
1594 }
1595
1596 if (_ACs.size() == 1) {
1597 QVectorIterator<cmbCorr*> it(corrs(sys));
1598 while (it.hasNext()) {
1599 cmbCorr* corr = it.next();
1600 QString prn = corr->_prn;
1601 if (corr->_acName == _masterOrbitAC[sys] && masterCorr.find(prn) == masterCorr.end()) {
1602 masterCorr[prn] = new cmbCorr(*corr);
1603 }
1604 }
1605 break;
1606 }
1607
1608 // Remove Outliers
1609 // ---------------
1610 bool removed = false;
1611 QMutableVectorIterator<cmbCorr*> im(corrs(sys));
1612 while (im.hasNext()) {
1613 cmbCorr* corr = im.next();
1614 QString prn = corr->_prn;
1615 if (numCorr[prn] < 2) {
1616 delete corr;
1617 im.remove();
1618 }
1619 else if (corr == maxDiff[prn]) {
1620 double norm = corr->_diffRao2Mean.NormFrobenius();
1621 if (norm > _MAX_DISPLACEMENT) {
1622 out << epoTime.datestr().c_str() << " "
1623 << epoTime.timestr().c_str() << " "
1624 << "Orbit Outlier: "
1625 << corr->_acName.toLatin1().data() << " "
1626 << prn.mid(0,3).toLatin1().data() << " "
1627 << corr->_iod << " "
1628 << norm << "\n";
1629 delete corr;
1630 im.remove();
1631 removed = true;
1632 }
1633 }
1634 }
1635 // Set master orbit
1636 // -----------------------------------------
1637 if (!removed) {
1638 QVectorIterator<cmbCorr*> it(corrs(sys));
1639 while (it.hasNext()) {
1640 cmbCorr* corr = it.next();
1641 QString prn = corr->_prn;
1642 if (corr->_acName == _masterOrbitAC[sys] && masterCorr.find(prn) == masterCorr.end()) {
1643 masterCorr[prn] = new cmbCorr(*corr);
1644 }
1645 }
1646 // Remove satellites that are not in masterOrbit
1647 // and compute differences wrt. masterOrbit
1648 // ----------------------------------------------
1649 QMutableVectorIterator<cmbCorr*> im(corrs(sys));
1650 while (im.hasNext()) {
1651 cmbCorr* corr = im.next();
1652 QString prn = corr->_prn;
1653 if (masterCorr.find(prn) == masterCorr.end()) {
1654 delete corr;
1655 im.remove();
1656 }
1657 }
1658 break;
1659 }
1660 }
1661
1662 return success;
1663}
1664
1665//
1666////////////////////////////////////////////////////////////////////////////
1667void bncComb::slotProviderIDChanged(QString mountPoint) {
1668 QMutexLocker locker(&_mutex);
1669
1670 QTextStream out(&_log, QIODevice::WriteOnly);
1671
1672 // Find the AC Name
1673 // ----------------
1674 QString acName;
1675 QListIterator<cmbAC*> icAC(_ACs);
1676 while (icAC.hasNext()) {
1677 cmbAC *AC = icAC.next();
1678 if (AC->mountPoint == mountPoint) {
1679 acName = AC->name;
1680 out << "SSR Provider or Service changed: AC " << AC->name.toLatin1().data() << " "
1681 << _resTime.datestr().c_str() << " " << _resTime.timestr().c_str()
1682 << "\n";
1683 break;
1684 }
1685 }
1686 if (acName.isEmpty()) {
1687 return;
1688 }
1689 QMapIterator<char, unsigned> itSys(_cmbSysPrn);
1690 while (itSys.hasNext()) {
1691 itSys.next();
1692 char sys = itSys.key();
1693 // Remove all corrections of the corresponding AC
1694 // ----------------------------------------------
1695 QVector<cmbCorr*> &corrVec = _buffer[sys].corrs;
1696 QMutableVectorIterator<cmbCorr*> it(corrVec);
1697 while (it.hasNext()) {
1698 cmbCorr *corr = it.next();
1699 if (acName == corr->_acName) {
1700 delete corr;
1701 it.remove();
1702 }
1703 }
1704 // Reset Satellite Offsets
1705 // -----------------------
1706 if (_method == filter) {
1707 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
1708 cmbParam *pp = _params[sys][iPar - 1];
1709 if (pp->AC == acName && pp->type == cmbParam::offACSat) {
1710 pp->xx = 0.0;
1711 _QQ[sys].Row(iPar) = 0.0;
1712 _QQ[sys].Column(iPar) = 0.0;
1713 _QQ[sys](iPar, iPar) = pp->sig0 * pp->sig0;
1714 }
1715 }
1716 }
1717 }
1718}
1719
1720//
1721////////////////////////////////////////////////////////////////////////////
1722bool bncComb::excludeSat(const t_prn& prn, const QStringList excludeSats) const {
1723 QStringListIterator it(excludeSats);
1724 while (it.hasNext()) {
1725 string prnStr = it.next().toLatin1().data();
1726 if (prnStr == prn.toString() || // prn
1727 prnStr == prn.toString().substr(0,1)) { // sys
1728 return true;
1729 }
1730 }
1731 return false;
1732}
Note: See TracBrowser for help on using the repository browser.