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

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

try the old RTNET buffer reading code again

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