source: ntrip/branches/BNC_2.13.beta/src/upload/bncrtnetuploadcaster.cpp@ 10132

Last change on this file since 10132 was 10095, checked in by stuerze, 19 months ago

allow 30 sec update rate for sp3 files

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