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