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

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

minor changes

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