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

Last change on this file since 9877 was 9877, checked in by stuerze, 2 years ago

minor changes

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