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

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

minor changes

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