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

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

restore RTNET buffer reading code

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