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

Last change on this file since 10551 was 10548, checked in by stuerze, 4 weeks ago

replacement of obsolete qt-class members

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