[2898] | 1 | /* -------------------------------------------------------------------------
|
---|
| 2 | * BKG NTRIP Client
|
---|
| 3 | * -------------------------------------------------------------------------
|
---|
| 4 | *
|
---|
| 5 | * Class: bncComb
|
---|
| 6 | *
|
---|
| 7 | * Purpose: Combinations of Orbit/Clock Corrections
|
---|
| 8 | *
|
---|
| 9 | * Author: L. Mervart
|
---|
| 10 | *
|
---|
| 11 | * Created: 22-Jan-2011
|
---|
| 12 | *
|
---|
| 13 | * Changes:
|
---|
| 14 | *
|
---|
| 15 | * -----------------------------------------------------------------------*/
|
---|
| 16 |
|
---|
[2933] | 17 | #include <newmatio.h>
|
---|
[2921] | 18 | #include <iomanip>
|
---|
[2898] | 19 |
|
---|
| 20 | #include "bnccomb.h"
|
---|
| 21 | #include "bncapp.h"
|
---|
[2927] | 22 | #include "cmbcaster.h"
|
---|
[2910] | 23 | #include "bncsettings.h"
|
---|
[2933] | 24 | #include "bncmodel.h"
|
---|
[2988] | 25 | #include "bncutils.h"
|
---|
[3027] | 26 | #include "bncpppclient.h"
|
---|
[3046] | 27 | #include "bnssp3.h"
|
---|
[3052] | 28 | #include "bncantex.h"
|
---|
[3055] | 29 | #include "bnctides.h"
|
---|
[2898] | 30 |
|
---|
| 31 | using namespace std;
|
---|
| 32 |
|
---|
| 33 | // Constructor
|
---|
| 34 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3032] | 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_;
|
---|
[2933] | 45 | xx = 0.0;
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | // Destructor
|
---|
| 49 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 50 | cmbParam::~cmbParam() {
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | // Partial
|
---|
| 54 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3032] | 55 | double cmbParam::partial(const QString& AC_, t_corr* corr) {
|
---|
[2933] | 56 |
|
---|
[2934] | 57 | if (type == AC_offset) {
|
---|
[3032] | 58 | if (AC == AC_) {
|
---|
[2934] | 59 | return 1.0;
|
---|
| 60 | }
|
---|
| 61 | }
|
---|
| 62 | else if (type == Sat_offset) {
|
---|
[3032] | 63 | if (AC == AC_ && prn == corr->prn) {
|
---|
[2933] | 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 |
|
---|
[2990] | 76 | //
|
---|
| 77 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 78 | QString cmbParam::toString() const {
|
---|
[2933] | 79 |
|
---|
[2990] | 80 | QString outStr;
|
---|
| 81 |
|
---|
| 82 | if (type == AC_offset) {
|
---|
[2992] | 83 | outStr = "AC offset " + AC;
|
---|
[2990] | 84 | }
|
---|
| 85 | else if (type == Sat_offset) {
|
---|
[2992] | 86 | outStr = "Sat Offset " + AC + " " + prn;
|
---|
[2990] | 87 | }
|
---|
| 88 | else if (type == clk) {
|
---|
[2992] | 89 | outStr = "Clk Corr " + prn;
|
---|
[2990] | 90 | }
|
---|
[2933] | 91 |
|
---|
[2990] | 92 | return outStr;
|
---|
| 93 | }
|
---|
| 94 |
|
---|
[2933] | 95 | // Constructor
|
---|
| 96 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2898] | 97 | bncComb::bncComb() {
|
---|
[2910] | 98 |
|
---|
| 99 | bncSettings settings;
|
---|
| 100 |
|
---|
| 101 | QStringList combineStreams = settings.value("combineStreams").toStringList();
|
---|
[2918] | 102 |
|
---|
| 103 | if (combineStreams.size() >= 2) {
|
---|
[2910] | 104 | QListIterator<QString> it(combineStreams);
|
---|
| 105 | while (it.hasNext()) {
|
---|
| 106 | QStringList hlp = it.next().split(" ");
|
---|
[2918] | 107 | cmbAC* newAC = new cmbAC();
|
---|
| 108 | newAC->mountPoint = hlp[0];
|
---|
| 109 | newAC->name = hlp[1];
|
---|
| 110 | newAC->weight = hlp[2].toDouble();
|
---|
[3064] | 111 | if (_masterAC.isEmpty()) {
|
---|
| 112 | _masterAC = newAC->name;
|
---|
| 113 | }
|
---|
[2918] | 114 | _ACs[newAC->mountPoint] = newAC;
|
---|
[2910] | 115 | }
|
---|
| 116 | }
|
---|
[2927] | 117 |
|
---|
| 118 | _caster = new cmbCaster();
|
---|
[2990] | 119 | connect(this, SIGNAL(newMessage(QByteArray,bool)),
|
---|
| 120 | ((bncApp*)qApp), SLOT(slotMessage(const QByteArray,bool)));
|
---|
[2933] | 121 |
|
---|
[3032] | 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 | // ----------------------------------------------------------------------
|
---|
[2933] | 134 | int nextPar = 0;
|
---|
[2991] | 135 | QMapIterator<QString, cmbAC*> it(_ACs);
|
---|
| 136 | while (it.hasNext()) {
|
---|
| 137 | it.next();
|
---|
| 138 | cmbAC* AC = it.value();
|
---|
[3032] | 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 | }
|
---|
[2991] | 147 | }
|
---|
| 148 | }
|
---|
[2933] | 149 | for (int iGps = 1; iGps <= 32; iGps++) {
|
---|
| 150 | QString prn = QString("G%1").arg(iGps, 2, 10, QChar('0'));
|
---|
[3032] | 151 | _params.push_back(new cmbParam(cmbParam::clk, ++nextPar, "", prn,
|
---|
| 152 | sigClk_0, sigClk_P));
|
---|
[2933] | 153 | }
|
---|
| 154 |
|
---|
[3032] | 155 | // Initialize Variance-Covariance Matrix
|
---|
| 156 | // -------------------------------------
|
---|
| 157 | _QQ.ReSize(_params.size());
|
---|
[2933] | 158 | _QQ = 0.0;
|
---|
| 159 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 160 | cmbParam* pp = _params[iPar-1];
|
---|
[3032] | 161 | _QQ(iPar,iPar) = pp->sig_0 * pp->sig_0;
|
---|
[2933] | 162 | }
|
---|
[3035] | 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;
|
---|
[3046] | 175 |
|
---|
| 176 | // SP3 writer
|
---|
| 177 | // ----------
|
---|
[3047] | 178 | if ( settings.value("cmbSP3Path").toString().isEmpty() ) {
|
---|
[3046] | 179 | _sp3 = 0;
|
---|
| 180 | }
|
---|
| 181 | else {
|
---|
[3047] | 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);
|
---|
[3046] | 188 | }
|
---|
[3047] | 189 |
|
---|
| 190 | _append = Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked;
|
---|
[3052] | 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 | }
|
---|
[2898] | 204 | }
|
---|
| 205 |
|
---|
| 206 | // Destructor
|
---|
| 207 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 208 | bncComb::~bncComb() {
|
---|
[2918] | 209 | QMapIterator<QString, cmbAC*> it(_ACs);
|
---|
| 210 | while (it.hasNext()) {
|
---|
| 211 | it.next();
|
---|
| 212 | delete it.value();
|
---|
| 213 | }
|
---|
[2927] | 214 | delete _caster;
|
---|
[3035] | 215 | delete _out;
|
---|
[3046] | 216 | delete _sp3;
|
---|
[3052] | 217 | delete _antex;
|
---|
[2898] | 218 | }
|
---|
| 219 |
|
---|
[2928] | 220 | // Read and store one correction line
|
---|
[2898] | 221 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 222 | void bncComb::processCorrLine(const QString& staID, const QString& line) {
|
---|
[2906] | 223 | QMutexLocker locker(&_mutex);
|
---|
[2913] | 224 |
|
---|
[2918] | 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 | // -------------------
|
---|
[2913] | 234 | t_corr* newCorr = new t_corr();
|
---|
| 235 | if (!newCorr->readLine(line) == success) {
|
---|
| 236 | delete newCorr;
|
---|
| 237 | return;
|
---|
| 238 | }
|
---|
| 239 |
|
---|
[2924] | 240 | // Reject delayed corrections
|
---|
| 241 | // --------------------------
|
---|
| 242 | if (_processedBeforeTime.valid() && newCorr->tt < _processedBeforeTime) {
|
---|
| 243 | delete newCorr;
|
---|
| 244 | return;
|
---|
| 245 | }
|
---|
| 246 |
|
---|
[3029] | 247 | // Check the Ephemeris
|
---|
| 248 | //--------------------
|
---|
[2986] | 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;
|
---|
[3029] | 256 | if (lastEph && lastEph->IOD() == newCorr->iod) {
|
---|
| 257 | newCorr->eph = lastEph;
|
---|
[2986] | 258 | }
|
---|
[3029] | 259 | else if (prevEph && prevEph->IOD() == newCorr->iod) {
|
---|
| 260 | newCorr->eph = prevEph;
|
---|
| 261 | }
|
---|
| 262 | else {
|
---|
[2986] | 263 | delete newCorr;
|
---|
| 264 | return;
|
---|
| 265 | }
|
---|
| 266 | }
|
---|
| 267 |
|
---|
[2924] | 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 |
|
---|
[2927] | 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 |
|
---|
[2920] | 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 |
|
---|
[2918] | 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) {
|
---|
[2927] | 314 | newEpoch = new cmbEpoch(AC->name);
|
---|
[2918] | 315 | newEpoch->time = newCorr->tt;
|
---|
| 316 | AC->epochs.append(newEpoch);
|
---|
| 317 | }
|
---|
[2924] | 318 |
|
---|
| 319 | // Merge or add the correction
|
---|
| 320 | // ---------------------------
|
---|
[2918] | 321 | if (newEpoch->corr.find(newCorr->prn) != newEpoch->corr.end()) {
|
---|
[2919] | 322 | newEpoch->corr[newCorr->prn]->readLine(line); // merge (multiple messages)
|
---|
[2918] | 323 | }
|
---|
[2919] | 324 | else {
|
---|
| 325 | newEpoch->corr[newCorr->prn] = newCorr;
|
---|
| 326 | }
|
---|
[2898] | 327 | }
|
---|
| 328 |
|
---|
[2928] | 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 |
|
---|
[3078] | 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 |
|
---|
[2928] | 355 | QMapIterator<QString, t_corr*> it(resCorr);
|
---|
| 356 | while (it.hasNext()) {
|
---|
| 357 | it.next();
|
---|
| 358 | t_corr* corr = it.value();
|
---|
| 359 |
|
---|
[2931] | 360 | struct ClockOrbit::SatData* sd = 0;
|
---|
[2928] | 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;
|
---|
[2930] | 373 | sd->Clock.DeltaA0 = corr->dClk * t_CST::c;
|
---|
[2928] | 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 |
|
---|
[3078] | 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 |
|
---|
[3047] | 420 | // SP3 Output
|
---|
| 421 | // ----------
|
---|
| 422 | if (_sp3) {
|
---|
[3048] | 423 | ColumnVector xc(4);
|
---|
| 424 | ColumnVector vv(3);
|
---|
[3051] | 425 | corr->eph->position(resTime.gpsw(), resTime.gpssec(),
|
---|
[3048] | 426 | xc.data(), vv.data());
|
---|
[3051] | 427 | bncPPPclient::applyCorr(resTime, corr, xc, vv);
|
---|
[3054] | 428 |
|
---|
| 429 | // Relativistic Correction
|
---|
| 430 | // -----------------------
|
---|
[3051] | 431 | xc(4) += 2.0 * DotProduct(xc.Rows(1,3),vv) / t_CST::c / t_CST::c;
|
---|
[3054] | 432 |
|
---|
| 433 | // Correction Phase Center --> CoM
|
---|
| 434 | // -------------------------------
|
---|
[3052] | 435 | if (_antex) {
|
---|
[3055] | 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);
|
---|
[3052] | 442 | }
|
---|
| 443 | else {
|
---|
| 444 | cout << "antenna not found" << endl;
|
---|
| 445 | }
|
---|
| 446 | }
|
---|
[3048] | 447 | _sp3->write(resTime.gpsw(), resTime.gpssec(), corr->prn, xc, _append);
|
---|
[3047] | 448 | }
|
---|
| 449 |
|
---|
[2928] | 450 | delete corr;
|
---|
| 451 | }
|
---|
| 452 |
|
---|
[3025] | 453 | // Send Corrections to Caster
|
---|
| 454 | // --------------------------
|
---|
[2928] | 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 | }
|
---|
[3024] | 463 |
|
---|
[3078] | 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 |
|
---|
[3035] | 473 | // Optionall send new Corrections to PPP client and/or write into file
|
---|
| 474 | // -------------------------------------------------------------------
|
---|
| 475 | RTCM3coDecoder::reopen(_outNameSkl, _outName, _out);
|
---|
[3027] | 476 | bncApp* app = (bncApp*) qApp;
|
---|
[3035] | 477 | if (app->_bncPPPclient || _out) {
|
---|
[3027] | 478 | QStringList corrLines;
|
---|
| 479 | co.messageType = COTYPE_GPSCOMBINED;
|
---|
| 480 | QStringListIterator il(RTCM3coDecoder::corrsToASCIIlines(resTime.gpsw(),
|
---|
| 481 | resTime.gpssec(), co, 0));
|
---|
| 482 | while (il.hasNext()) {
|
---|
[3035] | 483 | QString line = il.next();
|
---|
| 484 | if (_out) {
|
---|
| 485 | *_out << line.toAscii().data() << endl;
|
---|
| 486 | _out->flush();
|
---|
| 487 | }
|
---|
| 488 | line += " " + _caster->mountpoint();
|
---|
[3027] | 489 | corrLines << line;
|
---|
| 490 | }
|
---|
[3035] | 491 |
|
---|
| 492 | if (app->_bncPPPclient) {
|
---|
| 493 | app->_bncPPPclient->slotNewCorrections(corrLines);
|
---|
| 494 | }
|
---|
[3024] | 495 | }
|
---|
[2928] | 496 | }
|
---|
| 497 |
|
---|
[2986] | 498 | // Change the correction so that it refers to last received ephemeris
|
---|
| 499 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3029] | 500 | void bncComb::switchToLastEph(const t_eph* lastEph, t_corr* corr) {
|
---|
[3028] | 501 |
|
---|
[2987] | 502 | ColumnVector oldXC(4);
|
---|
| 503 | ColumnVector oldVV(3);
|
---|
[3029] | 504 | corr->eph->position(corr->tt.gpsw(), corr->tt.gpssec(),
|
---|
| 505 | oldXC.data(), oldVV.data());
|
---|
[2988] | 506 |
|
---|
[2987] | 507 | ColumnVector newXC(4);
|
---|
| 508 | ColumnVector newVV(3);
|
---|
[3029] | 509 | lastEph->position(corr->tt.gpsw(), corr->tt.gpssec(),
|
---|
[2987] | 510 | newXC.data(), newVV.data());
|
---|
[2988] | 511 |
|
---|
| 512 | ColumnVector dX = newXC.Rows(1,3) - oldXC.Rows(1,3);
|
---|
[2989] | 513 | ColumnVector dV = newVV - oldVV;
|
---|
| 514 | double dC = newXC(4) - oldXC(4);
|
---|
| 515 |
|
---|
[2988] | 516 | ColumnVector dRAO(3);
|
---|
| 517 | XYZ_to_RSW(newXC.Rows(1,3), newVV, dX, dRAO);
|
---|
[2989] | 518 |
|
---|
| 519 | ColumnVector dDotRAO(3);
|
---|
| 520 | XYZ_to_RSW(newXC.Rows(1,3), newVV, dV, dDotRAO);
|
---|
| 521 |
|
---|
[3029] | 522 | QString msg = "switch " + corr->prn
|
---|
| 523 | + QString(" %1 -> %2 %3").arg(corr->iod,3)
|
---|
[3013] | 524 | .arg(lastEph->IOD(),3).arg(dC*t_CST::c, 8, 'f', 4);
|
---|
| 525 |
|
---|
[3029] | 526 | emit newMessage(msg.toAscii(), false);
|
---|
[3028] | 527 |
|
---|
[3029] | 528 | corr->iod = lastEph->IOD();
|
---|
| 529 | corr->eph = lastEph;
|
---|
[3031] | 530 | corr->rao += dRAO;
|
---|
| 531 | corr->dotRao += dDotRAO;
|
---|
[3029] | 532 | corr->dClk -= dC;
|
---|
[2986] | 533 | }
|
---|
| 534 |
|
---|
[2928] | 535 | // Process Epochs
|
---|
| 536 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2927] | 537 | void bncComb::processEpochs(const QList<cmbEpoch*>& epochs) {
|
---|
[2918] | 538 |
|
---|
[2990] | 539 | _log.clear();
|
---|
| 540 |
|
---|
| 541 | QTextStream out(&_log, QIODevice::WriteOnly);
|
---|
| 542 |
|
---|
[2991] | 543 | out << "Combination:" << endl
|
---|
| 544 | << "------------------------------" << endl;
|
---|
[2990] | 545 |
|
---|
[2933] | 546 | // Predict Parameters Values, Add White Noise
|
---|
| 547 | // ------------------------------------------
|
---|
| 548 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 549 | cmbParam* pp = _params[iPar-1];
|
---|
[3032] | 550 | if (pp->sig_P != 0.0) {
|
---|
[2933] | 551 | pp->xx = 0.0;
|
---|
| 552 | for (int jj = 1; jj <= _params.size(); jj++) {
|
---|
| 553 | _QQ(iPar, jj) = 0.0;
|
---|
| 554 | }
|
---|
[3032] | 555 | _QQ(iPar,iPar) = pp->sig_P * pp->sig_P;
|
---|
[2933] | 556 | }
|
---|
| 557 | }
|
---|
| 558 |
|
---|
[2928] | 559 | bncTime resTime = epochs.first()->time;
|
---|
| 560 | QMap<QString, t_corr*> resCorr;
|
---|
| 561 |
|
---|
[2933] | 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 | // ------------------
|
---|
[2927] | 573 | QListIterator<cmbEpoch*> itEpo(epochs);
|
---|
| 574 | while (itEpo.hasNext()) {
|
---|
| 575 | cmbEpoch* epo = itEpo.next();
|
---|
[3029] | 576 | QMutableMapIterator<QString, t_corr*> itCorr(epo->corr);
|
---|
[2927] | 577 | while (itCorr.hasNext()) {
|
---|
| 578 | itCorr.next();
|
---|
[3029] | 579 | t_corr* corr = itCorr.value();
|
---|
| 580 |
|
---|
[3032] | 581 | // Switch to last ephemeris
|
---|
| 582 | // ------------------------
|
---|
[3029] | 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 | }
|
---|
[2933] | 596 | }
|
---|
| 597 | }
|
---|
[2928] | 598 |
|
---|
[2933] | 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 |
|
---|
[3032] | 615 | if (epo->acName == _masterAC) {
|
---|
[2933] | 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);
|
---|
[3034] | 625 | }
|
---|
[2990] | 626 |
|
---|
[3034] | 627 | delete epo;
|
---|
[2933] | 628 | }
|
---|
[2928] | 629 |
|
---|
[3081] | 630 | const double MAXRES = 999.10; // TODO: make it an option
|
---|
[3080] | 631 |
|
---|
[2933] | 632 | ColumnVector dx;
|
---|
[3080] | 633 | SymmetricMatrix QQ_sav = _QQ;
|
---|
[2933] | 634 |
|
---|
[3080] | 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 |
|
---|
[2933] | 656 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
| 657 | cmbParam* pp = _params[iPar-1];
|
---|
| 658 | pp->xx += dx(iPar);
|
---|
[2935] | 659 | if (pp->type == cmbParam::clk) {
|
---|
[2936] | 660 | if (resCorr.find(pp->prn) != resCorr.end()) {
|
---|
| 661 | resCorr[pp->prn]->dClk = pp->xx / t_CST::c;
|
---|
| 662 | }
|
---|
[2935] | 663 | }
|
---|
[3011] | 664 | out << currentDateAndTimeGPS().toString("yy-MM-dd hh:mm:ss ").toAscii().data();
|
---|
[2990] | 665 | out.setRealNumberNotation(QTextStream::FixedNotation);
|
---|
| 666 | out.setFieldWidth(8);
|
---|
| 667 | out.setRealNumberPrecision(4);
|
---|
| 668 | out << pp->toString() << " "
|
---|
[2991] | 669 | << pp->xx << " +- " << sqrt(_QQ(pp->index,pp->index)) << endl;
|
---|
[2918] | 670 | }
|
---|
| 671 | }
|
---|
[2919] | 672 |
|
---|
[3015] | 673 | printResults(out, resTime, resCorr);
|
---|
[2928] | 674 | dumpResults(resTime, resCorr);
|
---|
| 675 |
|
---|
[2990] | 676 | emit newMessage(_log, false);
|
---|
[2918] | 677 | }
|
---|
[3011] | 678 |
|
---|
| 679 | // Print results to caster
|
---|
| 680 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3015] | 681 | void bncComb::printResults(QTextStream& out, const bncTime& resTime,
|
---|
[3011] | 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();
|
---|
[3029] | 688 | const t_eph* eph = corr->eph;
|
---|
[3015] | 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 | }
|
---|
[3011] | 702 | }
|
---|
| 703 | }
|
---|