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