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

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

minor changes

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