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

Last change on this file since 10233 was 10227, checked in by stuerze, 13 months ago

minor changes

File size: 42.6 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) {
[10227]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) {
[10227]842 char obuffer[CLOCKORBIT_BUFFERSIZE] = {'\0'};
[4174]843 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
[4754]844 co.UpdateInterval = ephUpdInd;
[10227]845 int len1 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_GPSORBIT, 1, obuffer, sizeof(obuffer));
[4754]846 co.UpdateInterval = clkUpdInd;
[3493]847 if (len1 > 0) {
848 hlpBufferCo += QByteArray(obuffer, len1);
849 }
850 }
[8808]851 int mmsg = (co.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0 ||
852 co.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0 ||
853 co.NumberOfSat[CLOCKORBIT_SATQZSS] > 0 ||
854 co.NumberOfSat[CLOCKORBIT_SATSBAS] > 0 ||
855 co.NumberOfSat[CLOCKORBIT_SATBDS] > 0 ) ? 1 : 0;
[10227]856 int len2 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_GPSCLOCK, mmsg, obuffer, sizeof(obuffer));
[3493]857 if (len2 > 0) {
858 hlpBufferCo += QByteArray(obuffer, len2);
859 }
860 }
[5666]861 if (co.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0) {
[10221]862 char obuffer[CLOCKORBIT_BUFFERSIZE] = {'\0'};
[4174]863 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
[4754]864 co.UpdateInterval = ephUpdInd;
[10227]865 int len1 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_GLONASSORBIT, 1, obuffer, sizeof(obuffer));
[4754]866 co.UpdateInterval = clkUpdInd;
[3493]867 if (len1 > 0) {
868 hlpBufferCo += QByteArray(obuffer, len1);
869 }
870 }
[8808]871 int mmsg = (co.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0 ||
872 co.NumberOfSat[CLOCKORBIT_SATQZSS] > 0 ||
873 co.NumberOfSat[CLOCKORBIT_SATSBAS] > 0 ||
874 co.NumberOfSat[CLOCKORBIT_SATBDS] > 0 ) ? 1 : 0;
[10227]875 int len2 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_GLONASSCLOCK, mmsg, obuffer, sizeof(obuffer));
[3493]876 if (len2 > 0) {
877 hlpBufferCo += QByteArray(obuffer, len2);
878 }
879 }
[6844]880 if (co.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0) {
[10221]881 char obuffer[CLOCKORBIT_BUFFERSIZE] = {'\0'};
[6844]882 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
883 co.UpdateInterval = ephUpdInd;
[10227]884 int len1 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_GALILEOORBIT, 1, obuffer, sizeof(obuffer));
[6844]885 co.UpdateInterval = clkUpdInd;
886 if (len1 > 0) {
887 hlpBufferCo += QByteArray(obuffer, len1);
888 }
889 }
[8808]890 int mmsg = (co.NumberOfSat[CLOCKORBIT_SATQZSS] > 0 ||
891 co.NumberOfSat[CLOCKORBIT_SATSBAS] > 0 ||
892 co.NumberOfSat[CLOCKORBIT_SATBDS] > 0 ) ? 1 : 0;
[10227]893 int len2 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_GALILEOCLOCK, mmsg, obuffer, sizeof(obuffer));
[6844]894 if (len2 > 0) {
895 hlpBufferCo += QByteArray(obuffer, len2);
896 }
897 }
898 if (co.NumberOfSat[CLOCKORBIT_SATQZSS] > 0) {
[10221]899 char obuffer[CLOCKORBIT_BUFFERSIZE] = {'\0'};
[6844]900 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
901 co.UpdateInterval = ephUpdInd;
[10227]902 int len1 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_QZSSORBIT, 1, obuffer, sizeof(obuffer));
[6844]903 co.UpdateInterval = clkUpdInd;
904 if (len1 > 0) {
905 hlpBufferCo += QByteArray(obuffer, len1);
906 }
907 }
[8808]908 int mmsg = (co.NumberOfSat[CLOCKORBIT_SATSBAS] > 0 ||
909 co.NumberOfSat[CLOCKORBIT_SATBDS] > 0 ) ? 1 : 0;
[10227]910 int len2 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_QZSSCLOCK, mmsg, obuffer, sizeof(obuffer));
[6844]911 if (len2 > 0) {
912 hlpBufferCo += QByteArray(obuffer, len2);
913 }
914 }
915 if (co.NumberOfSat[CLOCKORBIT_SATSBAS] > 0) {
[10221]916 char obuffer[CLOCKORBIT_BUFFERSIZE] = {'\0'};
[6844]917 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
918 co.UpdateInterval = ephUpdInd;
[10227]919 int len1 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_SBASORBIT, 1, obuffer, sizeof(obuffer));
[6844]920 co.UpdateInterval = clkUpdInd;
921 if (len1 > 0) {
922 hlpBufferCo += QByteArray(obuffer, len1);
923 }
924 }
925 int mmsg = (co.NumberOfSat[CLOCKORBIT_SATBDS] > 0) ? 1 : 0;
[9025]926 int len2 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_SBASCLOCK, mmsg, obuffer,
[6877]927 sizeof(obuffer));
[6844]928 if (len2 > 0) {
929 hlpBufferCo += QByteArray(obuffer, len2);
930 }
931 }
932 if (co.NumberOfSat[CLOCKORBIT_SATBDS] > 0) {
[10221]933 char obuffer[CLOCKORBIT_BUFFERSIZE] = {'\0'};
[6844]934 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
935 co.UpdateInterval = ephUpdInd;
[10227]936 int len1 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_BDSORBIT, 1, obuffer, sizeof(obuffer));
[6844]937 co.UpdateInterval = clkUpdInd;
938 if (len1 > 0) {
939 hlpBufferCo += QByteArray(obuffer, len1);
940 }
941 }
[8808]942 int mmsg = 0;
[10227]943 int len2 = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_BDSCLOCK, mmsg, obuffer, sizeof(obuffer));
[6844]944 if (len2 > 0) {
945 hlpBufferCo += QByteArray(obuffer, len2);
946 }
947 }
[3493]948 }
[5662]949
[6850]950 // Code Biases
951 // -----------
[5662]952 QByteArray hlpBufferBias;
[6877]953 if (bias.NumberOfSat[CLOCKORBIT_SATGPS] > 0
954 || bias.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0
955 || bias.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0
956 || bias.NumberOfSat[CLOCKORBIT_SATQZSS] > 0
957 || bias.NumberOfSat[CLOCKORBIT_SATSBAS] > 0
958 || bias.NumberOfSat[CLOCKORBIT_SATBDS] > 0) {
[10221]959 char obuffer[CLOCKORBIT_BUFFERSIZE] = {'\0'};
[9140]960 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
961 int len = _ssrCorr->MakeCodeBias(&bias, _ssrCorr->CBTYPE_AUTO, 0, obuffer, sizeof(obuffer));
962 if (len > 0) {
963 hlpBufferBias = QByteArray(obuffer, len);
964 }
[3222]965 }
966 }
[3227]967
[6850]968 // Phase Biases
969 // ------------
970 QByteArray hlpBufferPhaseBias;
[9128]971 if ((phasebias.NumberOfSat[CLOCKORBIT_SATGPS] > 0
[6877]972 || phasebias.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0
973 || phasebias.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0
974 || phasebias.NumberOfSat[CLOCKORBIT_SATQZSS] > 0
975 || phasebias.NumberOfSat[CLOCKORBIT_SATSBAS] > 0
[9129]976 || phasebias.NumberOfSat[CLOCKORBIT_SATBDS] > 0)
977 && (_phaseBiasInformationDecoded)) {
[10221]978 char obuffer[CLOCKORBIT_BUFFERSIZE] = {'\0'};
[9140]979 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
980 int len = _ssrCorr->MakePhaseBias(&phasebias, _ssrCorr->PBTYPE_AUTO, 0, obuffer, sizeof(obuffer));
981 if (len > 0) {
982 hlpBufferPhaseBias = QByteArray(obuffer, len);
983 }
[6850]984 }
985 }
986
987 // VTEC
988 // ----
989 QByteArray hlpBufferVtec;
[6860]990 if (vtec.NumLayers > 0) {
[10221]991 char obuffer[CLOCKORBIT_BUFFERSIZE] = {'\0'};
[9025]992 int len = _ssrCorr->MakeVTEC(&vtec, 0, obuffer, sizeof(obuffer));
[6860]993 if (len > 0) {
994 hlpBufferVtec = QByteArray(obuffer, len);
995 }
996 }
[6850]997
[9868]998 _outBuffer += hlpBufferCo + hlpBufferBias + hlpBufferPhaseBias + hlpBufferVtec + '\0';
[3222]999}
[5662]1000//
[3222]1001////////////////////////////////////////////////////////////////////////////
[8542]1002t_irc bncRtnetUploadCaster::processSatellite(const t_eph* eph, int GPSweek,
[6877]1003 double GPSweeks, const QString& prn, const ColumnVector& rtnAPC,
[8483]1004 double rtnUra, const ColumnVector& rtnClk, const ColumnVector& rtnVel,
1005 const ColumnVector& rtnCoM, const ColumnVector& rtnClkSig,
[9025]1006 struct SsrCorr::ClockOrbit::SatData* sd, QString& outLine) {
[3222]1007
[4930]1008 // Broadcast Position and Velocity
1009 // -------------------------------
[8542]1010 ColumnVector xB(6);
[4930]1011 ColumnVector vB(3);
[8542]1012 t_irc irc = eph->getCrd(bncTime(GPSweek, GPSweeks), xB, vB, false);
[5662]1013
[8542]1014 if (irc != success) {
1015 return irc;
1016 }
1017
[4991]1018 // Precise Position
1019 // ----------------
1020 ColumnVector xP = _CoM ? rtnCoM : rtnAPC;
[3222]1021
[8542]1022 if (xP.size() == 0) {
1023 return failure;
1024 }
1025
[5662]1026 double dc = 0.0;
[9911]1027 if (_crdTrafo != "IGS20") {
1028 crdTrafo14(GPSweek, xP, dc); // ITRF2020 => ITRF2014
1029 crdTrafo(GPSweek, xP, dc); // ITRF2014 to other reference frames
[8094]1030 }
[5662]1031
[4930]1032 // Difference in xyz
1033 // -----------------
[6877]1034 ColumnVector dx = xB.Rows(1, 3) - xP;
1035 ColumnVector dv = vB - rtnVel;
[5662]1036
[4930]1037 // Difference in RSW
1038 // -----------------
[3222]1039 ColumnVector rsw(3);
[6877]1040 XYZ_to_RSW(xB.Rows(1, 3), vB, dx, rsw);
[3222]1041
[4930]1042 ColumnVector dotRsw(3);
[6877]1043 XYZ_to_RSW(xB.Rows(1, 3), vB, dv, dotRsw);
[3222]1044
[4930]1045 // Clock Correction
1046 // ----------------
[8499]1047 double dClkA0 = rtnClk(1) - (xB(4) - dc) * t_CST::c;
[8679]1048 double dClkA1 = 0.0;
1049 if (rtnClk(2)) {
[9126]1050 dClkA1 = rtnClk(2) - xB(5) * t_CST::c;
[8679]1051 }
1052 double dClkA2 = 0.0;
1053 if (rtnClk(3)) {
[9126]1054 dClkA2 = rtnClk(3) - xB(6) * t_CST::c;
[8679]1055 }
[3222]1056
1057 if (sd) {
[6877]1058 sd->ID = prn.mid(1).toInt();
1059 sd->IOD = eph->IOD();
[8483]1060 sd->Clock.DeltaA0 = dClkA0;
1061 sd->Clock.DeltaA1 = dClkA1;
1062 sd->Clock.DeltaA2 = dClkA2;
1063 sd->UserRangeAccuracy = rtnUra;
1064 sd->Orbit.DeltaRadial = rsw(1);
[6877]1065 sd->Orbit.DeltaAlongTrack = rsw(2);
1066 sd->Orbit.DeltaCrossTrack = rsw(3);
[8483]1067 sd->Orbit.DotDeltaRadial = dotRsw(1);
[4930]1068 sd->Orbit.DotDeltaAlongTrack = dotRsw(2);
1069 sd->Orbit.DotDeltaCrossTrack = dotRsw(3);
[9179]1070
[9930]1071 if (corrIsOutOfRange(sd)) {
[9179]1072 return failure;
1073 }
[3222]1074 }
1075
[9675]1076 outLine = QString().asprintf("%d %.1f %s %u %10.3f %8.3f %8.3f %8.3f %8.3f %8.3f\n", GPSweek,
[8483]1077 GPSweeks, eph->prn().toString().c_str(), eph->IOD(), dClkA0, dClkA1, dClkA2,
[9928]1078 rsw(1), rsw(2), rsw(3)); //fprintf(stderr, "%s\n", outLine.toStdString().c_str());
[3222]1079
[8499]1080 // RTNET full clock for RINEX and SP3 file
1081 // ---------------------------------------
[4991]1082 double relativity = -2.0 * DotProduct(xP, rtnVel) / t_CST::c;
[8499]1083 double clkRnx = (rtnClk[0] - relativity) / t_CST::c; // [s]
[10024]1084 double clkRnxRate = rtnClk[1] / t_CST::c; // [s/s = -]
1085 double clkRnxAcc = rtnClk[2] / t_CST::c; // [s/s² = -/s]
[4991]1086
[3222]1087 if (_rnx) {
[8510]1088 double clkRnxSig, clkRnxRateSig, clkRnxAccSig;
1089 int s = rtnClkSig.size();
1090 switch (s) {
1091 case 1:
1092 clkRnxSig = rtnClkSig[0] / t_CST::c; // [s]
1093 clkRnxRateSig = 0.0; // [s/s = -]
1094 clkRnxAccSig = 0.0; // [s/s² ) -/s]
1095 break;
1096 case 2:
1097 clkRnxSig = rtnClkSig[0] / t_CST::c; // [s]
1098 clkRnxRateSig = rtnClkSig[1] / t_CST::c; // [s/s = -]
1099 clkRnxAccSig = 0.0; // [s/s² ) -/s]
1100 break;
1101 case 3:
1102 clkRnxSig = rtnClkSig[0] / t_CST::c; // [s]
1103 clkRnxRateSig = rtnClkSig[1] / t_CST::c; // [s/s = -]
1104 clkRnxAccSig = rtnClkSig[2] / t_CST::c; // [s/s² ) -/s]
1105 break;
1106 }
[8483]1107 _rnx->write(GPSweek, GPSweeks, prn, clkRnx, clkRnxRate, clkRnxAcc,
1108 clkRnxSig, clkRnxRateSig, clkRnxAccSig);
[3222]1109 }
1110 if (_sp3) {
[8483]1111 _sp3->write(GPSweek, GPSweeks, prn, rtnCoM, clkRnx, rtnVel, clkRnxRate);
[3222]1112 }
[8542]1113 return success;
[3222]1114}
1115
1116// Transform Coordinates
1117////////////////////////////////////////////////////////////////////////////
[5662]1118void bncRtnetUploadCaster::crdTrafo(int GPSWeek, ColumnVector& xyz,
[6877]1119 double& dc) {
[3222]1120
1121 // Current epoch minus 2000.0 in years
1122 // ------------------------------------
[6877]1123 double dt = (GPSWeek - (1042.0 + 6.0 / 7.0)) / 365.2422 * 7.0 + 2000.0 - _t0;
[3222]1124
1125 ColumnVector dx(3);
1126
1127 dx(1) = _dx + dt * _dxr;
1128 dx(2) = _dy + dt * _dyr;
1129 dx(3) = _dz + dt * _dzr;
1130
1131 static const double arcSec = 180.0 * 3600.0 / M_PI;
1132
1133 double ox = (_ox + dt * _oxr) / arcSec;
1134 double oy = (_oy + dt * _oyr) / arcSec;
1135 double oz = (_oz + dt * _ozr) / arcSec;
1136
1137 double sc = 1.0 + _sc * 1e-9 + dt * _scr * 1e-9;
1138
[4912]1139 // Specify approximate center of area
1140 // ----------------------------------
1141 ColumnVector meanSta(3);
1142
[6877]1143 if (_crdTrafo == "ETRF2000") {
1144 meanSta(1) = 3661090.0;
1145 meanSta(2) = 845230.0;
1146 meanSta(3) = 5136850.0;
[4908]1147 }
[8094]1148 else if (_crdTrafo == "GDA2020") {
[4973]1149 meanSta(1) = -4052050.0;
[6877]1150 meanSta(2) = 4212840.0;
[4973]1151 meanSta(3) = -2545110.0;
[4912]1152 }
1153 else if (_crdTrafo == "SIRGAS2000") {
[6877]1154 meanSta(1) = 3740860.0;
[4973]1155 meanSta(2) = -4964290.0;
1156 meanSta(3) = -1425420.0;
[4912]1157 }
[5343]1158 else if (_crdTrafo == "DREF91") {
[6877]1159 meanSta(1) = 3959579.0;
1160 meanSta(2) = 721719.0;
1161 meanSta(3) = 4931539.0;
[5343]1162 }
[4912]1163 else if (_crdTrafo == "Custom") {
[9911]1164 meanSta(1) = 0.0;
1165 meanSta(2) = 0.0;
1166 meanSta(3) = 0.0;
[4912]1167 }
[4908]1168
[4912]1169 // Clock correction proportional to topocentric distance to satellites
1170 // -------------------------------------------------------------------
[8904]1171 double rho = (xyz - meanSta).NormFrobenius();
[4913]1172 dc = rho * (sc - 1.0) / sc / t_CST::c;
[4908]1173
[6877]1174 Matrix rMat(3, 3);
1175 rMat(1, 1) = 1.0;
1176 rMat(1, 2) = -oz;
1177 rMat(1, 3) = oy;
1178 rMat(2, 1) = oz;
1179 rMat(2, 2) = 1.0;
1180 rMat(2, 3) = -ox;
1181 rMat(3, 1) = -oy;
1182 rMat(3, 2) = ox;
1183 rMat(3, 3) = 1.0;
[3222]1184
1185 xyz = sc * rMat * xyz + dx;
1186}
1187
[9911]1188// Transform Coordinates
1189////////////////////////////////////////////////////////////////////////////
1190void bncRtnetUploadCaster::crdTrafo14(int GPSWeek, ColumnVector& xyz,
1191 double& dc) {
1192
1193 // Current epoch minus 2000.0 in years
1194 // ------------------------------------
1195 double dt = (GPSWeek - (1042.0 + 6.0 / 7.0)) / 365.2422 * 7.0 + 2000.0 - _t0;
1196
1197 ColumnVector dx(3);
1198
1199 dx(1) = _dx14 + dt * _dxr14;
1200 dx(2) = _dy14 + dt * _dyr14;
1201 dx(3) = _dz14 + dt * _dzr14;
1202
1203 static const double arcSec = 180.0 * 3600.0 / M_PI;
1204
1205 double ox = (_ox14 + dt * _oxr14) / arcSec;
1206 double oy = (_oy14 + dt * _oyr14) / arcSec;
1207 double oz = (_oz14 + dt * _ozr14) / arcSec;
1208
1209 double sc = 1.0 + _sc14 * 1e-9 + dt * _scr14 * 1e-9;
1210
1211 // Specify approximate center of area
1212 // ----------------------------------
1213 ColumnVector meanSta(3);
1214 meanSta(1) = 0.0; // TODO
1215 meanSta(2) = 0.0; // TODO
1216 meanSta(3) = 0.0; // TODO
1217
1218 // Clock correction proportional to topocentric distance to satellites
1219 // -------------------------------------------------------------------
1220 double rho = (xyz - meanSta).NormFrobenius();
1221 dc = rho * (sc - 1.0) / sc / t_CST::c;
1222
1223 Matrix rMat(3, 3);
1224 rMat(1, 1) = 1.0;
1225 rMat(1, 2) = -oz;
1226 rMat(1, 3) = oy;
1227 rMat(2, 1) = oz;
1228 rMat(2, 2) = 1.0;
1229 rMat(2, 3) = -ox;
1230 rMat(3, 1) = -oy;
1231 rMat(3, 2) = ox;
1232 rMat(3, 3) = 1.0;
1233
1234 xyz = sc * rMat * xyz + dx;
1235}
1236
1237// Update Interval
1238////////////////////////////////////////////////////////////////////////////
[6557]1239int bncRtnetUploadCaster::determineUpdateInd(double samplingRate) {
1240
1241 if (samplingRate == 10.0) {
1242 return 3;
1243 }
1244 else if (samplingRate == 15.0) {
1245 return 4;
1246 }
1247 else if (samplingRate == 30.0) {
1248 return 5;
1249 }
1250 else if (samplingRate == 60.0) {
1251 return 6;
1252 }
1253 else if (samplingRate == 120.0) {
1254 return 7;
1255 }
1256 else if (samplingRate == 240.0) {
1257 return 8;
1258 }
1259 else if (samplingRate == 300.0) {
1260 return 9;
1261 }
1262 else if (samplingRate == 600.0) {
1263 return 10;
1264 }
1265 else if (samplingRate == 900.0) {
1266 return 11;
1267 }
1268 else if (samplingRate == 1800.0) {
1269 return 12;
1270 }
1271 else if (samplingRate == 3600.0) {
1272 return 13;
1273 }
1274 else if (samplingRate == 7200.0) {
1275 return 14;
1276 }
1277 else if (samplingRate == 10800.0) {
1278 return 15;
1279 }
[6877]1280 return 2; // default
[6557]1281}
[9179]1282
[9911]1283// Check corrections
1284////////////////////////////////////////////////////////////////////////////
[9179]1285bool bncRtnetUploadCaster::corrIsOutOfRange(struct SsrCorr::ClockOrbit::SatData* sd) {
1286
1287 if (fabs(sd->Clock.DeltaA0) > 209.7151) {return true;}
1288 if (fabs(sd->Clock.DeltaA1) > 1.048575) {return true;}
1289 if (fabs(sd->Clock.DeltaA2) > 1.34217726) {return true;}
1290
1291 if (fabs(sd->Orbit.DeltaRadial) > 209.7151) {return true;}
1292 if (fabs(sd->Orbit.DeltaAlongTrack) > 209.7148) {return true;}
1293 if (fabs(sd->Orbit.DeltaCrossTrack) > 209.7148) {return true;}
1294
1295 if (fabs(sd->Orbit.DotDeltaRadial) > 1.048575) {return true;}
1296 if (fabs(sd->Orbit.DotDeltaAlongTrack) > 1.048572) {return true;}
1297 if (fabs(sd->Orbit.DotDeltaCrossTrack) > 1.048572) {return true;}
1298 return false;
[9275]1299}
Note: See TracBrowser for help on using the repository browser.