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

Last change on this file since 10949 was 10949, checked in by stuerze, 7 weeks ago

emitMessage now used in bncComb

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