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

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

minor changes

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