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

Last change on this file since 11140 was 11140, checked in by stuerze, 7 days ago

General option 'Ephemeris streams' is added and valid for combination, upload of SSR corrections and SSR QC

File size: 54.9 KB
Line 
1/* -------------------------------------------------------------------------
2 * BKG NTRIP Server
3 * -------------------------------------------------------------------------
4 *
5 * Class: bncRtnetUploadCaster
6 *
7 * Purpose: Connection to NTRIP Caster
8 *
9 * Author: L. Mervart
10 *
11 * Created: 29-Mar-2011
12 *
13 * Changes:
14 *
15 * -----------------------------------------------------------------------*/
16
17#include <math.h>
18#include "bncrtnetuploadcaster.h"
19#include "bncsettings.h"
20#include "bncephuser.h"
21#include "bncclockrinex.h"
22#include "bncbiassinex.h"
23#include "bncsp3.h"
24#include "gnss.h"
25#include "bncutils.h"
26
27using namespace std;
28
29// Constructor
30////////////////////////////////////////////////////////////////////////////
31bncRtnetUploadCaster::bncRtnetUploadCaster(const QString& mountpoint,
32 const QString& outHost, int outPort,
33 const QString& ntripVersion,
34 const QString& userName, const QString& password,
35 const QString& crdTrafo, const QString& ssrFormat, bool CoM, const QString& sp3FileName,
36 const QString& rnxFileName, const QString& bsxFileName, int PID, int SID, int IOD, int iRow) :
37 bncUploadCaster(mountpoint, outHost, outPort, ntripVersion, userName, password, iRow, 0) {
38
39 if (!mountpoint.isEmpty()) {
40 _casterID += mountpoint;
41 }
42 if (!outHost.isEmpty()) {
43 _casterID += " " + outHost;
44 if (outPort) {
45 _casterID += ":" + QString("%1").arg(outPort, 10);
46 }
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
58 if (!bsxFileName.isEmpty()) {
59 _casterID += " " + bsxFileName;
60 }
61
62 _crdTrafoStr = crdTrafo;
63
64 _ssrFormat = ssrFormat;
65
66 _ssrCorr = 0;
67 if (_ssrFormat == "IGS-SSR") {
68 _ssrCorr = new SsrCorrIgs();
69 }
70 else if (_ssrFormat == "RTCM-SSR") {
71 _ssrCorr = new SsrCorrRtcm();
72 }
73 else if (ssrFormat == "RTCM-NEW-SSR") {
74 _ssrCorr = new SsrCorrRtcmNew();
75 }
76
77 _CoM = CoM;
78 _PID = PID;
79 _SID = SID;
80 _IOD = IOD;
81 _phaseBiasInformationDecoded = false;
82
83 // Member that receives the ephemeris
84 // ----------------------------------
85 _ephUser = new bncEphUser(true);
86 _ephUser->useEphMounts("bncRtnetUploadCaster " + mountpoint);
87
88 bncSettings settings;
89 QString intr = settings.value("uploadIntr").toString();
90 QStringList hlp = settings.value("cmbStreams").toStringList();
91 _samplRtcmEphCorr = settings.value("uploadSamplRtcmEphCorr").toString().split("sec").first().toDouble();
92
93 if (hlp.size() > 1) { // combination stream upload
94 _samplRtcmClkCorr = settings.value("cmbSampl").toString().split("sec").first().toDouble();
95 }
96 else { // single stream upload or sp3 file generation
97 _samplRtcmClkCorr = 5.0; // default
98 }
99 _samplRtcmVtec = 60.0;
100 _samplRtcmCrs = 60.0;
101 int samplSp3 = settings.value("uploadSamplSp3").toString().split("sec").first().toInt();
102 int samplClkRnx = settings.value("uploadSamplClkRnx").toInt();
103 int samplBiaSnx = settings.value("uploadSamplBiaSnx").toInt();
104
105 if (_samplRtcmEphCorr == 0.0) {
106 _usedEph = 0;
107 }
108 else {
109 _usedEph = new QMap<QString, const t_eph*>;
110 }
111
112 // RINEX writer
113 // ------------
114 if (!rnxFileName.isEmpty()) {
115 _rnx = new bncClockRinex(rnxFileName, intr, samplClkRnx);
116 }
117 else {
118 _rnx = 0;
119 }
120
121 // SP3 writer
122 // ----------
123 if (!sp3FileName.isEmpty()) {
124 _sp3 = new bncSP3(sp3FileName, intr, samplSp3);
125 }
126 else {
127 _sp3 = 0;
128 }
129
130 // SINEX writer
131 // ------------
132 if (!bsxFileName.isEmpty()) {
133 _bsx = new bncBiasSinex(bsxFileName, intr, samplBiaSnx);
134 }
135 else {
136 _bsx = 0;
137 }
138
139
140 // Set Transformation Parameters
141 // -----------------------------
142 // Transformation Parameters from ITRF2014 to ETRF2000
143 // http://etrs89.ign.fr/pub/EUREF-TN-1-Mar-04-2024.pdf
144 if (_crdTrafoStr == "ETRF2000") {
145 _dx = 0.0552;
146 _dy = 0.0527;
147 _dz = -0.0836;
148
149 _dxr = 0.0001;
150 _dyr = 0.0001;
151 _dzr = -0.0019;
152
153 _ox = 0.002106;
154 _oy = 0.012740;
155 _oz = -0.020592;
156
157 _oxr = 0.000081;
158 _oyr = 0.000490;
159 _ozr = -0.000792;
160
161 _sc = 2.67;
162 _scr = 0.11;
163
164 _t0 = 2015.0;
165 }
166 // Transformation Parameters from ITRF2014 to GDA2020 (Ryan Ruddick, GA)
167 else if (_crdTrafoStr == "GDA2020") {
168 _dx = 0.0;
169 _dy = 0.0;
170 _dz = 0.0;
171
172 _dxr = 0.0;
173 _dyr = 0.0;
174 _dzr = 0.0;
175
176 _ox = 0.0;
177 _oy = 0.0;
178 _oz = 0.0;
179
180 _oxr = 0.00150379;
181 _oyr = 0.00118346;
182 _ozr = 0.00120716;
183
184 _sc = 0.0;
185 _scr = 0.0;
186
187 _t0 = 2020.0;
188 }
189 // Transformation Parameters from IGb14 to SIRGAS2000 (Thanks to Sonia Costa, BRA)
190 // June 29 2020: TX:-0.0027 m TY:-0.0025 m TZ:-0.0042 m SCL:1.20 (ppb) no rotations and no rates.*/
191 else if (_crdTrafoStr == "SIRGAS2000") {
192 _dx = -0.0027;
193 _dy = -0.0025;
194 _dz = -0.0042;
195
196 _dxr = 0.0;
197 _dyr = 0.0;
198 _dzr = 0.0;
199
200 _ox = 0.0;
201 _oy = 0.0;
202 _oz = 0.0;
203
204 _oxr = 0.0;
205 _oyr = 0.0;
206 _ozr = 0.0;
207
208 _sc = 1.2;
209 _scr = 0.0;
210 _t0 = 2000.0;
211 }
212 // Transformation Parameters from ITRF2014 to DREF91
213 else if (_crdTrafoStr == "DREF91") {
214 _dx = 0.0547;
215 _dy = 0.0522;
216 _dz = -0.0741;
217
218 _dxr = 0.0001;
219 _dyr = 0.0001;
220 _dzr = -0.0019;
221 // ERTF200 + rotation parameters (ETRF2000 => DREF91)
222 _ox = 0.001701 + 0.000658;
223 _oy = 0.010290 - 0.000208;
224 _oz = -0.016632 + 0.000755;
225
226 _oxr = 0.000081;
227 _oyr = 0.000490;
228 _ozr = -0.000729;
229
230 _sc = 2.12;
231 _scr = 0.11;
232
233 _t0 = 2010.0;
234 }
235 else if (_crdTrafoStr == "Custom") {
236 _dx = settings.value("trafo_dx").toDouble();
237 _dy = settings.value("trafo_dy").toDouble();
238 _dz = settings.value("trafo_dz").toDouble();
239 _dxr = settings.value("trafo_dxr").toDouble();
240 _dyr = settings.value("trafo_dyr").toDouble();
241 _dzr = settings.value("trafo_dzr").toDouble();
242 _ox = settings.value("trafo_ox").toDouble();
243 _oy = settings.value("trafo_oy").toDouble();
244 _oz = settings.value("trafo_oz").toDouble();
245 _oxr = settings.value("trafo_oxr").toDouble();
246 _oyr = settings.value("trafo_oyr").toDouble();
247 _ozr = settings.value("trafo_ozr").toDouble();
248 _sc = settings.value("trafo_sc").toDouble();
249 _scr = settings.value("trafo_scr").toDouble();
250 _t0 = settings.value("trafo_t0").toDouble();
251 }
252 // TODO: the following lines can be deleted if all parameters are updated regarding ITRF2020
253 if (_crdTrafoStr == "ETRF2000" ||
254 _crdTrafoStr == "GDA2020" ||
255 _crdTrafoStr == "DREF91" ||
256 _crdTrafoStr == "SIRGAS2000") {
257 // Transformation Parameters from ITRF2020 to ITRF2014
258 // from ITRF web site: https://itrf.ign.fr/en/solutions/transformations
259 _dx14 = -0.0014;
260 _dy14 = -0.0009;
261 _dz14 = 0.0014;
262 _dxr14 = 0.0;
263 _dyr14 = -0.0001;
264 _dzr14 = -0.0002;
265 _ox14 = 0.0;
266 _oy14 = 0.0;
267 _oz14 = 0.0;
268 _oxr14 = 0.0;
269 _oyr14 = 0.0;
270 _ozr14 = 0.0;
271 _sc14 = -0.42;
272 _scr14 = 0.0;
273 _t014 = 2015.0;
274 }
275}
276
277// Destructor
278////////////////////////////////////////////////////////////////////////////
279bncRtnetUploadCaster::~bncRtnetUploadCaster() {
280 if (isRunning()) {
281 wait();
282 }
283 delete _rnx;
284 delete _sp3;
285 delete _bsx;
286 delete _ephUser;
287 delete _usedEph;
288 delete _ssrCorr;
289}
290
291//
292////////////////////////////////////////////////////////////////////////////
293void bncRtnetUploadCaster::decodeRtnetStream(char* buffer, int bufLen) {
294
295 QMutexLocker locker(&_mutex);
296
297 // Append to internal buffer
298 // -------------------------
299 _rtnetStreamBuffer.append(QByteArray(buffer, bufLen));
300
301 // Select buffer part that contains last epoch
302 // -------------------------------------------
303 QStringList lines;
304 int iEpoBeg = _rtnetStreamBuffer.lastIndexOf('*'); // begin of last epoch
305 if (iEpoBeg == -1) {
306 _rtnetStreamBuffer.clear();
307 return;
308 }
309 _rtnetStreamBuffer = _rtnetStreamBuffer.mid(iEpoBeg);
310
311 int iEpoEnd = _rtnetStreamBuffer.lastIndexOf("EOE"); // end of last epoch
312 if (iEpoEnd == -1) {
313 return;
314 }
315 else {
316 lines = _rtnetStreamBuffer.left(iEpoEnd).split('\n', Qt::SkipEmptyParts);
317 _rtnetStreamBuffer = _rtnetStreamBuffer.mid(iEpoEnd + 3);
318 }
319
320 if (lines.size() < 2) {
321 emit(newMessage(
322 "bncRtnetUploadCaster: less than 2 lines to decode " + _casterID.toLatin1(), false));
323 return;
324 }
325
326 // Keep the last unfinished line in buffer
327 // ---------------------------------------
328 int iLastEOL = _rtnetStreamBuffer.lastIndexOf('\n');
329 if (iLastEOL != -1) {
330 _rtnetStreamBuffer = _rtnetStreamBuffer.mid(iLastEOL + 1);
331 }
332
333
334 // Read first line (with epoch time)
335 // ---------------------------------
336 //QTextStream in(lines[0].toLatin1());
337 QTextStream in(&lines[0], QIODevice::ReadOnly);
338 QString hlp;
339 int year, month, day, hour, min;
340 double sec;
341 in >> hlp >> year >> month >> day >> hour >> min >> sec;
342 bncTime epoTime;
343 epoTime.set(year, month, day, hour, min, sec);
344
345 emit(newMessage(
346 "bncRtnetUploadCaster: decode " + QByteArray(epoTime.datestr().c_str())
347 + " " + QByteArray(epoTime.timestr().c_str()) + " "
348 + _casterID.toLatin1(), false));
349
350 struct SsrCorr::ClockOrbit co;
351 memset(&co, 0, sizeof(co));
352 co.EpochTime[CLOCKORBIT_SATGPS] = static_cast<int>(epoTime.gpssec());
353 if (_ssrFormat == "IGS-SSR") {
354 // SSR Epoch Time (IDF003) in one continuous time scale for all GNSS:
355 // GPS seconds of week also for GLONASS and BDS (IGS SSR v1.00)
356 co.EpochTime[CLOCKORBIT_SATGLONASS] = static_cast<int>(epoTime.gpssec());
357 co.EpochTime[CLOCKORBIT_SATBDS] = static_cast<int>(epoTime.gpssec());
358 }
359 else {
360 // RTCM-SSR (old and new): GLONASS Epoch Time DF386, seconds since the
361 // beginning of the GLONASS day (GLONASS time = UTC(SU) + 3h)
362 double gt = epoTime.gpssec() - gnumleap(year, month, day) + 3 * 3600;
363 co.EpochTime[CLOCKORBIT_SATGLONASS] = static_cast<int>(fmod(gt, 86400.0));
364 co.EpochTime[CLOCKORBIT_SATBDS] = static_cast<int>(epoTime.bdssec());
365 }
366 co.EpochTime[CLOCKORBIT_SATGALILEO] = static_cast<int>(epoTime.gpssec());
367 co.EpochTime[CLOCKORBIT_SATQZSS] = static_cast<int>(epoTime.gpssec());
368 co.EpochTime[CLOCKORBIT_SATSBAS] = static_cast<int>(epoTime.gpssec());
369 co.Supplied[_ssrCorr->COBOFS_CLOCK] = 1;
370 co.Supplied[_ssrCorr->COBOFS_ORBIT] = 1;
371 (_crdTrafoStr == "IGS20") ?
372 co.SatRefDatum = _ssrCorr->DATUM_ITRF :
373 co.SatRefDatum = _ssrCorr->DATUM_LOCAL;
374 co.SSRIOD = _IOD;
375 co.SSRProviderID = _PID; // 256 .. BKG, 257 ... EUREF
376 co.SSRSolutionID = _SID;
377 co.Supplied[_ssrCorr->COBOFS_CLOCK] = 1;
378 co.Supplied[_ssrCorr->COBOFS_ORBIT] = 1;
379
380 t_serviceCrs serviceCrs;
381 t_rtcmCrs rtcmCrs;
382 if (_crdTrafoStr == "IGS20") {
383 serviceCrs._CE = serviceCrs._coordinateEpoch = 0;
384 int nc = _crdTrafoStr.length();
385 if (nc > 31) { nc = 31; }
386 for (int i = 0; i < nc; i++) {
387 serviceCrs._name[i] =
388 rtcmCrs._name[i] = _crdTrafoStr.toStdString()[i];
389 }
390 serviceCrs._name[nc] = 0;
391 rtcmCrs._name[nc] = 0;
392 rtcmCrs._anchor = 0; // global CRS
393 rtcmCrs._plateNumber = 0; // unknown
394 rtcmCrs._databaseLinks << "ISO.DATUM.979" << "ISO.CRS:980";
395 }
396 else {
397 if (_crdTrafoStr != "Custom") {
398 serviceCrs._coordinateEpoch = _t0;
399 serviceCrs.setCEFromCoordinateEpoch();
400 int nc = _crdTrafoStr.length();
401 if (nc > 31) { nc = 31; }
402 for (int i = 0; i < nc; i++) {
403 serviceCrs._name[i] = _crdTrafoStr.toStdString()[i];
404 }
405 serviceCrs._name[nc] = 0;
406 QString rtcmcrsname = _crdTrafoStr + QString("(%1)").arg(_t0, 4, 'd', 0);
407 nc = rtcmcrsname.length();
408 if (nc > 31) { nc = 31; }
409 for (int i = 0; i < nc; i++) {
410 rtcmCrs._name[i] = rtcmcrsname.toStdString()[i];
411 }
412 rtcmCrs._name[nc] = 0;
413 if (_crdTrafoStr == "ETRF2000") {
414 rtcmCrs._anchor = 1; // plate-fixed CRS
415 rtcmCrs._plateNumber = 7; // Eurasia
416 rtcmCrs._databaseLinks << "ISO.DATUM.187" << "ISO.CRS:260" << "ISO.CRS:457"
417 << "EPSG.DATUM:1186" << "EPSG.CRS:7930" << "EPSG.CRS:7931";
418 }
419 else if (_crdTrafoStr == "DREF91") {
420 rtcmCrs._anchor = 1; // plate-fixed CRS
421 rtcmCrs._plateNumber = 7; // Eurasia
422 }
423 else if (_crdTrafoStr == "GDA2020") {
424 rtcmCrs._anchor = 1; // plate-fixed CRS
425 rtcmCrs._plateNumber = 4; // Australia
426 rtcmCrs._databaseLinks << "ISO.DATUM.186" << "ISO.CRS:404" << "ISO.CRS:329"
427 << "EPSG.DATUM:1168" << "EPSG.CRS:7842" << "EPSG.CRS:7843";
428 }
429 else if (_crdTrafoStr == "SIRGAS2000") {
430 rtcmCrs._anchor = 1; // plate-fixed CRS
431 rtcmCrs._plateNumber = 12; // S.America
432 rtcmCrs._databaseLinks << "ISO.DATUM:169" << "ISO.CRS:384" << "ISO.CRS:313"
433 << "EPSG.DATUM:6674" << "EPSG.CRS:4988" << "EPSG.CRS:4989";
434 }
435 }
436 }
437
438 struct SsrCorr::CodeBias bias;
439 memset(&bias, 0, sizeof(bias));
440 bias.EpochTime[CLOCKORBIT_SATGPS] = co.EpochTime[CLOCKORBIT_SATGPS];
441 bias.EpochTime[CLOCKORBIT_SATGLONASS] = co.EpochTime[CLOCKORBIT_SATGLONASS];
442 bias.EpochTime[CLOCKORBIT_SATGALILEO] = co.EpochTime[CLOCKORBIT_SATGALILEO];
443 bias.EpochTime[CLOCKORBIT_SATQZSS] = co.EpochTime[CLOCKORBIT_SATQZSS];
444 bias.EpochTime[CLOCKORBIT_SATSBAS] = co.EpochTime[CLOCKORBIT_SATSBAS];
445 bias.EpochTime[CLOCKORBIT_SATBDS] = co.EpochTime[CLOCKORBIT_SATBDS];
446 bias.SSRIOD = _IOD;
447 bias.SSRProviderID = _PID;
448 bias.SSRSolutionID = _SID;
449
450 struct SsrCorr::PhaseBias phasebias;
451 memset(&phasebias, 0, sizeof(phasebias));
452 unsigned int dispersiveBiasConsistenyIndicator = 0;
453 unsigned int mwConsistencyIndicator = 0;
454 phasebias.EpochTime[CLOCKORBIT_SATGPS] = co.EpochTime[CLOCKORBIT_SATGPS];
455 phasebias.EpochTime[CLOCKORBIT_SATGLONASS] = co.EpochTime[CLOCKORBIT_SATGLONASS];
456 phasebias.EpochTime[CLOCKORBIT_SATGALILEO] = co.EpochTime[CLOCKORBIT_SATGALILEO];
457 phasebias.EpochTime[CLOCKORBIT_SATQZSS] = co.EpochTime[CLOCKORBIT_SATQZSS];
458 phasebias.EpochTime[CLOCKORBIT_SATSBAS] = co.EpochTime[CLOCKORBIT_SATSBAS];
459 phasebias.EpochTime[CLOCKORBIT_SATBDS] = co.EpochTime[CLOCKORBIT_SATBDS];
460 phasebias.SSRIOD = _IOD;
461 phasebias.SSRProviderID = _PID;
462 phasebias.SSRSolutionID = _SID;
463
464 struct SsrCorr::VTEC vtec;
465 memset(&vtec, 0, sizeof(vtec));
466 vtec.EpochTime = static_cast<int>(epoTime.gpssec());
467 vtec.SSRIOD = _IOD;
468 vtec.SSRProviderID = _PID;
469 vtec.SSRSolutionID = _SID;
470
471 // Update Interval
472 // ---------------
473
474 if (_samplRtcmEphCorr == 0.0) {// combined orb and clock
475 _samplRtcmEphCorr = _samplRtcmClkCorr = 5.0;
476 }
477 int clkUpdInd = determineUpdateInd(_samplRtcmClkCorr);
478 int ephUpdInd = determineUpdateInd(_samplRtcmEphCorr);
479
480 co.UpdateInterval = clkUpdInd;
481 bias.UpdateInterval = ephUpdInd;
482 phasebias.UpdateInterval = ephUpdInd;
483
484 for (int ii = 1; ii < lines.size(); ii++) {
485 QString key; // prn or key VTEC, IND (phase bias indicators)
486 double rtnUra = 0.0; // [m]
487 ColumnVector rtnAPC; rtnAPC.ReSize(3); rtnAPC = 0.0; // [m, m, m]
488 ColumnVector rtnVel; rtnVel.ReSize(3); rtnVel = 0.0; // [m/s, m/s, m/s]
489 ColumnVector rtnCoM; rtnCoM.ReSize(3); rtnCoM = 0.0; // [m, m, m]
490 ColumnVector rtnClk; rtnClk.ReSize(3); rtnClk = 0.0; // [m, m/s, m/s²]
491 ColumnVector rtnClkSig; rtnClkSig.ReSize(3); rtnClkSig = 0.0; // [m, m/s, m/s²]
492
493 //QTextStream in(lines[ii].toLatin1());
494 QTextStream in(&lines[ii], QIODevice::ReadOnly);
495 in >> key;
496
497 // non-satellite specific parameters
498 if (key.contains("IND", Qt::CaseSensitive)) {
499 in >> dispersiveBiasConsistenyIndicator >> mwConsistencyIndicator;
500 continue;
501 }
502 // non-satellite specific parameters
503 if (key.contains("VTEC", Qt::CaseSensitive)) {
504 double ui;
505 in >> ui >> vtec.NumLayers;
506 vtec.UpdateInterval = (unsigned int)determineUpdateInd(ui);
507 if (vtec.NumLayers > VTEC_NUMIONOLAYERS) {
508 vtec.NumLayers = 0;
509 }
510 for (unsigned ll = 0; ll < vtec.NumLayers; ll++) {
511 int dummy;
512 in >> dummy >> vtec.Layers[ll].Degree >> vtec.Layers[ll].Order
513 >> vtec.Layers[ll].Height;
514 if (vtec.Layers[ll].Degree < 1 || vtec.Layers[ll].Degree > VTEC_MAXIONODEGREE ||
515 vtec.Layers[ll].Order < 1 || vtec.Layers[ll].Order > VTEC_MAXIONOORDER) {
516 vtec.NumLayers = 0;
517 break;
518 }
519 for (unsigned iDeg = 0; iDeg <= vtec.Layers[ll].Degree; iDeg++) {
520 for (unsigned iOrd = 0; iOrd <= vtec.Layers[ll].Order; iOrd++) {
521 in >> vtec.Layers[ll].Cosinus[iDeg][iOrd];
522 }
523 }
524 for (unsigned iDeg = 0; iDeg <= vtec.Layers[ll].Degree; iDeg++) {
525 for (unsigned iOrd = 0; iOrd <= vtec.Layers[ll].Order; iOrd++) {
526 in >> vtec.Layers[ll].Sinus[iDeg][iOrd];
527 }
528 }
529 }
530 continue;
531 }
532 // satellite specific parameters
533 t_prn prn;
534 char sys = key.mid(0, 1).at(0).toLatin1();
535 int num = key.mid(1, 2).toInt();
536 int flag = t_corrSSR::getSsrNavTypeFlag(sys, num);
537 if (!num) {
538 continue;
539 }
540 prn.set(sys, num, flag);
541 QString prnInternalStr = QString::fromStdString(prn.toInternalString());
542 QString prnStr = QString::fromStdString(prn.toString());
543
544 const t_eph* ephLast = _ephUser->ephLast(prnInternalStr);
545 const t_eph* ephPrev = _ephUser->ephPrev(prnInternalStr);
546 const t_eph* eph = ephLast;
547 if (eph) {
548
549 // Use previous ephemeris if the last one is too recent
550 // ----------------------------------------------------
551 const int MINAGE = 60; // seconds
552 if (ephPrev && eph->receptDateTime().isValid() &&
553 eph->receptDateTime().secsTo(currentDateAndTimeGPS()) < MINAGE) {
554 eph = ephPrev;
555 }
556
557 // Make sure the clock messages refer to same IOD as orbit messages
558 // ----------------------------------------------------------------
559 // The ephemeris is selected at the first correction epoch of each
560 // sampling interval: the grid epoch itself for corrections on the
561 // sampling grid, otherwise (e.g. Galileo HAS at ...:02, ...:12)
562 // the first epoch after it, which previously never selected one
563 if (_usedEph) {
564 bool select = (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0);
565 if (!select && _samplRtcmEphCorr > 0.0) {
566 select = !_usedEphEpoch.valid() || epoTime == _usedEphEpoch ||
567 epoTime.gpsw() != _usedEphEpoch.gpsw() ||
568 floor(epoTime.gpssec() / _samplRtcmEphCorr) !=
569 floor(_usedEphEpoch.gpssec() / _samplRtcmEphCorr);
570 }
571 if (select) {
572 (*_usedEph)[prnInternalStr] = eph;
573 _usedEphEpoch = epoTime;
574 }
575 else {
576 eph = 0;
577 if (_usedEph->contains(prnInternalStr)) {
578 const t_eph* usedEph = _usedEph->value(prnInternalStr);
579 if (usedEph == ephLast) {
580 eph = ephLast;
581 }
582 else if (usedEph == ephPrev) {
583 eph = ephPrev;
584 }
585 }
586 }
587 }
588 }
589
590 QDateTime now = currentDateAndTimeGPS();
591 bncTime currentTime(now.toString(Qt::ISODate).toStdString());
592 if (eph &&
593 !outDatedBcep(eph, currentTime) && // detected from storage because of no update
594 eph->checkState() != t_eph::bad &&
595 eph->checkState() != t_eph::unhealthy &&
596 eph->checkState() != t_eph::outdated) { // detected during reception (bncephuser)
597 QMap<QString, double> codeBiases;
598 QList<phaseBiasSignal> phaseBiasList;
599 phaseBiasesSat pbSat;
600 _phaseBiasInformationDecoded = false;
601
602 while (true) {
603 QString key;
604 int numVal = 0;
605 in >> key;
606 if (in.status() != QTextStream::Ok) {
607 break;
608 }
609 if (key == "APC") {
610 in >> numVal;
611 rtnAPC.ReSize(3); rtnAPC = 0.0;
612 for (int ii = 0; ii < numVal; ii++) {
613 in >> rtnAPC[ii];
614 }
615 }
616 else if (key == "Ura") {
617 in >> numVal;
618 if (numVal == 1)
619 in >> rtnUra;
620 }
621 else if (key == "Clk") {
622 in >> numVal;
623 rtnClk.ReSize(3); rtnClk = 0.0;
624 for (int ii = 0; ii < numVal; ii++) {
625 in >> rtnClk[ii];
626 }
627 }
628 else if (key == "ClkSig") {
629 in >> numVal;
630 rtnClkSig.ReSize(3); rtnClkSig = 0.0;
631 for (int ii = 0; ii < numVal; ii++) {
632 in >> rtnClkSig[ii];
633 }
634 }
635 else if (key == "Vel") {
636 in >> numVal;
637 rtnVel.ReSize(3); rtnVel = 0.0;
638 for (int ii = 0; ii < numVal; ii++) {
639 in >> rtnVel[ii];
640 }
641 }
642 else if (key == "CoM") {
643 in >> numVal;
644 rtnCoM.ReSize(3); rtnCoM = 0.0;
645 for (int ii = 0; ii < numVal; ii++) {
646 in >> rtnCoM[ii];
647 }
648 }
649 else if (key == "CodeBias") {
650 in >> numVal;
651 for (int ii = 0; ii < numVal; ii++) {
652 QString type;
653 double value;
654 in >> type >> value;
655 codeBiases[type] = value;
656 }
657 }
658 else if (key == "YawAngle") {
659 _phaseBiasInformationDecoded = true;
660 in >> numVal >> pbSat.yawAngle;
661 if (pbSat.yawAngle < 0.0) {
662 pbSat.yawAngle += (2 * M_PI);
663 }
664 else if (pbSat.yawAngle > 2 * M_PI) {
665 pbSat.yawAngle -= (2 * M_PI);
666 }
667 }
668 else if (key == "YawRate") {
669 _phaseBiasInformationDecoded = true;
670 in >> numVal >> pbSat.yawRate;
671 }
672 else if (key == "PhaseBias") {
673 _phaseBiasInformationDecoded = true;
674 in >> numVal;
675 for (int ii = 0; ii < numVal; ii++) {
676 phaseBiasSignal pb;
677 in >> pb.type >> pb.bias >> pb.integerIndicator
678 >> pb.wlIndicator >> pb.discontinuityCounter;
679 phaseBiasList.append(pb);
680 }
681 }
682 else {
683 in >> numVal;
684 for (int ii = 0; ii < numVal; ii++) {
685 double dummy;
686 in >> dummy;
687 }
688 emit(newMessage(" RTNET format error: "
689 + lines[ii].toLatin1(), false));
690 break;
691 }
692 }
693
694 struct SsrCorr::ClockOrbit::SatData* sd = 0;
695 if (prn.system() == 'G') {
696 sd = co.Sat + co.NumberOfSat[CLOCKORBIT_SATGPS];
697 ++co.NumberOfSat[CLOCKORBIT_SATGPS];
698 }
699 else if (prn.system() == 'R') {
700 sd = co.Sat + CLOCKORBIT_NUMGPS + co.NumberOfSat[CLOCKORBIT_SATGLONASS];
701 ++co.NumberOfSat[CLOCKORBIT_SATGLONASS];
702 }
703 else if (prn.system() == 'E') {
704 sd = co.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
705 + co.NumberOfSat[CLOCKORBIT_SATGALILEO];
706 ++co.NumberOfSat[CLOCKORBIT_SATGALILEO];
707 }
708 else if (prn.system() == 'J') {
709 sd = co.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
710 + CLOCKORBIT_NUMGALILEO
711 + co.NumberOfSat[CLOCKORBIT_SATQZSS];
712 ++co.NumberOfSat[CLOCKORBIT_SATQZSS];
713 }
714 else if (prn.system() == 'S') {
715 sd = co.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
716 + CLOCKORBIT_NUMGALILEO + CLOCKORBIT_NUMQZSS
717 + co.NumberOfSat[CLOCKORBIT_SATSBAS];
718 ++co.NumberOfSat[CLOCKORBIT_SATSBAS];
719 }
720 else if (prn.system() == 'C') {
721 sd = co.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
722 + CLOCKORBIT_NUMGALILEO + CLOCKORBIT_NUMQZSS
723 + CLOCKORBIT_NUMSBAS
724 + co.NumberOfSat[CLOCKORBIT_SATBDS];
725 ++co.NumberOfSat[CLOCKORBIT_SATBDS];
726 }
727 if (sd) {
728 QString outLine;
729 t_irc irc = processSatellite(eph, epoTime.gpsw(), epoTime.gpssec(), prnStr, rtnAPC,
730 rtnUra, rtnClk, rtnVel, rtnCoM, rtnClkSig, sd, outLine);
731 if (irc != success) {
732 continue;
733 }
734 }
735
736 // Code Biases
737 // -----------
738 struct SsrCorr::CodeBias::BiasSat* biasSat = 0;
739 if (!codeBiases.isEmpty()) {
740 if (prn.system() == 'G') {
741 biasSat = bias.Sat + bias.NumberOfSat[CLOCKORBIT_SATGPS];
742 ++bias.NumberOfSat[CLOCKORBIT_SATGPS];
743 }
744 else if (prn.system() == 'R') {
745 biasSat = bias.Sat + CLOCKORBIT_NUMGPS
746 + bias.NumberOfSat[CLOCKORBIT_SATGLONASS];
747 ++bias.NumberOfSat[CLOCKORBIT_SATGLONASS];
748 }
749 else if (prn.system() == 'E') {
750 biasSat = bias.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
751 + bias.NumberOfSat[CLOCKORBIT_SATGALILEO];
752 ++bias.NumberOfSat[CLOCKORBIT_SATGALILEO];
753 }
754 else if (prn.system() == 'J') {
755 biasSat = bias.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
756 + CLOCKORBIT_NUMGALILEO
757 + bias.NumberOfSat[CLOCKORBIT_SATQZSS];
758 ++bias.NumberOfSat[CLOCKORBIT_SATQZSS];
759 }
760 else if (prn.system() == 'S') {
761 biasSat = bias.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
762 + CLOCKORBIT_NUMGALILEO + CLOCKORBIT_NUMQZSS
763 + bias.NumberOfSat[CLOCKORBIT_SATSBAS];
764 ++bias.NumberOfSat[CLOCKORBIT_SATSBAS];
765 }
766 else if (prn.system() == 'C') {
767 biasSat = bias.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
768 + CLOCKORBIT_NUMGALILEO + CLOCKORBIT_NUMQZSS
769 + CLOCKORBIT_NUMSBAS
770 + bias.NumberOfSat[CLOCKORBIT_SATBDS];
771 ++bias.NumberOfSat[CLOCKORBIT_SATBDS];
772 }
773 }
774
775 if (biasSat) {
776 biasSat->ID = prn.number();
777 biasSat->NumberOfCodeBiases = 0;
778 QMapIterator<QString, double> it(codeBiases);
779 while (it.hasNext()) {
780 it.next();
781 int ii = biasSat->NumberOfCodeBiases;
782 if (ii >= CLOCKORBIT_NUMBIAS)
783 break;
784 SsrCorr::CodeType type = _ssrCorr->rnxTypeToCodeType(prn.system(), it.key().toStdString());
785 if (type != _ssrCorr->CODETYPE_RESERVED) {
786 biasSat->NumberOfCodeBiases += 1;
787 biasSat->Biases[ii].Type = type;
788 biasSat->Biases[ii].Bias = it.value();
789 if (_bsx) {
790 QString obsCode = 'C' + it.key();
791 _bsx->write(epoTime.gpsw(), epoTime.gpssec(), prnStr, obsCode, it.value());
792 }
793 }
794 }
795 }
796
797 // Phase Biases
798 // ------------
799 struct SsrCorr::PhaseBias::PhaseBiasSat* phasebiasSat = 0;
800 if (prn.system() == 'G') {
801 phasebiasSat = phasebias.Sat
802 + phasebias.NumberOfSat[CLOCKORBIT_SATGPS];
803 ++phasebias.NumberOfSat[CLOCKORBIT_SATGPS];
804 }
805 else if (prn.system() == 'R') {
806 phasebiasSat = phasebias.Sat + CLOCKORBIT_NUMGPS
807 + phasebias.NumberOfSat[CLOCKORBIT_SATGLONASS];
808 ++phasebias.NumberOfSat[CLOCKORBIT_SATGLONASS];
809 }
810 else if (prn.system() == 'E') {
811 phasebiasSat = phasebias.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
812 + phasebias.NumberOfSat[CLOCKORBIT_SATGALILEO];
813 ++phasebias.NumberOfSat[CLOCKORBIT_SATGALILEO];
814 }
815 else if (prn.system() == 'J') {
816 phasebiasSat = phasebias.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
817 + CLOCKORBIT_NUMGALILEO
818 + phasebias.NumberOfSat[CLOCKORBIT_SATQZSS];
819 ++phasebias.NumberOfSat[CLOCKORBIT_SATQZSS];
820 }
821 else if (prn.system() == 'S') {
822 phasebiasSat = phasebias.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
823 + CLOCKORBIT_NUMGALILEO + CLOCKORBIT_NUMQZSS
824 + phasebias.NumberOfSat[CLOCKORBIT_SATSBAS];
825 ++phasebias.NumberOfSat[CLOCKORBIT_SATSBAS];
826 }
827 else if (prn.system() == 'C') {
828 phasebiasSat = phasebias.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
829 + CLOCKORBIT_NUMGALILEO + CLOCKORBIT_NUMQZSS
830 + CLOCKORBIT_NUMSBAS
831 + phasebias.NumberOfSat[CLOCKORBIT_SATBDS];
832 ++phasebias.NumberOfSat[CLOCKORBIT_SATBDS];
833 }
834
835 if (phasebiasSat && _phaseBiasInformationDecoded) {
836 phasebias.DispersiveBiasConsistencyIndicator = dispersiveBiasConsistenyIndicator;
837 phasebias.MWConsistencyIndicator = mwConsistencyIndicator;
838 phasebiasSat->ID = prn.number();
839 phasebiasSat->NumberOfPhaseBiases = 0;
840 phasebiasSat->YawAngle = pbSat.yawAngle;
841 phasebiasSat->YawRate = pbSat.yawRate;
842 QListIterator<phaseBiasSignal> it(phaseBiasList);
843 while (it.hasNext()) {
844 const phaseBiasSignal& pbSig = it.next();
845 int ii = phasebiasSat->NumberOfPhaseBiases;
846 if (ii >= CLOCKORBIT_NUMBIAS)
847 break;
848 SsrCorr::CodeType type = _ssrCorr->rnxTypeToCodeType(prn.system(), pbSig.type.toStdString());
849 if (type != _ssrCorr->PBEXTTYPE_RESERVED) {
850 phasebiasSat->NumberOfPhaseBiases += 1;
851 phasebiasSat->Biases[ii].Type = type;
852 phasebiasSat->Biases[ii].Bias = pbSig.bias;
853 phasebiasSat->Biases[ii].IntegerIndicator = pbSig.integerIndicator;
854 phasebiasSat->Biases[ii].WidelaneGroupIndicator = pbSig.wlIndicator;
855 phasebiasSat->Biases[ii].DiscontinuityCounter = pbSig.discontinuityCounter;
856 if (_bsx) {
857 QString obsCode = 'L' + pbSig.type;
858 _bsx->write(epoTime.gpsw(), epoTime.gpssec(), prnStr, obsCode, pbSig.bias);
859 }
860 }
861 }
862 }
863 }
864 }
865
866 QByteArray hlpBufferCo;
867 char obuffer[CLOCKORBIT_BUFFERSIZE];
868 size_t len = 0;
869
870 // Orbit and Clock Corrections together
871 // ------------------------------------
872 if (_samplRtcmEphCorr == _samplRtcmClkCorr) {
873 if (co.NumberOfSat[CLOCKORBIT_SATGPS] > 0
874 || co.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0
875 || co.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0
876 || co.NumberOfSat[CLOCKORBIT_SATBDS] > 0
877 || co.NumberOfSat[CLOCKORBIT_SATQZSS] > 0
878 || co.NumberOfSat[CLOCKORBIT_SATSBAS] > 0) {
879 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
880 memset(obuffer, 0, sizeof(obuffer));
881 len = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_AUTO, 0, obuffer, sizeof(obuffer));
882 if (len > 0) {
883 hlpBufferCo = QByteArray(obuffer, int(len));
884 }
885 }
886 }
887 }
888
889 // Orbit and Clock Corrections separately
890 // --------------------------------------
891 else {
892 if (co.NumberOfSat[CLOCKORBIT_SATGPS] > 0) {
893 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
894 co.UpdateInterval = ephUpdInd;
895 memset(obuffer, 0, sizeof(obuffer));
896 len = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_GPSORBIT, 1, obuffer, sizeof(obuffer));
897 if (len > 0) {
898 hlpBufferCo += QByteArray(obuffer, int(len));
899 }
900 }
901 int mmsg = (co.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0 ||
902 co.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0 ||
903 co.NumberOfSat[CLOCKORBIT_SATBDS] > 0 ||
904 co.NumberOfSat[CLOCKORBIT_SATQZSS] > 0 ||
905 co.NumberOfSat[CLOCKORBIT_SATSBAS] > 0) ? 1 : 0;
906 if (fmod(epoTime.gpssec(), _samplRtcmClkCorr) == 0.0) {
907 co.UpdateInterval = clkUpdInd;
908 memset(obuffer, 0, sizeof(obuffer));
909 len = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_GPSCLOCK, mmsg, obuffer, sizeof(obuffer));
910 if (len > 0) {
911 hlpBufferCo += QByteArray(obuffer, int(len));
912 }
913 }
914 }
915 if (co.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0) {
916 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
917 co.UpdateInterval = ephUpdInd;
918 memset(obuffer, 0, sizeof(obuffer));
919 len = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_GLONASSORBIT, 1, obuffer, sizeof(obuffer));
920 if (len > 0) {
921 hlpBufferCo += QByteArray(obuffer, int(len));
922 }
923 }
924 int mmsg = (co.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0 ||
925 co.NumberOfSat[CLOCKORBIT_SATBDS] > 0 ||
926 co.NumberOfSat[CLOCKORBIT_SATQZSS] > 0 ||
927 co.NumberOfSat[CLOCKORBIT_SATSBAS] > 0) ? 1 : 0;
928 if (fmod(epoTime.gpssec(), _samplRtcmClkCorr) == 0.0) {
929 co.UpdateInterval = clkUpdInd;
930 memset(obuffer, 0, sizeof(obuffer));
931 len = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_GLONASSCLOCK, mmsg, obuffer, sizeof(obuffer));
932 if (len > 0) {
933 hlpBufferCo += QByteArray(obuffer, int(len));
934 }
935 }
936 }
937 if (co.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0) {
938 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
939 co.UpdateInterval = ephUpdInd;
940 memset(obuffer, 0, sizeof(obuffer));
941 len = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_GALILEOORBIT, 1, obuffer, sizeof(obuffer));
942 if (len > 0) {
943 hlpBufferCo += QByteArray(obuffer, int(len));
944 }
945 }
946 int mmsg = (co.NumberOfSat[CLOCKORBIT_SATBDS] > 0 ||
947 co.NumberOfSat[CLOCKORBIT_SATQZSS] > 0 ||
948 co.NumberOfSat[CLOCKORBIT_SATSBAS] > 0) ? 1 : 0;
949 if (fmod(epoTime.gpssec(), _samplRtcmClkCorr) == 0.0) {
950 co.UpdateInterval = clkUpdInd;
951 memset(obuffer, 0, sizeof(obuffer));
952 len = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_GALILEOCLOCK, mmsg, obuffer, sizeof(obuffer));
953 if (len > 0) {
954 hlpBufferCo += QByteArray(obuffer, int(len));
955 }
956 }
957 }
958 if (co.NumberOfSat[CLOCKORBIT_SATBDS] > 0) {
959 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
960 co.UpdateInterval = ephUpdInd;
961 memset(obuffer, 0, sizeof(obuffer));
962 len = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_BDSORBIT, 1, obuffer, sizeof(obuffer));
963 if (len > 0) {
964 hlpBufferCo += QByteArray(obuffer, int(len));
965 }
966 }
967 int mmsg = (co.NumberOfSat[CLOCKORBIT_SATQZSS] > 0 ||
968 co.NumberOfSat[CLOCKORBIT_SATSBAS] > 0) ? 1 : 0;
969 if (fmod(epoTime.gpssec(), _samplRtcmClkCorr) == 0.0) {
970 co.UpdateInterval = clkUpdInd;
971 memset(obuffer, 0, sizeof(obuffer));
972 len = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_BDSCLOCK, mmsg, obuffer, sizeof(obuffer));
973 if (len > 0) {
974 hlpBufferCo += QByteArray(obuffer, int(len));
975 }
976 }
977 }
978 if (co.NumberOfSat[CLOCKORBIT_SATQZSS] > 0) {
979 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
980 co.UpdateInterval = ephUpdInd;
981 memset(obuffer, 0, sizeof(obuffer));
982 len = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_QZSSORBIT, 1, obuffer, sizeof(obuffer));
983 if (len > 0) {
984 hlpBufferCo += QByteArray(obuffer, int(len));
985 }
986 }
987 int mmsg = (co.NumberOfSat[CLOCKORBIT_SATSBAS] > 0) ? 1 : 0;
988 if (fmod(epoTime.gpssec(), _samplRtcmClkCorr) == 0.0) {
989 co.UpdateInterval = clkUpdInd;
990 memset(obuffer, 0, sizeof(obuffer));
991 len = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_QZSSCLOCK, mmsg, obuffer, sizeof(obuffer));
992 if (len > 0) {
993 hlpBufferCo += QByteArray(obuffer, int(len));
994 }
995 }
996 }
997 if (co.NumberOfSat[CLOCKORBIT_SATSBAS] > 0) {
998 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
999 co.UpdateInterval = ephUpdInd;
1000 memset(obuffer, 0, sizeof(obuffer));
1001 len = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_SBASORBIT, 1, obuffer, sizeof(obuffer));
1002 co.UpdateInterval = clkUpdInd;
1003 if (len > 0) {
1004 hlpBufferCo += QByteArray(obuffer, int(len));
1005 }
1006 }
1007 int mmsg = 0;
1008 if (fmod(epoTime.gpssec(), _samplRtcmClkCorr) == 0.0) {
1009 co.UpdateInterval = clkUpdInd;
1010 memset(obuffer, 0, sizeof(obuffer));
1011 len = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_SBASCLOCK, mmsg, obuffer, sizeof(obuffer));
1012 if (len > 0) {
1013 hlpBufferCo += QByteArray(obuffer, int(len));
1014 }
1015 }
1016 }
1017 }
1018
1019 // Code Biases
1020 // -----------
1021 QByteArray hlpBufferBias;
1022 if (bias.NumberOfSat[CLOCKORBIT_SATGPS] > 0
1023 || bias.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0
1024 || bias.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0
1025 || bias.NumberOfSat[CLOCKORBIT_SATBDS] > 0
1026 || bias.NumberOfSat[CLOCKORBIT_SATQZSS] > 0
1027 || bias.NumberOfSat[CLOCKORBIT_SATSBAS] > 0) {
1028 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
1029 memset(obuffer, 0, sizeof(obuffer));
1030 len = _ssrCorr->MakeCodeBias(&bias, _ssrCorr->CBTYPE_AUTO, 0, obuffer, sizeof(obuffer));
1031 if (len > 0) {
1032 hlpBufferBias = QByteArray(obuffer, int(len));
1033 }
1034 }
1035 }
1036
1037 // Phase Biases
1038 // ------------
1039 QByteArray hlpBufferPhaseBias;
1040 if ((phasebias.NumberOfSat[CLOCKORBIT_SATGPS] > 0
1041 || phasebias.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0
1042 || phasebias.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0
1043 || phasebias.NumberOfSat[CLOCKORBIT_SATBDS] > 0
1044 || phasebias.NumberOfSat[CLOCKORBIT_SATQZSS] > 0
1045 || phasebias.NumberOfSat[CLOCKORBIT_SATSBAS] > 0) && (_phaseBiasInformationDecoded)) {
1046 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
1047 memset(obuffer, 0, sizeof(obuffer));
1048 len = _ssrCorr->MakePhaseBias(&phasebias, _ssrCorr->PBTYPE_AUTO, 0, obuffer, sizeof(obuffer));
1049 if (len > 0) {
1050 hlpBufferPhaseBias = QByteArray(obuffer, int(len));
1051 }
1052 }
1053 }
1054
1055 // VTEC
1056 // ----
1057 QByteArray hlpBufferVtec;
1058 if (vtec.NumLayers > 0) {
1059 if (fmod(epoTime.gpssec(), _samplRtcmVtec) == 0.0) {
1060 memset(obuffer, 0, sizeof(obuffer));
1061 len = _ssrCorr->MakeVTEC(&vtec, 0, obuffer, sizeof(obuffer));
1062 if (len > 0) {
1063 hlpBufferVtec = QByteArray(obuffer, int(len));
1064 }
1065 }
1066 }
1067
1068 // Service CRS
1069 // -----------
1070 QByteArray hlpBufferServiceCrs;
1071 if (serviceCrs._name[0]) { // no CRS messages for a custom transformation
1072 if (fmod(epoTime.gpssec(), _samplRtcmCrs) == 0.0) {
1073 memset(obuffer, 0, sizeof(obuffer));
1074 len = t_crsEncoder::RTCM3(serviceCrs, obuffer, sizeof(obuffer));
1075 if (len > 0) {
1076 hlpBufferServiceCrs = QByteArray(obuffer, int(len));
1077 }
1078 }
1079 }
1080
1081 // RTCM CRS
1082 // --------
1083 QByteArray hlpBufferRtcmCrs;
1084 if (rtcmCrs._name[0]) {
1085 if (fmod(epoTime.gpssec(), _samplRtcmCrs) == 0.0) {
1086 memset(obuffer, 0, sizeof(obuffer));
1087 len = t_crsEncoder::RTCM3(rtcmCrs, obuffer, sizeof(obuffer));
1088 if (len > 0) {
1089 hlpBufferRtcmCrs = QByteArray(obuffer, int(len));
1090 }
1091 }
1092 }
1093
1094 // Create OutBuffer
1095 // ----------------
1096 _outBuffer += hlpBufferCo + hlpBufferBias + hlpBufferPhaseBias + hlpBufferVtec
1097 + hlpBufferServiceCrs + hlpBufferRtcmCrs + '\0';
1098}
1099//
1100////////////////////////////////////////////////////////////////////////////
1101t_irc bncRtnetUploadCaster::processSatellite(const t_eph* eph, int GPSweek,
1102 double GPSweeks, const QString& prn, const ColumnVector& rtnAPC,
1103 double rtnUra, const ColumnVector& rtnClk, const ColumnVector& rtnVel,
1104 const ColumnVector& rtnCoM, const ColumnVector& rtnClkSig,
1105 struct SsrCorr::ClockOrbit::SatData* sd, QString& outLine) {
1106
1107 // Broadcast Position and Velocity
1108 // -------------------------------
1109 ColumnVector xB(6);
1110 ColumnVector vB(3);
1111 t_irc irc = eph->getCrd(bncTime(GPSweek, GPSweeks), xB, vB, false);
1112
1113 if (irc != success) {
1114 return irc;
1115 }
1116
1117 // Precise Position
1118 // ----------------
1119 ColumnVector xP = _CoM ? rtnCoM : rtnAPC;
1120
1121 if (xP.size() == 0) {
1122 return failure;
1123 }
1124
1125 double dc = 0.0;
1126 if (_crdTrafoStr != "IGS20") {
1127 crdTrafo14(GPSweek, xP, dc); // ITRF2020 => ITRF2014
1128 crdTrafo(GPSweek, xP, dc); // ITRF2014 to other reference frames
1129 }
1130
1131 // Difference in xyz
1132 // -----------------
1133 ColumnVector dx = xB.Rows(1, 3) - xP;
1134 ColumnVector dv = vB - rtnVel;
1135
1136 // Difference in RSW
1137 // -----------------
1138 ColumnVector rsw(3);
1139 XYZ_to_RSW(xB.Rows(1, 3), vB, dx, rsw);
1140
1141 ColumnVector dotRsw(3);
1142 XYZ_to_RSW(xB.Rows(1, 3), vB, dv, dotRsw);
1143
1144 // Clock Correction
1145 // ----------------
1146 double dClkA0 = rtnClk(1) - (xB(4) - dc) * t_CST::c;
1147 double dClkA1 = 0.0;
1148 if (rtnClk(2)) {
1149 dClkA1 = rtnClk(2) - xB(5) * t_CST::c;
1150 }
1151 double dClkA2 = 0.0;
1152 if (rtnClk(3)) {
1153 dClkA2 = rtnClk(3) - xB(6) * t_CST::c;
1154 }
1155
1156 if (sd) {
1157 sd->ID = prn.mid(1).toInt();
1158 sd->IOD = eph->IOD();
1159 sd->Clock.DeltaA0 = dClkA0;
1160 sd->Clock.DeltaA1 = dClkA1;
1161 sd->Clock.DeltaA2 = dClkA2;
1162 sd->UserRangeAccuracy = rtnUra;
1163 sd->Orbit.DeltaRadial = rsw(1);
1164 sd->Orbit.DeltaAlongTrack = rsw(2);
1165 sd->Orbit.DeltaCrossTrack = rsw(3);
1166 sd->Orbit.DotDeltaRadial = dotRsw(1);
1167 sd->Orbit.DotDeltaAlongTrack = dotRsw(2);
1168 sd->Orbit.DotDeltaCrossTrack = dotRsw(3);
1169
1170 if (corrIsOutOfRange(sd)) {
1171 emit(newMessage(QString("bncRtnetUploadCaster: SSR parameter is out of its defined range").toLatin1(), false));
1172 return failure;
1173 }
1174 }
1175
1176 outLine = QString().asprintf("%d %.1f %s %u %10.3f %8.3f %8.3f %8.3f %8.3f %8.3f\n", GPSweek,
1177 GPSweeks, eph->prn().toString().c_str(), eph->IOD(), dClkA0, dClkA1, dClkA2,
1178 rsw(1), rsw(2), rsw(3)); //fprintf(stderr, "%s\n", outLine.toStdString().c_str());
1179
1180 // RTNET full clock for RINEX and SP3 file
1181 // ---------------------------------------
1182 // Always use CoM (the position actually written to the SP3/RINEX clock
1183 // file) here, independent of the APC/CoM and reference frame settings
1184 // that govern the uploaded SSR Broadcast Correction stream. Otherwise
1185 // the saved clock value would depend on those settings even though the
1186 // saved position does not, making the SP3/CLK output internally
1187 // inconsistent and non-reproducible across differently configured SSR streams.
1188 double relativity = -2.0 * DotProduct(rtnCoM, rtnVel) / t_CST::c;
1189 double clkRnx = (rtnClk[0] - relativity) / t_CST::c; // [s]
1190 double clkRnxRate = rtnClk[1] / t_CST::c; // [s/s = -]
1191 double clkRnxAcc = rtnClk[2] / t_CST::c; // [s/s² = -/s]
1192
1193 // Corrections on epochs off the output sampling grid (e.g. Galileo HAS
1194 // at ...:02, ...:12) are written at the nearest grid epoch, see gridEpoch;
1195 // the clock is propagated with its rate, the orbit via the broadcast
1196 // orbit at the grid epoch plus the (slowly varying) difference
1197 // precise - broadcast at the correction epoch
1198 // -----------------------------------------------------------------------
1199 bncTime tt(GPSweek, GPSweeks);
1200 bncTime tg;
1201 double clkRate = (clkRnxRate != 0.0) ? clkRnxRate : xB(5);
1202
1203 if (_rnx && gridEpoch(_rnx->sampl(), tt, tg, _rnxGridEpo, _rnxGridSrc)) {
1204 double clkRnxSig, clkRnxRateSig, clkRnxAccSig;
1205 int s = rtnClkSig.size();
1206 switch (s) {
1207 case 1:
1208 clkRnxSig = rtnClkSig[0] / t_CST::c; // [s]
1209 clkRnxRateSig = 0.0; // [s/s = -]
1210 clkRnxAccSig = 0.0; // [s/s² ) -/s]
1211 break;
1212 case 2:
1213 clkRnxSig = rtnClkSig[0] / t_CST::c; // [s]
1214 clkRnxRateSig = rtnClkSig[1] / t_CST::c; // [s/s = -]
1215 clkRnxAccSig = 0.0; // [s/s² ) -/s]
1216 break;
1217 case 3:
1218 clkRnxSig = rtnClkSig[0] / t_CST::c; // [s]
1219 clkRnxRateSig = rtnClkSig[1] / t_CST::c; // [s/s = -]
1220 clkRnxAccSig = rtnClkSig[2] / t_CST::c; // [s/s² ) -/s]
1221 break;
1222 }
1223 _rnx->write(tg.gpsw(), tg.gpssec(), prn, clkRnx + clkRate * (tg - tt),
1224 clkRnxRate, clkRnxAcc, clkRnxSig, clkRnxRateSig, clkRnxAccSig);
1225 }
1226 if (_sp3 && gridEpoch(_sp3->sampl(), tt, tg, _sp3GridEpo, _sp3GridSrc)) {
1227 ColumnVector xyz = rtnCoM;
1228 ColumnVector vel = rtnVel;
1229 if (!(tg == tt)) {
1230 ColumnVector xBg(6);
1231 ColumnVector vBg(3);
1232 if (eph->getCrd(tg, xBg, vBg, false) != success) {
1233 return success;
1234 }
1235 xyz = xBg.Rows(1, 3) + (rtnCoM - xB.Rows(1, 3));
1236 vel = vBg + (rtnVel - vB);
1237 }
1238 _sp3->write(tg.gpsw(), tg.gpssec(), prn, xyz, clkRnx + clkRate * (tg - tt),
1239 vel, clkRnxRate);
1240 }
1241 return success;
1242}
1243
1244// Output epoch for SP3/CLK files with sampling interval sampl [s]: the
1245// correction epoch itself if it is on the sampling grid, otherwise the
1246// preceding grid epoch if at most 5 s (and less than half the sampling
1247// interval) earlier. Only preceding grid epochs are used, so a correction
1248// epoch on the grid always arrives first and takes precedence. Each grid
1249// epoch is derived from one correction epoch only.
1250////////////////////////////////////////////////////////////////////////////
1251bool bncRtnetUploadCaster::gridEpoch(int sampl, const bncTime& tt, bncTime& tg,
1252 bncTime& lastGrid, bncTime& lastSrc) const {
1253 if (sampl <= 0) {
1254 tg = tt;
1255 return true;
1256 }
1257 double sec = tt.gpssec();
1258 double back = sec - floor(sec / sampl) * sampl; // [0, sampl)
1259 if (back > 1.e-6 && (back > 5.0 || back >= 0.5 * sampl)) {
1260 return false;
1261 }
1262 tg = (back <= 1.e-6) ? tt : tt - back;
1263 if (lastGrid.valid() && tg == lastGrid && !(tt == lastSrc)) {
1264 return false;
1265 }
1266 lastGrid = tg;
1267 lastSrc = tt;
1268 return true;
1269}
1270
1271// Transform Coordinates
1272////////////////////////////////////////////////////////////////////////////
1273void bncRtnetUploadCaster::crdTrafo(int GPSWeek, ColumnVector& xyz,
1274 double& dc) {
1275
1276 // Current epoch minus 2000.0 in years
1277 // ------------------------------------
1278 double dt = (GPSWeek - (1042.0 + 6.0 / 7.0)) / 365.2422 * 7.0 + 2000.0 - _t0;
1279
1280 ColumnVector dx(3);
1281
1282 dx(1) = _dx + dt * _dxr;
1283 dx(2) = _dy + dt * _dyr;
1284 dx(3) = _dz + dt * _dzr;
1285
1286 static const double arcSec = 180.0 * 3600.0 / M_PI;
1287
1288 double ox = (_ox + dt * _oxr) / arcSec;
1289 double oy = (_oy + dt * _oyr) / arcSec;
1290 double oz = (_oz + dt * _ozr) / arcSec;
1291
1292 double sc = 1.0 + _sc * 1e-9 + dt * _scr * 1e-9;
1293
1294 // Specify approximate center of area
1295 // ----------------------------------
1296 ColumnVector meanSta(3);
1297
1298 if (_crdTrafoStr == "ETRF2000") {
1299 meanSta(1) = 3661090.0;
1300 meanSta(2) = 845230.0;
1301 meanSta(3) = 5136850.0;
1302 }
1303 else if (_crdTrafoStr == "GDA2020") {
1304 meanSta(1) = -4052050.0;
1305 meanSta(2) = 4212840.0;
1306 meanSta(3) = -2545110.0;
1307 }
1308 else if (_crdTrafoStr == "SIRGAS2000") {
1309 meanSta(1) = 3740860.0;
1310 meanSta(2) = -4964290.0;
1311 meanSta(3) = -1425420.0;
1312 }
1313 else if (_crdTrafoStr == "DREF91") {
1314 meanSta(1) = 3959579.0;
1315 meanSta(2) = 721719.0;
1316 meanSta(3) = 4931539.0;
1317 }
1318 else if (_crdTrafoStr == "Custom") {
1319 meanSta(1) = 0.0;
1320 meanSta(2) = 0.0;
1321 meanSta(3) = 0.0;
1322 }
1323
1324 // Clock correction proportional to topocentric distance to satellites
1325 // -------------------------------------------------------------------
1326 double rho = (xyz - meanSta).NormFrobenius();
1327 dc = rho * (sc - 1.0) / sc / t_CST::c;
1328
1329 Matrix rMat(3, 3);
1330 rMat(1, 1) = 1.0;
1331 rMat(1, 2) = -oz;
1332 rMat(1, 3) = oy;
1333 rMat(2, 1) = oz;
1334 rMat(2, 2) = 1.0;
1335 rMat(2, 3) = -ox;
1336 rMat(3, 1) = -oy;
1337 rMat(3, 2) = ox;
1338 rMat(3, 3) = 1.0;
1339
1340 xyz = sc * rMat * xyz + dx;
1341}
1342
1343// Transform Coordinates
1344////////////////////////////////////////////////////////////////////////////
1345void bncRtnetUploadCaster::crdTrafo14(int GPSWeek, ColumnVector& xyz,
1346 double& dc) {
1347
1348 // Current epoch minus 2000.0 in years
1349 // ------------------------------------
1350 double dt = (GPSWeek - (1042.0 + 6.0 / 7.0)) / 365.2422 * 7.0 + 2000.0 - _t0;
1351
1352 ColumnVector dx(3);
1353
1354 dx(1) = _dx14 + dt * _dxr14;
1355 dx(2) = _dy14 + dt * _dyr14;
1356 dx(3) = _dz14 + dt * _dzr14;
1357
1358 static const double arcSec = 180.0 * 3600.0 / M_PI;
1359
1360 double ox = (_ox14 + dt * _oxr14) / arcSec;
1361 double oy = (_oy14 + dt * _oyr14) / arcSec;
1362 double oz = (_oz14 + dt * _ozr14) / arcSec;
1363
1364 double sc = 1.0 + _sc14 * 1e-9 + dt * _scr14 * 1e-9;
1365
1366 // Specify approximate center of area
1367 // ----------------------------------
1368 ColumnVector meanSta(3);
1369 meanSta(1) = 0.0; // TODO
1370 meanSta(2) = 0.0; // TODO
1371 meanSta(3) = 0.0; // TODO
1372
1373 // Clock correction proportional to topocentric distance to satellites
1374 // -------------------------------------------------------------------
1375 double rho = (xyz - meanSta).NormFrobenius();
1376 dc = rho * (sc - 1.0) / sc / t_CST::c;
1377
1378 Matrix rMat(3, 3);
1379 rMat(1, 1) = 1.0;
1380 rMat(1, 2) = -oz;
1381 rMat(1, 3) = oy;
1382 rMat(2, 1) = oz;
1383 rMat(2, 2) = 1.0;
1384 rMat(2, 3) = -ox;
1385 rMat(3, 1) = -oy;
1386 rMat(3, 2) = ox;
1387 rMat(3, 3) = 1.0;
1388
1389 xyz = sc * rMat * xyz + dx;
1390}
1391
1392// Update Interval
1393////////////////////////////////////////////////////////////////////////////
1394int bncRtnetUploadCaster::determineUpdateInd(double samplingRate) {
1395
1396 if (samplingRate == 1.0) {
1397 return 0;
1398 }
1399 else if (samplingRate == 2.0) {
1400 return 1;
1401 }
1402 else if (samplingRate == 5.0) {
1403 return 2;
1404 }
1405 else if (samplingRate == 10.0) {
1406 return 3;
1407 }
1408 else if (samplingRate == 15.0) {
1409 return 4;
1410 }
1411 else if (samplingRate == 30.0) {
1412 return 5;
1413 }
1414 else if (samplingRate == 60.0) {
1415 return 6;
1416 }
1417 else if (samplingRate == 120.0) {
1418 return 7;
1419 }
1420 else if (samplingRate == 240.0) {
1421 return 8;
1422 }
1423 else if (samplingRate == 300.0) {
1424 return 9;
1425 }
1426 else if (samplingRate == 600.0) {
1427 return 10;
1428 }
1429 else if (samplingRate == 900.0) {
1430 return 11;
1431 }
1432 else if (samplingRate == 1800.0) {
1433 return 12;
1434 }
1435 else if (samplingRate == 3600.0) {
1436 return 13;
1437 }
1438 else if (samplingRate == 7200.0) {
1439 return 14;
1440 }
1441 else if (samplingRate == 10800.0) {
1442 return 15;
1443 }
1444 return 2; // default
1445}
1446
1447// Check corrections
1448////////////////////////////////////////////////////////////////////////////
1449bool bncRtnetUploadCaster::corrIsOutOfRange(struct SsrCorr::ClockOrbit::SatData* sd) {
1450
1451 if (fabs(sd->Clock.DeltaA0) > 209.7151) { return true; }
1452 if (fabs(sd->Clock.DeltaA1) > 1.048575) { return true; }
1453 if (fabs(sd->Clock.DeltaA2) > 1.34217726) { return true; }
1454
1455 if (fabs(sd->Orbit.DeltaRadial) > 209.7151) { return true; }
1456 if (fabs(sd->Orbit.DeltaAlongTrack) > 209.7148) { return true; }
1457 if (fabs(sd->Orbit.DeltaCrossTrack) > 209.7148) { return true; }
1458
1459 if (fabs(sd->Orbit.DotDeltaRadial) > 1.048575) { return true; }
1460 if (fabs(sd->Orbit.DotDeltaAlongTrack) > 1.048572) { return true; }
1461 if (fabs(sd->Orbit.DotDeltaCrossTrack) > 1.048572) { return true; }
1462 return false;
1463}
Note: See TracBrowser for help on using the repository browser.