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

Last change on this file since 9883 was 9883, checked in by stuerze, 17 months ago

minor changes

File size: 40.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").toInt() * 60;
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.0000;
190 _dyr = 0.0000;
191 _dzr = 0.0000;
192
193 _ox = 0.000000;
194 _oy = 0.000000;
195 _oz = 0.000000;
196
197 _oxr = 0.000000;
198 _oyr = 0.000000;
199 _ozr = 0.000000;
200
201 _sc = 1.20000;
202 _scr = 0.00000;
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 (ETRF200 => 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}
246
247// Destructor
248////////////////////////////////////////////////////////////////////////////
249bncRtnetUploadCaster::~bncRtnetUploadCaster() {
250 if (isRunning()) {
251 wait();
252 }
253 delete _rnx;
254 delete _sp3;
255 delete _ephUser;
256 delete _usedEph;
257 delete _ssrCorr;
258}
259
260//
261////////////////////////////////////////////////////////////////////////////
262void bncRtnetUploadCaster::decodeRtnetStream(char* buffer, int bufLen) {
263
264 QMutexLocker locker(&_mutex);
265
266 // Append to internal buffer
267 // -------------------------
268 _rtnetStreamBuffer.append(QByteArray(buffer, bufLen));
269
270 // Select buffer part that contains last epoch
271 // -------------------------------------------
272
273 // Find the begin of last epoch
274 int iEpoBeg = _rtnetStreamBuffer.lastIndexOf('*');
275 if (iEpoBeg == -1) {
276 _rtnetStreamBuffer.clear();
277 emit(newMessage(QString("bncRtnetUploadCaster: no Epoch line found: %1").arg(_casterID).toLatin1(), false));
278 return;
279 }
280
281 // Find the begin of the first epoch
282 int iEpoBegEarlier = _rtnetStreamBuffer.indexOf('*');
283 if (iEpoBegEarlier != -1 && iEpoBegEarlier < iEpoBeg) {
284 _rtnetStreamBuffer = _rtnetStreamBuffer.mid(iEpoBegEarlier);
285 }
286 else {
287 _rtnetStreamBuffer = _rtnetStreamBuffer.mid(iEpoBeg);
288 }
289
290 // Find End of the last epoch
291 int iEpoEnd = _rtnetStreamBuffer.lastIndexOf("EOE");
292 if (iEpoEnd == -1) {
293 _rtnetStreamBuffer.clear();
294 emit(newMessage(QString("bncRtnetUploadCaster: no EOE found: %1").arg(_casterID).toLatin1(), false));
295 return;
296 }
297
298 QStringList lines;
299 // If there is there more than 1 epoch line in the buffer
300 while (_rtnetStreamBuffer.count('*') > 1) {
301 cout << "more than 1 epoch in buffer: " << _rtnetStreamBuffer.count('*') << endl;
302 emit(newMessage(QString("bncRtnetUploadCaster: more than 1 epoch in buffer: %1").arg(_rtnetStreamBuffer.count('*')).toLatin1(), false));
303 QString rtnetStreamBuffer = _rtnetStreamBuffer;
304 int nextEpoch = rtnetStreamBuffer.indexOf('*');
305 int nextEpochEnd = rtnetStreamBuffer.indexOf("EOE");
306 _rtnetStreamBuffer = _rtnetStreamBuffer.mid(1);
307 if (nextEpoch != -1 && nextEpoch < iEpoEnd) {
308 rtnetStreamBuffer = rtnetStreamBuffer.mid(nextEpoch, nextEpochEnd);cout <<"===\n" << rtnetStreamBuffer.toStdString().c_str() << "\n==="<<endl;
309 lines = _rtnetStreamBuffer.split('\n', QString::SkipEmptyParts);
310 if (lines.size() > 2) {
311 decodeRtnetEpoch(lines);
312 }
313 nextEpochEnd = rtnetStreamBuffer.indexOf("EOE");
314 _rtnetStreamBuffer = _rtnetStreamBuffer.mid(nextEpochEnd+3);
315
316 }
317 else if (nextEpoch != -1 && nextEpoch >= iEpoEnd) {cout << "bin hier" << endl;
318 break;
319 }
320 }
321
322 lines = _rtnetStreamBuffer.left(iEpoEnd).split('\n', QString::SkipEmptyParts);
323
324 _rtnetStreamBuffer = _rtnetStreamBuffer.mid(iEpoEnd + 3);
325
326 if (lines.size() < 2) {
327 emit(newMessage(QString("bncRtnetUploadCaster: less than 2 lines to decode : %1").arg(_casterID).toLatin1(), false));
328 return;
329 }
330
331 decodeRtnetEpoch(lines);
332
333}
334
335//
336////////////////////////////////////////////////////////////////////////////
337void bncRtnetUploadCaster::decodeRtnetEpoch(QStringList epochLines) {
338
339 // Read first line (with epoch time)
340 // ---------------------------------
341 QTextStream in(epochLines[0].toLatin1()); cout << epochLines[0].toLatin1().toStdString() << " : " << endl;
342 QString hlp;
343 int year, month, day, hour, min;
344 double sec;
345 in >> hlp >> year >> month >> day >> hour >> min >> sec;
346 bncTime epoTime;
347 epoTime.set(year, month, day, hour, min, sec); cout << "decodeEpoch: " << epoTime.timestr().c_str() << endl;
348
349 emit(newMessage(
350 "bncRtnetUploadCaster: decode " + QByteArray(epoTime.datestr().c_str())
351 + " " + QByteArray(epoTime.timestr().c_str()) + " "
352 + _casterID.toLatin1(), false));
353
354 struct SsrCorr::ClockOrbit co;
355 memset(&co, 0, sizeof(co));
356 co.EpochTime[CLOCKORBIT_SATGPS] = static_cast<int>(epoTime.gpssec());
357 if (_ssrFormat == "RTCM-SSR") {
358 double gt = epoTime.gpssec() + 3 * 3600 - gnumleap(year, month, day);
359 co.EpochTime[CLOCKORBIT_SATGLONASS] = static_cast<int>(fmod(gt, 86400.0));
360 }
361 else if (_ssrFormat == "IGS-SSR") {
362 co.EpochTime[CLOCKORBIT_SATGLONASS] = static_cast<int>(epoTime.gpssec());
363 }
364 co.EpochTime[CLOCKORBIT_SATGALILEO] = static_cast<int>(epoTime.gpssec());
365 co.EpochTime[CLOCKORBIT_SATQZSS] = static_cast<int>(epoTime.gpssec());
366 co.EpochTime[CLOCKORBIT_SATSBAS] = static_cast<int>(epoTime.gpssec());
367 if (_ssrFormat == "RTCM-SSR") {
368 co.EpochTime[CLOCKORBIT_SATBDS] = static_cast<int>(epoTime.bdssec());
369 }
370 else if (_ssrFormat == "IGS-SSR") {
371 co.EpochTime[CLOCKORBIT_SATBDS] = static_cast<int>(epoTime.gpssec());
372 }
373 co.Supplied[_ssrCorr->COBOFS_CLOCK] = 1;
374 co.Supplied[_ssrCorr->COBOFS_ORBIT] = 1;
375 co.SatRefDatum = _ssrCorr->DATUM_ITRF; // ToDo: to decode from RTNET format
376 co.SSRIOD = _IOD;
377 co.SSRProviderID = _PID; // 256 .. BKG, 257 ... EUREF
378 co.SSRSolutionID = _SID;
379
380 struct SsrCorr::CodeBias bias;
381 memset(&bias, 0, sizeof(bias));
382 bias.EpochTime[CLOCKORBIT_SATGPS] = co.EpochTime[CLOCKORBIT_SATGPS];
383 bias.EpochTime[CLOCKORBIT_SATGLONASS] = co.EpochTime[CLOCKORBIT_SATGLONASS];
384 bias.EpochTime[CLOCKORBIT_SATGALILEO] = co.EpochTime[CLOCKORBIT_SATGALILEO];
385 bias.EpochTime[CLOCKORBIT_SATQZSS] = co.EpochTime[CLOCKORBIT_SATQZSS];
386 bias.EpochTime[CLOCKORBIT_SATSBAS] = co.EpochTime[CLOCKORBIT_SATSBAS];
387 bias.EpochTime[CLOCKORBIT_SATBDS] = co.EpochTime[CLOCKORBIT_SATBDS];
388 bias.SSRIOD = _IOD;
389 bias.SSRProviderID = _PID;
390 bias.SSRSolutionID = _SID;
391
392 struct SsrCorr::PhaseBias phasebias;
393 memset(&phasebias, 0, sizeof(phasebias));
394 unsigned int dispersiveBiasConsistenyIndicator = 0;
395 unsigned int mwConsistencyIndicator = 0;
396 phasebias.EpochTime[CLOCKORBIT_SATGPS] = co.EpochTime[CLOCKORBIT_SATGPS];
397 phasebias.EpochTime[CLOCKORBIT_SATGLONASS] = co.EpochTime[CLOCKORBIT_SATGLONASS];
398 phasebias.EpochTime[CLOCKORBIT_SATGALILEO] = co.EpochTime[CLOCKORBIT_SATGALILEO];
399 phasebias.EpochTime[CLOCKORBIT_SATQZSS] = co.EpochTime[CLOCKORBIT_SATQZSS];
400 phasebias.EpochTime[CLOCKORBIT_SATSBAS] = co.EpochTime[CLOCKORBIT_SATSBAS];
401 phasebias.EpochTime[CLOCKORBIT_SATBDS] = co.EpochTime[CLOCKORBIT_SATBDS];
402 phasebias.SSRIOD = _IOD;
403 phasebias.SSRProviderID = _PID;
404 phasebias.SSRSolutionID = _SID;
405
406 struct SsrCorr::VTEC vtec;
407 memset(&vtec, 0, sizeof(vtec));
408 vtec.EpochTime = static_cast<int>(epoTime.gpssec());
409 vtec.SSRIOD = _IOD;
410 vtec.SSRProviderID = _PID;
411 vtec.SSRSolutionID = _SID;
412
413 // Default Update Interval
414 // -----------------------
415 int clkUpdInd = 2; // 5 sec
416 int ephUpdInd = clkUpdInd; // default
417
418 if (!_samplRtcmEphCorr) {
419 _samplRtcmEphCorr = 5.0;
420 }
421
422 if (_samplRtcmClkCorr > 5.0 && _samplRtcmEphCorr <= 5.0) { // combined orb and clock
423 ephUpdInd = determineUpdateInd(_samplRtcmClkCorr);
424 }
425 if (_samplRtcmClkCorr > 5.0) {
426 clkUpdInd = determineUpdateInd(_samplRtcmClkCorr);
427 }
428 if (_samplRtcmEphCorr > 5.0) {
429 ephUpdInd = determineUpdateInd(_samplRtcmEphCorr);
430 }
431
432 co.UpdateInterval = clkUpdInd;
433 bias.UpdateInterval = ephUpdInd;
434 phasebias.UpdateInterval = ephUpdInd;
435
436 for (int ii = 1; ii < epochLines.size(); ii++) {
437 QString key; // prn or key VTEC, IND (phase bias indicators)
438 double rtnUra = 0.0; // [m]
439 ColumnVector rtnAPC; rtnAPC.ReSize(3); rtnAPC = 0.0; // [m, m, m]
440 ColumnVector rtnVel; rtnVel.ReSize(3); rtnVel = 0.0; // [m/s, m/s, m/s]
441 ColumnVector rtnCoM; rtnCoM.ReSize(3); rtnCoM = 0.0; // [m, m, m]
442 ColumnVector rtnClk; rtnClk.ReSize(3); rtnClk = 0.0; // [m, m/s, m/s²]
443 ColumnVector rtnClkSig; rtnClkSig.ReSize(3); rtnClkSig = 0.0; // [m, m/s, m/s²]
444 t_prn prn;
445
446 QTextStream in(epochLines[ii].toLatin1());
447
448 in >> key;
449
450 // non-satellite specific parameters
451 if (key.contains("IND", Qt::CaseSensitive)) {
452 in >> dispersiveBiasConsistenyIndicator >> mwConsistencyIndicator;
453 continue;
454 }
455 // non-satellite specific parameters
456 if (key.contains("VTEC", Qt::CaseSensitive)) {
457 double ui;
458 in >> ui >> vtec.NumLayers;
459 vtec.UpdateInterval = (unsigned int) determineUpdateInd(ui);
460 for (unsigned ll = 0; ll < vtec.NumLayers; ll++) {
461 int dummy;
462 in >> dummy >> vtec.Layers[ll].Degree >> vtec.Layers[ll].Order
463 >> vtec.Layers[ll].Height;
464 for (unsigned iDeg = 0; iDeg <= vtec.Layers[ll].Degree; iDeg++) {
465 for (unsigned iOrd = 0; iOrd <= vtec.Layers[ll].Order; iOrd++) {
466 in >> vtec.Layers[ll].Cosinus[iDeg][iOrd];
467 }
468 }
469 for (unsigned iDeg = 0; iDeg <= vtec.Layers[ll].Degree; iDeg++) {
470 for (unsigned iOrd = 0; iOrd <= vtec.Layers[ll].Order; iOrd++) {
471 in >> vtec.Layers[ll].Sinus[iDeg][iOrd];
472 }
473 }
474 }
475 continue;
476 }
477 // satellite specific parameters
478 char sys = key.mid(0, 1).at(0).toLatin1();
479 int number = key.mid(1, 2).toInt();
480 int flags = 0;
481 if (sys == 'E') { // I/NAV
482 flags = 1;
483 }
484 if (number == 0) {
485 continue;
486 }
487 prn.set(sys, number, flags);
488 QString prnInternalStr = QString::fromStdString(prn.toInternalString());
489 QString prnStr = QString::fromStdString(prn.toString());
490
491 const t_eph* ephLast = _ephUser->ephLast(prnInternalStr);
492 const t_eph* ephPrev = _ephUser->ephPrev(prnInternalStr);
493 const t_eph* eph = ephLast;
494 if (eph) {
495
496 // Use previous ephemeris if the last one is too recent
497 // ----------------------------------------------------
498 const int MINAGE = 60; // seconds
499 if (ephPrev && eph->receptDateTime().isValid()
500 && eph->receptDateTime().secsTo(currentDateAndTimeGPS()) < MINAGE) {
501 eph = ephPrev;
502 }
503
504 // Make sure the clock messages refer to same IOD as orbit messages
505 // ----------------------------------------------------------------
506 if (_usedEph) {
507 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
508 (*_usedEph)[prnInternalStr] = eph;
509 }
510 else {
511 eph = 0;
512 if (_usedEph->contains(prnInternalStr)) {
513 const t_eph* usedEph = _usedEph->value(prnInternalStr);
514 if (usedEph == ephLast) {
515 eph = ephLast;
516 }
517 else if (usedEph == ephPrev) {
518 eph = ephPrev;
519 }
520 }
521 }
522 }
523 }
524
525 if (eph &&
526 !outDatedBcep(eph) && // detected from storage because of no update
527 eph->checkState() != t_eph::bad &&
528 eph->checkState() != t_eph::unhealthy &&
529 eph->checkState() != t_eph::outdated) { // detected during reception (bncephuser)
530 QMap<QString, double> codeBiases;
531 QList<phaseBiasSignal> phaseBiasList;
532 phaseBiasesSat pbSat;
533 _phaseBiasInformationDecoded = false;
534
535 while (true) {
536 QString key;
537 int numVal = 0;
538 in >> key;
539 if (in.status() != QTextStream::Ok) {
540 break;
541 }
542 if (key == "APC") {
543 in >> numVal;
544 rtnAPC.ReSize(3); rtnAPC = 0.0;
545 for (int ii = 0; ii < numVal; ii++) {
546 in >> rtnAPC[ii];
547 }
548 }
549 else if (key == "Ura") {
550 in >> numVal;
551 if (numVal == 1)
552 in >> rtnUra;
553 }
554 else if (key == "Clk") {
555 in >> numVal;
556 rtnClk.ReSize(3); rtnClk = 0.0;
557 for (int ii = 0; ii < numVal; ii++) {
558 in >> rtnClk[ii];
559 }
560 }
561 else if (key == "ClkSig") {
562 in >> numVal;
563 rtnClkSig.ReSize(3); rtnClkSig = 0.0;
564 for (int ii = 0; ii < numVal; ii++) {
565 in >> rtnClkSig[ii];
566 }
567 }
568 else if (key == "Vel") {
569 in >> numVal;
570 rtnVel.ReSize(3); rtnVel = 0.0;
571 for (int ii = 0; ii < numVal; ii++) {
572 in >> rtnVel[ii];
573 }
574 }
575 else if (key == "CoM") {
576 in >> numVal;
577 rtnCoM.ReSize(3); rtnCoM = 0.0;
578 for (int ii = 0; ii < numVal; ii++) {
579 in >> rtnCoM[ii];
580 }
581 }
582 else if (key == "CodeBias") {
583 in >> numVal;
584 for (int ii = 0; ii < numVal; ii++) {
585 QString type;
586 double value;
587 in >> type >> value;
588 codeBiases[type] = value;
589 }
590 }
591 else if (key == "YawAngle") {
592 _phaseBiasInformationDecoded = true;
593 in >> numVal >> pbSat.yawAngle;
594 if (pbSat.yawAngle < 0.0) {
595 pbSat.yawAngle += (2*M_PI);
596 }
597 else if (pbSat.yawAngle > 2*M_PI) {
598 pbSat.yawAngle -= (2*M_PI);
599 }
600 }
601 else if (key == "YawRate") {
602 _phaseBiasInformationDecoded = true;
603 in >> numVal >> pbSat.yawRate;
604 }
605 else if (key == "PhaseBias") {
606 _phaseBiasInformationDecoded = true;
607 in >> numVal;
608 for (int ii = 0; ii < numVal; ii++) {
609 phaseBiasSignal pb;
610 in >> pb.type >> pb.bias >> pb.integerIndicator
611 >> pb.wlIndicator >> pb.discontinuityCounter;
612 phaseBiasList.append(pb);
613 }
614 }
615 else {
616 in >> numVal;
617 for (int ii = 0; ii < numVal; ii++) {
618 double dummy;
619 in >> dummy;
620 }
621 emit(newMessage(" RTNET format error: "
622 + epochLines[ii].toLatin1(), false));
623 break;
624 }
625 }
626
627 struct SsrCorr::ClockOrbit::SatData* sd = 0;
628 if (prn.system() == 'G') {
629 sd = co.Sat + co.NumberOfSat[CLOCKORBIT_SATGPS];
630 ++co.NumberOfSat[CLOCKORBIT_SATGPS];
631 }
632 else if (prn.system() == 'R') {
633 sd = co.Sat + CLOCKORBIT_NUMGPS + co.NumberOfSat[CLOCKORBIT_SATGLONASS];
634 ++co.NumberOfSat[CLOCKORBIT_SATGLONASS];
635 }
636 else if (prn.system() == 'E') {
637 sd = co.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
638 + co.NumberOfSat[CLOCKORBIT_SATGALILEO];
639 ++co.NumberOfSat[CLOCKORBIT_SATGALILEO];
640 }
641 else if (prn.system() == 'J') {
642 sd = co.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
643 + CLOCKORBIT_NUMGALILEO
644 + co.NumberOfSat[CLOCKORBIT_SATQZSS];
645 ++co.NumberOfSat[CLOCKORBIT_SATQZSS];
646 }
647 else if (prn.system() == 'S') {
648 sd = co.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
649 + CLOCKORBIT_NUMGALILEO + CLOCKORBIT_NUMQZSS
650 + co.NumberOfSat[CLOCKORBIT_SATSBAS];
651 ++co.NumberOfSat[CLOCKORBIT_SATSBAS];
652 }
653 else if (prn.system() == 'C') {
654 sd = co.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
655 + CLOCKORBIT_NUMGALILEO + CLOCKORBIT_NUMQZSS
656 + CLOCKORBIT_NUMSBAS
657 + co.NumberOfSat[CLOCKORBIT_SATBDS];
658 ++co.NumberOfSat[CLOCKORBIT_SATBDS];
659 }
660 if (sd) {
661 QString outLine;
662 t_irc irc = processSatellite(eph, epoTime.gpsw(), epoTime.gpssec(), prnStr, rtnAPC,
663 rtnUra, rtnClk, rtnVel, rtnCoM, rtnClkSig, sd, outLine);
664 if (irc != success) {
665 continue;
666 }
667 }
668
669 // Code Biases
670 // -----------
671 struct SsrCorr::CodeBias::BiasSat* biasSat = 0;
672 if (!codeBiases.isEmpty()) {
673 if (prn.system() == 'G') {
674 biasSat = bias.Sat + bias.NumberOfSat[CLOCKORBIT_SATGPS];
675 ++bias.NumberOfSat[CLOCKORBIT_SATGPS];
676 }
677 else if (prn.system() == 'R') {
678 biasSat = bias.Sat + CLOCKORBIT_NUMGPS
679 + bias.NumberOfSat[CLOCKORBIT_SATGLONASS];
680 ++bias.NumberOfSat[CLOCKORBIT_SATGLONASS];
681 }
682 else if (prn.system() == 'E') {
683 biasSat = bias.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
684 + bias.NumberOfSat[CLOCKORBIT_SATGALILEO];
685 ++bias.NumberOfSat[CLOCKORBIT_SATGALILEO];
686 }
687 else if (prn.system() == 'J') {
688 biasSat = bias.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
689 + CLOCKORBIT_NUMGALILEO
690 + bias.NumberOfSat[CLOCKORBIT_SATQZSS];
691 ++bias.NumberOfSat[CLOCKORBIT_SATQZSS];
692 }
693 else if (prn.system() == 'S') {
694 biasSat = bias.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
695 + CLOCKORBIT_NUMGALILEO + CLOCKORBIT_NUMQZSS
696 + bias.NumberOfSat[CLOCKORBIT_SATSBAS];
697 ++bias.NumberOfSat[CLOCKORBIT_SATSBAS];
698 }
699 else if (prn.system() == 'C') {
700 biasSat = bias.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
701 + CLOCKORBIT_NUMGALILEO + CLOCKORBIT_NUMQZSS
702 + CLOCKORBIT_NUMSBAS
703 + bias.NumberOfSat[CLOCKORBIT_SATBDS];
704 ++bias.NumberOfSat[CLOCKORBIT_SATBDS];
705 }
706 }
707
708 if (biasSat) {
709 biasSat->ID = prn.number();
710 biasSat->NumberOfCodeBiases = 0;
711 QMapIterator<QString, double> it(codeBiases);
712 while (it.hasNext()) {
713 it.next();
714 int ii = biasSat->NumberOfCodeBiases;
715 if (ii >= CLOCKORBIT_NUMBIAS)
716 break;
717 SsrCorr::CodeType type = _ssrCorr->rnxTypeToCodeType(prn.system(), it.key().toStdString());
718 if (type != _ssrCorr->RESERVED) {
719 biasSat->NumberOfCodeBiases += 1;
720 biasSat->Biases[ii].Type = type;
721 biasSat->Biases[ii].Bias = it.value();
722 if (_bsx) {
723 QString obsCode = 'C' + it.key();
724 _bsx->write(epoTime.gpsw(), epoTime.gpssec(), prnStr, obsCode, it.value());
725 }
726 }
727 }
728 }
729
730 // Phase Biases
731 // ------------
732 struct SsrCorr::PhaseBias::PhaseBiasSat* phasebiasSat = 0;
733 if (prn.system() == 'G') {
734 phasebiasSat = phasebias.Sat
735 + phasebias.NumberOfSat[CLOCKORBIT_SATGPS];
736 ++phasebias.NumberOfSat[CLOCKORBIT_SATGPS];
737 }
738 else if (prn.system() == 'R') {
739 phasebiasSat = phasebias.Sat + CLOCKORBIT_NUMGPS
740 + phasebias.NumberOfSat[CLOCKORBIT_SATGLONASS];
741 ++phasebias.NumberOfSat[CLOCKORBIT_SATGLONASS];
742 }
743 else if (prn.system() == 'E') {
744 phasebiasSat = phasebias.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
745 + phasebias.NumberOfSat[CLOCKORBIT_SATGALILEO];
746 ++phasebias.NumberOfSat[CLOCKORBIT_SATGALILEO];
747 }
748 else if (prn.system() == 'J') {
749 phasebiasSat = phasebias.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
750 + CLOCKORBIT_NUMGALILEO
751 + phasebias.NumberOfSat[CLOCKORBIT_SATQZSS];
752 ++phasebias.NumberOfSat[CLOCKORBIT_SATQZSS];
753 }
754 else if (prn.system() == 'S') {
755 phasebiasSat = phasebias.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
756 + CLOCKORBIT_NUMGALILEO + CLOCKORBIT_NUMQZSS
757 + phasebias.NumberOfSat[CLOCKORBIT_SATSBAS];
758 ++phasebias.NumberOfSat[CLOCKORBIT_SATSBAS];
759 }
760 else if (prn.system() == 'C') {
761 phasebiasSat = phasebias.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
762 + CLOCKORBIT_NUMGALILEO + CLOCKORBIT_NUMQZSS
763 + CLOCKORBIT_NUMSBAS
764 + phasebias.NumberOfSat[CLOCKORBIT_SATBDS];
765 ++phasebias.NumberOfSat[CLOCKORBIT_SATBDS];
766 }
767
768 if (phasebiasSat && _phaseBiasInformationDecoded) {
769 phasebias.DispersiveBiasConsistencyIndicator = dispersiveBiasConsistenyIndicator;
770 phasebias.MWConsistencyIndicator = mwConsistencyIndicator;
771 phasebiasSat->ID = prn.number();
772 phasebiasSat->NumberOfPhaseBiases = 0;
773 phasebiasSat->YawAngle = pbSat.yawAngle;
774 phasebiasSat->YawRate = pbSat.yawRate;
775 QListIterator<phaseBiasSignal> it(phaseBiasList);
776 while (it.hasNext()) {
777 const phaseBiasSignal &pbSig = it.next();
778 int ii = phasebiasSat->NumberOfPhaseBiases;
779 if (ii >= CLOCKORBIT_NUMBIAS)
780 break;
781 SsrCorr::CodeType type = _ssrCorr->rnxTypeToCodeType(prn.system(), pbSig.type.toStdString());
782 if (type != _ssrCorr->RESERVED) {
783 phasebiasSat->NumberOfPhaseBiases += 1;
784 phasebiasSat->Biases[ii].Type = type;
785 phasebiasSat->Biases[ii].Bias = pbSig.bias;
786 phasebiasSat->Biases[ii].SignalIntegerIndicator = pbSig.integerIndicator;
787 phasebiasSat->Biases[ii].SignalsWideLaneIntegerIndicator = pbSig.wlIndicator;
788 phasebiasSat->Biases[ii].SignalDiscontinuityCounter = pbSig.discontinuityCounter;
789 if (_bsx) {
790 QString obsCode = 'L' + pbSig.type;
791 _bsx->write(epoTime.gpsw(), epoTime.gpssec(), prnStr, obsCode, pbSig.bias);
792 }
793 }
794 }
795 }
796 }
797 }
798
799 QByteArray hlpBufferCo;
800
801 // Orbit and Clock Corrections together
802 // ------------------------------------
803 if (_samplRtcmEphCorr == _samplRtcmClkCorr) {
804 if (co.NumberOfSat[CLOCKORBIT_SATGPS] > 0
805 || co.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0
806 || co.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0
807 || co.NumberOfSat[CLOCKORBIT_SATQZSS] > 0
808 || co.NumberOfSat[CLOCKORBIT_SATSBAS] > 0
809 || co.NumberOfSat[CLOCKORBIT_SATBDS] > 0) {
810 char obuffer[CLOCKORBIT_BUFFERSIZE] = {0};
811 int len = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_AUTO, 0, obuffer, sizeof(obuffer));
812 if (len > 0) {
813 hlpBufferCo = QByteArray(obuffer, len);
814 }
815 }
816 }
817
818 // Orbit and Clock Corrections separately
819 // --------------------------------------
820 else {
821 if (co.NumberOfSat[CLOCKORBIT_SATGPS] > 0) {
822 char obuffer[CLOCKORBIT_BUFFERSIZE] = {0};
823 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
824 co.UpdateInterval = ephUpdInd;
825 int len1 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_GPSORBIT, 1, obuffer,
826 sizeof(obuffer));
827 co.UpdateInterval = clkUpdInd;
828 if (len1 > 0) {
829 hlpBufferCo += QByteArray(obuffer, len1);
830 }
831 }
832 int mmsg = (co.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0 ||
833 co.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0 ||
834 co.NumberOfSat[CLOCKORBIT_SATQZSS] > 0 ||
835 co.NumberOfSat[CLOCKORBIT_SATSBAS] > 0 ||
836 co.NumberOfSat[CLOCKORBIT_SATBDS] > 0 ) ? 1 : 0;
837 int len2 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_GPSCLOCK, mmsg, obuffer,
838 sizeof(obuffer));
839 if (len2 > 0) {
840 hlpBufferCo += QByteArray(obuffer, len2);
841 }
842 }
843 if (co.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0) {
844 char obuffer[CLOCKORBIT_BUFFERSIZE] = {0};
845 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
846 co.UpdateInterval = ephUpdInd;
847 int len1 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_GLONASSORBIT, 1, obuffer,
848 sizeof(obuffer));
849 co.UpdateInterval = clkUpdInd;
850 if (len1 > 0) {
851 hlpBufferCo += QByteArray(obuffer, len1);
852 }
853 }
854 int mmsg = (co.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0 ||
855 co.NumberOfSat[CLOCKORBIT_SATQZSS] > 0 ||
856 co.NumberOfSat[CLOCKORBIT_SATSBAS] > 0 ||
857 co.NumberOfSat[CLOCKORBIT_SATBDS] > 0 ) ? 1 : 0;
858 int len2 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_GLONASSCLOCK, mmsg, obuffer,
859 sizeof(obuffer));
860 if (len2 > 0) {
861 hlpBufferCo += QByteArray(obuffer, len2);
862 }
863 }
864 if (co.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0) {
865 char obuffer[CLOCKORBIT_BUFFERSIZE] = {0};
866 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
867 co.UpdateInterval = ephUpdInd;
868 int len1 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_GALILEOORBIT, 1, obuffer,
869 sizeof(obuffer));
870 co.UpdateInterval = clkUpdInd;
871 if (len1 > 0) {
872 hlpBufferCo += QByteArray(obuffer, len1);
873 }
874 }
875 int mmsg = (co.NumberOfSat[CLOCKORBIT_SATQZSS] > 0 ||
876 co.NumberOfSat[CLOCKORBIT_SATSBAS] > 0 ||
877 co.NumberOfSat[CLOCKORBIT_SATBDS] > 0 ) ? 1 : 0;
878 int len2 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_GALILEOCLOCK, mmsg, obuffer,
879 sizeof(obuffer));
880 if (len2 > 0) {
881 hlpBufferCo += QByteArray(obuffer, len2);
882 }
883 }
884 if (co.NumberOfSat[CLOCKORBIT_SATQZSS] > 0) {
885 char obuffer[CLOCKORBIT_BUFFERSIZE] = {0};
886 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
887 co.UpdateInterval = ephUpdInd;
888 int len1 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_QZSSORBIT, 1, obuffer,
889 sizeof(obuffer));
890 co.UpdateInterval = clkUpdInd;
891 if (len1 > 0) {
892 hlpBufferCo += QByteArray(obuffer, len1);
893 }
894 }
895 int mmsg = (co.NumberOfSat[CLOCKORBIT_SATSBAS] > 0 ||
896 co.NumberOfSat[CLOCKORBIT_SATBDS] > 0 ) ? 1 : 0;
897 int len2 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_QZSSCLOCK, mmsg, obuffer,
898 sizeof(obuffer));
899 if (len2 > 0) {
900 hlpBufferCo += QByteArray(obuffer, len2);
901 }
902 }
903 if (co.NumberOfSat[CLOCKORBIT_SATSBAS] > 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_SBASORBIT, 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_SATBDS] > 0) ? 1 : 0;
915 int len2 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_SBASCLOCK, mmsg, obuffer,
916 sizeof(obuffer));
917 if (len2 > 0) {
918 hlpBufferCo += QByteArray(obuffer, len2);
919 }
920 }
921 if (co.NumberOfSat[CLOCKORBIT_SATBDS] > 0) {
922 char obuffer[CLOCKORBIT_BUFFERSIZE] = {0};
923 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
924 co.UpdateInterval = ephUpdInd;
925 int len1 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_BDSORBIT, 1, obuffer,
926 sizeof(obuffer));
927 co.UpdateInterval = clkUpdInd;
928 if (len1 > 0) {
929 hlpBufferCo += QByteArray(obuffer, len1);
930 }
931 }
932 int mmsg = 0;
933 int len2 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_BDSCLOCK, mmsg, obuffer,
934 sizeof(obuffer));
935 if (len2 > 0) {
936 hlpBufferCo += QByteArray(obuffer, len2);
937 }
938 }
939 }
940
941 // Code Biases
942 // -----------
943 QByteArray hlpBufferBias;
944 if (bias.NumberOfSat[CLOCKORBIT_SATGPS] > 0
945 || bias.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0
946 || bias.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0
947 || bias.NumberOfSat[CLOCKORBIT_SATQZSS] > 0
948 || bias.NumberOfSat[CLOCKORBIT_SATSBAS] > 0
949 || bias.NumberOfSat[CLOCKORBIT_SATBDS] > 0) {
950 char obuffer[CLOCKORBIT_BUFFERSIZE] = {0};
951 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
952 int len = _ssrCorr->MakeCodeBias(&bias, _ssrCorr->CBTYPE_AUTO, 0, obuffer, sizeof(obuffer));
953 if (len > 0) {
954 hlpBufferBias = QByteArray(obuffer, len);
955 }
956 }
957 }
958
959 // Phase Biases
960 // ------------
961 QByteArray hlpBufferPhaseBias;
962 if ((phasebias.NumberOfSat[CLOCKORBIT_SATGPS] > 0
963 || phasebias.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0
964 || phasebias.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0
965 || phasebias.NumberOfSat[CLOCKORBIT_SATQZSS] > 0
966 || phasebias.NumberOfSat[CLOCKORBIT_SATSBAS] > 0
967 || phasebias.NumberOfSat[CLOCKORBIT_SATBDS] > 0)
968 && (_phaseBiasInformationDecoded)) {
969 char obuffer[CLOCKORBIT_BUFFERSIZE] = {0};
970 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
971 int len = _ssrCorr->MakePhaseBias(&phasebias, _ssrCorr->PBTYPE_AUTO, 0, obuffer, sizeof(obuffer));
972 if (len > 0) {
973 hlpBufferPhaseBias = QByteArray(obuffer, len);
974 }
975 }
976 }
977
978 // VTEC
979 // ----
980 QByteArray hlpBufferVtec;
981 if (vtec.NumLayers > 0) {
982 char obuffer[CLOCKORBIT_BUFFERSIZE] = {0};
983 int len = _ssrCorr->MakeVTEC(&vtec, 0, obuffer, sizeof(obuffer));
984 if (len > 0) {
985 hlpBufferVtec = QByteArray(obuffer, len);
986 }
987 }
988
989 _outBuffer += hlpBufferCo + hlpBufferBias + hlpBufferPhaseBias + hlpBufferVtec + '\0';
990}
991//
992////////////////////////////////////////////////////////////////////////////
993t_irc bncRtnetUploadCaster::processSatellite(const t_eph* eph, int GPSweek,
994 double GPSweeks, const QString& prn, const ColumnVector& rtnAPC,
995 double rtnUra, const ColumnVector& rtnClk, const ColumnVector& rtnVel,
996 const ColumnVector& rtnCoM, const ColumnVector& rtnClkSig,
997 struct SsrCorr::ClockOrbit::SatData* sd, QString& outLine) {
998
999 // Broadcast Position and Velocity
1000 // -------------------------------
1001 ColumnVector xB(6);
1002 ColumnVector vB(3);
1003 t_irc irc = eph->getCrd(bncTime(GPSweek, GPSweeks), xB, vB, false);
1004
1005 if (irc != success) {
1006 return irc;
1007 }
1008
1009 // Precise Position
1010 // ----------------
1011 ColumnVector xP = _CoM ? rtnCoM : rtnAPC;
1012
1013 if (xP.size() == 0) {
1014 return failure;
1015 }
1016
1017 double dc = 0.0;
1018 if (_crdTrafo != "IGS14") {
1019 crdTrafo(GPSweek, xP, dc);
1020 }
1021
1022 // Difference in xyz
1023 // -----------------
1024 ColumnVector dx = xB.Rows(1, 3) - xP;
1025 ColumnVector dv = vB - rtnVel;
1026
1027 // Difference in RSW
1028 // -----------------
1029 ColumnVector rsw(3);
1030 XYZ_to_RSW(xB.Rows(1, 3), vB, dx, rsw);
1031
1032 ColumnVector dotRsw(3);
1033 XYZ_to_RSW(xB.Rows(1, 3), vB, dv, dotRsw);
1034
1035 // Clock Correction
1036 // ----------------
1037 double dClkA0 = rtnClk(1) - (xB(4) - dc) * t_CST::c;
1038 double dClkA1 = 0.0;
1039 if (rtnClk(2)) {
1040 dClkA1 = rtnClk(2) - xB(5) * t_CST::c;
1041 }
1042 double dClkA2 = 0.0;
1043 if (rtnClk(3)) {
1044 dClkA2 = rtnClk(3) - xB(6) * t_CST::c;
1045 }
1046
1047 if (sd) {
1048 sd->ID = prn.mid(1).toInt();
1049 sd->IOD = eph->IOD();
1050 sd->Clock.DeltaA0 = dClkA0;
1051 sd->Clock.DeltaA1 = dClkA1;
1052 sd->Clock.DeltaA2 = dClkA2;
1053 sd->UserRangeAccuracy = rtnUra;
1054 sd->Orbit.DeltaRadial = rsw(1);
1055 sd->Orbit.DeltaAlongTrack = rsw(2);
1056 sd->Orbit.DeltaCrossTrack = rsw(3);
1057 sd->Orbit.DotDeltaRadial = dotRsw(1);
1058 sd->Orbit.DotDeltaAlongTrack = dotRsw(2);
1059 sd->Orbit.DotDeltaCrossTrack = dotRsw(3);
1060
1061 if (corrIsOutOfRange(sd)) {
1062 return failure;
1063 }
1064 }
1065
1066 outLine = QString().asprintf("%d %.1f %s %u %10.3f %8.3f %8.3f %8.3f %8.3f %8.3f\n", GPSweek,
1067 GPSweeks, eph->prn().toString().c_str(), eph->IOD(), dClkA0, dClkA1, dClkA2,
1068 rsw(1), rsw(2), rsw(3)); //fprintf(stderr, "%s\n", outLine.toStdString().c_str());
1069
1070 // RTNET full clock for RINEX and SP3 file
1071 // ---------------------------------------
1072 double relativity = -2.0 * DotProduct(xP, rtnVel) / t_CST::c;
1073 double clkRnx = (rtnClk[0] - relativity) / t_CST::c; // [s]
1074 double clkRnxRate = rtnClk[1] / t_CST::c; // [s/s = -]
1075 double clkRnxAcc = rtnClk[2] / t_CST::c; // [s/s² ) -/s]
1076
1077 if (_rnx) {
1078 double clkRnxSig, clkRnxRateSig, clkRnxAccSig;
1079 int s = rtnClkSig.size();
1080 switch (s) {
1081 case 1:
1082 clkRnxSig = rtnClkSig[0] / t_CST::c; // [s]
1083 clkRnxRateSig = 0.0; // [s/s = -]
1084 clkRnxAccSig = 0.0; // [s/s² ) -/s]
1085 break;
1086 case 2:
1087 clkRnxSig = rtnClkSig[0] / t_CST::c; // [s]
1088 clkRnxRateSig = rtnClkSig[1] / t_CST::c; // [s/s = -]
1089 clkRnxAccSig = 0.0; // [s/s² ) -/s]
1090 break;
1091 case 3:
1092 clkRnxSig = rtnClkSig[0] / t_CST::c; // [s]
1093 clkRnxRateSig = rtnClkSig[1] / t_CST::c; // [s/s = -]
1094 clkRnxAccSig = rtnClkSig[2] / t_CST::c; // [s/s² ) -/s]
1095 break;
1096 }
1097 _rnx->write(GPSweek, GPSweeks, prn, clkRnx, clkRnxRate, clkRnxAcc,
1098 clkRnxSig, clkRnxRateSig, clkRnxAccSig);
1099 }
1100 if (_sp3) {
1101 _sp3->write(GPSweek, GPSweeks, prn, rtnCoM, clkRnx, rtnVel, clkRnxRate);
1102 }
1103 return success;
1104}
1105
1106// Transform Coordinates
1107////////////////////////////////////////////////////////////////////////////
1108void bncRtnetUploadCaster::crdTrafo(int GPSWeek, ColumnVector& xyz,
1109 double& dc) {
1110
1111 // Current epoch minus 2000.0 in years
1112 // ------------------------------------
1113 double dt = (GPSWeek - (1042.0 + 6.0 / 7.0)) / 365.2422 * 7.0 + 2000.0 - _t0;
1114
1115 ColumnVector dx(3);
1116
1117 dx(1) = _dx + dt * _dxr;
1118 dx(2) = _dy + dt * _dyr;
1119 dx(3) = _dz + dt * _dzr;
1120
1121 static const double arcSec = 180.0 * 3600.0 / M_PI;
1122
1123 double ox = (_ox + dt * _oxr) / arcSec;
1124 double oy = (_oy + dt * _oyr) / arcSec;
1125 double oz = (_oz + dt * _ozr) / arcSec;
1126
1127 double sc = 1.0 + _sc * 1e-9 + dt * _scr * 1e-9;
1128
1129 // Specify approximate center of area
1130 // ----------------------------------
1131 ColumnVector meanSta(3);
1132
1133 if (_crdTrafo == "ETRF2000") {
1134 meanSta(1) = 3661090.0;
1135 meanSta(2) = 845230.0;
1136 meanSta(3) = 5136850.0;
1137 }
1138 else if (_crdTrafo == "GDA2020") {
1139 meanSta(1) = -4052050.0;
1140 meanSta(2) = 4212840.0;
1141 meanSta(3) = -2545110.0;
1142 }
1143 else if (_crdTrafo == "SIRGAS2000") {
1144 meanSta(1) = 3740860.0;
1145 meanSta(2) = -4964290.0;
1146 meanSta(3) = -1425420.0;
1147 }
1148 else if (_crdTrafo == "DREF91") {
1149 meanSta(1) = 3959579.0;
1150 meanSta(2) = 721719.0;
1151 meanSta(3) = 4931539.0;
1152 }
1153 else if (_crdTrafo == "Custom") {
1154 meanSta(1) = 0.0; // TODO
1155 meanSta(2) = 0.0; // TODO
1156 meanSta(3) = 0.0; // TODO
1157 }
1158
1159 // Clock correction proportional to topocentric distance to satellites
1160 // -------------------------------------------------------------------
1161 double rho = (xyz - meanSta).NormFrobenius();
1162 dc = rho * (sc - 1.0) / sc / t_CST::c;
1163
1164 Matrix rMat(3, 3);
1165 rMat(1, 1) = 1.0;
1166 rMat(1, 2) = -oz;
1167 rMat(1, 3) = oy;
1168 rMat(2, 1) = oz;
1169 rMat(2, 2) = 1.0;
1170 rMat(2, 3) = -ox;
1171 rMat(3, 1) = -oy;
1172 rMat(3, 2) = ox;
1173 rMat(3, 3) = 1.0;
1174
1175 xyz = sc * rMat * xyz + dx;
1176}
1177
1178int bncRtnetUploadCaster::determineUpdateInd(double samplingRate) {
1179
1180 if (samplingRate == 10.0) {
1181 return 3;
1182 }
1183 else if (samplingRate == 15.0) {
1184 return 4;
1185 }
1186 else if (samplingRate == 30.0) {
1187 return 5;
1188 }
1189 else if (samplingRate == 60.0) {
1190 return 6;
1191 }
1192 else if (samplingRate == 120.0) {
1193 return 7;
1194 }
1195 else if (samplingRate == 240.0) {
1196 return 8;
1197 }
1198 else if (samplingRate == 300.0) {
1199 return 9;
1200 }
1201 else if (samplingRate == 600.0) {
1202 return 10;
1203 }
1204 else if (samplingRate == 900.0) {
1205 return 11;
1206 }
1207 else if (samplingRate == 1800.0) {
1208 return 12;
1209 }
1210 else if (samplingRate == 3600.0) {
1211 return 13;
1212 }
1213 else if (samplingRate == 7200.0) {
1214 return 14;
1215 }
1216 else if (samplingRate == 10800.0) {
1217 return 15;
1218 }
1219 return 2; // default
1220}
1221
1222bool bncRtnetUploadCaster::corrIsOutOfRange(struct SsrCorr::ClockOrbit::SatData* sd) {
1223
1224 if (fabs(sd->Clock.DeltaA0) > 209.7151) {return true;}
1225 if (fabs(sd->Clock.DeltaA1) > 1.048575) {return true;}
1226 if (fabs(sd->Clock.DeltaA2) > 1.34217726) {return true;}
1227
1228 if (fabs(sd->Orbit.DeltaRadial) > 209.7151) {return true;}
1229 if (fabs(sd->Orbit.DeltaAlongTrack) > 209.7148) {return true;}
1230 if (fabs(sd->Orbit.DeltaCrossTrack) > 209.7148) {return true;}
1231
1232 if (fabs(sd->Orbit.DotDeltaRadial) > 1.048575) {return true;}
1233 if (fabs(sd->Orbit.DotDeltaAlongTrack) > 1.048572) {return true;}
1234 if (fabs(sd->Orbit.DotDeltaCrossTrack) > 1.048572) {return true;}
1235 return false;
1236}
Note: See TracBrowser for help on using the repository browser.