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 | QMapIterator<QString, t_corr*> it(resCorr);
|
---|
350 | while (it.hasNext()) {
|
---|
351 | it.next();
|
---|
352 | t_corr* corr = it.value();
|
---|
353 |
|
---|
354 | struct ClockOrbit::SatData* sd = 0;
|
---|
355 | if (corr->prn[0] == 'G') {
|
---|
356 | sd = co.Sat + co.NumberOfGPSSat;
|
---|
357 | ++co.NumberOfGPSSat;
|
---|
358 | }
|
---|
359 | else if (corr->prn[0] == 'R') {
|
---|
360 | sd = co.Sat + CLOCKORBIT_NUMGPS + co.NumberOfGLONASSSat;
|
---|
361 | ++co.NumberOfGLONASSSat;
|
---|
362 | }
|
---|
363 |
|
---|
364 | if (sd != 0) {
|
---|
365 | sd->ID = corr->prn.mid(1).toInt();
|
---|
366 | sd->IOD = corr->iod;
|
---|
367 | sd->Clock.DeltaA0 = corr->dClk * t_CST::c;
|
---|
368 | sd->Orbit.DeltaRadial = corr->rao(1);
|
---|
369 | sd->Orbit.DeltaAlongTrack = corr->rao(2);
|
---|
370 | sd->Orbit.DeltaCrossTrack = corr->rao(3);
|
---|
371 | sd->Orbit.DotDeltaRadial = corr->dotRao(1);
|
---|
372 | sd->Orbit.DotDeltaAlongTrack = corr->dotRao(2);
|
---|
373 | sd->Orbit.DotDeltaCrossTrack = corr->dotRao(3);
|
---|
374 | }
|
---|
375 |
|
---|
376 | // SP3 Output
|
---|
377 | // ----------
|
---|
378 | if (_sp3) {
|
---|
379 | ColumnVector xc(4);
|
---|
380 | ColumnVector vv(3);
|
---|
381 | corr->eph->position(resTime.gpsw(), resTime.gpssec(),
|
---|
382 | xc.data(), vv.data());
|
---|
383 | bncPPPclient::applyCorr(resTime, corr, xc, vv);
|
---|
384 |
|
---|
385 | // Relativistic Correction
|
---|
386 | // -----------------------
|
---|
387 | xc(4) += 2.0 * DotProduct(xc.Rows(1,3),vv) / t_CST::c / t_CST::c;
|
---|
388 |
|
---|
389 | // Correction Phase Center --> CoM
|
---|
390 | // -------------------------------
|
---|
391 | if (_antex) {
|
---|
392 | ColumnVector dx(3); dx = 0.0;
|
---|
393 | double Mjd = resTime.mjd() + resTime.daysec()/86400.0;
|
---|
394 | if (_antex->satCoMcorrection(corr->prn, Mjd, xc.Rows(1,3), dx) == success) {
|
---|
395 | xc(1) -= dx(1);
|
---|
396 | xc(2) -= dx(2);
|
---|
397 | xc(3) -= dx(3);
|
---|
398 | }
|
---|
399 | else {
|
---|
400 | cout << "antenna not found" << endl;
|
---|
401 | }
|
---|
402 | }
|
---|
403 | _sp3->write(resTime.gpsw(), resTime.gpssec(), corr->prn, xc, _append);
|
---|
404 | }
|
---|
405 |
|
---|
406 | delete corr;
|
---|
407 | }
|
---|
408 |
|
---|
409 | // Send Corrections to Caster
|
---|
410 | // --------------------------
|
---|
411 | if ( _caster->usedSocket() &&
|
---|
412 | (co.NumberOfGPSSat > 0 || co.NumberOfGLONASSSat > 0) ) {
|
---|
413 | char obuffer[CLOCKORBIT_BUFFERSIZE];
|
---|
414 | int len = MakeClockOrbit(&co, COTYPE_AUTO, 0, obuffer, sizeof(obuffer));
|
---|
415 | if (len > 0) {
|
---|
416 | _caster->write(obuffer, len);
|
---|
417 | }
|
---|
418 | }
|
---|
419 |
|
---|
420 | // Optionall send new Corrections to PPP client and/or write into file
|
---|
421 | // -------------------------------------------------------------------
|
---|
422 | RTCM3coDecoder::reopen(_outNameSkl, _outName, _out);
|
---|
423 | bncApp* app = (bncApp*) qApp;
|
---|
424 | if (app->_bncPPPclient || _out) {
|
---|
425 | QStringList corrLines;
|
---|
426 | co.messageType = COTYPE_GPSCOMBINED;
|
---|
427 | QStringListIterator il(RTCM3coDecoder::corrsToASCIIlines(resTime.gpsw(),
|
---|
428 | resTime.gpssec(), co, 0));
|
---|
429 | while (il.hasNext()) {
|
---|
430 | QString line = il.next();
|
---|
431 | if (_out) {
|
---|
432 | *_out << line.toAscii().data() << endl;
|
---|
433 | _out->flush();
|
---|
434 | }
|
---|
435 | line += " " + _caster->mountpoint();
|
---|
436 | corrLines << line;
|
---|
437 | }
|
---|
438 |
|
---|
439 | if (app->_bncPPPclient) {
|
---|
440 | app->_bncPPPclient->slotNewCorrections(corrLines);
|
---|
441 | }
|
---|
442 | }
|
---|
443 | }
|
---|
444 |
|
---|
445 | // Change the correction so that it refers to last received ephemeris
|
---|
446 | ////////////////////////////////////////////////////////////////////////////
|
---|
447 | void bncComb::switchToLastEph(const t_eph* lastEph, t_corr* corr) {
|
---|
448 |
|
---|
449 | ColumnVector oldXC(4);
|
---|
450 | ColumnVector oldVV(3);
|
---|
451 | corr->eph->position(corr->tt.gpsw(), corr->tt.gpssec(),
|
---|
452 | oldXC.data(), oldVV.data());
|
---|
453 |
|
---|
454 | ColumnVector newXC(4);
|
---|
455 | ColumnVector newVV(3);
|
---|
456 | lastEph->position(corr->tt.gpsw(), corr->tt.gpssec(),
|
---|
457 | newXC.data(), newVV.data());
|
---|
458 |
|
---|
459 | ColumnVector dX = newXC.Rows(1,3) - oldXC.Rows(1,3);
|
---|
460 | ColumnVector dV = newVV - oldVV;
|
---|
461 | double dC = newXC(4) - oldXC(4);
|
---|
462 |
|
---|
463 | ColumnVector dRAO(3);
|
---|
464 | XYZ_to_RSW(newXC.Rows(1,3), newVV, dX, dRAO);
|
---|
465 |
|
---|
466 | ColumnVector dDotRAO(3);
|
---|
467 | XYZ_to_RSW(newXC.Rows(1,3), newVV, dV, dDotRAO);
|
---|
468 |
|
---|
469 | QString msg = "switch " + corr->prn
|
---|
470 | + QString(" %1 -> %2 %3").arg(corr->iod,3)
|
---|
471 | .arg(lastEph->IOD(),3).arg(dC*t_CST::c, 8, 'f', 4);
|
---|
472 |
|
---|
473 | emit newMessage(msg.toAscii(), false);
|
---|
474 |
|
---|
475 | corr->iod = lastEph->IOD();
|
---|
476 | corr->eph = lastEph;
|
---|
477 | corr->rao += dRAO;
|
---|
478 | corr->dotRao += dDotRAO;
|
---|
479 | corr->dClk -= dC;
|
---|
480 | }
|
---|
481 |
|
---|
482 | // Process Epochs
|
---|
483 | ////////////////////////////////////////////////////////////////////////////
|
---|
484 | void bncComb::processEpochs(const QList<cmbEpoch*>& epochs) {
|
---|
485 |
|
---|
486 | _log.clear();
|
---|
487 |
|
---|
488 | QTextStream out(&_log, QIODevice::WriteOnly);
|
---|
489 |
|
---|
490 | out << "Combination:" << endl
|
---|
491 | << "------------------------------" << endl;
|
---|
492 |
|
---|
493 | // Predict Parameters Values, Add White Noise
|
---|
494 | // ------------------------------------------
|
---|
495 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
496 | cmbParam* pp = _params[iPar-1];
|
---|
497 | if (pp->sig_P != 0.0) {
|
---|
498 | pp->xx = 0.0;
|
---|
499 | for (int jj = 1; jj <= _params.size(); jj++) {
|
---|
500 | _QQ(iPar, jj) = 0.0;
|
---|
501 | }
|
---|
502 | _QQ(iPar,iPar) = pp->sig_P * pp->sig_P;
|
---|
503 | }
|
---|
504 | }
|
---|
505 |
|
---|
506 | bncTime resTime = epochs.first()->time;
|
---|
507 | QMap<QString, t_corr*> resCorr;
|
---|
508 |
|
---|
509 | int nPar = _params.size();
|
---|
510 | int nObs = 0;
|
---|
511 |
|
---|
512 | ColumnVector x0(nPar);
|
---|
513 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
514 | cmbParam* pp = _params[iPar-1];
|
---|
515 | x0(iPar) = pp->xx;
|
---|
516 | }
|
---|
517 |
|
---|
518 | // Count Observations
|
---|
519 | // ------------------
|
---|
520 | QListIterator<cmbEpoch*> itEpo(epochs);
|
---|
521 | while (itEpo.hasNext()) {
|
---|
522 | cmbEpoch* epo = itEpo.next();
|
---|
523 | QMutableMapIterator<QString, t_corr*> itCorr(epo->corr);
|
---|
524 | while (itCorr.hasNext()) {
|
---|
525 | itCorr.next();
|
---|
526 | t_corr* corr = itCorr.value();
|
---|
527 |
|
---|
528 | // Switch to last ephemeris
|
---|
529 | // ------------------------
|
---|
530 | t_eph* lastEph = _eph[corr->prn]->last;
|
---|
531 | if (lastEph == corr->eph) {
|
---|
532 | ++nObs;
|
---|
533 | }
|
---|
534 | else {
|
---|
535 | if (corr->eph == _eph[corr->prn]->prev) {
|
---|
536 | switchToLastEph(lastEph, corr);
|
---|
537 | ++nObs;
|
---|
538 | }
|
---|
539 | else {
|
---|
540 | itCorr.remove();
|
---|
541 | }
|
---|
542 | }
|
---|
543 | }
|
---|
544 | }
|
---|
545 |
|
---|
546 | if (nObs > 0) {
|
---|
547 | Matrix AA(nObs, nPar);
|
---|
548 | ColumnVector ll(nObs);
|
---|
549 | DiagonalMatrix PP(nObs); PP = 1.0;
|
---|
550 |
|
---|
551 | int iObs = 0;
|
---|
552 | QListIterator<cmbEpoch*> itEpo(epochs);
|
---|
553 | while (itEpo.hasNext()) {
|
---|
554 | cmbEpoch* epo = itEpo.next();
|
---|
555 | QMapIterator<QString, t_corr*> itCorr(epo->corr);
|
---|
556 |
|
---|
557 | while (itCorr.hasNext()) {
|
---|
558 | itCorr.next();
|
---|
559 | ++iObs;
|
---|
560 | t_corr* corr = itCorr.value();
|
---|
561 |
|
---|
562 | if (epo->acName == _masterAC) {
|
---|
563 | resCorr[corr->prn] = new t_corr(*corr);
|
---|
564 | }
|
---|
565 |
|
---|
566 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
567 | cmbParam* pp = _params[iPar-1];
|
---|
568 | AA(iObs, iPar) = pp->partial(epo->acName, corr);
|
---|
569 | }
|
---|
570 |
|
---|
571 | ll(iObs) = corr->dClk * t_CST::c - DotProduct(AA.Row(iObs), x0);
|
---|
572 | }
|
---|
573 |
|
---|
574 | delete epo;
|
---|
575 | }
|
---|
576 |
|
---|
577 | ColumnVector dx;
|
---|
578 | bncModel::kalman(AA, ll, PP, _QQ, dx);
|
---|
579 | ColumnVector vv = ll - AA * dx;
|
---|
580 |
|
---|
581 | for (int iPar = 1; iPar <= _params.size(); iPar++) {
|
---|
582 | cmbParam* pp = _params[iPar-1];
|
---|
583 | pp->xx += dx(iPar);
|
---|
584 | if (pp->type == cmbParam::clk) {
|
---|
585 | if (resCorr.find(pp->prn) != resCorr.end()) {
|
---|
586 | resCorr[pp->prn]->dClk = pp->xx / t_CST::c;
|
---|
587 | }
|
---|
588 | }
|
---|
589 | out << currentDateAndTimeGPS().toString("yy-MM-dd hh:mm:ss ").toAscii().data();
|
---|
590 | out.setRealNumberNotation(QTextStream::FixedNotation);
|
---|
591 | out.setFieldWidth(8);
|
---|
592 | out.setRealNumberPrecision(4);
|
---|
593 | out << pp->toString() << " "
|
---|
594 | << pp->xx << " +- " << sqrt(_QQ(pp->index,pp->index)) << endl;
|
---|
595 | }
|
---|
596 | }
|
---|
597 |
|
---|
598 | printResults(out, resTime, resCorr);
|
---|
599 | dumpResults(resTime, resCorr);
|
---|
600 |
|
---|
601 | emit newMessage(_log, false);
|
---|
602 | }
|
---|
603 |
|
---|
604 | // Print results to caster
|
---|
605 | ////////////////////////////////////////////////////////////////////////////
|
---|
606 | void bncComb::printResults(QTextStream& out, const bncTime& resTime,
|
---|
607 | const QMap<QString, t_corr*>& resCorr) {
|
---|
608 |
|
---|
609 | QMapIterator<QString, t_corr*> it(resCorr);
|
---|
610 | while (it.hasNext()) {
|
---|
611 | it.next();
|
---|
612 | t_corr* corr = it.value();
|
---|
613 | const t_eph* eph = corr->eph;
|
---|
614 | if (eph) {
|
---|
615 | double xx, yy, zz, cc;
|
---|
616 | eph->position(resTime.gpsw(), resTime.gpssec(), xx, yy, zz, cc);
|
---|
617 |
|
---|
618 | out << currentDateAndTimeGPS().toString("yy-MM-dd hh:mm:ss ").toAscii().data();
|
---|
619 | out.setFieldWidth(3);
|
---|
620 | out << "Full Clock " << corr->prn << " " << corr->iod << " ";
|
---|
621 | out.setFieldWidth(14);
|
---|
622 | out << (cc + corr->dClk) * t_CST::c << endl;
|
---|
623 | }
|
---|
624 | else {
|
---|
625 | out << "bncComb::printResuls bug" << endl;
|
---|
626 | }
|
---|
627 | }
|
---|
628 | }
|
---|