| 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 |
|
|---|
| 20 | #include "bnccomb.h"
|
|---|
| 21 | #include "bncapp.h"
|
|---|
| 22 | #include "cmbcaster.h"
|
|---|
| 23 | #include "bncsettings.h"
|
|---|
| 24 | #include "bncmodel.h"
|
|---|
| 25 | #include "bncutils.h"
|
|---|
| 26 | #include "bncpppclient.h"
|
|---|
| 27 | #include "bnssp3.h"
|
|---|
| 28 | #include "bncantex.h"
|
|---|
| 29 | #include "bnctides.h"
|
|---|
| 30 |
|
|---|
| 31 | using namespace std;
|
|---|
| 32 |
|
|---|
| 33 | // Constructor
|
|---|
| 34 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 35 | cmbParam::cmbParam(cmbParam::parType type_, int index_,
|
|---|
| 36 | const QString& ac_, const QString& prn_,
|
|---|
| 37 | double sig_0_, double sig_P_) {
|
|---|
| 38 |
|
|---|
| 39 | type = type_;
|
|---|
| 40 | index = index_;
|
|---|
| 41 | AC = ac_;
|
|---|
| 42 | prn = prn_;
|
|---|
| 43 | sig_0 = sig_0_;
|
|---|
| 44 | sig_P = sig_P_;
|
|---|
| 45 | xx = 0.0;
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | // Destructor
|
|---|
| 49 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 50 | cmbParam::~cmbParam() {
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | // Partial
|
|---|
| 54 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 55 | double cmbParam::partial(const QString& AC_, t_corr* corr) {
|
|---|
| 56 |
|
|---|
| 57 | if (type == AC_offset) {
|
|---|
| 58 | if (AC == AC_) {
|
|---|
| 59 | return 1.0;
|
|---|
| 60 | }
|
|---|
| 61 | }
|
|---|
| 62 | else if (type == Sat_offset) {
|
|---|
| 63 | if (AC == AC_ && prn == corr->prn) {
|
|---|
| 64 | return 1.0;
|
|---|
| 65 | }
|
|---|
| 66 | }
|
|---|
| 67 | else if (type == clk) {
|
|---|
| 68 | if (prn == corr->prn) {
|
|---|
| 69 | return 1.0;
|
|---|
| 70 | }
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | return 0.0;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | //
|
|---|
| 77 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 78 | QString cmbParam::toString() const {
|
|---|
| 79 |
|
|---|
| 80 | QString outStr;
|
|---|
| 81 |
|
|---|
| 82 | if (type == AC_offset) {
|
|---|
| 83 | outStr = "AC offset " + AC;
|
|---|
| 84 | }
|
|---|
| 85 | else if (type == Sat_offset) {
|
|---|
| 86 | outStr = "Sat Offset " + AC + " " + prn;
|
|---|
| 87 | }
|
|---|
| 88 | else if (type == clk) {
|
|---|
| 89 | outStr = "Clk Corr " + prn;
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | return outStr;
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | // Constructor
|
|---|
| 96 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 97 | bncComb::bncComb() {
|
|---|
| 98 |
|
|---|
| 99 | bncSettings settings;
|
|---|
| 100 |
|
|---|
| 101 | QStringList combineStreams = settings.value("combineStreams").toStringList();
|
|---|
| 102 |
|
|---|
| 103 | if (combineStreams.size() >= 2) {
|
|---|
| 104 | QListIterator<QString> it(combineStreams);
|
|---|
| 105 | while (it.hasNext()) {
|
|---|
| 106 | QStringList hlp = it.next().split(" ");
|
|---|
| 107 | cmbAC* newAC = new cmbAC();
|
|---|
| 108 | newAC->mountPoint = hlp[0];
|
|---|
| 109 | newAC->name = hlp[1];
|
|---|
| 110 | newAC->weight = hlp[2].toDouble();
|
|---|
| 111 | if (_masterAC.isEmpty()) {
|
|---|
| 112 | _masterAC = newAC->name;
|
|---|
| 113 | }
|
|---|
| 114 | _ACs[newAC->mountPoint] = newAC;
|
|---|
| 115 | }
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | _caster = new cmbCaster();
|
|---|
| 119 | connect(this, SIGNAL(newMessage(QByteArray,bool)),
|
|---|
| 120 | ((bncApp*)qApp), SLOT(slotMessage(const QByteArray,bool)));
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 | // A Priori Sigmas (in Meters)
|
|---|
| 124 | // ---------------------------
|
|---|
| 125 | double sigAC_0 = 100.0;
|
|---|
| 126 | double sigAC_P = 100.0;
|
|---|
| 127 | double sigSat_0 = 100.0;
|
|---|
| 128 | double sigSat_P = 0.0;
|
|---|
| 129 | double sigClk_0 = 100.0;
|
|---|
| 130 | double sigClk_P = 100.0;
|
|---|
| 131 |
|
|---|
| 132 | // Initialize Parameters (model: Clk_Corr = AC_Offset + Sat_Offset + Clk)
|
|---|
| 133 | // ----------------------------------------------------------------------
|
|---|
| 134 | int nextPar = 0;
|
|---|
| 135 | QMapIterator<QString, cmbAC*> it(_ACs);
|
|---|
| 136 | while (it.hasNext()) {
|
|---|
| 137 | it.next();
|
|---|
| 138 | cmbAC* AC = it.value();
|
|---|
| 139 | if (AC->name != _masterAC) {
|
|---|
| 140 | _params.push_back(new cmbParam(cmbParam::AC_offset, ++nextPar,
|
|---|
| 141 | AC->name, "", sigAC_0, sigAC_P));
|
|---|
| 142 | for (int iGps = 1; iGps <= 32; iGps++) {
|
|---|
| 143 | QString prn = QString("G%1").arg(iGps, 2, 10, QChar('0'));
|
|---|
| 144 | _params.push_back(new cmbParam(cmbParam::Sat_offset, ++nextPar,
|
|---|
| 145 | AC->name, prn, sigSat_0, sigSat_P));
|
|---|
| 146 | }
|
|---|
| 147 | }
|
|---|
| 148 | }
|
|---|
| 149 | for (int iGps = 1; iGps <= 32; iGps++) {
|
|---|
| 150 | QString prn = QString("G%1").arg(iGps, 2, 10, QChar('0'));
|
|---|
| 151 | _params.push_back(new cmbParam(cmbParam::clk, ++nextPar, "", prn,
|
|---|
| 152 | sigClk_0, sigClk_P));
|
|---|
| 153 | }
|
|---|
| 154 |
|
|---|
| 155 | // Initialize Variance-Covariance Matrix
|
|---|
| 156 | // -------------------------------------
|
|---|
| 157 | _QQ.ReSize(_params.size());
|
|---|
| 158 | _QQ = 0.0;
|
|---|
| 159 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
|---|
| 160 | cmbParam* pp = _params[iPar-1];
|
|---|
| 161 | _QQ(iPar,iPar) = pp->sig_0 * pp->sig_0;
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 | // Output File (skeleton name)
|
|---|
| 165 | // ---------------------------
|
|---|
| 166 | QString path = settings.value("cmbOutPath").toString();
|
|---|
| 167 | if (!path.isEmpty() && !_caster->mountpoint().isEmpty()) {
|
|---|
| 168 | expandEnvVar(path);
|
|---|
| 169 | if ( path.length() > 0 && path[path.length()-1] != QDir::separator() ) {
|
|---|
| 170 | path += QDir::separator();
|
|---|
| 171 | }
|
|---|
| 172 | _outNameSkl = path + _caster->mountpoint();
|
|---|
| 173 | }
|
|---|
| 174 | _out = 0;
|
|---|
| 175 |
|
|---|
| 176 | // SP3 writer
|
|---|
| 177 | // ----------
|
|---|
| 178 | if ( settings.value("cmbSP3Path").toString().isEmpty() ) {
|
|---|
| 179 | _sp3 = 0;
|
|---|
| 180 | }
|
|---|
| 181 | else {
|
|---|
| 182 | QString prep = "BNC";
|
|---|
| 183 | QString ext = ".sp3";
|
|---|
| 184 | QString path = settings.value("cmbSP3Path").toString();
|
|---|
| 185 | QString interval = "";
|
|---|
| 186 | int sampl = 0;
|
|---|
| 187 | _sp3 = new bnsSP3(prep, ext, path, interval, sampl);
|
|---|
| 188 | }
|
|---|
| 189 |
|
|---|
| 190 | _append = Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked;
|
|---|
| 191 |
|
|---|
| 192 | // ANTEX File
|
|---|
| 193 | // ----------
|
|---|
| 194 | _antex = 0;
|
|---|
| 195 | QString antexFileName = settings.value("pppAntex").toString();
|
|---|
| 196 | if (!antexFileName.isEmpty()) {
|
|---|
| 197 | _antex = new bncAntex();
|
|---|
| 198 | if (_antex->readFile(antexFileName) != success) {
|
|---|
| 199 | emit newMessage("wrong ANTEX file", true);
|
|---|
| 200 | delete _antex;
|
|---|
| 201 | _antex = 0;
|
|---|
| 202 | }
|
|---|
| 203 | }
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | // Destructor
|
|---|
| 207 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 208 | bncComb::~bncComb() {
|
|---|
| 209 | QMapIterator<QString, cmbAC*> it(_ACs);
|
|---|
| 210 | while (it.hasNext()) {
|
|---|
| 211 | it.next();
|
|---|
| 212 | delete it.value();
|
|---|
| 213 | }
|
|---|
| 214 | delete _caster;
|
|---|
| 215 | delete _out;
|
|---|
| 216 | delete _sp3;
|
|---|
| 217 | delete _antex;
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | // Read and store one correction line
|
|---|
| 221 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 222 | void bncComb::processCorrLine(const QString& staID, const QString& line) {
|
|---|
| 223 | QMutexLocker locker(&_mutex);
|
|---|
| 224 |
|
|---|
| 225 | // Find the relevant instance of cmbAC class
|
|---|
| 226 | // -----------------------------------------
|
|---|
| 227 | if (_ACs.find(staID) == _ACs.end()) {
|
|---|
| 228 | return;
|
|---|
| 229 | }
|
|---|
| 230 | cmbAC* AC = _ACs[staID];
|
|---|
| 231 |
|
|---|
| 232 | // Read the Correction
|
|---|
| 233 | // -------------------
|
|---|
| 234 | t_corr* newCorr = new t_corr();
|
|---|
| 235 | if (!newCorr->readLine(line) == success) {
|
|---|
| 236 | delete newCorr;
|
|---|
| 237 | return;
|
|---|
| 238 | }
|
|---|
| 239 |
|
|---|
| 240 | // Reject delayed corrections
|
|---|
| 241 | // --------------------------
|
|---|
| 242 | if (_processedBeforeTime.valid() && newCorr->tt < _processedBeforeTime) {
|
|---|
| 243 | delete newCorr;
|
|---|
| 244 | return;
|
|---|
| 245 | }
|
|---|
| 246 |
|
|---|
| 247 | // Check the Ephemeris
|
|---|
| 248 | //--------------------
|
|---|
| 249 | if (_eph.find(newCorr->prn) == _eph.end()) {
|
|---|
| 250 | delete newCorr;
|
|---|
| 251 | return;
|
|---|
| 252 | }
|
|---|
| 253 | else {
|
|---|
| 254 | t_eph* lastEph = _eph[newCorr->prn]->last;
|
|---|
| 255 | t_eph* prevEph = _eph[newCorr->prn]->prev;
|
|---|
| 256 | if (lastEph && lastEph->IOD() == newCorr->iod) {
|
|---|
| 257 | newCorr->eph = lastEph;
|
|---|
| 258 | }
|
|---|
| 259 | else if (prevEph && prevEph->IOD() == newCorr->iod) {
|
|---|
| 260 | newCorr->eph = prevEph;
|
|---|
| 261 | }
|
|---|
| 262 | else {
|
|---|
| 263 | delete newCorr;
|
|---|
| 264 | return;
|
|---|
| 265 | }
|
|---|
| 266 | }
|
|---|
| 267 |
|
|---|
| 268 | // Process all older Epochs (if there are any)
|
|---|
| 269 | // -------------------------------------------
|
|---|
| 270 | const double waitTime = 5.0; // wait 5 sec
|
|---|
| 271 | _processedBeforeTime = newCorr->tt - waitTime;
|
|---|
| 272 |
|
|---|
| 273 | QList<cmbEpoch*> epochsToProcess;
|
|---|
| 274 |
|
|---|
| 275 | QMapIterator<QString, cmbAC*> itAC(_ACs);
|
|---|
| 276 | while (itAC.hasNext()) {
|
|---|
| 277 | itAC.next();
|
|---|
| 278 | cmbAC* AC = itAC.value();
|
|---|
| 279 |
|
|---|
| 280 | QMutableListIterator<cmbEpoch*> itEpo(AC->epochs);
|
|---|
| 281 | while (itEpo.hasNext()) {
|
|---|
| 282 | cmbEpoch* epoch = itEpo.next();
|
|---|
| 283 | if (epoch->time < _processedBeforeTime) {
|
|---|
| 284 | epochsToProcess.append(epoch);
|
|---|
| 285 | itEpo.remove();
|
|---|
| 286 | }
|
|---|
| 287 | }
|
|---|
| 288 | }
|
|---|
| 289 |
|
|---|
| 290 | if (epochsToProcess.size()) {
|
|---|
| 291 | processEpochs(epochsToProcess);
|
|---|
| 292 | }
|
|---|
| 293 |
|
|---|
| 294 | // Check Modulo Time
|
|---|
| 295 | // -----------------
|
|---|
| 296 | const int moduloTime = 10;
|
|---|
| 297 | if (int(newCorr->tt.gpssec()) % moduloTime != 0.0) {
|
|---|
| 298 | delete newCorr;
|
|---|
| 299 | return;
|
|---|
| 300 | }
|
|---|
| 301 |
|
|---|
| 302 | // Find/Create the instance of cmbEpoch class
|
|---|
| 303 | // ------------------------------------------
|
|---|
| 304 | cmbEpoch* newEpoch = 0;
|
|---|
| 305 | QListIterator<cmbEpoch*> it(AC->epochs);
|
|---|
| 306 | while (it.hasNext()) {
|
|---|
| 307 | cmbEpoch* hlpEpoch = it.next();
|
|---|
| 308 | if (hlpEpoch->time == newCorr->tt) {
|
|---|
| 309 | newEpoch = hlpEpoch;
|
|---|
| 310 | break;
|
|---|
| 311 | }
|
|---|
| 312 | }
|
|---|
| 313 | if (newEpoch == 0) {
|
|---|
| 314 | newEpoch = new cmbEpoch(AC->name);
|
|---|
| 315 | newEpoch->time = newCorr->tt;
|
|---|
| 316 | AC->epochs.append(newEpoch);
|
|---|
| 317 | }
|
|---|
| 318 |
|
|---|
| 319 | // Merge or add the correction
|
|---|
| 320 | // ---------------------------
|
|---|
| 321 | if (newEpoch->corr.find(newCorr->prn) != newEpoch->corr.end()) {
|
|---|
| 322 | newEpoch->corr[newCorr->prn]->readLine(line); // merge (multiple messages)
|
|---|
| 323 | }
|
|---|
| 324 | else {
|
|---|
| 325 | newEpoch->corr[newCorr->prn] = newCorr;
|
|---|
| 326 | }
|
|---|
| 327 | }
|
|---|
| 328 |
|
|---|
| 329 | // Send results to caster
|
|---|
| 330 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 331 | void bncComb::dumpResults(const bncTime& resTime,
|
|---|
| 332 | const QMap<QString, t_corr*>& resCorr) {
|
|---|
| 333 |
|
|---|
| 334 | _caster->open();
|
|---|
| 335 |
|
|---|
| 336 | unsigned year, month, day;
|
|---|
| 337 | resTime.civil_date (year, month, day);
|
|---|
| 338 | double GPSweeks = resTime.gpssec();
|
|---|
| 339 |
|
|---|
| 340 | struct ClockOrbit co;
|
|---|
| 341 | memset(&co, 0, sizeof(co));
|
|---|
| 342 | co.GPSEpochTime = (int)GPSweeks;
|
|---|
| 343 | co.GLONASSEpochTime = (int)fmod(GPSweeks, 86400.0)
|
|---|
| 344 | + 3 * 3600 - gnumleap(year, month, day);
|
|---|
| 345 | co.ClockDataSupplied = 1;
|
|---|
| 346 | co.OrbitDataSupplied = 1;
|
|---|
| 347 | co.SatRefDatum = DATUM_ITRF;
|
|---|
| 348 |
|
|---|
| 349 | struct Bias bias;
|
|---|
| 350 | memset(&bias, 0, sizeof(bias));
|
|---|
| 351 | bias.GPSEpochTime = (int)GPSweeks;
|
|---|
| 352 | bias.GLONASSEpochTime = (int)fmod(GPSweeks, 86400.0)
|
|---|
| 353 | + 3 * 3600 - gnumleap(year, month, day);
|
|---|
| 354 |
|
|---|
| 355 | QMapIterator<QString, t_corr*> it(resCorr);
|
|---|
| 356 | while (it.hasNext()) {
|
|---|
| 357 | it.next();
|
|---|
| 358 | t_corr* corr = it.value();
|
|---|
| 359 |
|
|---|
| 360 | struct ClockOrbit::SatData* sd = 0;
|
|---|
| 361 | if (corr->prn[0] == 'G') {
|
|---|
| 362 | sd = co.Sat + co.NumberOfGPSSat;
|
|---|
| 363 | ++co.NumberOfGPSSat;
|
|---|
| 364 | }
|
|---|
| 365 | else if (corr->prn[0] == 'R') {
|
|---|
| 366 | sd = co.Sat + CLOCKORBIT_NUMGPS + co.NumberOfGLONASSSat;
|
|---|
| 367 | ++co.NumberOfGLONASSSat;
|
|---|
| 368 | }
|
|---|
| 369 |
|
|---|
| 370 | if (sd != 0) {
|
|---|
| 371 | sd->ID = corr->prn.mid(1).toInt();
|
|---|
| 372 | sd->IOD = corr->iod;
|
|---|
| 373 | sd->Clock.DeltaA0 = corr->dClk * t_CST::c;
|
|---|
| 374 | sd->Orbit.DeltaRadial = corr->rao(1);
|
|---|
| 375 | sd->Orbit.DeltaAlongTrack = corr->rao(2);
|
|---|
| 376 | sd->Orbit.DeltaCrossTrack = corr->rao(3);
|
|---|
| 377 | sd->Orbit.DotDeltaRadial = corr->dotRao(1);
|
|---|
| 378 | sd->Orbit.DotDeltaAlongTrack = corr->dotRao(2);
|
|---|
| 379 | sd->Orbit.DotDeltaCrossTrack = corr->dotRao(3);
|
|---|
| 380 | }
|
|---|
| 381 |
|
|---|
| 382 | struct Bias::BiasSat* biasSat = 0;
|
|---|
| 383 | if (corr->prn[0] == 'G') {
|
|---|
| 384 | biasSat = bias.Sat + bias.NumberOfGPSSat;
|
|---|
| 385 | ++bias.NumberOfGPSSat;
|
|---|
| 386 | }
|
|---|
| 387 | else if (corr->prn[0] == 'R') {
|
|---|
| 388 | biasSat = bias.Sat + CLOCKORBIT_NUMGPS + bias.NumberOfGLONASSSat;
|
|---|
| 389 | ++bias.NumberOfGLONASSSat;
|
|---|
| 390 | }
|
|---|
| 391 |
|
|---|
| 392 | // Coefficient of Ionosphere-Free LC
|
|---|
| 393 | // ---------------------------------
|
|---|
| 394 | const static double a_L1_GPS = 2.54572778;
|
|---|
| 395 | const static double a_L2_GPS = -1.54572778;
|
|---|
| 396 | const static double a_L1_Glo = 2.53125000;
|
|---|
| 397 | const static double a_L2_Glo = -1.53125000;
|
|---|
| 398 |
|
|---|
| 399 | if (biasSat) {
|
|---|
| 400 | biasSat->ID = corr->prn.mid(1).toInt();
|
|---|
| 401 | biasSat->NumberOfCodeBiases = 3;
|
|---|
| 402 | if (corr->prn[0] == 'G') {
|
|---|
| 403 | biasSat->Biases[0].Type = CODETYPEGPS_L1_Z;
|
|---|
| 404 | biasSat->Biases[0].Bias = - a_L2_GPS * 0.0; // xx(10);
|
|---|
| 405 | biasSat->Biases[1].Type = CODETYPEGPS_L1_CA;
|
|---|
| 406 | biasSat->Biases[1].Bias = - a_L2_GPS * 0.0; // xx(10) + xx(9);
|
|---|
| 407 | biasSat->Biases[2].Type = CODETYPEGPS_L2_Z;
|
|---|
| 408 | biasSat->Biases[2].Bias = a_L1_GPS * 0.0; // xx(10);
|
|---|
| 409 | }
|
|---|
| 410 | else if (corr->prn[0] == 'R') {
|
|---|
| 411 | biasSat->Biases[0].Type = CODETYPEGLONASS_L1_P;
|
|---|
| 412 | biasSat->Biases[0].Bias = - a_L2_Glo * 0.0; // xx(10);
|
|---|
| 413 | biasSat->Biases[1].Type = CODETYPEGLONASS_L1_CA;
|
|---|
| 414 | biasSat->Biases[1].Bias = - a_L2_Glo * 0.0; // xx(10) + xx(9);
|
|---|
| 415 | biasSat->Biases[2].Type = CODETYPEGLONASS_L2_P;
|
|---|
| 416 | biasSat->Biases[2].Bias = a_L1_Glo * 0.0; // xx(10);
|
|---|
| 417 | }
|
|---|
| 418 | }
|
|---|
| 419 |
|
|---|
| 420 | // SP3 Output
|
|---|
| 421 | // ----------
|
|---|
| 422 | if (_sp3) {
|
|---|
| 423 | ColumnVector xc(4);
|
|---|
| 424 | ColumnVector vv(3);
|
|---|
| 425 | corr->eph->position(resTime.gpsw(), resTime.gpssec(),
|
|---|
| 426 | xc.data(), vv.data());
|
|---|
| 427 | bncPPPclient::applyCorr(resTime, corr, xc, vv);
|
|---|
| 428 |
|
|---|
| 429 | // Relativistic Correction
|
|---|
| 430 | // -----------------------
|
|---|
| 431 | xc(4) += 2.0 * DotProduct(xc.Rows(1,3),vv) / t_CST::c / t_CST::c;
|
|---|
| 432 |
|
|---|
| 433 | // Correction Phase Center --> CoM
|
|---|
| 434 | // -------------------------------
|
|---|
| 435 | if (_antex) {
|
|---|
| 436 | ColumnVector dx(3); dx = 0.0;
|
|---|
| 437 | double Mjd = resTime.mjd() + resTime.daysec()/86400.0;
|
|---|
| 438 | if (_antex->satCoMcorrection(corr->prn, Mjd, xc.Rows(1,3), dx) == success) {
|
|---|
| 439 | xc(1) -= dx(1);
|
|---|
| 440 | xc(2) -= dx(2);
|
|---|
| 441 | xc(3) -= dx(3);
|
|---|
| 442 | }
|
|---|
| 443 | else {
|
|---|
| 444 | cout << "antenna not found" << endl;
|
|---|
| 445 | }
|
|---|
| 446 | }
|
|---|
| 447 | _sp3->write(resTime.gpsw(), resTime.gpssec(), corr->prn, xc, _append);
|
|---|
| 448 | }
|
|---|
| 449 |
|
|---|
| 450 | delete corr;
|
|---|
| 451 | }
|
|---|
| 452 |
|
|---|
| 453 | // Send Corrections to Caster
|
|---|
| 454 | // --------------------------
|
|---|
| 455 | if ( _caster->usedSocket() &&
|
|---|
| 456 | (co.NumberOfGPSSat > 0 || co.NumberOfGLONASSSat > 0) ) {
|
|---|
| 457 | char obuffer[CLOCKORBIT_BUFFERSIZE];
|
|---|
| 458 | int len = MakeClockOrbit(&co, COTYPE_AUTO, 0, obuffer, sizeof(obuffer));
|
|---|
| 459 | if (len > 0) {
|
|---|
| 460 | _caster->write(obuffer, len);
|
|---|
| 461 | }
|
|---|
| 462 | }
|
|---|
| 463 |
|
|---|
| 464 | if ( _caster->usedSocket() &&
|
|---|
| 465 | (bias.NumberOfGPSSat > 0 || bias.NumberOfGLONASSSat > 0) ) {
|
|---|
| 466 | char obuffer[CLOCKORBIT_BUFFERSIZE];
|
|---|
| 467 | int len = MakeBias(&bias, BTYPE_AUTO, 0, obuffer, sizeof(obuffer));
|
|---|
| 468 | if (len > 0) {
|
|---|
| 469 | _caster->write(obuffer, len);
|
|---|
| 470 | }
|
|---|
| 471 | }
|
|---|
| 472 |
|
|---|
| 473 | // Optionall send new Corrections to PPP client and/or write into file
|
|---|
| 474 | // -------------------------------------------------------------------
|
|---|
| 475 | RTCM3coDecoder::reopen(_outNameSkl, _outName, _out);
|
|---|
| 476 | bncApp* app = (bncApp*) qApp;
|
|---|
| 477 | if (app->_bncPPPclient || _out) {
|
|---|
| 478 | QStringList corrLines;
|
|---|
| 479 | co.messageType = COTYPE_GPSCOMBINED;
|
|---|
| 480 | QStringListIterator il(RTCM3coDecoder::corrsToASCIIlines(resTime.gpsw(),
|
|---|
| 481 | resTime.gpssec(), co, 0));
|
|---|
| 482 | while (il.hasNext()) {
|
|---|
| 483 | QString line = il.next();
|
|---|
| 484 | if (_out) {
|
|---|
| 485 | *_out << line.toAscii().data() << endl;
|
|---|
| 486 | _out->flush();
|
|---|
| 487 | }
|
|---|
| 488 | line += " " + _caster->mountpoint();
|
|---|
| 489 | corrLines << line;
|
|---|
| 490 | }
|
|---|
| 491 |
|
|---|
| 492 | if (app->_bncPPPclient) {
|
|---|
| 493 | app->_bncPPPclient->slotNewCorrections(corrLines);
|
|---|
| 494 | }
|
|---|
| 495 | }
|
|---|
| 496 | }
|
|---|
| 497 |
|
|---|
| 498 | // Change the correction so that it refers to last received ephemeris
|
|---|
| 499 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 500 | void bncComb::switchToLastEph(const t_eph* lastEph, t_corr* corr) {
|
|---|
| 501 |
|
|---|
| 502 | ColumnVector oldXC(4);
|
|---|
| 503 | ColumnVector oldVV(3);
|
|---|
| 504 | corr->eph->position(corr->tt.gpsw(), corr->tt.gpssec(),
|
|---|
| 505 | oldXC.data(), oldVV.data());
|
|---|
| 506 |
|
|---|
| 507 | ColumnVector newXC(4);
|
|---|
| 508 | ColumnVector newVV(3);
|
|---|
| 509 | lastEph->position(corr->tt.gpsw(), corr->tt.gpssec(),
|
|---|
| 510 | newXC.data(), newVV.data());
|
|---|
| 511 |
|
|---|
| 512 | ColumnVector dX = newXC.Rows(1,3) - oldXC.Rows(1,3);
|
|---|
| 513 | ColumnVector dV = newVV - oldVV;
|
|---|
| 514 | double dC = newXC(4) - oldXC(4);
|
|---|
| 515 |
|
|---|
| 516 | ColumnVector dRAO(3);
|
|---|
| 517 | XYZ_to_RSW(newXC.Rows(1,3), newVV, dX, dRAO);
|
|---|
| 518 |
|
|---|
| 519 | ColumnVector dDotRAO(3);
|
|---|
| 520 | XYZ_to_RSW(newXC.Rows(1,3), newVV, dV, dDotRAO);
|
|---|
| 521 |
|
|---|
| 522 | QString msg = "switch " + corr->prn
|
|---|
| 523 | + QString(" %1 -> %2 %3").arg(corr->iod,3)
|
|---|
| 524 | .arg(lastEph->IOD(),3).arg(dC*t_CST::c, 8, 'f', 4);
|
|---|
| 525 |
|
|---|
| 526 | emit newMessage(msg.toAscii(), false);
|
|---|
| 527 |
|
|---|
| 528 | corr->iod = lastEph->IOD();
|
|---|
| 529 | corr->eph = lastEph;
|
|---|
| 530 | corr->rao += dRAO;
|
|---|
| 531 | corr->dotRao += dDotRAO;
|
|---|
| 532 | corr->dClk -= dC;
|
|---|
| 533 | }
|
|---|
| 534 |
|
|---|
| 535 | // Process Epochs
|
|---|
| 536 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 537 | void bncComb::processEpochs(const QList<cmbEpoch*>& epochs) {
|
|---|
| 538 |
|
|---|
| 539 | _log.clear();
|
|---|
| 540 |
|
|---|
| 541 | QTextStream out(&_log, QIODevice::WriteOnly);
|
|---|
| 542 |
|
|---|
| 543 | out << "Combination:" << endl
|
|---|
| 544 | << "------------------------------" << endl;
|
|---|
| 545 |
|
|---|
| 546 | // Predict Parameters Values, Add White Noise
|
|---|
| 547 | // ------------------------------------------
|
|---|
| 548 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
|---|
| 549 | cmbParam* pp = _params[iPar-1];
|
|---|
| 550 | if (pp->sig_P != 0.0) {
|
|---|
| 551 | pp->xx = 0.0;
|
|---|
| 552 | for (int jj = 1; jj <= _params.size(); jj++) {
|
|---|
| 553 | _QQ(iPar, jj) = 0.0;
|
|---|
| 554 | }
|
|---|
| 555 | _QQ(iPar,iPar) = pp->sig_P * pp->sig_P;
|
|---|
| 556 | }
|
|---|
| 557 | }
|
|---|
| 558 |
|
|---|
| 559 | bncTime resTime = epochs.first()->time;
|
|---|
| 560 | QMap<QString, t_corr*> resCorr;
|
|---|
| 561 |
|
|---|
| 562 | int nPar = _params.size();
|
|---|
| 563 | int nObs = 0;
|
|---|
| 564 |
|
|---|
| 565 | ColumnVector x0(nPar);
|
|---|
| 566 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
|---|
| 567 | cmbParam* pp = _params[iPar-1];
|
|---|
| 568 | x0(iPar) = pp->xx;
|
|---|
| 569 | }
|
|---|
| 570 |
|
|---|
| 571 | // Count Observations
|
|---|
| 572 | // ------------------
|
|---|
| 573 | QListIterator<cmbEpoch*> itEpo(epochs);
|
|---|
| 574 | while (itEpo.hasNext()) {
|
|---|
| 575 | cmbEpoch* epo = itEpo.next();
|
|---|
| 576 | QMutableMapIterator<QString, t_corr*> itCorr(epo->corr);
|
|---|
| 577 | while (itCorr.hasNext()) {
|
|---|
| 578 | itCorr.next();
|
|---|
| 579 | t_corr* corr = itCorr.value();
|
|---|
| 580 |
|
|---|
| 581 | // Switch to last ephemeris
|
|---|
| 582 | // ------------------------
|
|---|
| 583 | t_eph* lastEph = _eph[corr->prn]->last;
|
|---|
| 584 | if (lastEph == corr->eph) {
|
|---|
| 585 | ++nObs;
|
|---|
| 586 | }
|
|---|
| 587 | else {
|
|---|
| 588 | if (corr->eph == _eph[corr->prn]->prev) {
|
|---|
| 589 | switchToLastEph(lastEph, corr);
|
|---|
| 590 | ++nObs;
|
|---|
| 591 | }
|
|---|
| 592 | else {
|
|---|
| 593 | itCorr.remove();
|
|---|
| 594 | }
|
|---|
| 595 | }
|
|---|
| 596 | }
|
|---|
| 597 | }
|
|---|
| 598 |
|
|---|
| 599 | if (nObs > 0) {
|
|---|
| 600 | Matrix AA(nObs, nPar);
|
|---|
| 601 | ColumnVector ll(nObs);
|
|---|
| 602 | DiagonalMatrix PP(nObs); PP = 1.0;
|
|---|
| 603 |
|
|---|
| 604 | int iObs = 0;
|
|---|
| 605 | QListIterator<cmbEpoch*> itEpo(epochs);
|
|---|
| 606 | while (itEpo.hasNext()) {
|
|---|
| 607 | cmbEpoch* epo = itEpo.next();
|
|---|
| 608 | QMapIterator<QString, t_corr*> itCorr(epo->corr);
|
|---|
| 609 |
|
|---|
| 610 | while (itCorr.hasNext()) {
|
|---|
| 611 | itCorr.next();
|
|---|
| 612 | ++iObs;
|
|---|
| 613 | t_corr* corr = itCorr.value();
|
|---|
| 614 |
|
|---|
| 615 | if (epo->acName == _masterAC) {
|
|---|
| 616 | resCorr[corr->prn] = new t_corr(*corr);
|
|---|
| 617 | }
|
|---|
| 618 |
|
|---|
| 619 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
|---|
| 620 | cmbParam* pp = _params[iPar-1];
|
|---|
| 621 | AA(iObs, iPar) = pp->partial(epo->acName, corr);
|
|---|
| 622 | }
|
|---|
| 623 |
|
|---|
| 624 | ll(iObs) = corr->dClk * t_CST::c - DotProduct(AA.Row(iObs), x0);
|
|---|
| 625 | }
|
|---|
| 626 |
|
|---|
| 627 | delete epo;
|
|---|
| 628 | }
|
|---|
| 629 |
|
|---|
| 630 | const double MAXRES = 999.10; // TODO: make it an option
|
|---|
| 631 |
|
|---|
| 632 | ColumnVector dx;
|
|---|
| 633 | SymmetricMatrix QQ_sav = _QQ;
|
|---|
| 634 |
|
|---|
| 635 | for (int ii = 1; ii < 10; ii++) {
|
|---|
| 636 | bncModel::kalman(AA, ll, PP, _QQ, dx);
|
|---|
| 637 | ColumnVector vv = ll - AA * dx;
|
|---|
| 638 |
|
|---|
| 639 | int maxResIndex;
|
|---|
| 640 | double maxRes = vv.maximum_absolute_value1(maxResIndex);
|
|---|
| 641 | out.setRealNumberNotation(QTextStream::FixedNotation);
|
|---|
| 642 | out.setRealNumberPrecision(3);
|
|---|
| 643 | out << "Maximum Residuum " << maxRes << " (index " << maxResIndex << ")\n";
|
|---|
| 644 |
|
|---|
| 645 | if (maxRes > MAXRES) {
|
|---|
| 646 | out << "Outlier Detected" << endl;
|
|---|
| 647 | _QQ = QQ_sav;
|
|---|
| 648 | AA.Row(maxResIndex) = 0.0;
|
|---|
| 649 | ll.Row(maxResIndex) = 0.0;
|
|---|
| 650 | }
|
|---|
| 651 | else {
|
|---|
| 652 | break;
|
|---|
| 653 | }
|
|---|
| 654 | }
|
|---|
| 655 |
|
|---|
| 656 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
|---|
| 657 | cmbParam* pp = _params[iPar-1];
|
|---|
| 658 | pp->xx += dx(iPar);
|
|---|
| 659 | if (pp->type == cmbParam::clk) {
|
|---|
| 660 | if (resCorr.find(pp->prn) != resCorr.end()) {
|
|---|
| 661 | resCorr[pp->prn]->dClk = pp->xx / t_CST::c;
|
|---|
| 662 | }
|
|---|
| 663 | }
|
|---|
| 664 | out << currentDateAndTimeGPS().toString("yy-MM-dd hh:mm:ss ").toAscii().data();
|
|---|
| 665 | out.setRealNumberNotation(QTextStream::FixedNotation);
|
|---|
| 666 | out.setFieldWidth(8);
|
|---|
| 667 | out.setRealNumberPrecision(4);
|
|---|
| 668 | out << pp->toString() << " "
|
|---|
| 669 | << pp->xx << " +- " << sqrt(_QQ(pp->index,pp->index)) << endl;
|
|---|
| 670 | }
|
|---|
| 671 | }
|
|---|
| 672 |
|
|---|
| 673 | printResults(out, resTime, resCorr);
|
|---|
| 674 | dumpResults(resTime, resCorr);
|
|---|
| 675 |
|
|---|
| 676 | emit newMessage(_log, false);
|
|---|
| 677 | }
|
|---|
| 678 |
|
|---|
| 679 | // Print results to caster
|
|---|
| 680 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 681 | void bncComb::printResults(QTextStream& out, const bncTime& resTime,
|
|---|
| 682 | const QMap<QString, t_corr*>& resCorr) {
|
|---|
| 683 |
|
|---|
| 684 | QMapIterator<QString, t_corr*> it(resCorr);
|
|---|
| 685 | while (it.hasNext()) {
|
|---|
| 686 | it.next();
|
|---|
| 687 | t_corr* corr = it.value();
|
|---|
| 688 | const t_eph* eph = corr->eph;
|
|---|
| 689 | if (eph) {
|
|---|
| 690 | double xx, yy, zz, cc;
|
|---|
| 691 | eph->position(resTime.gpsw(), resTime.gpssec(), xx, yy, zz, cc);
|
|---|
| 692 |
|
|---|
| 693 | out << currentDateAndTimeGPS().toString("yy-MM-dd hh:mm:ss ").toAscii().data();
|
|---|
| 694 | out.setFieldWidth(3);
|
|---|
| 695 | out << "Full Clock " << corr->prn << " " << corr->iod << " ";
|
|---|
| 696 | out.setFieldWidth(14);
|
|---|
| 697 | out << (cc + corr->dClk) * t_CST::c << endl;
|
|---|
| 698 | }
|
|---|
| 699 | else {
|
|---|
| 700 | out << "bncComb::printResuls bug" << endl;
|
|---|
| 701 | }
|
|---|
| 702 | }
|
|---|
| 703 | }
|
|---|