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

Last change on this file since 10903 was 10827, checked in by stuerze, 7 weeks ago

bug fixed regarding ssr upload

File size: 50.7 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 co.Supplied[_ssrCorr->COBOFS_CLOCK] = 1;
370 co.Supplied[_ssrCorr->COBOFS_ORBIT] = 1;
371
372 t_serviceCrs serviceCrs;
373 t_rtcmCrs rtcmCrs;
374 if (_crdTrafoStr == "IGS20") {
375 serviceCrs._CE = serviceCrs._coordinateEpoch = 0;
376 int nc = _crdTrafoStr.length();
377 if (nc > 31) { nc = 31; }
378 for (int i = 0; i < nc; i++) {
379 serviceCrs._name[i] =
380 rtcmCrs._name[i] = _crdTrafoStr.toStdString()[i];
381 }
382 serviceCrs._name[nc] = 0;
383 rtcmCrs._name[nc] = 0;
384 rtcmCrs._anchor = 0; // global CRS
385 rtcmCrs._plateNumber = 0; // unknown
386 rtcmCrs._databaseLinks << "ISO.DATUM.979" << "ISO.CRS:980";
387 }
388 else {
389 if (_crdTrafoStr != "Custom") {
390 serviceCrs._coordinateEpoch = _t0;
391 serviceCrs.setCEFromCoordinateEpoch();
392 int nc = _crdTrafoStr.length();
393 if (nc > 31) { nc = 31; }
394 for (int i = 0; i < nc; i++) {
395 serviceCrs._name[i] = _crdTrafoStr.toStdString()[i];
396 }
397 serviceCrs._name[nc] = 0;
398 QString rtcmcrsname = _crdTrafoStr + QString("(%1)").arg(_t0, 4, 'd', 0);
399 nc = rtcmcrsname.length();
400 if (nc > 31) { nc = 31; }
401 for (int i = 0; i < nc; i++) {
402 rtcmCrs._name[i] = rtcmcrsname.toStdString()[i];
403 }
404 rtcmCrs._name[nc] = 0;
405 if (_crdTrafoStr == "ETRF2000") {
406 rtcmCrs._anchor = 1; // plate-fixed CRS
407 rtcmCrs._plateNumber = 7; // Eurasia
408 rtcmCrs._databaseLinks << "ISO.DATUM.187" << "ISO.CRS:260" << "ISO.CRS:457"
409 << "EPSG.DATUM:1186" << "EPSG.CRS:7930" << "EPSG.CRS:7931";
410 }
411 else if (_crdTrafoStr == "DREF91") {
412 rtcmCrs._anchor = 1; // plate-fixed CRS
413 rtcmCrs._plateNumber = 7; // Eurasia
414 }
415 else if (_crdTrafoStr == "GDA2020") {
416 rtcmCrs._anchor = 1; // plate-fixed CRS
417 rtcmCrs._plateNumber = 4; // Australia
418 rtcmCrs._databaseLinks << "ISO.DATUM.186" << "ISO.CRS:404" << "ISO.CRS:329"
419 << "EPSG.DATUM:1168" << "EPSG.CRS:7842" << "EPSG.CRS:7843";
420 }
421 else if (_crdTrafoStr == "SIRGAS2000") {
422 rtcmCrs._anchor = 1; // plate-fixed CRS
423 rtcmCrs._plateNumber = 12; // S.America
424 rtcmCrs._databaseLinks << "ISO.DATUM:169" << "ISO.CRS:384" << "ISO.CRS:313"
425 << "EPSG.DATUM:6674" << "EPSG.CRS:4988" << "EPSG.CRS:4989";
426 }
427 }
428 }
429
430 struct SsrCorr::CodeBias bias;
431 memset(&bias, 0, sizeof(bias));
432 bias.EpochTime[CLOCKORBIT_SATGPS] = co.EpochTime[CLOCKORBIT_SATGPS];
433 bias.EpochTime[CLOCKORBIT_SATGLONASS] = co.EpochTime[CLOCKORBIT_SATGLONASS];
434 bias.EpochTime[CLOCKORBIT_SATGALILEO] = co.EpochTime[CLOCKORBIT_SATGALILEO];
435 bias.EpochTime[CLOCKORBIT_SATQZSS] = co.EpochTime[CLOCKORBIT_SATQZSS];
436 bias.EpochTime[CLOCKORBIT_SATSBAS] = co.EpochTime[CLOCKORBIT_SATSBAS];
437 bias.EpochTime[CLOCKORBIT_SATBDS] = co.EpochTime[CLOCKORBIT_SATBDS];
438 bias.SSRIOD = _IOD;
439 bias.SSRProviderID = _PID;
440 bias.SSRSolutionID = _SID;
441
442 struct SsrCorr::PhaseBias phasebias;
443 memset(&phasebias, 0, sizeof(phasebias));
444 unsigned int dispersiveBiasConsistenyIndicator = 0;
445 unsigned int mwConsistencyIndicator = 0;
446 phasebias.EpochTime[CLOCKORBIT_SATGPS] = co.EpochTime[CLOCKORBIT_SATGPS];
447 phasebias.EpochTime[CLOCKORBIT_SATGLONASS] = co.EpochTime[CLOCKORBIT_SATGLONASS];
448 phasebias.EpochTime[CLOCKORBIT_SATGALILEO] = co.EpochTime[CLOCKORBIT_SATGALILEO];
449 phasebias.EpochTime[CLOCKORBIT_SATQZSS] = co.EpochTime[CLOCKORBIT_SATQZSS];
450 phasebias.EpochTime[CLOCKORBIT_SATSBAS] = co.EpochTime[CLOCKORBIT_SATSBAS];
451 phasebias.EpochTime[CLOCKORBIT_SATBDS] = co.EpochTime[CLOCKORBIT_SATBDS];
452 phasebias.SSRIOD = _IOD;
453 phasebias.SSRProviderID = _PID;
454 phasebias.SSRSolutionID = _SID;
455
456 struct SsrCorr::VTEC vtec;
457 memset(&vtec, 0, sizeof(vtec));
458 vtec.EpochTime = static_cast<int>(epoTime.gpssec());
459 vtec.SSRIOD = _IOD;
460 vtec.SSRProviderID = _PID;
461 vtec.SSRSolutionID = _SID;
462
463 // Update Interval
464 // ---------------
465
466 if (_samplRtcmEphCorr == 0.0) {// combined orb and clock
467 _samplRtcmEphCorr = _samplRtcmClkCorr = 5.0;
468 }
469 int clkUpdInd = determineUpdateInd(_samplRtcmClkCorr);
470 int ephUpdInd = determineUpdateInd(_samplRtcmEphCorr);
471
472 co.UpdateInterval = clkUpdInd;
473 bias.UpdateInterval = ephUpdInd;
474 phasebias.UpdateInterval = ephUpdInd;
475
476 for (int ii = 1; ii < lines.size(); ii++) {
477 QString key; // prn or key VTEC, IND (phase bias indicators)
478 double rtnUra = 0.0; // [m]
479 ColumnVector rtnAPC; rtnAPC.ReSize(3); rtnAPC = 0.0; // [m, m, m]
480 ColumnVector rtnVel; rtnVel.ReSize(3); rtnVel = 0.0; // [m/s, m/s, m/s]
481 ColumnVector rtnCoM; rtnCoM.ReSize(3); rtnCoM = 0.0; // [m, m, m]
482 ColumnVector rtnClk; rtnClk.ReSize(3); rtnClk = 0.0; // [m, m/s, m/s²]
483 ColumnVector rtnClkSig; rtnClkSig.ReSize(3); rtnClkSig = 0.0; // [m, m/s, m/s²]
484
485 //QTextStream in(lines[ii].toLatin1());
486 QTextStream in(&lines[ii], QIODevice::ReadOnly);
487 in >> key;
488
489 // non-satellite specific parameters
490 if (key.contains("IND", Qt::CaseSensitive)) {
491 in >> dispersiveBiasConsistenyIndicator >> mwConsistencyIndicator;
492 continue;
493 }
494 // non-satellite specific parameters
495 if (key.contains("VTEC", Qt::CaseSensitive)) {
496 double ui;
497 in >> ui >> vtec.NumLayers;
498 vtec.UpdateInterval = (unsigned int)determineUpdateInd(ui);
499 for (unsigned ll = 0; ll < vtec.NumLayers; ll++) {
500 int dummy;
501 in >> dummy >> vtec.Layers[ll].Degree >> vtec.Layers[ll].Order
502 >> vtec.Layers[ll].Height;
503 for (unsigned iDeg = 0; iDeg <= vtec.Layers[ll].Degree; iDeg++) {
504 for (unsigned iOrd = 0; iOrd <= vtec.Layers[ll].Order; iOrd++) {
505 in >> vtec.Layers[ll].Cosinus[iDeg][iOrd];
506 }
507 }
508 for (unsigned iDeg = 0; iDeg <= vtec.Layers[ll].Degree; iDeg++) {
509 for (unsigned iOrd = 0; iOrd <= vtec.Layers[ll].Order; iOrd++) {
510 in >> vtec.Layers[ll].Sinus[iDeg][iOrd];
511 }
512 }
513 }
514 continue;
515 }
516 // satellite specific parameters
517 t_prn prn;
518 char sys = key.mid(0, 1).at(0).toLatin1();
519 int num = key.mid(1, 2).toInt();
520 int flag = t_corrSSR::getSsrNavTypeFlag(sys, num);
521 if (!num) {
522 continue;
523 }
524 prn.set(sys, num, flag);
525 QString prnInternalStr = QString::fromStdString(prn.toInternalString());
526 QString prnStr = QString::fromStdString(prn.toString());
527
528 const t_eph* ephLast = _ephUser->ephLast(prnInternalStr);
529 const t_eph* ephPrev = _ephUser->ephPrev(prnInternalStr);
530 const t_eph* eph = ephLast;
531 if (eph) {
532
533 // Use previous ephemeris if the last one is too recent
534 // ----------------------------------------------------
535 const int MINAGE = 60; // seconds
536 if (ephPrev && eph->receptDateTime().isValid() &&
537 eph->receptDateTime().secsTo(currentDateAndTimeGPS()) < MINAGE) {
538 eph = ephPrev;
539 }
540
541 // Make sure the clock messages refer to same IOD as orbit messages
542 // ----------------------------------------------------------------
543 if (_usedEph) {
544 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
545 (*_usedEph)[prnInternalStr] = eph;
546 }
547 else {
548 eph = 0;
549 if (_usedEph->contains(prnInternalStr)) {
550 const t_eph* usedEph = _usedEph->value(prnInternalStr);
551 if (usedEph == ephLast) {
552 eph = ephLast;
553 }
554 else if (usedEph == ephPrev) {
555 eph = ephPrev;
556 }
557 }
558 }
559 }
560 }
561
562 QDateTime now = currentDateAndTimeGPS();
563 bncTime currentTime(now.toString(Qt::ISODate).toStdString());
564 if (eph &&
565 !outDatedBcep(eph, currentTime) && // detected from storage because of no update
566 eph->checkState() != t_eph::bad &&
567 eph->checkState() != t_eph::unhealthy &&
568 eph->checkState() != t_eph::outdated) { // detected during reception (bncephuser)
569 QMap<QString, double> codeBiases;
570 QList<phaseBiasSignal> phaseBiasList;
571 phaseBiasesSat pbSat;
572 _phaseBiasInformationDecoded = false;
573
574 while (true) {
575 QString key;
576 int numVal = 0;
577 in >> key;
578 if (in.status() != QTextStream::Ok) {
579 break;
580 }
581 if (key == "APC") {
582 in >> numVal;
583 rtnAPC.ReSize(3); rtnAPC = 0.0;
584 for (int ii = 0; ii < numVal; ii++) {
585 in >> rtnAPC[ii];
586 }
587 }
588 else if (key == "Ura") {
589 in >> numVal;
590 if (numVal == 1)
591 in >> rtnUra;
592 }
593 else if (key == "Clk") {
594 in >> numVal;
595 rtnClk.ReSize(3); rtnClk = 0.0;
596 for (int ii = 0; ii < numVal; ii++) {
597 in >> rtnClk[ii];
598 }
599 }
600 else if (key == "ClkSig") {
601 in >> numVal;
602 rtnClkSig.ReSize(3); rtnClkSig = 0.0;
603 for (int ii = 0; ii < numVal; ii++) {
604 in >> rtnClkSig[ii];
605 }
606 }
607 else if (key == "Vel") {
608 in >> numVal;
609 rtnVel.ReSize(3); rtnVel = 0.0;
610 for (int ii = 0; ii < numVal; ii++) {
611 in >> rtnVel[ii];
612 }
613 }
614 else if (key == "CoM") {
615 in >> numVal;
616 rtnCoM.ReSize(3); rtnCoM = 0.0;
617 for (int ii = 0; ii < numVal; ii++) {
618 in >> rtnCoM[ii];
619 }
620 }
621 else if (key == "CodeBias") {
622 in >> numVal;
623 for (int ii = 0; ii < numVal; ii++) {
624 QString type;
625 double value;
626 in >> type >> value;
627 codeBiases[type] = value;
628 }
629 }
630 else if (key == "YawAngle") {
631 _phaseBiasInformationDecoded = true;
632 in >> numVal >> pbSat.yawAngle;
633 if (pbSat.yawAngle < 0.0) {
634 pbSat.yawAngle += (2 * M_PI);
635 }
636 else if (pbSat.yawAngle > 2 * M_PI) {
637 pbSat.yawAngle -= (2 * M_PI);
638 }
639 }
640 else if (key == "YawRate") {
641 _phaseBiasInformationDecoded = true;
642 in >> numVal >> pbSat.yawRate;
643 }
644 else if (key == "PhaseBias") {
645 _phaseBiasInformationDecoded = true;
646 in >> numVal;
647 for (int ii = 0; ii < numVal; ii++) {
648 phaseBiasSignal pb;
649 in >> pb.type >> pb.bias >> pb.integerIndicator
650 >> pb.wlIndicator >> pb.discontinuityCounter;
651 phaseBiasList.append(pb);
652 }
653 }
654 else {
655 in >> numVal;
656 for (int ii = 0; ii < numVal; ii++) {
657 double dummy;
658 in >> dummy;
659 }
660 emit(newMessage(" RTNET format error: "
661 + lines[ii].toLatin1(), false));
662 break;
663 }
664 }
665
666 struct SsrCorr::ClockOrbit::SatData* sd = 0;
667 if (prn.system() == 'G') {
668 sd = co.Sat + co.NumberOfSat[CLOCKORBIT_SATGPS];
669 ++co.NumberOfSat[CLOCKORBIT_SATGPS];
670 }
671 else if (prn.system() == 'R') {
672 sd = co.Sat + CLOCKORBIT_NUMGPS + co.NumberOfSat[CLOCKORBIT_SATGLONASS];
673 ++co.NumberOfSat[CLOCKORBIT_SATGLONASS];
674 }
675 else if (prn.system() == 'E') {
676 sd = co.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
677 + co.NumberOfSat[CLOCKORBIT_SATGALILEO];
678 ++co.NumberOfSat[CLOCKORBIT_SATGALILEO];
679 }
680 else if (prn.system() == 'J') {
681 sd = co.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
682 + CLOCKORBIT_NUMGALILEO
683 + co.NumberOfSat[CLOCKORBIT_SATQZSS];
684 ++co.NumberOfSat[CLOCKORBIT_SATQZSS];
685 }
686 else if (prn.system() == 'S') {
687 sd = co.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
688 + CLOCKORBIT_NUMGALILEO + CLOCKORBIT_NUMQZSS
689 + co.NumberOfSat[CLOCKORBIT_SATSBAS];
690 ++co.NumberOfSat[CLOCKORBIT_SATSBAS];
691 }
692 else if (prn.system() == 'C') {
693 sd = co.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
694 + CLOCKORBIT_NUMGALILEO + CLOCKORBIT_NUMQZSS
695 + CLOCKORBIT_NUMSBAS
696 + co.NumberOfSat[CLOCKORBIT_SATBDS];
697 ++co.NumberOfSat[CLOCKORBIT_SATBDS];
698 }
699 if (sd) {
700 QString outLine;
701 t_irc irc = processSatellite(eph, epoTime.gpsw(), epoTime.gpssec(), prnStr, rtnAPC,
702 rtnUra, rtnClk, rtnVel, rtnCoM, rtnClkSig, sd, outLine);
703 if (irc != success) {
704 continue;
705 }
706 }
707
708 // Code Biases
709 // -----------
710 struct SsrCorr::CodeBias::BiasSat* biasSat = 0;
711 if (!codeBiases.isEmpty()) {
712 if (prn.system() == 'G') {
713 biasSat = bias.Sat + bias.NumberOfSat[CLOCKORBIT_SATGPS];
714 ++bias.NumberOfSat[CLOCKORBIT_SATGPS];
715 }
716 else if (prn.system() == 'R') {
717 biasSat = bias.Sat + CLOCKORBIT_NUMGPS
718 + bias.NumberOfSat[CLOCKORBIT_SATGLONASS];
719 ++bias.NumberOfSat[CLOCKORBIT_SATGLONASS];
720 }
721 else if (prn.system() == 'E') {
722 biasSat = bias.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
723 + bias.NumberOfSat[CLOCKORBIT_SATGALILEO];
724 ++bias.NumberOfSat[CLOCKORBIT_SATGALILEO];
725 }
726 else if (prn.system() == 'J') {
727 biasSat = bias.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
728 + CLOCKORBIT_NUMGALILEO
729 + bias.NumberOfSat[CLOCKORBIT_SATQZSS];
730 ++bias.NumberOfSat[CLOCKORBIT_SATQZSS];
731 }
732 else if (prn.system() == 'S') {
733 biasSat = bias.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
734 + CLOCKORBIT_NUMGALILEO + CLOCKORBIT_NUMQZSS
735 + bias.NumberOfSat[CLOCKORBIT_SATSBAS];
736 ++bias.NumberOfSat[CLOCKORBIT_SATSBAS];
737 }
738 else if (prn.system() == 'C') {
739 biasSat = bias.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
740 + CLOCKORBIT_NUMGALILEO + CLOCKORBIT_NUMQZSS
741 + CLOCKORBIT_NUMSBAS
742 + bias.NumberOfSat[CLOCKORBIT_SATBDS];
743 ++bias.NumberOfSat[CLOCKORBIT_SATBDS];
744 }
745 }
746
747 if (biasSat) {
748 biasSat->ID = prn.number();
749 biasSat->NumberOfCodeBiases = 0;
750 QMapIterator<QString, double> it(codeBiases);
751 while (it.hasNext()) {
752 it.next();
753 int ii = biasSat->NumberOfCodeBiases;
754 if (ii >= CLOCKORBIT_NUMBIAS)
755 break;
756 SsrCorr::CodeType type = _ssrCorr->rnxTypeToCodeType(prn.system(), it.key().toStdString());
757 if (type != _ssrCorr->CODETYPE_RESERVED) {
758 biasSat->NumberOfCodeBiases += 1;
759 biasSat->Biases[ii].Type = type;
760 biasSat->Biases[ii].Bias = it.value();
761 if (_bsx) {
762 QString obsCode = 'C' + it.key();
763 _bsx->write(epoTime.gpsw(), epoTime.gpssec(), prnStr, obsCode, it.value());
764 }
765 }
766 }
767 }
768
769 // Phase Biases
770 // ------------
771 struct SsrCorr::PhaseBias::PhaseBiasSat* phasebiasSat = 0;
772 if (prn.system() == 'G') {
773 phasebiasSat = phasebias.Sat
774 + phasebias.NumberOfSat[CLOCKORBIT_SATGPS];
775 ++phasebias.NumberOfSat[CLOCKORBIT_SATGPS];
776 }
777 else if (prn.system() == 'R') {
778 phasebiasSat = phasebias.Sat + CLOCKORBIT_NUMGPS
779 + phasebias.NumberOfSat[CLOCKORBIT_SATGLONASS];
780 ++phasebias.NumberOfSat[CLOCKORBIT_SATGLONASS];
781 }
782 else if (prn.system() == 'E') {
783 phasebiasSat = phasebias.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
784 + phasebias.NumberOfSat[CLOCKORBIT_SATGALILEO];
785 ++phasebias.NumberOfSat[CLOCKORBIT_SATGALILEO];
786 }
787 else if (prn.system() == 'J') {
788 phasebiasSat = phasebias.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
789 + CLOCKORBIT_NUMGALILEO
790 + phasebias.NumberOfSat[CLOCKORBIT_SATQZSS];
791 ++phasebias.NumberOfSat[CLOCKORBIT_SATQZSS];
792 }
793 else if (prn.system() == 'S') {
794 phasebiasSat = phasebias.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
795 + CLOCKORBIT_NUMGALILEO + CLOCKORBIT_NUMQZSS
796 + phasebias.NumberOfSat[CLOCKORBIT_SATSBAS];
797 ++phasebias.NumberOfSat[CLOCKORBIT_SATSBAS];
798 }
799 else if (prn.system() == 'C') {
800 phasebiasSat = phasebias.Sat + CLOCKORBIT_NUMGPS + CLOCKORBIT_NUMGLONASS
801 + CLOCKORBIT_NUMGALILEO + CLOCKORBIT_NUMQZSS
802 + CLOCKORBIT_NUMSBAS
803 + phasebias.NumberOfSat[CLOCKORBIT_SATBDS];
804 ++phasebias.NumberOfSat[CLOCKORBIT_SATBDS];
805 }
806
807 if (phasebiasSat && _phaseBiasInformationDecoded) {
808 phasebias.DispersiveBiasConsistencyIndicator = dispersiveBiasConsistenyIndicator;
809 phasebias.MWConsistencyIndicator = mwConsistencyIndicator;
810 phasebiasSat->ID = prn.number();
811 phasebiasSat->NumberOfPhaseBiases = 0;
812 phasebiasSat->YawAngle = pbSat.yawAngle;
813 phasebiasSat->YawRate = pbSat.yawRate;
814 QListIterator<phaseBiasSignal> it(phaseBiasList);
815 while (it.hasNext()) {
816 const phaseBiasSignal& pbSig = it.next();
817 int ii = phasebiasSat->NumberOfPhaseBiases;
818 if (ii >= CLOCKORBIT_NUMBIAS)
819 break;
820 SsrCorr::CodeType type = _ssrCorr->rnxTypeToCodeType(prn.system(), pbSig.type.toStdString());
821 if (type != _ssrCorr->PBEXTTYPE_RESERVED) {
822 phasebiasSat->NumberOfPhaseBiases += 1;
823 phasebiasSat->Biases[ii].Type = type;
824 phasebiasSat->Biases[ii].Bias = pbSig.bias;
825 phasebiasSat->Biases[ii].SignalIntegerIndicator = pbSig.integerIndicator;
826 phasebiasSat->Biases[ii].SignalsWideLaneIntegerIndicator = pbSig.wlIndicator;
827 phasebiasSat->Biases[ii].SignalDiscontinuityCounter = pbSig.discontinuityCounter;
828 if (_bsx) {
829 QString obsCode = 'L' + pbSig.type;
830 _bsx->write(epoTime.gpsw(), epoTime.gpssec(), prnStr, obsCode, pbSig.bias);
831 }
832 }
833 }
834 }
835 }
836 }
837
838 QByteArray hlpBufferCo;
839 char obuffer[CLOCKORBIT_BUFFERSIZE];
840 size_t len = 0;
841
842 // Orbit and Clock Corrections together
843 // ------------------------------------
844 if (_samplRtcmEphCorr == _samplRtcmClkCorr) {
845 if (co.NumberOfSat[CLOCKORBIT_SATGPS] > 0
846 || co.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0
847 || co.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0
848 || co.NumberOfSat[CLOCKORBIT_SATBDS] > 0
849 || co.NumberOfSat[CLOCKORBIT_SATQZSS] > 0
850 || co.NumberOfSat[CLOCKORBIT_SATSBAS] > 0) {
851 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
852 memset(obuffer, 0, sizeof(obuffer));
853 len = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_AUTO, 0, obuffer, sizeof(obuffer));
854 if (len > 0) {
855 hlpBufferCo = QByteArray(obuffer, int(len));
856 }
857 }
858 }
859 }
860
861 // Orbit and Clock Corrections separately
862 // --------------------------------------
863 else {
864 if (co.NumberOfSat[CLOCKORBIT_SATGPS] > 0) {
865 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
866 co.UpdateInterval = ephUpdInd;
867 memset(obuffer, 0, sizeof(obuffer));
868 len = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_GPSORBIT, 1, obuffer, sizeof(obuffer));
869 if (len > 0) {
870 hlpBufferCo += QByteArray(obuffer, int(len));
871 }
872 }
873 int mmsg = (co.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0 ||
874 co.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0 ||
875 co.NumberOfSat[CLOCKORBIT_SATBDS] > 0 ||
876 co.NumberOfSat[CLOCKORBIT_SATQZSS] > 0 ||
877 co.NumberOfSat[CLOCKORBIT_SATSBAS] > 0) ? 1 : 0;
878 if (fmod(epoTime.gpssec(), _samplRtcmClkCorr) == 0.0) {
879 co.UpdateInterval = clkUpdInd;
880 memset(obuffer, 0, sizeof(obuffer));
881 len = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_GPSCLOCK, mmsg, obuffer, sizeof(obuffer));
882 if (len > 0) {
883 hlpBufferCo += QByteArray(obuffer, int(len));
884 }
885 }
886 }
887 if (co.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0) {
888 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
889 co.UpdateInterval = ephUpdInd;
890 memset(obuffer, 0, sizeof(obuffer));
891 len = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_GLONASSORBIT, 1, obuffer, sizeof(obuffer));
892 if (len > 0) {
893 hlpBufferCo += QByteArray(obuffer, int(len));
894 }
895 }
896 int mmsg = (co.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0 ||
897 co.NumberOfSat[CLOCKORBIT_SATBDS] > 0 ||
898 co.NumberOfSat[CLOCKORBIT_SATQZSS] > 0 ||
899 co.NumberOfSat[CLOCKORBIT_SATSBAS] > 0) ? 1 : 0;
900 if (fmod(epoTime.gpssec(), _samplRtcmClkCorr) == 0.0) {
901 co.UpdateInterval = clkUpdInd;
902 memset(obuffer, 0, sizeof(obuffer));
903 len = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_GLONASSCLOCK, mmsg, obuffer, sizeof(obuffer));
904 if (len > 0) {
905 hlpBufferCo += QByteArray(obuffer, int(len));
906 }
907 }
908 }
909 if (co.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0) {
910 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
911 co.UpdateInterval = ephUpdInd;
912 memset(obuffer, 0, sizeof(obuffer));
913 len = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_GALILEOORBIT, 1, obuffer, sizeof(obuffer));
914 if (len > 0) {
915 hlpBufferCo += QByteArray(obuffer, int(len));
916 }
917 }
918 int mmsg = (co.NumberOfSat[CLOCKORBIT_SATBDS] > 0 ||
919 co.NumberOfSat[CLOCKORBIT_SATQZSS] > 0 ||
920 co.NumberOfSat[CLOCKORBIT_SATSBAS] > 0) ? 1 : 0;
921 if (fmod(epoTime.gpssec(), _samplRtcmClkCorr) == 0.0) {
922 co.UpdateInterval = clkUpdInd;
923 memset(obuffer, 0, sizeof(obuffer));
924 len = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_GALILEOCLOCK, mmsg, obuffer, sizeof(obuffer));
925 if (len > 0) {
926 hlpBufferCo += QByteArray(obuffer, int(len));
927 }
928 }
929 }
930 if (co.NumberOfSat[CLOCKORBIT_SATBDS] > 0) {
931 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
932 co.UpdateInterval = ephUpdInd;
933 memset(obuffer, 0, sizeof(obuffer));
934 len = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_BDSORBIT, 1, obuffer, sizeof(obuffer));
935 if (len > 0) {
936 hlpBufferCo += QByteArray(obuffer, int(len));
937 }
938 }
939 int mmsg = (co.NumberOfSat[CLOCKORBIT_SATQZSS] > 0 ||
940 co.NumberOfSat[CLOCKORBIT_SATSBAS] > 0) ? 1 : 0;
941 if (fmod(epoTime.gpssec(), _samplRtcmClkCorr) == 0.0) {
942 co.UpdateInterval = clkUpdInd;
943 memset(obuffer, 0, sizeof(obuffer));
944 len = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_BDSCLOCK, mmsg, obuffer, sizeof(obuffer));
945 if (len > 0) {
946 hlpBufferCo += QByteArray(obuffer, int(len));
947 }
948 }
949 }
950 if (co.NumberOfSat[CLOCKORBIT_SATQZSS] > 0) {
951 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
952 co.UpdateInterval = ephUpdInd;
953 memset(obuffer, 0, sizeof(obuffer));
954 len = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_QZSSORBIT, 1, obuffer, sizeof(obuffer));
955 if (len > 0) {
956 hlpBufferCo += QByteArray(obuffer, int(len));
957 }
958 }
959 int mmsg = (co.NumberOfSat[CLOCKORBIT_SATSBAS] > 0) ? 1 : 0;
960 if (fmod(epoTime.gpssec(), _samplRtcmClkCorr) == 0.0) {
961 co.UpdateInterval = clkUpdInd;
962 memset(obuffer, 0, sizeof(obuffer));
963 len = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_QZSSCLOCK, mmsg, obuffer, sizeof(obuffer));
964 if (len > 0) {
965 hlpBufferCo += QByteArray(obuffer, int(len));
966 }
967 }
968 }
969 if (co.NumberOfSat[CLOCKORBIT_SATSBAS] > 0) {
970 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
971 co.UpdateInterval = ephUpdInd;
972 memset(obuffer, 0, sizeof(obuffer));
973 len = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_SBASORBIT, 1, obuffer, sizeof(obuffer));
974 co.UpdateInterval = clkUpdInd;
975 if (len > 0) {
976 hlpBufferCo += QByteArray(obuffer, int(len));
977 }
978 }
979 int mmsg = 0;
980 if (fmod(epoTime.gpssec(), _samplRtcmClkCorr) == 0.0) {
981 co.UpdateInterval = clkUpdInd;
982 memset(obuffer, 0, sizeof(obuffer));
983 len = _ssrCorr->MakeClockOrbit(&co, _ssrCorr->COTYPE_SBASCLOCK, mmsg, obuffer, sizeof(obuffer));
984 if (len > 0) {
985 hlpBufferCo += QByteArray(obuffer, int(len));
986 }
987 }
988 }
989 }
990
991 // Code Biases
992 // -----------
993 QByteArray hlpBufferBias;
994 if (bias.NumberOfSat[CLOCKORBIT_SATGPS] > 0
995 || bias.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0
996 || bias.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0
997 || bias.NumberOfSat[CLOCKORBIT_SATBDS] > 0
998 || bias.NumberOfSat[CLOCKORBIT_SATQZSS] > 0
999 || bias.NumberOfSat[CLOCKORBIT_SATSBAS] > 0) {
1000 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
1001 memset(obuffer, 0, sizeof(obuffer));
1002 len = _ssrCorr->MakeCodeBias(&bias, _ssrCorr->CBTYPE_AUTO, 0, obuffer, sizeof(obuffer));
1003 if (len > 0) {
1004 hlpBufferBias = QByteArray(obuffer, int(len));
1005 }
1006 }
1007 }
1008
1009 // Phase Biases
1010 // ------------
1011 QByteArray hlpBufferPhaseBias;
1012 if ((phasebias.NumberOfSat[CLOCKORBIT_SATGPS] > 0
1013 || phasebias.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0
1014 || phasebias.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0
1015 || phasebias.NumberOfSat[CLOCKORBIT_SATBDS] > 0
1016 || phasebias.NumberOfSat[CLOCKORBIT_SATQZSS] > 0
1017 || phasebias.NumberOfSat[CLOCKORBIT_SATSBAS] > 0) && (_phaseBiasInformationDecoded)) {
1018 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
1019 memset(obuffer, 0, sizeof(obuffer));
1020 len = _ssrCorr->MakePhaseBias(&phasebias, _ssrCorr->PBTYPE_AUTO, 0, obuffer, sizeof(obuffer));
1021 if (len > 0) {
1022 hlpBufferPhaseBias = QByteArray(obuffer, int(len));
1023 }
1024 }
1025 }
1026
1027 // VTEC
1028 // ----
1029 QByteArray hlpBufferVtec;
1030 if (vtec.NumLayers > 0) {
1031 if (fmod(epoTime.gpssec(), _samplRtcmVtec) == 0.0) {
1032 memset(obuffer, 0, sizeof(obuffer));
1033 len = _ssrCorr->MakeVTEC(&vtec, 0, obuffer, sizeof(obuffer));
1034 if (len > 0) {
1035 hlpBufferVtec = QByteArray(obuffer, int(len));
1036 }
1037 }
1038 }
1039
1040 // Service CRS
1041 // -----------
1042 QByteArray hlpBufferServiceCrs;
1043 if (sizeof(serviceCrs._name) > 0) {
1044 if (fmod(epoTime.gpssec(), _samplRtcmCrs) == 0.0) {
1045 memset(obuffer, 0, sizeof(obuffer));
1046 len = t_crsEncoder::RTCM3(serviceCrs, obuffer, sizeof(obuffer));
1047 if (len > 0) {
1048 hlpBufferServiceCrs = QByteArray(obuffer, int(len));
1049 }
1050 }
1051 }
1052
1053 // RTCM CRS
1054 // --------
1055 QByteArray hlpBufferRtcmCrs;
1056 if (sizeof(rtcmCrs._name) > 0) {
1057 if (fmod(epoTime.gpssec(), _samplRtcmCrs) == 0.0) {
1058 memset(obuffer, 0, sizeof(obuffer));
1059 len = t_crsEncoder::RTCM3(rtcmCrs, obuffer, sizeof(obuffer));
1060 if (len > 0) {
1061 hlpBufferRtcmCrs = QByteArray(obuffer, int(len));
1062 }
1063 }
1064 }
1065
1066 // Create OutBuffer
1067 // ----------------
1068 _outBuffer += hlpBufferCo + hlpBufferBias + hlpBufferPhaseBias + hlpBufferVtec
1069 + hlpBufferServiceCrs + hlpBufferRtcmCrs + '\0';
1070}
1071//
1072////////////////////////////////////////////////////////////////////////////
1073t_irc bncRtnetUploadCaster::processSatellite(const t_eph* eph, int GPSweek,
1074 double GPSweeks, const QString& prn, const ColumnVector& rtnAPC,
1075 double rtnUra, const ColumnVector& rtnClk, const ColumnVector& rtnVel,
1076 const ColumnVector& rtnCoM, const ColumnVector& rtnClkSig,
1077 struct SsrCorr::ClockOrbit::SatData* sd, QString& outLine) {
1078
1079 // Broadcast Position and Velocity
1080 // -------------------------------
1081 ColumnVector xB(6);
1082 ColumnVector vB(3);
1083 t_irc irc = eph->getCrd(bncTime(GPSweek, GPSweeks), xB, vB, false);
1084
1085 if (irc != success) {
1086 return irc;
1087 }
1088
1089 // Precise Position
1090 // ----------------
1091 ColumnVector xP = _CoM ? rtnCoM : rtnAPC;
1092
1093 if (xP.size() == 0) {
1094 return failure;
1095 }
1096
1097 double dc = 0.0;
1098 if (_crdTrafoStr != "IGS20") {
1099 crdTrafo14(GPSweek, xP, dc); // ITRF2020 => ITRF2014
1100 crdTrafo(GPSweek, xP, dc); // ITRF2014 to other reference frames
1101 }
1102
1103 // Difference in xyz
1104 // -----------------
1105 ColumnVector dx = xB.Rows(1, 3) - xP;
1106 ColumnVector dv = vB - rtnVel;
1107
1108 // Difference in RSW
1109 // -----------------
1110 ColumnVector rsw(3);
1111 XYZ_to_RSW(xB.Rows(1, 3), vB, dx, rsw);
1112
1113 ColumnVector dotRsw(3);
1114 XYZ_to_RSW(xB.Rows(1, 3), vB, dv, dotRsw);
1115
1116 // Clock Correction
1117 // ----------------
1118 double dClkA0 = rtnClk(1) - (xB(4) - dc) * t_CST::c;
1119 double dClkA1 = 0.0;
1120 if (rtnClk(2)) {
1121 dClkA1 = rtnClk(2) - xB(5) * t_CST::c;
1122 }
1123 double dClkA2 = 0.0;
1124 if (rtnClk(3)) {
1125 dClkA2 = rtnClk(3) - xB(6) * t_CST::c;
1126 }
1127
1128 if (sd) {
1129 sd->ID = prn.mid(1).toInt();
1130 sd->IOD = eph->IOD();
1131 sd->Clock.DeltaA0 = dClkA0;
1132 sd->Clock.DeltaA1 = dClkA1;
1133 sd->Clock.DeltaA2 = dClkA2;
1134 sd->UserRangeAccuracy = rtnUra;
1135 sd->Orbit.DeltaRadial = rsw(1);
1136 sd->Orbit.DeltaAlongTrack = rsw(2);
1137 sd->Orbit.DeltaCrossTrack = rsw(3);
1138 sd->Orbit.DotDeltaRadial = dotRsw(1);
1139 sd->Orbit.DotDeltaAlongTrack = dotRsw(2);
1140 sd->Orbit.DotDeltaCrossTrack = dotRsw(3);
1141
1142 if (corrIsOutOfRange(sd)) {
1143 emit(newMessage(QString("bncRtnetUploadCaster: SSR parameter is out of its defined range").toLatin1(), false));
1144 return failure;
1145 }
1146 }
1147
1148 outLine = QString().asprintf("%d %.1f %s %u %10.3f %8.3f %8.3f %8.3f %8.3f %8.3f\n", GPSweek,
1149 GPSweeks, eph->prn().toString().c_str(), eph->IOD(), dClkA0, dClkA1, dClkA2,
1150 rsw(1), rsw(2), rsw(3)); //fprintf(stderr, "%s\n", outLine.toStdString().c_str());
1151
1152 // RTNET full clock for RINEX and SP3 file
1153 // ---------------------------------------
1154 double relativity = -2.0 * DotProduct(xP, rtnVel) / t_CST::c;
1155 double clkRnx = (rtnClk[0] - relativity) / t_CST::c; // [s]
1156 double clkRnxRate = rtnClk[1] / t_CST::c; // [s/s = -]
1157 double clkRnxAcc = rtnClk[2] / t_CST::c; // [s/s² = -/s]
1158
1159 if (_rnx) {
1160 double clkRnxSig, clkRnxRateSig, clkRnxAccSig;
1161 int s = rtnClkSig.size();
1162 switch (s) {
1163 case 1:
1164 clkRnxSig = rtnClkSig[0] / t_CST::c; // [s]
1165 clkRnxRateSig = 0.0; // [s/s = -]
1166 clkRnxAccSig = 0.0; // [s/s² ) -/s]
1167 break;
1168 case 2:
1169 clkRnxSig = rtnClkSig[0] / t_CST::c; // [s]
1170 clkRnxRateSig = rtnClkSig[1] / t_CST::c; // [s/s = -]
1171 clkRnxAccSig = 0.0; // [s/s² ) -/s]
1172 break;
1173 case 3:
1174 clkRnxSig = rtnClkSig[0] / t_CST::c; // [s]
1175 clkRnxRateSig = rtnClkSig[1] / t_CST::c; // [s/s = -]
1176 clkRnxAccSig = rtnClkSig[2] / t_CST::c; // [s/s² ) -/s]
1177 break;
1178 }
1179 _rnx->write(GPSweek, GPSweeks, prn, clkRnx, clkRnxRate, clkRnxAcc,
1180 clkRnxSig, clkRnxRateSig, clkRnxAccSig);
1181 }
1182 if (_sp3) {
1183 _sp3->write(GPSweek, GPSweeks, prn, rtnCoM, clkRnx, rtnVel, clkRnxRate);
1184 }
1185 return success;
1186}
1187
1188// Transform Coordinates
1189////////////////////////////////////////////////////////////////////////////
1190void bncRtnetUploadCaster::crdTrafo(int GPSWeek, ColumnVector& xyz,
1191 double& dc) {
1192
1193 // Current epoch minus 2000.0 in years
1194 // ------------------------------------
1195 double dt = (GPSWeek - (1042.0 + 6.0 / 7.0)) / 365.2422 * 7.0 + 2000.0 - _t0;
1196
1197 ColumnVector dx(3);
1198
1199 dx(1) = _dx + dt * _dxr;
1200 dx(2) = _dy + dt * _dyr;
1201 dx(3) = _dz + dt * _dzr;
1202
1203 static const double arcSec = 180.0 * 3600.0 / M_PI;
1204
1205 double ox = (_ox + dt * _oxr) / arcSec;
1206 double oy = (_oy + dt * _oyr) / arcSec;
1207 double oz = (_oz + dt * _ozr) / arcSec;
1208
1209 double sc = 1.0 + _sc * 1e-9 + dt * _scr * 1e-9;
1210
1211 // Specify approximate center of area
1212 // ----------------------------------
1213 ColumnVector meanSta(3);
1214
1215 if (_crdTrafoStr == "ETRF2000") {
1216 meanSta(1) = 3661090.0;
1217 meanSta(2) = 845230.0;
1218 meanSta(3) = 5136850.0;
1219 }
1220 else if (_crdTrafoStr == "GDA2020") {
1221 meanSta(1) = -4052050.0;
1222 meanSta(2) = 4212840.0;
1223 meanSta(3) = -2545110.0;
1224 }
1225 else if (_crdTrafoStr == "SIRGAS2000") {
1226 meanSta(1) = 3740860.0;
1227 meanSta(2) = -4964290.0;
1228 meanSta(3) = -1425420.0;
1229 }
1230 else if (_crdTrafoStr == "DREF91") {
1231 meanSta(1) = 3959579.0;
1232 meanSta(2) = 721719.0;
1233 meanSta(3) = 4931539.0;
1234 }
1235 else if (_crdTrafoStr == "Custom") {
1236 meanSta(1) = 0.0;
1237 meanSta(2) = 0.0;
1238 meanSta(3) = 0.0;
1239 }
1240
1241 // Clock correction proportional to topocentric distance to satellites
1242 // -------------------------------------------------------------------
1243 double rho = (xyz - meanSta).NormFrobenius();
1244 dc = rho * (sc - 1.0) / sc / t_CST::c;
1245
1246 Matrix rMat(3, 3);
1247 rMat(1, 1) = 1.0;
1248 rMat(1, 2) = -oz;
1249 rMat(1, 3) = oy;
1250 rMat(2, 1) = oz;
1251 rMat(2, 2) = 1.0;
1252 rMat(2, 3) = -ox;
1253 rMat(3, 1) = -oy;
1254 rMat(3, 2) = ox;
1255 rMat(3, 3) = 1.0;
1256
1257 xyz = sc * rMat * xyz + dx;
1258}
1259
1260// Transform Coordinates
1261////////////////////////////////////////////////////////////////////////////
1262void bncRtnetUploadCaster::crdTrafo14(int GPSWeek, ColumnVector& xyz,
1263 double& dc) {
1264
1265 // Current epoch minus 2000.0 in years
1266 // ------------------------------------
1267 double dt = (GPSWeek - (1042.0 + 6.0 / 7.0)) / 365.2422 * 7.0 + 2000.0 - _t0;
1268
1269 ColumnVector dx(3);
1270
1271 dx(1) = _dx14 + dt * _dxr14;
1272 dx(2) = _dy14 + dt * _dyr14;
1273 dx(3) = _dz14 + dt * _dzr14;
1274
1275 static const double arcSec = 180.0 * 3600.0 / M_PI;
1276
1277 double ox = (_ox14 + dt * _oxr14) / arcSec;
1278 double oy = (_oy14 + dt * _oyr14) / arcSec;
1279 double oz = (_oz14 + dt * _ozr14) / arcSec;
1280
1281 double sc = 1.0 + _sc14 * 1e-9 + dt * _scr14 * 1e-9;
1282
1283 // Specify approximate center of area
1284 // ----------------------------------
1285 ColumnVector meanSta(3);
1286 meanSta(1) = 0.0; // TODO
1287 meanSta(2) = 0.0; // TODO
1288 meanSta(3) = 0.0; // TODO
1289
1290 // Clock correction proportional to topocentric distance to satellites
1291 // -------------------------------------------------------------------
1292 double rho = (xyz - meanSta).NormFrobenius();
1293 dc = rho * (sc - 1.0) / sc / t_CST::c;
1294
1295 Matrix rMat(3, 3);
1296 rMat(1, 1) = 1.0;
1297 rMat(1, 2) = -oz;
1298 rMat(1, 3) = oy;
1299 rMat(2, 1) = oz;
1300 rMat(2, 2) = 1.0;
1301 rMat(2, 3) = -ox;
1302 rMat(3, 1) = -oy;
1303 rMat(3, 2) = ox;
1304 rMat(3, 3) = 1.0;
1305
1306 xyz = sc * rMat * xyz + dx;
1307}
1308
1309// Update Interval
1310////////////////////////////////////////////////////////////////////////////
1311int bncRtnetUploadCaster::determineUpdateInd(double samplingRate) {
1312
1313 if (samplingRate == 1.0) {
1314 return 0;
1315 }
1316 else if (samplingRate == 2.0) {
1317 return 1;
1318 }
1319 else if (samplingRate == 5.0) {
1320 return 2;
1321 }
1322 else if (samplingRate == 10.0) {
1323 return 3;
1324 }
1325 else if (samplingRate == 15.0) {
1326 return 4;
1327 }
1328 else if (samplingRate == 30.0) {
1329 return 5;
1330 }
1331 else if (samplingRate == 60.0) {
1332 return 6;
1333 }
1334 else if (samplingRate == 120.0) {
1335 return 7;
1336 }
1337 else if (samplingRate == 240.0) {
1338 return 8;
1339 }
1340 else if (samplingRate == 300.0) {
1341 return 9;
1342 }
1343 else if (samplingRate == 600.0) {
1344 return 10;
1345 }
1346 else if (samplingRate == 900.0) {
1347 return 11;
1348 }
1349 else if (samplingRate == 1800.0) {
1350 return 12;
1351 }
1352 else if (samplingRate == 3600.0) {
1353 return 13;
1354 }
1355 else if (samplingRate == 7200.0) {
1356 return 14;
1357 }
1358 else if (samplingRate == 10800.0) {
1359 return 15;
1360 }
1361 return 2; // default
1362}
1363
1364// Check corrections
1365////////////////////////////////////////////////////////////////////////////
1366bool bncRtnetUploadCaster::corrIsOutOfRange(struct SsrCorr::ClockOrbit::SatData* sd) {
1367
1368 if (fabs(sd->Clock.DeltaA0) > 209.7151) { return true; }
1369 if (fabs(sd->Clock.DeltaA1) > 1.048575) { return true; }
1370 if (fabs(sd->Clock.DeltaA2) > 1.34217726) { return true; }
1371
1372 if (fabs(sd->Orbit.DeltaRadial) > 209.7151) { return true; }
1373 if (fabs(sd->Orbit.DeltaAlongTrack) > 209.7148) { return true; }
1374 if (fabs(sd->Orbit.DeltaCrossTrack) > 209.7148) { return true; }
1375
1376 if (fabs(sd->Orbit.DotDeltaRadial) > 1.048575) { return true; }
1377 if (fabs(sd->Orbit.DotDeltaAlongTrack) > 1.048572) { return true; }
1378 if (fabs(sd->Orbit.DotDeltaCrossTrack) > 1.048572) { return true; }
1379 return false;
1380}
Note: See TracBrowser for help on using the repository browser.