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

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

minor changes

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