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

Last change on this file since 10754 was 10754, checked in by stuerze, 3 months ago

initial preparation for adding the new RTCM-SSR format

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