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

Last change on this file since 10695 was 10667, checked in by stuerze, 9 months ago

minor changes

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