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

Last change on this file since 10599 was 10599, checked in by stuerze, 12 days ago

ADDED: consideration of NAV type in all applications

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