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

Last change on this file since 10610 was 10610, checked in by stuerze, 12 days ago

minor changes

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