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

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

restore RTNET buffer reading code

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