source: ntrip/trunk/BNC/src/upload/bncrtnetuploadcaster.cpp@ 10230

Last change on this file since 10230 was 10227, checked in by stuerze, 13 months ago

minor changes

File size: 42.6 KB
Line 
1/* -------------------------------------------------------------------------
2 * BKG NTRIP Server
3 * -------------------------------------------------------------------------
4 *
5 * Class: bncRtnetUploadCaster
6 *
7 * Purpose: Connection to NTRIP Caster
8 *
9 * Author: L. Mervart
10 *
11 * Created: 29-Mar-2011
12 *
13 * Changes:
14 *
15 * -----------------------------------------------------------------------*/
16
17#include <math.h>
18#include "bncrtnetuploadcaster.h"
19#include "bncsettings.h"
20#include "bncephuser.h"
21#include "bncclockrinex.h"
22#include "bncbiassinex.h"
23#include "bncsp3.h"
24#include "gnss.h"
25#include "bncutils.h"
26
27using namespace std;
28
29// Constructor
30////////////////////////////////////////////////////////////////////////////
31bncRtnetUploadCaster::bncRtnetUploadCaster(const QString& mountpoint,
32 const QString& outHost, int outPort,
33 const QString& ntripVersion,
34 const QString& userName, const QString& password,
35 const QString& crdTrafo, const QString& ssrFormat, bool CoM, const QString& sp3FileName,
36 const QString& rnxFileName, const QString& bsxFileName, int PID, int SID, int IOD, int iRow) :
37 bncUploadCaster(mountpoint, outHost, outPort, ntripVersion, userName, password, iRow, 0) {
38
39 if (!mountpoint.isEmpty()) {
40 _casterID += mountpoint;
41 }
42 if (!outHost.isEmpty()) {
43 _casterID += " " + outHost;
44 if (outPort) {
45 _casterID += ":" + QString("%1").arg(outPort, 10);
46 }
47 }
48 if (!crdTrafo.isEmpty()) {
49 _casterID += " " + crdTrafo;
50 }
51 if (!sp3FileName.isEmpty()) {
52 _casterID += " " + sp3FileName;
53 }
54 if (!rnxFileName.isEmpty()) {
55 _casterID += " " + rnxFileName;
56 }
57
58 if (!bsxFileName.isEmpty()) {
59 _casterID += " " + bsxFileName;
60 }
61
62 _crdTrafo = crdTrafo;
63
64 _ssrFormat = ssrFormat;
65
66 _ssrCorr = 0;
67 if (_ssrFormat == "IGS-SSR") {
68 _ssrCorr = new SsrCorrIgs();
69 }
70 else if (_ssrFormat == "RTCM-SSR") {
71 _ssrCorr = new SsrCorrRtcm();
72 }
73
74 _CoM = CoM;
75 _PID = PID;
76 _SID = SID;
77 _IOD = IOD;
78 _phaseBiasInformationDecoded = false;
79
80 // Member that receives the ephemeris
81 // ----------------------------------
82 _ephUser = new bncEphUser(true);
83
84 bncSettings settings;
85 QString intr = settings.value("uploadIntr").toString();
86 QStringList hlp = settings.value("cmbStreams").toStringList();
87 _samplRtcmEphCorr = settings.value("uploadSamplRtcmEphCorr").toDouble();
88 if (hlp.size() > 1) { // combination stream upload
89 _samplRtcmClkCorr = settings.value("cmbSampl").toInt();
90 }
91 else { // single stream upload or sp3 file generation
92 _samplRtcmClkCorr = 5; // default
93 }
94 int samplClkRnx = settings.value("uploadSamplClkRnx").toInt();
95 int samplSp3 = settings.value("uploadSamplSp3").toString().split("sec").first().toInt();
96 int samplBiaSnx = settings.value("uploadSamplBiaSnx").toInt();
97
98 if (_samplRtcmEphCorr == 0.0) {
99 _usedEph = 0;
100 }
101 else {
102 _usedEph = new QMap<QString, const t_eph*>;
103 }
104
105 // RINEX writer
106 // ------------
107 if (!rnxFileName.isEmpty()) {
108 _rnx = new bncClockRinex(rnxFileName, intr, samplClkRnx);
109 }
110 else {
111 _rnx = 0;
112 }
113
114 // SP3 writer
115 // ----------
116 if (!sp3FileName.isEmpty()) {
117 _sp3 = new bncSP3(sp3FileName, intr, samplSp3);
118 }
119 else {
120 _sp3 = 0;
121 }
122
123 // SINEX writer
124 // ------------
125 if (!bsxFileName.isEmpty()) {
126 _bsx = new bncBiasSinex(bsxFileName, intr, samplBiaSnx);
127 }
128 else {
129 _bsx = 0;
130 }
131
132
133 // Set Transformation Parameters
134 // -----------------------------
135 // Transformation Parameters from ITRF2014 to ETRF2000
136 // EUREF Technical Note 1 Relationship and Transformation between the ITRF and ETRF
137 // Zuheir Altamimi, June 28, 2018
138 if (_crdTrafo == "ETRF2000") {
139 _dx = 0.0547;
140 _dy = 0.0522;
141 _dz = -0.0741;
142
143 _dxr = 0.0001;
144 _dyr = 0.0001;
145 _dzr = -0.0019;
146
147 _ox = 0.001701;
148 _oy = 0.010290;
149 _oz = -0.016632;
150
151 _oxr = 0.000081;
152 _oyr = 0.000490;
153 _ozr = -0.000729;
154
155 _sc = 2.12;
156 _scr = 0.11;
157
158 _t0 = 2010.0;
159 }
160 // Transformation Parameters from ITRF2014 to GDA2020 (Ryan Ruddick, GA)
161 else if (_crdTrafo == "GDA2020") {
162 _dx = 0.0;
163 _dy = 0.0;
164 _dz = 0.0;
165
166 _dxr = 0.0;
167 _dyr = 0.0;
168 _dzr = 0.0;
169
170 _ox = 0.0;
171 _oy = 0.0;
172 _oz = 0.0;
173
174 _oxr = 0.00150379;
175 _oyr = 0.00118346;
176 _ozr = 0.00120716;
177
178 _sc = 0.0;
179 _scr = 0.0;
180
181 _t0 = 2020.0;
182 }
183 // Transformation Parameters from IGb14 to SIRGAS2000 (Thanks to Sonia Costa, BRA)
184 // June 29 2020: TX:-0.0027 m TY:-0.0025 m TZ:-0.0042 m SCL:1.20 (ppb) no rotations and no rates.*/
185 else if (_crdTrafo == "SIRGAS2000") {
186 _dx = -0.0027;
187 _dy = -0.0025;
188 _dz = -0.0042;
189
190 _dxr = 0.0;
191 _dyr = 0.0;
192 _dzr = 0.0;
193
194 _ox = 0.0;
195 _oy = 0.0;
196 _oz = 0.0;
197
198 _oxr = 0.0;
199 _oyr = 0.0;
200 _ozr = 0.0;
201
202 _sc = 1.2;
203 _scr = 0.0;
204 _t0 = 2000.0;
205 }
206 // Transformation Parameters from ITRF2014 to DREF91
207 else if (_crdTrafo == "DREF91") {
208 _dx = 0.0547;
209 _dy = 0.0522;
210 _dz = -0.0741;
211
212 _dxr = 0.0001;
213 _dyr = 0.0001;
214 _dzr = -0.0019;
215 // ERTF200 + rotation parameters (ETRF2000 => DREF91)
216 _ox = 0.001701 + 0.000658;
217 _oy = 0.010290 - 0.000208;
218 _oz = -0.016632 + 0.000755;
219
220 _oxr = 0.000081;
221 _oyr = 0.000490;
222 _ozr = -0.000729;
223
224 _sc = 2.12;
225 _scr = 0.11;
226
227 _t0 = 2010.0;
228 }
229 else if (_crdTrafo == "Custom") {
230 _dx = settings.value("trafo_dx").toDouble();
231 _dy = settings.value("trafo_dy").toDouble();
232 _dz = settings.value("trafo_dz").toDouble();
233 _dxr = settings.value("trafo_dxr").toDouble();
234 _dyr = settings.value("trafo_dyr").toDouble();
235 _dzr = settings.value("trafo_dzr").toDouble();
236 _ox = settings.value("trafo_ox").toDouble();
237 _oy = settings.value("trafo_oy").toDouble();
238 _oz = settings.value("trafo_oz").toDouble();
239 _oxr = settings.value("trafo_oxr").toDouble();
240 _oyr = settings.value("trafo_oyr").toDouble();
241 _ozr = settings.value("trafo_ozr").toDouble();
242 _sc = settings.value("trafo_sc").toDouble();
243 _scr = settings.value("trafo_scr").toDouble();
244 _t0 = settings.value("trafo_t0").toDouble();
245 }
246 // TODO: the following lines can be deleted if all parameters are updated regarding ITRF2020
247 if (_crdTrafo == "ETRF2000" ||
248 _crdTrafo == "GDA2020" ||
249 _crdTrafo == "DREF91" ||
250 _crdTrafo == "SIRGAS2000") {
251 // Transformation Parameters from ITRF2020 to ITRF2014
252 // from ITRF web site: https://itrf.ign.fr/en/solutions/transformations
253 _dx14 = -0.0014;
254 _dy14 = -0.0009;
255 _dz14 = 0.0014;
256 _dxr14 = 0.0;
257 _dyr14 = -0.0001;
258 _dzr14 = -0.0002;
259 _ox14 = 0.0;
260 _oy14 = 0.0;
261 _oz14 = 0.0;
262 _oxr14 = 0.0;
263 _oyr14 = 0.0;
264 _ozr14 = 0.0;
265 _sc14 = -0.42;
266 _scr14 = 0.0;
267 _t014 = 2015.0;
268 }
269}
270
271// Destructor
272////////////////////////////////////////////////////////////////////////////
273bncRtnetUploadCaster::~bncRtnetUploadCaster() {
274 if (isRunning()) {
275 wait();
276 }
277 delete _rnx;
278 delete _sp3;
279 delete _ephUser;
280 delete _usedEph;
281 delete _ssrCorr;
282}
283
284//
285////////////////////////////////////////////////////////////////////////////
286void bncRtnetUploadCaster::decodeRtnetStream(char* buffer, int bufLen) {
287
288 QMutexLocker locker(&_mutex);
289
290 // Append to internal buffer
291 // -------------------------
292 _rtnetStreamBuffer.append(QByteArray(buffer, bufLen));
293
294 // Select buffer part that contains last epoch
295 // -------------------------------------------
296
297 // Find the begin of last epoch
298 int iEpoBeg = _rtnetStreamBuffer.lastIndexOf('*');
299 if (iEpoBeg == -1) {
300 _rtnetStreamBuffer.clear();
301 emit(newMessage(QString("bncRtnetUploadCaster: no Epoch line found: %1").arg(_casterID).toLatin1(), false));
302 return;
303 }
304
305 // Find the begin of the first epoch
306 int iEpoBegEarlier = _rtnetStreamBuffer.indexOf('*');
307 if (iEpoBegEarlier != -1 && iEpoBegEarlier < iEpoBeg) {
308 _rtnetStreamBuffer = _rtnetStreamBuffer.mid(iEpoBegEarlier);
309 }
310 else {
311 _rtnetStreamBuffer = _rtnetStreamBuffer.mid(iEpoBeg);
312 }
313
314 // Find End of the last epoch
315 int iEpoEnd = _rtnetStreamBuffer.lastIndexOf("EOE");
316 if (iEpoEnd == -1) {
317 _rtnetStreamBuffer.clear();
318 emit(newMessage(QString("bncRtnetUploadCaster: no EOE found: %1").arg(_casterID).toLatin1(), false));
319 return;
320 }
321
322 QStringList lines;
323 // If there is there more than 1 epoch line in the buffer
324 while (_rtnetStreamBuffer.count('*') > 1) {
325 emit(newMessage(QString("bncRtnetUploadCaster: more than 1 epoch in buffer: %1").arg(_rtnetStreamBuffer.count('*')).toLatin1(), false));
326 QString rtnetStreamBuffer = _rtnetStreamBuffer;
327 int nextEpoch = rtnetStreamBuffer.indexOf('*');
328 int nextEpochEnd = rtnetStreamBuffer.indexOf("EOE");
329 _rtnetStreamBuffer = _rtnetStreamBuffer.mid(1);
330 if (nextEpoch != -1 && nextEpoch < iEpoEnd) {
331 rtnetStreamBuffer = rtnetStreamBuffer.mid(nextEpoch, nextEpochEnd);
332 lines = rtnetStreamBuffer.split('\n', QString::SkipEmptyParts);
333 if (lines.size() > 2) {
334 decodeRtnetEpoch(lines);
335 }
336 nextEpochEnd = _rtnetStreamBuffer.indexOf("EOE");
337 _rtnetStreamBuffer = _rtnetStreamBuffer.mid(nextEpochEnd+3);
338 }
339 else if (nextEpoch != -1 && nextEpoch >= iEpoEnd) {
340 break;
341 }
342 }
343
344 lines = _rtnetStreamBuffer.left(iEpoEnd).split('\n', QString::SkipEmptyParts);
345
346 _rtnetStreamBuffer = _rtnetStreamBuffer.mid(iEpoEnd + 3);
347
348 if (lines.size() < 2) {
349 emit(newMessage(QString("bncRtnetUploadCaster: less than 2 lines to decode : %1").arg(_casterID).toLatin1(), false));
350 return;
351 }
352 decodeRtnetEpoch(lines);
353}
354
355//
356////////////////////////////////////////////////////////////////////////////
357void bncRtnetUploadCaster::decodeRtnetEpoch(QStringList epochLines) {
358
359 // Read first line (with epoch time)
360 // ---------------------------------
361 QTextStream in(epochLines[0].toLatin1());
362 QString hlp;
363 int year, month, day, hour, min;
364 double sec;
365 in >> hlp >> year >> month >> day >> hour >> min >> sec;
366 bncTime epoTime;
367 epoTime.set(year, month, day, hour, min, sec);
368
369 emit(newMessage(
370 "bncRtnetUploadCaster: decode " + QByteArray(epoTime.datestr().c_str())
371 + " " + QByteArray(epoTime.timestr().c_str()) + " "
372 + _casterID.toLatin1(), false));
373
374 struct SsrCorr::ClockOrbit co;
375 memset(&co, 0, sizeof(co));
376 co.EpochTime[CLOCKORBIT_SATGPS] = static_cast<int>(epoTime.gpssec());
377 if (_ssrFormat == "RTCM-SSR") {
378 double gt = epoTime.gpssec() + 3 * 3600 - gnumleap(year, month, day);
379 co.EpochTime[CLOCKORBIT_SATGLONASS] = static_cast<int>(fmod(gt, 86400.0));
380 }
381 else if (_ssrFormat == "IGS-SSR") {
382 co.EpochTime[CLOCKORBIT_SATGLONASS] = static_cast<int>(epoTime.gpssec());
383 }
384 co.EpochTime[CLOCKORBIT_SATGALILEO] = static_cast<int>(epoTime.gpssec());
385 co.EpochTime[CLOCKORBIT_SATQZSS] = static_cast<int>(epoTime.gpssec());
386 co.EpochTime[CLOCKORBIT_SATSBAS] = static_cast<int>(epoTime.gpssec());
387 if (_ssrFormat == "RTCM-SSR") {
388 co.EpochTime[CLOCKORBIT_SATBDS] = static_cast<int>(epoTime.bdssec());
389 }
390 else if (_ssrFormat == "IGS-SSR") {
391 co.EpochTime[CLOCKORBIT_SATBDS] = static_cast<int>(epoTime.gpssec());
392 }
393 co.Supplied[_ssrCorr->COBOFS_CLOCK] = 1;
394 co.Supplied[_ssrCorr->COBOFS_ORBIT] = 1;
395 co.SatRefDatum = _ssrCorr->DATUM_ITRF; // ToDo: to decode from RTNET format
396 co.SSRIOD = _IOD;
397 co.SSRProviderID = _PID; // 256 .. BKG, 257 ... EUREF
398 co.SSRSolutionID = _SID;
399
400 struct SsrCorr::CodeBias bias;
401 memset(&bias, 0, sizeof(bias));
402 bias.EpochTime[CLOCKORBIT_SATGPS] = co.EpochTime[CLOCKORBIT_SATGPS];
403 bias.EpochTime[CLOCKORBIT_SATGLONASS] = co.EpochTime[CLOCKORBIT_SATGLONASS];
404 bias.EpochTime[CLOCKORBIT_SATGALILEO] = co.EpochTime[CLOCKORBIT_SATGALILEO];
405 bias.EpochTime[CLOCKORBIT_SATQZSS] = co.EpochTime[CLOCKORBIT_SATQZSS];
406 bias.EpochTime[CLOCKORBIT_SATSBAS] = co.EpochTime[CLOCKORBIT_SATSBAS];
407 bias.EpochTime[CLOCKORBIT_SATBDS] = co.EpochTime[CLOCKORBIT_SATBDS];
408 bias.SSRIOD = _IOD;
409 bias.SSRProviderID = _PID;
410 bias.SSRSolutionID = _SID;
411
412 struct SsrCorr::PhaseBias phasebias;
413 memset(&phasebias, 0, sizeof(phasebias));
414 unsigned int dispersiveBiasConsistenyIndicator = 0;
415 unsigned int mwConsistencyIndicator = 0;
416 phasebias.EpochTime[CLOCKORBIT_SATGPS] = co.EpochTime[CLOCKORBIT_SATGPS];
417 phasebias.EpochTime[CLOCKORBIT_SATGLONASS] = co.EpochTime[CLOCKORBIT_SATGLONASS];
418 phasebias.EpochTime[CLOCKORBIT_SATGALILEO] = co.EpochTime[CLOCKORBIT_SATGALILEO];
419 phasebias.EpochTime[CLOCKORBIT_SATQZSS] = co.EpochTime[CLOCKORBIT_SATQZSS];
420 phasebias.EpochTime[CLOCKORBIT_SATSBAS] = co.EpochTime[CLOCKORBIT_SATSBAS];
421 phasebias.EpochTime[CLOCKORBIT_SATBDS] = co.EpochTime[CLOCKORBIT_SATBDS];
422 phasebias.SSRIOD = _IOD;
423 phasebias.SSRProviderID = _PID;
424 phasebias.SSRSolutionID = _SID;
425
426 struct SsrCorr::VTEC vtec;
427 memset(&vtec, 0, sizeof(vtec));
428 vtec.EpochTime = static_cast<int>(epoTime.gpssec());
429 vtec.SSRIOD = _IOD;
430 vtec.SSRProviderID = _PID;
431 vtec.SSRSolutionID = _SID;
432
433 // Default Update Interval
434 // -----------------------
435 int clkUpdInd = 2; // 5 sec
436 int ephUpdInd = clkUpdInd; // default
437
438 if (!_samplRtcmEphCorr) {
439 _samplRtcmEphCorr = 5.0;
440 }
441
442 if (_samplRtcmClkCorr > 5.0 && _samplRtcmEphCorr <= 5.0) { // combined orb and clock
443 ephUpdInd = determineUpdateInd(_samplRtcmClkCorr);
444 }
445 if (_samplRtcmClkCorr > 5.0) {
446 clkUpdInd = determineUpdateInd(_samplRtcmClkCorr);
447 }
448 if (_samplRtcmEphCorr > 5.0) {
449 ephUpdInd = determineUpdateInd(_samplRtcmEphCorr);
450 }
451
452 co.UpdateInterval = clkUpdInd;
453 bias.UpdateInterval = ephUpdInd;
454 phasebias.UpdateInterval = ephUpdInd;
455
456 for (int ii = 1; ii < epochLines.size(); ii++) {
457 QString key; // prn or key VTEC, IND (phase bias indicators)
458 double rtnUra = 0.0; // [m]
459 ColumnVector rtnAPC; rtnAPC.ReSize(3); rtnAPC = 0.0; // [m, m, m]
460 ColumnVector rtnVel; rtnVel.ReSize(3); rtnVel = 0.0; // [m/s, m/s, m/s]
461 ColumnVector rtnCoM; rtnCoM.ReSize(3); rtnCoM = 0.0; // [m, m, m]
462 ColumnVector rtnClk; rtnClk.ReSize(3); rtnClk = 0.0; // [m, m/s, m/s²]
463 ColumnVector rtnClkSig; rtnClkSig.ReSize(3); rtnClkSig = 0.0; // [m, m/s, m/s²]
464 t_prn prn;
465
466 QTextStream in(epochLines[ii].toLatin1());
467
468 in >> key;
469
470 // non-satellite specific parameters
471 if (key.contains("IND", Qt::CaseSensitive)) {
472 in >> dispersiveBiasConsistenyIndicator >> mwConsistencyIndicator;
473 continue;
474 }
475 // non-satellite specific parameters
476 if (key.contains("VTEC", Qt::CaseSensitive)) {
477 double ui;
478 in >> ui >> vtec.NumLayers;
479 vtec.UpdateInterval = (unsigned int) determineUpdateInd(ui);
480 for (unsigned ll = 0; ll < vtec.NumLayers; ll++) {
481 int dummy;
482 in >> dummy >> vtec.Layers[ll].Degree >> vtec.Layers[ll].Order
483 >> vtec.Layers[ll].Height;
484 for (unsigned iDeg = 0; iDeg <= vtec.Layers[ll].Degree; iDeg++) {
485 for (unsigned iOrd = 0; iOrd <= vtec.Layers[ll].Order; iOrd++) {
486 in >> vtec.Layers[ll].Cosinus[iDeg][iOrd];
487 }
488 }
489 for (unsigned iDeg = 0; iDeg <= vtec.Layers[ll].Degree; iDeg++) {
490 for (unsigned iOrd = 0; iOrd <= vtec.Layers[ll].Order; iOrd++) {
491 in >> vtec.Layers[ll].Sinus[iDeg][iOrd];
492 }
493 }
494 }
495 continue;
496 }
497 // satellite specific parameters
498 char sys = key.mid(0, 1).at(0).toLatin1();
499 int number = key.mid(1, 2).toInt();
500 int flags = 0;
501 if (sys == 'E') { // I/NAV
502 flags = 1;
503 }
504 if (number == 0) {
505 continue;
506 }
507 prn.set(sys, number, flags);
508 QString prnInternalStr = QString::fromStdString(prn.toInternalString());
509 QString prnStr = QString::fromStdString(prn.toString());
510
511 const t_eph* ephLast = _ephUser->ephLast(prnInternalStr);
512 const t_eph* ephPrev = _ephUser->ephPrev(prnInternalStr);
513 const t_eph* eph = ephLast;
514 if (eph) {
515
516 // Use previous ephemeris if the last one is too recent
517 // ----------------------------------------------------
518 const int MINAGE = 60; // seconds
519 if (ephPrev && eph->receptDateTime().isValid() &&
520 eph->receptDateTime().secsTo(currentDateAndTimeGPS()) < MINAGE) {
521 eph = ephPrev;
522 }
523
524 // Make sure the clock messages refer to same IOD as orbit messages
525 // ----------------------------------------------------------------
526 if (_usedEph) {
527 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
528 (*_usedEph)[prnInternalStr] = eph;
529 }
530 else {
531 eph = 0;
532 if (_usedEph->contains(prnInternalStr)) {
533 const t_eph* usedEph = _usedEph->value(prnInternalStr);
534 if (usedEph == ephLast) {
535 eph = ephLast;
536 }
537 else if (usedEph == ephPrev) {
538 eph = ephPrev;
539 }
540 }
541 }
542 }
543 }
544
545 if (eph &&
546 !outDatedBcep(eph) && // detected from storage because of no update
547 eph->checkState() != t_eph::bad &&
548 eph->checkState() != t_eph::unhealthy &&
549 eph->checkState() != t_eph::outdated) { // detected during reception (bncephuser)
550 QMap<QString, double> codeBiases;
551 QList<phaseBiasSignal> phaseBiasList;
552 phaseBiasesSat pbSat;
553 _phaseBiasInformationDecoded = false;
554
555 while (true) {
556 QString key;
557 int numVal = 0;
558 in >> key;
559 if (in.status() != QTextStream::Ok) {
560 break;
561 }
562 if (key == "APC") {
563 in >> numVal;
564 rtnAPC.ReSize(3); rtnAPC = 0.0;
565 for (int ii = 0; ii < numVal; ii++) {
566 in >> rtnAPC[ii];
567 }
568 }
569 else if (key == "Ura") {
570 in >> numVal;
571 if (numVal == 1)
572 in >> rtnUra;
573 }
574 else if (key == "Clk") {
575 in >> numVal;
576 rtnClk.ReSize(3); rtnClk = 0.0;
577 for (int ii = 0; ii < numVal; ii++) {
578 in >> rtnClk[ii];
579 }
580 }
581 else if (key == "ClkSig") {
582 in >> numVal;
583 rtnClkSig.ReSize(3); rtnClkSig = 0.0;
584 for (int ii = 0; ii < numVal; ii++) {
585 in >> rtnClkSig[ii];
586 }
587 }
588 else if (key == "Vel") {
589 in >> numVal;
590 rtnVel.ReSize(3); rtnVel = 0.0;
591 for (int ii = 0; ii < numVal; ii++) {
592 in >> rtnVel[ii];
593 }
594 }
595 else if (key == "CoM") {
596 in >> numVal;
597 rtnCoM.ReSize(3); rtnCoM = 0.0;
598 for (int ii = 0; ii < numVal; ii++) {
599 in >> rtnCoM[ii];
600 }
601 }
602 else if (key == "CodeBias") {
603 in >> numVal;
604 for (int ii = 0; ii < numVal; ii++) {
605 QString type;
606 double value;
607 in >> type >> value;
608 codeBiases[type] = value;
609 }
610 }
611 else if (key == "YawAngle") {
612 _phaseBiasInformationDecoded = true;
613 in >> numVal >> pbSat.yawAngle;
614 if (pbSat.yawAngle < 0.0) {
615 pbSat.yawAngle += (2*M_PI);
616 }
617 else if (pbSat.yawAngle > 2*M_PI) {
618 pbSat.yawAngle -= (2*M_PI);
619 }
620 }
621 else if (key == "YawRate") {
622 _phaseBiasInformationDecoded = true;
623 in >> numVal >> pbSat.yawRate;
624 }
625 else if (key == "PhaseBias") {
626 _phaseBiasInformationDecoded = true;
627 in >> numVal;
628 for (int ii = 0; ii < numVal; ii++) {
629 phaseBiasSignal pb;
630 in >> pb.type >> pb.bias >> pb.integerIndicator
631 >> pb.wlIndicator >> pb.discontinuityCounter;
632 phaseBiasList.append(pb);
633 }
634 }
635 else {
636 in >> numVal;
637 for (int ii = 0; ii < numVal; ii++) {
638 double dummy;
639 in >> dummy;
640 }
641 emit(newMessage(" RTNET format error: "
642 + epochLines[ii].toLatin1(), false));
643 break;
644 }
645 }
646
647 struct SsrCorr::ClockOrbit::SatData* sd = 0;
648 if (prn.system() == 'G') {
649 sd = co.Sat + co.NumberOfSat[CLOCKORBIT_SATGPS];
650 ++co.NumberOfSat[CLOCKORBIT_SATGPS];
651 }
652 else if (prn.system() == 'R') {
653 sd = co.Sat + CLOCKORBIT_NUMGPS + co.NumberOfSat[CLOCKORBIT_SATGLONASS];
654 ++co.NumberOfSat[CLOCKORBIT_SATGLONASS];
655 }
656 else if (prn.system() == 'E') {
657 sd = co.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
658 + co.NumberOfSat[CLOCKORBIT_SATGALILEO];
659 ++co.NumberOfSat[CLOCKORBIT_SATGALILEO];
660 }
661 else if (prn.system() == 'J') {
662 sd = co.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
663 + CLOCKORBIT_NUMGALILEO
664 + co.NumberOfSat[CLOCKORBIT_SATQZSS];
665 ++co.NumberOfSat[CLOCKORBIT_SATQZSS];
666 }
667 else if (prn.system() == 'S') {
668 sd = co.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
669 + CLOCKORBIT_NUMGALILEO + CLOCKORBIT_NUMQZSS
670 + co.NumberOfSat[CLOCKORBIT_SATSBAS];
671 ++co.NumberOfSat[CLOCKORBIT_SATSBAS];
672 }
673 else if (prn.system() == 'C') {
674 sd = co.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
675 + CLOCKORBIT_NUMGALILEO + CLOCKORBIT_NUMQZSS
676 + CLOCKORBIT_NUMSBAS
677 + co.NumberOfSat[CLOCKORBIT_SATBDS];
678 ++co.NumberOfSat[CLOCKORBIT_SATBDS];
679 }
680 if (sd) {
681 QString outLine;
682 t_irc irc = processSatellite(eph, epoTime.gpsw(), epoTime.gpssec(), prnStr, rtnAPC,
683 rtnUra, rtnClk, rtnVel, rtnCoM, rtnClkSig, sd, outLine);
684 if (irc != success) {
685 continue;
686 }
687 }
688
689 // Code Biases
690 // -----------
691 struct SsrCorr::CodeBias::BiasSat* biasSat = 0;
692 if (!codeBiases.isEmpty()) {
693 if (prn.system() == 'G') {
694 biasSat = bias.Sat + bias.NumberOfSat[CLOCKORBIT_SATGPS];
695 ++bias.NumberOfSat[CLOCKORBIT_SATGPS];
696 }
697 else if (prn.system() == 'R') {
698 biasSat = bias.Sat + CLOCKORBIT_NUMGPS
699 + bias.NumberOfSat[CLOCKORBIT_SATGLONASS];
700 ++bias.NumberOfSat[CLOCKORBIT_SATGLONASS];
701 }
702 else if (prn.system() == 'E') {
703 biasSat = bias.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
704 + bias.NumberOfSat[CLOCKORBIT_SATGALILEO];
705 ++bias.NumberOfSat[CLOCKORBIT_SATGALILEO];
706 }
707 else if (prn.system() == 'J') {
708 biasSat = bias.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
709 + CLOCKORBIT_NUMGALILEO
710 + bias.NumberOfSat[CLOCKORBIT_SATQZSS];
711 ++bias.NumberOfSat[CLOCKORBIT_SATQZSS];
712 }
713 else if (prn.system() == 'S') {
714 biasSat = bias.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
715 + CLOCKORBIT_NUMGALILEO + CLOCKORBIT_NUMQZSS
716 + bias.NumberOfSat[CLOCKORBIT_SATSBAS];
717 ++bias.NumberOfSat[CLOCKORBIT_SATSBAS];
718 }
719 else if (prn.system() == 'C') {
720 biasSat = bias.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
721 + CLOCKORBIT_NUMGALILEO + CLOCKORBIT_NUMQZSS
722 + CLOCKORBIT_NUMSBAS
723 + bias.NumberOfSat[CLOCKORBIT_SATBDS];
724 ++bias.NumberOfSat[CLOCKORBIT_SATBDS];
725 }
726 }
727
728 if (biasSat) {
729 biasSat->ID = prn.number();
730 biasSat->NumberOfCodeBiases = 0;
731 QMapIterator<QString, double> it(codeBiases);
732 while (it.hasNext()) {
733 it.next();
734 int ii = biasSat->NumberOfCodeBiases;
735 if (ii >= CLOCKORBIT_NUMBIAS)
736 break;
737 SsrCorr::CodeType type = _ssrCorr->rnxTypeToCodeType(prn.system(), it.key().toStdString());
738 if (type != _ssrCorr->RESERVED) {
739 biasSat->NumberOfCodeBiases += 1;
740 biasSat->Biases[ii].Type = type;
741 biasSat->Biases[ii].Bias = it.value();
742 if (_bsx) {
743 QString obsCode = 'C' + it.key();
744 _bsx->write(epoTime.gpsw(), epoTime.gpssec(), prnStr, obsCode, it.value());
745 }
746 }
747 }
748 }
749
750 // Phase Biases
751 // ------------
752 struct SsrCorr::PhaseBias::PhaseBiasSat* phasebiasSat = 0;
753 if (prn.system() == 'G') {
754 phasebiasSat = phasebias.Sat
755 + phasebias.NumberOfSat[CLOCKORBIT_SATGPS];
756 ++phasebias.NumberOfSat[CLOCKORBIT_SATGPS];
757 }
758 else if (prn.system() == 'R') {
759 phasebiasSat = phasebias.Sat + CLOCKORBIT_NUMGPS
760 + phasebias.NumberOfSat[CLOCKORBIT_SATGLONASS];
761 ++phasebias.NumberOfSat[CLOCKORBIT_SATGLONASS];
762 }
763 else if (prn.system() == 'E') {
764 phasebiasSat = phasebias.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
765 + phasebias.NumberOfSat[CLOCKORBIT_SATGALILEO];
766 ++phasebias.NumberOfSat[CLOCKORBIT_SATGALILEO];
767 }
768 else if (prn.system() == 'J') {
769 phasebiasSat = phasebias.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
770 + CLOCKORBIT_NUMGALILEO
771 + phasebias.NumberOfSat[CLOCKORBIT_SATQZSS];
772 ++phasebias.NumberOfSat[CLOCKORBIT_SATQZSS];
773 }
774 else if (prn.system() == 'S') {
775 phasebiasSat = phasebias.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
776 + CLOCKORBIT_NUMGALILEO + CLOCKORBIT_NUMQZSS
777 + phasebias.NumberOfSat[CLOCKORBIT_SATSBAS];
778 ++phasebias.NumberOfSat[CLOCKORBIT_SATSBAS];
779 }
780 else if (prn.system() == 'C') {
781 phasebiasSat = phasebias.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
782 + CLOCKORBIT_NUMGALILEO + CLOCKORBIT_NUMQZSS
783 + CLOCKORBIT_NUMSBAS
784 + phasebias.NumberOfSat[CLOCKORBIT_SATBDS];
785 ++phasebias.NumberOfSat[CLOCKORBIT_SATBDS];
786 }
787
788 if (phasebiasSat && _phaseBiasInformationDecoded) {
789 phasebias.DispersiveBiasConsistencyIndicator = dispersiveBiasConsistenyIndicator;
790 phasebias.MWConsistencyIndicator = mwConsistencyIndicator;
791 phasebiasSat->ID = prn.number();
792 phasebiasSat->NumberOfPhaseBiases = 0;
793 phasebiasSat->YawAngle = pbSat.yawAngle;
794 phasebiasSat->YawRate = pbSat.yawRate;
795 QListIterator<phaseBiasSignal> it(phaseBiasList);
796 while (it.hasNext()) {
797 const phaseBiasSignal &pbSig = it.next();
798 int ii = phasebiasSat->NumberOfPhaseBiases;
799 if (ii >= CLOCKORBIT_NUMBIAS)
800 break;
801 SsrCorr::CodeType type = _ssrCorr->rnxTypeToCodeType(prn.system(), pbSig.type.toStdString());
802 if (type != _ssrCorr->RESERVED) {
803 phasebiasSat->NumberOfPhaseBiases += 1;
804 phasebiasSat->Biases[ii].Type = type;
805 phasebiasSat->Biases[ii].Bias = pbSig.bias;
806 phasebiasSat->Biases[ii].SignalIntegerIndicator = pbSig.integerIndicator;
807 phasebiasSat->Biases[ii].SignalsWideLaneIntegerIndicator = pbSig.wlIndicator;
808 phasebiasSat->Biases[ii].SignalDiscontinuityCounter = pbSig.discontinuityCounter;
809 if (_bsx) {
810 QString obsCode = 'L' + pbSig.type;
811 _bsx->write(epoTime.gpsw(), epoTime.gpssec(), prnStr, obsCode, pbSig.bias);
812 }
813 }
814 }
815 }
816 }
817 }
818
819 QByteArray hlpBufferCo;
820
821 // Orbit and Clock Corrections together
822 // ------------------------------------
823 if (_samplRtcmEphCorr == _samplRtcmClkCorr) {
824 if (co.NumberOfSat[CLOCKORBIT_SATGPS] > 0
825 || co.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0
826 || co.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0
827 || co.NumberOfSat[CLOCKORBIT_SATQZSS] > 0
828 || co.NumberOfSat[CLOCKORBIT_SATSBAS] > 0
829 || co.NumberOfSat[CLOCKORBIT_SATBDS] > 0) {
830 char obuffer[CLOCKORBIT_BUFFERSIZE] = {'\0'};
831 int len = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_AUTO, 0, obuffer, sizeof(obuffer));
832 if (len > 0) {
833 hlpBufferCo = QByteArray(obuffer, len);
834 }
835 }
836 }
837
838 // Orbit and Clock Corrections separately
839 // --------------------------------------
840 else {
841 if (co.NumberOfSat[CLOCKORBIT_SATGPS] > 0) {
842 char obuffer[CLOCKORBIT_BUFFERSIZE] = {'\0'};
843 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
844 co.UpdateInterval = ephUpdInd;
845 int len1 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_GPSORBIT, 1, obuffer, sizeof(obuffer));
846 co.UpdateInterval = clkUpdInd;
847 if (len1 > 0) {
848 hlpBufferCo += QByteArray(obuffer, len1);
849 }
850 }
851 int mmsg = (co.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0 ||
852 co.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0 ||
853 co.NumberOfSat[CLOCKORBIT_SATQZSS] > 0 ||
854 co.NumberOfSat[CLOCKORBIT_SATSBAS] > 0 ||
855 co.NumberOfSat[CLOCKORBIT_SATBDS] > 0 ) ? 1 : 0;
856 int len2 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_GPSCLOCK, mmsg, obuffer, sizeof(obuffer));
857 if (len2 > 0) {
858 hlpBufferCo += QByteArray(obuffer, len2);
859 }
860 }
861 if (co.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0) {
862 char obuffer[CLOCKORBIT_BUFFERSIZE] = {'\0'};
863 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
864 co.UpdateInterval = ephUpdInd;
865 int len1 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_GLONASSORBIT, 1, obuffer, sizeof(obuffer));
866 co.UpdateInterval = clkUpdInd;
867 if (len1 > 0) {
868 hlpBufferCo += QByteArray(obuffer, len1);
869 }
870 }
871 int mmsg = (co.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0 ||
872 co.NumberOfSat[CLOCKORBIT_SATQZSS] > 0 ||
873 co.NumberOfSat[CLOCKORBIT_SATSBAS] > 0 ||
874 co.NumberOfSat[CLOCKORBIT_SATBDS] > 0 ) ? 1 : 0;
875 int len2 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_GLONASSCLOCK, mmsg, obuffer, sizeof(obuffer));
876 if (len2 > 0) {
877 hlpBufferCo += QByteArray(obuffer, len2);
878 }
879 }
880 if (co.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0) {
881 char obuffer[CLOCKORBIT_BUFFERSIZE] = {'\0'};
882 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
883 co.UpdateInterval = ephUpdInd;
884 int len1 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_GALILEOORBIT, 1, obuffer, sizeof(obuffer));
885 co.UpdateInterval = clkUpdInd;
886 if (len1 > 0) {
887 hlpBufferCo += QByteArray(obuffer, len1);
888 }
889 }
890 int mmsg = (co.NumberOfSat[CLOCKORBIT_SATQZSS] > 0 ||
891 co.NumberOfSat[CLOCKORBIT_SATSBAS] > 0 ||
892 co.NumberOfSat[CLOCKORBIT_SATBDS] > 0 ) ? 1 : 0;
893 int len2 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_GALILEOCLOCK, mmsg, obuffer, sizeof(obuffer));
894 if (len2 > 0) {
895 hlpBufferCo += QByteArray(obuffer, len2);
896 }
897 }
898 if (co.NumberOfSat[CLOCKORBIT_SATQZSS] > 0) {
899 char obuffer[CLOCKORBIT_BUFFERSIZE] = {'\0'};
900 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
901 co.UpdateInterval = ephUpdInd;
902 int len1 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_QZSSORBIT, 1, obuffer, sizeof(obuffer));
903 co.UpdateInterval = clkUpdInd;
904 if (len1 > 0) {
905 hlpBufferCo += QByteArray(obuffer, len1);
906 }
907 }
908 int mmsg = (co.NumberOfSat[CLOCKORBIT_SATSBAS] > 0 ||
909 co.NumberOfSat[CLOCKORBIT_SATBDS] > 0 ) ? 1 : 0;
910 int len2 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_QZSSCLOCK, mmsg, obuffer, sizeof(obuffer));
911 if (len2 > 0) {
912 hlpBufferCo += QByteArray(obuffer, len2);
913 }
914 }
915 if (co.NumberOfSat[CLOCKORBIT_SATSBAS] > 0) {
916 char obuffer[CLOCKORBIT_BUFFERSIZE] = {'\0'};
917 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
918 co.UpdateInterval = ephUpdInd;
919 int len1 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_SBASORBIT, 1, obuffer, sizeof(obuffer));
920 co.UpdateInterval = clkUpdInd;
921 if (len1 > 0) {
922 hlpBufferCo += QByteArray(obuffer, len1);
923 }
924 }
925 int mmsg = (co.NumberOfSat[CLOCKORBIT_SATBDS] > 0) ? 1 : 0;
926 int len2 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_SBASCLOCK, mmsg, obuffer,
927 sizeof(obuffer));
928 if (len2 > 0) {
929 hlpBufferCo += QByteArray(obuffer, len2);
930 }
931 }
932 if (co.NumberOfSat[CLOCKORBIT_SATBDS] > 0) {
933 char obuffer[CLOCKORBIT_BUFFERSIZE] = {'\0'};
934 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
935 co.UpdateInterval = ephUpdInd;
936 int len1 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_BDSORBIT, 1, obuffer, sizeof(obuffer));
937 co.UpdateInterval = clkUpdInd;
938 if (len1 > 0) {
939 hlpBufferCo += QByteArray(obuffer, len1);
940 }
941 }
942 int mmsg = 0;
943 int len2 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_BDSCLOCK, mmsg, obuffer, sizeof(obuffer));
944 if (len2 > 0) {
945 hlpBufferCo += QByteArray(obuffer, len2);
946 }
947 }
948 }
949
950 // Code Biases
951 // -----------
952 QByteArray hlpBufferBias;
953 if (bias.NumberOfSat[CLOCKORBIT_SATGPS] > 0
954 || bias.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0
955 || bias.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0
956 || bias.NumberOfSat[CLOCKORBIT_SATQZSS] > 0
957 || bias.NumberOfSat[CLOCKORBIT_SATSBAS] > 0
958 || bias.NumberOfSat[CLOCKORBIT_SATBDS] > 0) {
959 char obuffer[CLOCKORBIT_BUFFERSIZE] = {'\0'};
960 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
961 int len = _ssrCorr->MakeCodeBias(&bias, _ssrCorr->CBTYPE_AUTO, 0, obuffer, sizeof(obuffer));
962 if (len > 0) {
963 hlpBufferBias = QByteArray(obuffer, len);
964 }
965 }
966 }
967
968 // Phase Biases
969 // ------------
970 QByteArray hlpBufferPhaseBias;
971 if ((phasebias.NumberOfSat[CLOCKORBIT_SATGPS] > 0
972 || phasebias.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0
973 || phasebias.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0
974 || phasebias.NumberOfSat[CLOCKORBIT_SATQZSS] > 0
975 || phasebias.NumberOfSat[CLOCKORBIT_SATSBAS] > 0
976 || phasebias.NumberOfSat[CLOCKORBIT_SATBDS] > 0)
977 && (_phaseBiasInformationDecoded)) {
978 char obuffer[CLOCKORBIT_BUFFERSIZE] = {'\0'};
979 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
980 int len = _ssrCorr->MakePhaseBias(&phasebias, _ssrCorr->PBTYPE_AUTO, 0, obuffer, sizeof(obuffer));
981 if (len > 0) {
982 hlpBufferPhaseBias = QByteArray(obuffer, len);
983 }
984 }
985 }
986
987 // VTEC
988 // ----
989 QByteArray hlpBufferVtec;
990 if (vtec.NumLayers > 0) {
991 char obuffer[CLOCKORBIT_BUFFERSIZE] = {'\0'};
992 int len = _ssrCorr->MakeVTEC(&vtec, 0, obuffer, sizeof(obuffer));
993 if (len > 0) {
994 hlpBufferVtec = QByteArray(obuffer, len);
995 }
996 }
997
998 _outBuffer += hlpBufferCo + hlpBufferBias + hlpBufferPhaseBias + hlpBufferVtec + '\0';
999}
1000//
1001////////////////////////////////////////////////////////////////////////////
1002t_irc bncRtnetUploadCaster::processSatellite(const t_eph* eph, int GPSweek,
1003 double GPSweeks, const QString& prn, const ColumnVector& rtnAPC,
1004 double rtnUra, const ColumnVector& rtnClk, const ColumnVector& rtnVel,
1005 const ColumnVector& rtnCoM, const ColumnVector& rtnClkSig,
1006 struct SsrCorr::ClockOrbit::SatData* sd, QString& outLine) {
1007
1008 // Broadcast Position and Velocity
1009 // -------------------------------
1010 ColumnVector xB(6);
1011 ColumnVector vB(3);
1012 t_irc irc = eph->getCrd(bncTime(GPSweek, GPSweeks), xB, vB, false);
1013
1014 if (irc != success) {
1015 return irc;
1016 }
1017
1018 // Precise Position
1019 // ----------------
1020 ColumnVector xP = _CoM ? rtnCoM : rtnAPC;
1021
1022 if (xP.size() == 0) {
1023 return failure;
1024 }
1025
1026 double dc = 0.0;
1027 if (_crdTrafo != "IGS20") {
1028 crdTrafo14(GPSweek, xP, dc); // ITRF2020 => ITRF2014
1029 crdTrafo(GPSweek, xP, dc); // ITRF2014 to other reference frames
1030 }
1031
1032 // Difference in xyz
1033 // -----------------
1034 ColumnVector dx = xB.Rows(1, 3) - xP;
1035 ColumnVector dv = vB - rtnVel;
1036
1037 // Difference in RSW
1038 // -----------------
1039 ColumnVector rsw(3);
1040 XYZ_to_RSW(xB.Rows(1, 3), vB, dx, rsw);
1041
1042 ColumnVector dotRsw(3);
1043 XYZ_to_RSW(xB.Rows(1, 3), vB, dv, dotRsw);
1044
1045 // Clock Correction
1046 // ----------------
1047 double dClkA0 = rtnClk(1) - (xB(4) - dc) * t_CST::c;
1048 double dClkA1 = 0.0;
1049 if (rtnClk(2)) {
1050 dClkA1 = rtnClk(2) - xB(5) * t_CST::c;
1051 }
1052 double dClkA2 = 0.0;
1053 if (rtnClk(3)) {
1054 dClkA2 = rtnClk(3) - xB(6) * t_CST::c;
1055 }
1056
1057 if (sd) {
1058 sd->ID = prn.mid(1).toInt();
1059 sd->IOD = eph->IOD();
1060 sd->Clock.DeltaA0 = dClkA0;
1061 sd->Clock.DeltaA1 = dClkA1;
1062 sd->Clock.DeltaA2 = dClkA2;
1063 sd->UserRangeAccuracy = rtnUra;
1064 sd->Orbit.DeltaRadial = rsw(1);
1065 sd->Orbit.DeltaAlongTrack = rsw(2);
1066 sd->Orbit.DeltaCrossTrack = rsw(3);
1067 sd->Orbit.DotDeltaRadial = dotRsw(1);
1068 sd->Orbit.DotDeltaAlongTrack = dotRsw(2);
1069 sd->Orbit.DotDeltaCrossTrack = dotRsw(3);
1070
1071 if (corrIsOutOfRange(sd)) {
1072 return failure;
1073 }
1074 }
1075
1076 outLine = QString().asprintf("%d %.1f %s %u %10.3f %8.3f %8.3f %8.3f %8.3f %8.3f\n", GPSweek,
1077 GPSweeks, eph->prn().toString().c_str(), eph->IOD(), dClkA0, dClkA1, dClkA2,
1078 rsw(1), rsw(2), rsw(3)); //fprintf(stderr, "%s\n", outLine.toStdString().c_str());
1079
1080 // RTNET full clock for RINEX and SP3 file
1081 // ---------------------------------------
1082 double relativity = -2.0 * DotProduct(xP, rtnVel) / t_CST::c;
1083 double clkRnx = (rtnClk[0] - relativity) / t_CST::c; // [s]
1084 double clkRnxRate = rtnClk[1] / t_CST::c; // [s/s = -]
1085 double clkRnxAcc = rtnClk[2] / t_CST::c; // [s/s² = -/s]
1086
1087 if (_rnx) {
1088 double clkRnxSig, clkRnxRateSig, clkRnxAccSig;
1089 int s = rtnClkSig.size();
1090 switch (s) {
1091 case 1:
1092 clkRnxSig = rtnClkSig[0] / t_CST::c; // [s]
1093 clkRnxRateSig = 0.0; // [s/s = -]
1094 clkRnxAccSig = 0.0; // [s/s² ) -/s]
1095 break;
1096 case 2:
1097 clkRnxSig = rtnClkSig[0] / t_CST::c; // [s]
1098 clkRnxRateSig = rtnClkSig[1] / t_CST::c; // [s/s = -]
1099 clkRnxAccSig = 0.0; // [s/s² ) -/s]
1100 break;
1101 case 3:
1102 clkRnxSig = rtnClkSig[0] / t_CST::c; // [s]
1103 clkRnxRateSig = rtnClkSig[1] / t_CST::c; // [s/s = -]
1104 clkRnxAccSig = rtnClkSig[2] / t_CST::c; // [s/s² ) -/s]
1105 break;
1106 }
1107 _rnx->write(GPSweek, GPSweeks, prn, clkRnx, clkRnxRate, clkRnxAcc,
1108 clkRnxSig, clkRnxRateSig, clkRnxAccSig);
1109 }
1110 if (_sp3) {
1111 _sp3->write(GPSweek, GPSweeks, prn, rtnCoM, clkRnx, rtnVel, clkRnxRate);
1112 }
1113 return success;
1114}
1115
1116// Transform Coordinates
1117////////////////////////////////////////////////////////////////////////////
1118void bncRtnetUploadCaster::crdTrafo(int GPSWeek, ColumnVector& xyz,
1119 double& dc) {
1120
1121 // Current epoch minus 2000.0 in years
1122 // ------------------------------------
1123 double dt = (GPSWeek - (1042.0 + 6.0 / 7.0)) / 365.2422 * 7.0 + 2000.0 - _t0;
1124
1125 ColumnVector dx(3);
1126
1127 dx(1) = _dx + dt * _dxr;
1128 dx(2) = _dy + dt * _dyr;
1129 dx(3) = _dz + dt * _dzr;
1130
1131 static const double arcSec = 180.0 * 3600.0 / M_PI;
1132
1133 double ox = (_ox + dt * _oxr) / arcSec;
1134 double oy = (_oy + dt * _oyr) / arcSec;
1135 double oz = (_oz + dt * _ozr) / arcSec;
1136
1137 double sc = 1.0 + _sc * 1e-9 + dt * _scr * 1e-9;
1138
1139 // Specify approximate center of area
1140 // ----------------------------------
1141 ColumnVector meanSta(3);
1142
1143 if (_crdTrafo == "ETRF2000") {
1144 meanSta(1) = 3661090.0;
1145 meanSta(2) = 845230.0;
1146 meanSta(3) = 5136850.0;
1147 }
1148 else if (_crdTrafo == "GDA2020") {
1149 meanSta(1) = -4052050.0;
1150 meanSta(2) = 4212840.0;
1151 meanSta(3) = -2545110.0;
1152 }
1153 else if (_crdTrafo == "SIRGAS2000") {
1154 meanSta(1) = 3740860.0;
1155 meanSta(2) = -4964290.0;
1156 meanSta(3) = -1425420.0;
1157 }
1158 else if (_crdTrafo == "DREF91") {
1159 meanSta(1) = 3959579.0;
1160 meanSta(2) = 721719.0;
1161 meanSta(3) = 4931539.0;
1162 }
1163 else if (_crdTrafo == "Custom") {
1164 meanSta(1) = 0.0;
1165 meanSta(2) = 0.0;
1166 meanSta(3) = 0.0;
1167 }
1168
1169 // Clock correction proportional to topocentric distance to satellites
1170 // -------------------------------------------------------------------
1171 double rho = (xyz - meanSta).NormFrobenius();
1172 dc = rho * (sc - 1.0) / sc / t_CST::c;
1173
1174 Matrix rMat(3, 3);
1175 rMat(1, 1) = 1.0;
1176 rMat(1, 2) = -oz;
1177 rMat(1, 3) = oy;
1178 rMat(2, 1) = oz;
1179 rMat(2, 2) = 1.0;
1180 rMat(2, 3) = -ox;
1181 rMat(3, 1) = -oy;
1182 rMat(3, 2) = ox;
1183 rMat(3, 3) = 1.0;
1184
1185 xyz = sc * rMat * xyz + dx;
1186}
1187
1188// Transform Coordinates
1189////////////////////////////////////////////////////////////////////////////
1190void bncRtnetUploadCaster::crdTrafo14(int GPSWeek, ColumnVector& xyz,
1191 double& dc) {
1192
1193 // Current epoch minus 2000.0 in years
1194 // ------------------------------------
1195 double dt = (GPSWeek - (1042.0 + 6.0 / 7.0)) / 365.2422 * 7.0 + 2000.0 - _t0;
1196
1197 ColumnVector dx(3);
1198
1199 dx(1) = _dx14 + dt * _dxr14;
1200 dx(2) = _dy14 + dt * _dyr14;
1201 dx(3) = _dz14 + dt * _dzr14;
1202
1203 static const double arcSec = 180.0 * 3600.0 / M_PI;
1204
1205 double ox = (_ox14 + dt * _oxr14) / arcSec;
1206 double oy = (_oy14 + dt * _oyr14) / arcSec;
1207 double oz = (_oz14 + dt * _ozr14) / arcSec;
1208
1209 double sc = 1.0 + _sc14 * 1e-9 + dt * _scr14 * 1e-9;
1210
1211 // Specify approximate center of area
1212 // ----------------------------------
1213 ColumnVector meanSta(3);
1214 meanSta(1) = 0.0; // TODO
1215 meanSta(2) = 0.0; // TODO
1216 meanSta(3) = 0.0; // TODO
1217
1218 // Clock correction proportional to topocentric distance to satellites
1219 // -------------------------------------------------------------------
1220 double rho = (xyz - meanSta).NormFrobenius();
1221 dc = rho * (sc - 1.0) / sc / t_CST::c;
1222
1223 Matrix rMat(3, 3);
1224 rMat(1, 1) = 1.0;
1225 rMat(1, 2) = -oz;
1226 rMat(1, 3) = oy;
1227 rMat(2, 1) = oz;
1228 rMat(2, 2) = 1.0;
1229 rMat(2, 3) = -ox;
1230 rMat(3, 1) = -oy;
1231 rMat(3, 2) = ox;
1232 rMat(3, 3) = 1.0;
1233
1234 xyz = sc * rMat * xyz + dx;
1235}
1236
1237// Update Interval
1238////////////////////////////////////////////////////////////////////////////
1239int bncRtnetUploadCaster::determineUpdateInd(double samplingRate) {
1240
1241 if (samplingRate == 10.0) {
1242 return 3;
1243 }
1244 else if (samplingRate == 15.0) {
1245 return 4;
1246 }
1247 else if (samplingRate == 30.0) {
1248 return 5;
1249 }
1250 else if (samplingRate == 60.0) {
1251 return 6;
1252 }
1253 else if (samplingRate == 120.0) {
1254 return 7;
1255 }
1256 else if (samplingRate == 240.0) {
1257 return 8;
1258 }
1259 else if (samplingRate == 300.0) {
1260 return 9;
1261 }
1262 else if (samplingRate == 600.0) {
1263 return 10;
1264 }
1265 else if (samplingRate == 900.0) {
1266 return 11;
1267 }
1268 else if (samplingRate == 1800.0) {
1269 return 12;
1270 }
1271 else if (samplingRate == 3600.0) {
1272 return 13;
1273 }
1274 else if (samplingRate == 7200.0) {
1275 return 14;
1276 }
1277 else if (samplingRate == 10800.0) {
1278 return 15;
1279 }
1280 return 2; // default
1281}
1282
1283// Check corrections
1284////////////////////////////////////////////////////////////////////////////
1285bool bncRtnetUploadCaster::corrIsOutOfRange(struct SsrCorr::ClockOrbit::SatData* sd) {
1286
1287 if (fabs(sd->Clock.DeltaA0) > 209.7151) {return true;}
1288 if (fabs(sd->Clock.DeltaA1) > 1.048575) {return true;}
1289 if (fabs(sd->Clock.DeltaA2) > 1.34217726) {return true;}
1290
1291 if (fabs(sd->Orbit.DeltaRadial) > 209.7151) {return true;}
1292 if (fabs(sd->Orbit.DeltaAlongTrack) > 209.7148) {return true;}
1293 if (fabs(sd->Orbit.DeltaCrossTrack) > 209.7148) {return true;}
1294
1295 if (fabs(sd->Orbit.DotDeltaRadial) > 1.048575) {return true;}
1296 if (fabs(sd->Orbit.DotDeltaAlongTrack) > 1.048572) {return true;}
1297 if (fabs(sd->Orbit.DotDeltaCrossTrack) > 1.048572) {return true;}
1298 return false;
1299}
Note: See TracBrowser for help on using the repository browser.