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

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

Possibility to select how satellite attitude is modelled when converting Antenna Phase Center (APC) corrections to
Center-of-Mass (CoM) positions required for SP3 output

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