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

Last change on this file since 5898 was 5776, checked in by mervart, 10 years ago
File size: 24.3 KB
RevLine 
[3222]1/* -------------------------------------------------------------------------
2 * BKG NTRIP Server
3 * -------------------------------------------------------------------------
4 *
[3224]5 * Class: bncRtnetUploadCaster
[3222]6 *
7 * Purpose: Connection to NTRIP Caster
8 *
9 * Author: L. Mervart
10 *
11 * Created: 29-Mar-2011
12 *
[5662]13 * Changes:
[3222]14 *
15 * -----------------------------------------------------------------------*/
16
17#include <math.h>
[5662]18#include "bncrtnetuploadcaster.h"
[3222]19#include "bncsettings.h"
[3224]20#include "bncephuser.h"
[3222]21#include "bncclockrinex.h"
22#include "bncsp3.h"
23
24using namespace std;
25
26// Constructor
27////////////////////////////////////////////////////////////////////////////
[3224]28bncRtnetUploadCaster::bncRtnetUploadCaster(const QString& mountpoint,
[3222]29 const QString& outHost, int outPort,
[5662]30 const QString& password,
31 const QString& crdTrafo, bool CoM,
[3222]32 const QString& sp3FileName,
33 const QString& rnxFileName,
[4111]34 int PID, int SID, int IOD, int iRow) :
[3273]35 bncUploadCaster(mountpoint, outHost, outPort, password, iRow, 0) {
[3224]36
[5130]37 if (!outHost.isEmpty()) {
38 _casterID += outHost;
39 }
40 if (!crdTrafo.isEmpty()) {
41 _casterID += " " + crdTrafo;
42 }
43 if (!sp3FileName.isEmpty()) {
44 _casterID += " " + sp3FileName;
45 }
46 if (!rnxFileName.isEmpty()) {
47 _casterID += " " + rnxFileName;
48 }
49
[3222]50 _crdTrafo = crdTrafo;
51 _CoM = CoM;
[4111]52 _PID = PID;
53 _SID = SID;
54 _IOD = IOD;
[3222]55
[3224]56 // Member that receives the ephemeris
57 // ----------------------------------
58 _ephUser = new bncEphUser();
[3222]59
[3272]60 bncSettings settings;
61 QString intr = settings.value("uploadIntr").toString();
[4174]62
63 _samplRtcmEphCorr = settings.value("uploadSamplRtcmEphCorr").toDouble();
[4542]64 int samplClkRnx = settings.value("uploadSamplClkRnx").toInt();
65 int samplSp3 = settings.value("uploadSamplSp3").toInt() * 60;
[4174]66
67 if (_samplRtcmEphCorr == 0.0) {
[3753]68 _usedEph = 0;
69 }
70 else {
71 _usedEph = new QMap<QString, t_eph*>;
72 }
[3272]73
[3222]74 // RINEX writer
75 // ------------
76 if (!rnxFileName.isEmpty()) {
[4174]77 _rnx = new bncClockRinex(rnxFileName, intr, samplClkRnx);
[3222]78 }
79 else {
80 _rnx = 0;
81 }
82
83 // SP3 writer
84 // ----------
85 if (!sp3FileName.isEmpty()) {
[4174]86 _sp3 = new bncSP3(sp3FileName, intr, samplSp3);
[3222]87 }
88 else {
89 _sp3 = 0;
90 }
91
92 // Set Transformation Parameters
93 // -----------------------------
94 if (_crdTrafo == "ETRF2000") {
[3890]95 _dx = 0.0521;
96 _dy = 0.0493;
97 _dz = -0.0585;
98 _dxr = 0.0001;
[3222]99 _dyr = 0.0001;
100 _dzr = -0.0018;
101 _ox = 0.000891;
102 _oy = 0.005390;
103 _oz = -0.008712;
104 _oxr = 0.000081;
105 _oyr = 0.000490;
106 _ozr = -0.000792;
[3890]107 _sc = 1.34;
[3222]108 _scr = 0.08;
109 _t0 = 2000.0;
110 }
111 else if (_crdTrafo == "NAD83") {
[5345]112 _dx = 0.99343;
113 _dy = -1.90331;
114 _dz = -0.52655;
115 _dxr = 0.00079;
116 _dyr = -0.00060;
117 _dzr = -0.00134;
118 _ox = -0.02591467;
119 _oy = -0.00942645;
120 _oz = -0.01159935;
121 _oxr = -0.00006667;
122 _oyr = 0.00075744;
123 _ozr = 0.00005133;
124 _sc = 1.71504;
[5348]125 _scr = -0.10201;
[5345]126 _t0 = 1997.0;
[3222]127 }
128 else if (_crdTrafo == "GDA94") {
[4963]129 _dx = -0.08468;
130 _dy = -0.01942;
131 _dz = 0.03201;
132 _dxr = 0.00142;
133 _dyr = 0.00134;
134 _dzr = 0.00090;
135 _ox = 0.0004254;
136 _oy = -0.0022578;
137 _oz = -0.0024015;
138 _oxr = -0.0015461;
139 _oyr = -0.0011820;
140 _ozr = -0.0011551;
141 _sc = 9.710;
142 _scr = 0.109;
[3222]143 _t0 = 1994.0;
144 }
145 else if (_crdTrafo == "SIRGAS2000") {
[4956]146 _dx = 0.0020;
147 _dy = 0.0041;
148 _dz = 0.0039;
[3222]149 _dxr = 0.0000;
150 _dyr = 0.0000;
151 _dzr = 0.0000;
[4956]152 _ox = 0.000170;
153 _oy = -0.000030;
154 _oz = 0.000070;
[3222]155 _oxr = 0.000000;
156 _oyr = 0.000000;
157 _ozr = 0.000000;
[5662]158 _sc = -1.000;
[3222]159 _scr = 0.000;
160 _t0 = 0000.0;
161 }
162 else if (_crdTrafo == "SIRGAS95") {
163 _dx = 0.0077;
164 _dy = 0.0058;
165 _dz = -0.0138;
166 _dxr = 0.0000;
167 _dyr = 0.0000;
168 _dzr = 0.0000;
169 _ox = 0.000000;
170 _oy = 0.000000;
171 _oz = -0.000030;
172 _oxr = 0.000000;
173 _oyr = 0.000000;
174 _ozr = 0.000000;
175 _sc = 1.570;
176 _scr = 0.000;
177 _t0 = 0000.0;
178 }
[5347]179 else if (_crdTrafo == "DREF91") {
[5340]180 _dx = -0.0118;
181 _dy = 0.1432;
182 _dz = -0.1117;
183 _dxr = 0.0001;
184 _dyr = 0.0001;
185 _dzr = -0.0018;
186 _ox = 0.003291;
187 _oy = 0.006190;
188 _oz = -0.011012;
189 _oxr = 0.000081;
190 _oyr = 0.000490;
191 _ozr = -0.000792;
192 _sc = 12.24;
193 _scr = 0.08;
194 _t0 = 2000.0;
195 }
[3222]196 else if (_crdTrafo == "Custom") {
197 _dx = settings.value("trafo_dx").toDouble();
198 _dy = settings.value("trafo_dy").toDouble();
199 _dz = settings.value("trafo_dz").toDouble();
200 _dxr = settings.value("trafo_dxr").toDouble();
201 _dyr = settings.value("trafo_dyr").toDouble();
202 _dzr = settings.value("trafo_dzr").toDouble();
203 _ox = settings.value("trafo_ox").toDouble();
204 _oy = settings.value("trafo_oy").toDouble();
205 _oz = settings.value("trafo_oz").toDouble();
206 _oxr = settings.value("trafo_oxr").toDouble();
207 _oyr = settings.value("trafo_oyr").toDouble();
208 _ozr = settings.value("trafo_ozr").toDouble();
209 _sc = settings.value("trafo_sc").toDouble();
210 _scr = settings.value("trafo_scr").toDouble();
211 _t0 = settings.value("trafo_t0").toDouble();
212 }
213}
214
215// Destructor
216////////////////////////////////////////////////////////////////////////////
[3224]217bncRtnetUploadCaster::~bncRtnetUploadCaster() {
[3222]218 if (isRunning()) {
219 wait();
220 }
221 delete _rnx;
222 delete _sp3;
223 delete _ephUser;
[3753]224 delete _usedEph;
[3222]225}
226
[5662]227//
[3222]228////////////////////////////////////////////////////////////////////////////
[3224]229void bncRtnetUploadCaster::decodeRtnetStream(char* buffer, int bufLen) {
[5662]230
[3222]231 QMutexLocker locker(&_mutex);
232
[3230]233 // Append to internal buffer
234 // -------------------------
[3222]235 _rtnetStreamBuffer.append(QByteArray(buffer, bufLen));
[3230]236
237 // Select buffer part that contains last epoch
238 // -------------------------------------------
239 QStringList lines;
240 int iEpoBeg = _rtnetStreamBuffer.lastIndexOf('*'); // begin of last epoch
241 if (iEpoBeg == -1) {
[3226]242 _rtnetStreamBuffer.clear();
243 return;
[3222]244 }
[3230]245 _rtnetStreamBuffer = _rtnetStreamBuffer.mid(iEpoBeg);
246
247 int iEpoEnd = _rtnetStreamBuffer.lastIndexOf("EOE"); // end of last epoch
248 if (iEpoEnd == -1) {
249 return;
250 }
[3226]251 else {
[3230]252 lines = _rtnetStreamBuffer.left(iEpoEnd).split('\n', QString::SkipEmptyParts);
253 _rtnetStreamBuffer = _rtnetStreamBuffer.mid(iEpoEnd+3);
[3226]254 }
[3222]255
[3226]256 if (lines.size() < 2) {
[3222]257 return;
258 }
259
[3226]260 // Keep the last unfinished line in buffer
261 // ---------------------------------------
262 int iLastEOL = _rtnetStreamBuffer.lastIndexOf('\n');
263 if (iLastEOL != -1) {
264 _rtnetStreamBuffer = _rtnetStreamBuffer.mid(iLastEOL+1);
265 }
266
267 // Read first line (with epoch time)
268 // ---------------------------------
269 QTextStream in(lines[0].toAscii());
270 QString hlp;
271 int year, month, day, hour, min;
272 double sec;
273 in >> hlp >> year >> month >> day >> hour >> min >> sec;
274 bncTime epoTime; epoTime.set( year, month, day, hour, min, sec);
275
[5662]276 emit(newMessage("bncRtnetUploadCaster: decode " +
[5131]277 QByteArray(epoTime.datestr().c_str()) + " " +
[5662]278 QByteArray(epoTime.timestr().c_str()) + " " +
[5132]279 _casterID.toAscii(), false));
[4808]280
[3222]281 struct ClockOrbit co;
282 memset(&co, 0, sizeof(co));
[5672]283 co.EpochTime[CLOCKORBIT_SATGPS] = static_cast<int>(epoTime.gpssec());
284 double gt = epoTime.gpssec() + 3 * 3600 - gnumleap(year, month, day);
285 co.EpochTime[CLOCKORBIT_SATGLONASS] = static_cast<int>(fmod(gt, 86400.0));
286
[5666]287 co.Supplied[COBOFS_CLOCK] = 1;
288 co.Supplied[COBOFS_ORBIT] = 1;
[3222]289 co.SatRefDatum = DATUM_ITRF;
[4111]290 co.SSRIOD = _IOD;
291 co.SSRProviderID = _PID; // 256 .. BKG, 257 ... EUREF
292 co.SSRSolutionID = _SID;
[5662]293
[5666]294 struct CodeBias bias;
[3222]295 memset(&bias, 0, sizeof(bias));
[5666]296 bias.EpochTime[CLOCKORBIT_SATGPS] = co.EpochTime[CLOCKORBIT_SATGPS];
297 bias.EpochTime[CLOCKORBIT_SATGLONASS] = co.EpochTime[CLOCKORBIT_SATGLONASS];
[5662]298
[4753]299 // Default Update Interval
300 // -----------------------
[4754]301 int clkUpdInd = 2; // 5 sec
302 int ephUpdInd = clkUpdInd; // default
303 if (_samplRtcmEphCorr == 10.0) {
304 ephUpdInd = 3;
305 }
306 else if (_samplRtcmEphCorr == 15.0) {
307 ephUpdInd = 4;
308 }
309 else if (_samplRtcmEphCorr == 30.0) {
310 ephUpdInd = 5;
311 }
312 else if (_samplRtcmEphCorr == 60.0) {
313 ephUpdInd = 6;
314 }
315 else if (_samplRtcmEphCorr == 120.0) {
316 ephUpdInd = 7;
317 }
318 else if (_samplRtcmEphCorr == 240.0) {
319 ephUpdInd = 8;
320 }
321 else if (_samplRtcmEphCorr == 300.0) {
322 ephUpdInd = 9;
323 }
324 else if (_samplRtcmEphCorr == 600.0) {
325 ephUpdInd = 10;
326 }
327 else if (_samplRtcmEphCorr == 900.0) {
328 ephUpdInd = 11;
329 }
[4753]330
[4754]331 co.UpdateInterval = clkUpdInd;
332 bias.UpdateInterval = clkUpdInd;
[4753]333
[3226]334 for (int ii = 1; ii < lines.size(); ii++) {
[5662]335
[3222]336 QString prn;
[4991]337 ColumnVector rtnAPC;
338 ColumnVector rtnVel;
339 ColumnVector rtnCoM;
340 double rtnClk;
[5662]341
[3222]342 QTextStream in(lines[ii].toAscii());
343
344 in >> prn;
345
[3753]346 t_eph* eph = 0;
[3222]347 const bncEphUser::t_ephPair* ephPair = _ephUser->ephPair(prn);
348 if (ephPair) {
349
[3754]350 eph = ephPair->last;
351
[4098]352 // Use previous ephemeris if the last one is too recent
353 // ----------------------------------------------------
354 const int MINAGE = 60; // seconds
355 if (ephPair->prev && eph->receptDateTime().isValid() &&
356 eph->receptDateTime().secsTo(currentDateAndTimeGPS()) < MINAGE) {
357 eph = ephPair->prev;
358 }
[3754]359
[3753]360 // Make sure the clock messages refer to same IOD as orbit messages
361 // ----------------------------------------------------------------
362 if (_usedEph) {
[4174]363 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
[3753]364 (*_usedEph)[prn] = eph;
365 }
366 else {
367 eph = 0;
368 if (_usedEph->contains(prn)) {
369 t_eph* usedEph = _usedEph->value(prn);
370 if (usedEph == ephPair->last) {
371 eph = ephPair->last;
372 }
373 else if (usedEph == ephPair->prev) {
374 eph = ephPair->prev;
375 }
376 }
377 }
378 }
379 }
380
381 if (eph) {
382
[5503]383 QMap<QString, double> codeBiases;
384
[4991]385 while (true) {
386 QString key;
387 int numVal = 0;
388 in >> key >> numVal;
389 if (in.status() != QTextStream::Ok) {
390 break;
391 }
392 if (key == "APC") {
393 rtnAPC.ReSize(3);
394 in >> rtnAPC[0] >> rtnAPC[1] >> rtnAPC[2];
395 }
396 else if (key == "Clk") {
397 in >> rtnClk;
398 }
399 else if (key == "Vel") {
400 rtnVel.ReSize(3);
401 in >> rtnVel[0] >> rtnVel[1] >> rtnVel[2];
402 }
403 else if (key == "CoM") {
404 rtnCoM.ReSize(3);
405 in >> rtnCoM[0] >> rtnCoM[1] >> rtnCoM[2];
406 }
[5503]407 else if (key == "CodeBias") {
408 for (int ii = 0; ii < numVal; ii++) {
409 QString type;
410 double value;
411 in >> type >> value;
412 codeBiases[type] = value;
413 }
414 }
[4991]415 else {
416 for (int ii = 0; ii < numVal; ii++) {
417 double dummy;
418 in >> dummy;
419 }
420 }
[5662]421 }
[3222]422 struct ClockOrbit::SatData* sd = 0;
423 if (prn[0] == 'G') {
[5666]424 sd = co.Sat + co.NumberOfSat[CLOCKORBIT_SATGPS];
425 ++co.NumberOfSat[CLOCKORBIT_SATGPS];
[3222]426 }
427 else if (prn[0] == 'R') {
[5666]428 sd = co.Sat + CLOCKORBIT_NUMGPS + co.NumberOfSat[CLOCKORBIT_SATGLONASS];
429 ++co.NumberOfSat[CLOCKORBIT_SATGLONASS];
[3222]430 }
431 if (sd) {
432 QString outLine;
[5662]433 processSatellite(eph, epoTime.gpsw(), epoTime.gpssec(), prn,
[4991]434 rtnAPC, rtnClk, rtnVel, rtnCoM, sd, outLine);
[3222]435 }
[5662]436
[5666]437 struct CodeBias::BiasSat* biasSat = 0;
[3222]438 if (prn[0] == 'G') {
[5666]439 biasSat = bias.Sat + bias.NumberOfSat[CLOCKORBIT_SATGPS];
440 ++bias.NumberOfSat[CLOCKORBIT_SATGPS];
[3222]441 }
442 else if (prn[0] == 'R') {
[5666]443 biasSat = bias.Sat + CLOCKORBIT_NUMGPS + bias.NumberOfSat[CLOCKORBIT_SATGLONASS];
444 ++bias.NumberOfSat[CLOCKORBIT_SATGLONASS];
[3222]445 }
[5662]446
[5503]447 // Code Biases
448 // -----------
[3222]449 if (biasSat) {
450 biasSat->ID = prn.mid(1).toInt();
[5503]451 biasSat->NumberOfCodeBiases = 0;
[3222]452 if (prn[0] == 'G') {
[5503]453 QMapIterator<QString, double> it(codeBiases);
454 while (it.hasNext()) {
455 it.next();
[5504]456 if (it.key() == "1C") {
[5503]457 int ii = biasSat->NumberOfCodeBiases; if (ii >= CLOCKORBIT_NUMBIAS) break;
458 biasSat->NumberOfCodeBiases += 1;
459 biasSat->Biases[ii].Type = CODETYPEGPS_L1_CA;
460 biasSat->Biases[ii].Bias = it.value();
461 }
[5504]462 else if (it.key() == "1C") {
[5503]463 int ii = biasSat->NumberOfCodeBiases; if (ii >= CLOCKORBIT_NUMBIAS) break;
464 biasSat->NumberOfCodeBiases += 1;
465 biasSat->Biases[ii].Type = CODETYPEGPS_L1_CA;
466 biasSat->Biases[ii].Bias = it.value();
467 }
[5504]468 else if (it.key() == "1P") {
[5503]469 int ii = biasSat->NumberOfCodeBiases; if (ii >= CLOCKORBIT_NUMBIAS) break;
470 biasSat->NumberOfCodeBiases += 1;
471 biasSat->Biases[ii].Type = CODETYPEGPS_L1_P;
472 biasSat->Biases[ii].Bias = it.value();
473 }
[5504]474 else if (it.key() == "1W") {
[5503]475 int ii = biasSat->NumberOfCodeBiases; if (ii >= CLOCKORBIT_NUMBIAS) break;
476 biasSat->NumberOfCodeBiases += 1;
477 biasSat->Biases[ii].Type = CODETYPEGPS_L1_Z;
478 biasSat->Biases[ii].Bias = it.value();
479 }
[5504]480 else if (it.key() == "2C") {
[5503]481 int ii = biasSat->NumberOfCodeBiases; if (ii >= CLOCKORBIT_NUMBIAS) break;
482 biasSat->NumberOfCodeBiases += 1;
483 biasSat->Biases[ii].Type = CODETYPEGPS_L2_CA;
484 biasSat->Biases[ii].Bias = it.value();
485 }
[5504]486 else if (it.key() == "2D") {
[5503]487 int ii = biasSat->NumberOfCodeBiases; if (ii >= CLOCKORBIT_NUMBIAS) break;
488 biasSat->NumberOfCodeBiases += 1;
489 biasSat->Biases[ii].Type = CODETYPEGPS_SEMI_CODELESS;
490 biasSat->Biases[ii].Bias = it.value();
491 }
[5504]492 else if (it.key() == "2S") {
[5503]493 int ii = biasSat->NumberOfCodeBiases; if (ii >= CLOCKORBIT_NUMBIAS) break;
494 biasSat->NumberOfCodeBiases += 1;
495 biasSat->Biases[ii].Type = CODETYPEGPS_L2_CM;
496 biasSat->Biases[ii].Bias = it.value();
497 }
[5504]498 else if (it.key() == "2L") {
[5503]499 int ii = biasSat->NumberOfCodeBiases; if (ii >= CLOCKORBIT_NUMBIAS) break;
500 biasSat->NumberOfCodeBiases += 1;
501 biasSat->Biases[ii].Type = CODETYPEGPS_L2_CL;
502 biasSat->Biases[ii].Bias = it.value();
503 }
[5504]504 else if (it.key() == "2X") {
[5503]505 int ii = biasSat->NumberOfCodeBiases; if (ii >= CLOCKORBIT_NUMBIAS) break;
506 biasSat->NumberOfCodeBiases += 1;
507 biasSat->Biases[ii].Type = CODETYPEGPS_L2_CML;
508 biasSat->Biases[ii].Bias = it.value();
509 }
[5504]510 else if (it.key() == "2P") {
[5503]511 int ii = biasSat->NumberOfCodeBiases; if (ii >= CLOCKORBIT_NUMBIAS) break;
512 biasSat->NumberOfCodeBiases += 1;
513 biasSat->Biases[ii].Type = CODETYPEGPS_L2_P;
514 biasSat->Biases[ii].Bias = it.value();
515 }
[5510]516 else if (it.key() == "2W") {
[5503]517 int ii = biasSat->NumberOfCodeBiases; if (ii >= CLOCKORBIT_NUMBIAS) break;
518 biasSat->NumberOfCodeBiases += 1;
519 biasSat->Biases[ii].Type = CODETYPEGPS_L2_Z;
520 biasSat->Biases[ii].Bias = it.value();
521 }
[5504]522 else if (it.key() == "5I") {
[5503]523 int ii = biasSat->NumberOfCodeBiases; if (ii >= CLOCKORBIT_NUMBIAS) break;
524 biasSat->NumberOfCodeBiases += 1;
525 biasSat->Biases[ii].Type = CODETYPEGPS_L5_I;
526 biasSat->Biases[ii].Bias = it.value();
527 }
[5504]528 else if (it.key() == "5Q") {
[5503]529 int ii = biasSat->NumberOfCodeBiases; if (ii >= CLOCKORBIT_NUMBIAS) break;
530 biasSat->NumberOfCodeBiases += 1;
531 biasSat->Biases[ii].Type = CODETYPEGPS_L5_Q;
532 biasSat->Biases[ii].Bias = it.value();
533 }
534 }
[3222]535 }
536 else if (prn[0] == 'R') {
[5503]537 QMapIterator<QString, double> it(codeBiases);
538 while (it.hasNext()) {
539 it.next();
[5504]540 if (it.key() == "1C") {
[5503]541 int ii = biasSat->NumberOfCodeBiases; if (ii >= CLOCKORBIT_NUMBIAS) break;
542 biasSat->NumberOfCodeBiases += 1;
543 biasSat->Biases[ii].Type = CODETYPEGLONASS_L1_CA;
544 biasSat->Biases[ii].Bias = it.value();
545 }
[5504]546 else if (it.key() == "1P") {
[5503]547 int ii = biasSat->NumberOfCodeBiases; if (ii >= CLOCKORBIT_NUMBIAS) break;
548 biasSat->NumberOfCodeBiases += 1;
549 biasSat->Biases[ii].Type = CODETYPEGLONASS_L1_P;
550 biasSat->Biases[ii].Bias = it.value();
551 }
[5504]552 else if (it.key() == "2C") {
[5503]553 int ii = biasSat->NumberOfCodeBiases; if (ii >= CLOCKORBIT_NUMBIAS) break;
554 biasSat->NumberOfCodeBiases += 1;
555 biasSat->Biases[ii].Type = CODETYPEGLONASS_L2_CA;
556 biasSat->Biases[ii].Bias = it.value();
557 }
[5504]558 else if (it.key() == "2P") {
[5503]559 int ii = biasSat->NumberOfCodeBiases; if (ii >= CLOCKORBIT_NUMBIAS) break;
560 biasSat->NumberOfCodeBiases += 1;
561 biasSat->Biases[ii].Type = CODETYPEGLONASS_L2_P;
562 biasSat->Biases[ii].Bias = it.value();
563 }
564 }
[3222]565 }
566 }
567 }
568 }
[3227]569
[5662]570 QByteArray hlpBufferCo;
[3493]571
572 // Orbit and Clock Corrections together
573 // ------------------------------------
[4174]574 if (_samplRtcmEphCorr == 0.0) {
[5666]575 if (co.NumberOfSat[CLOCKORBIT_SATGPS] > 0 || co.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0) {
[3493]576 char obuffer[CLOCKORBIT_BUFFERSIZE];
577 int len = MakeClockOrbit(&co, COTYPE_AUTO, 0, obuffer, sizeof(obuffer));
578 if (len > 0) {
579 hlpBufferCo = QByteArray(obuffer, len);
580 }
[3222]581 }
582 }
[3493]583
584 // Orbit and Clock Corrections separately
585 // --------------------------------------
586 else {
[5666]587 if (co.NumberOfSat[CLOCKORBIT_SATGPS] > 0) {
[3493]588 char obuffer[CLOCKORBIT_BUFFERSIZE];
[4174]589 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
[4754]590 co.UpdateInterval = ephUpdInd;
[3591]591 int len1 = MakeClockOrbit(&co, COTYPE_GPSORBIT, 1, obuffer, sizeof(obuffer));
[4754]592 co.UpdateInterval = clkUpdInd;
[3493]593 if (len1 > 0) {
594 hlpBufferCo += QByteArray(obuffer, len1);
595 }
596 }
[5666]597 int mmsg = (co.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0) ? 1 : 0;
[3591]598 int len2 = MakeClockOrbit(&co, COTYPE_GPSCLOCK, mmsg, obuffer, sizeof(obuffer));
[3493]599 if (len2 > 0) {
600 hlpBufferCo += QByteArray(obuffer, len2);
601 }
602 }
[5666]603 if (co.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0) {
[3493]604 char obuffer[CLOCKORBIT_BUFFERSIZE];
[4174]605 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
[4754]606 co.UpdateInterval = ephUpdInd;
[3591]607 int len1 = MakeClockOrbit(&co, COTYPE_GLONASSORBIT, 1, obuffer, sizeof(obuffer));
[4754]608 co.UpdateInterval = clkUpdInd;
[3493]609 if (len1 > 0) {
610 hlpBufferCo += QByteArray(obuffer, len1);
611 }
612 }
613 int len2 = MakeClockOrbit(&co, COTYPE_GLONASSCLOCK, 0, obuffer, sizeof(obuffer));
614 if (len2 > 0) {
615 hlpBufferCo += QByteArray(obuffer, len2);
616 }
617 }
618 }
[5662]619
[3493]620 // Biases
621 // ------
[5662]622 QByteArray hlpBufferBias;
[5666]623 if (bias.NumberOfSat[CLOCKORBIT_SATGPS] > 0 || bias.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0) {
[3222]624 char obuffer[CLOCKORBIT_BUFFERSIZE];
[5666]625 int len = MakeCodeBias(&bias, BTYPE_AUTO, 0, obuffer, sizeof(obuffer));
[3222]626 if (len > 0) {
[3227]627 hlpBufferBias = QByteArray(obuffer, len);
[3222]628 }
629 }
[3227]630
[4808]631 _outBuffer += hlpBufferCo + hlpBufferBias;
[3222]632}
633
[5662]634//
[3222]635////////////////////////////////////////////////////////////////////////////
[5662]636void bncRtnetUploadCaster::processSatellite(t_eph* eph, int GPSweek,
[4991]637 double GPSweeks, const QString& prn,
638 const ColumnVector& rtnAPC,
639 double rtnClk,
640 const ColumnVector& rtnVel,
641 const ColumnVector& rtnCoM,
642 struct ClockOrbit::SatData* sd,
643 QString& outLine) {
[3222]644
[4930]645 // Broadcast Position and Velocity
646 // -------------------------------
647 ColumnVector xB(4);
648 ColumnVector vB(3);
649 eph->position(GPSweek, GPSweeks, xB.data(), vB.data());
[5662]650
[4991]651 // Precise Position
652 // ----------------
653 ColumnVector xP = _CoM ? rtnCoM : rtnAPC;
[3222]654
[5662]655 double dc = 0.0;
[4930]656 if (_crdTrafo != "IGS08") {
657 crdTrafo(GPSweek, xP, dc);
658 }
[5662]659
[4930]660 // Difference in xyz
661 // -----------------
662 ColumnVector dx = xB.Rows(1,3) - xP;
[4991]663 ColumnVector dv = vB - rtnVel;
[5662]664
[4930]665 // Difference in RSW
666 // -----------------
[3222]667 ColumnVector rsw(3);
[4930]668 XYZ_to_RSW(xB.Rows(1,3), vB, dx, rsw);
[3222]669
[4930]670 ColumnVector dotRsw(3);
671 XYZ_to_RSW(xB.Rows(1,3), vB, dv, dotRsw);
[3222]672
[4930]673 // Clock Correction
674 // ----------------
[4991]675 double dClk = rtnClk - (xB(4) - dc) * t_CST::c;
[3222]676
677 if (sd) {
[4930]678 sd->ID = prn.mid(1).toInt();
679 sd->IOD = eph->IOD();
680 sd->Clock.DeltaA0 = dClk;
[5655]681 sd->Clock.DeltaA1 = 0.0; // TODO
682 sd->Clock.DeltaA2 = 0.0; // TODO
[4930]683 sd->Orbit.DeltaRadial = rsw(1);
684 sd->Orbit.DeltaAlongTrack = rsw(2);
685 sd->Orbit.DeltaCrossTrack = rsw(3);
686 sd->Orbit.DotDeltaRadial = dotRsw(1);
687 sd->Orbit.DotDeltaAlongTrack = dotRsw(2);
688 sd->Orbit.DotDeltaCrossTrack = dotRsw(3);
[3222]689 }
690
[5662]691 outLine.sprintf("%d %.1f %s %3d %10.3f %8.3f %8.3f %8.3f\n",
[5776]692 GPSweek, GPSweeks, eph->prn().toString().c_str(),
[3222]693 eph->IOD(), dClk, rsw(1), rsw(2), rsw(3));
694
[4991]695 double relativity = -2.0 * DotProduct(xP, rtnVel) / t_CST::c;
696 double sp3Clk = (rtnClk - relativity) / t_CST::c; // in seconds
697
[3222]698 if (_rnx) {
[4991]699 _rnx->write(GPSweek, GPSweeks, prn, sp3Clk);
[3222]700 }
701 if (_sp3) {
[4991]702 _sp3->write(GPSweek, GPSweeks, prn, rtnCoM, sp3Clk);
[3222]703 }
704}
705
706// Transform Coordinates
707////////////////////////////////////////////////////////////////////////////
[5662]708void bncRtnetUploadCaster::crdTrafo(int GPSWeek, ColumnVector& xyz,
[4803]709 double& dc) {
[3222]710
711 // Current epoch minus 2000.0 in years
712 // ------------------------------------
713 double dt = (GPSWeek - (1042.0+6.0/7.0)) / 365.2422 * 7.0 + 2000.0 - _t0;
714
715 ColumnVector dx(3);
716
717 dx(1) = _dx + dt * _dxr;
718 dx(2) = _dy + dt * _dyr;
719 dx(3) = _dz + dt * _dzr;
720
721 static const double arcSec = 180.0 * 3600.0 / M_PI;
722
723 double ox = (_ox + dt * _oxr) / arcSec;
724 double oy = (_oy + dt * _oyr) / arcSec;
725 double oz = (_oz + dt * _ozr) / arcSec;
726
727 double sc = 1.0 + _sc * 1e-9 + dt * _scr * 1e-9;
728
[4912]729 // Specify approximate center of area
730 // ----------------------------------
731 ColumnVector meanSta(3);
732
733 if (_crdTrafo == "ETRF2000") {
[4973]734 meanSta(1) = 3661090.0;
735 meanSta(2) = 845230.0;
736 meanSta(3) = 5136850.0;
[4908]737 }
[4912]738 else if (_crdTrafo == "NAD83") {
[4973]739 meanSta(1) = -1092950.0;
740 meanSta(2) = -4383600.0;
741 meanSta(3) = 4487420.0;
[4912]742 }
743 else if (_crdTrafo == "GDA94") {
[4973]744 meanSta(1) = -4052050.0;
745 meanSta(2) = 4212840.0;
746 meanSta(3) = -2545110.0;
[4912]747 }
748 else if (_crdTrafo == "SIRGAS2000") {
[4973]749 meanSta(1) = 3740860.0;
750 meanSta(2) = -4964290.0;
751 meanSta(3) = -1425420.0;
[4912]752 }
753 else if (_crdTrafo == "SIRGAS95") {
[4973]754 meanSta(1) = 3135390.0;
755 meanSta(2) = -5017670.0;
756 meanSta(3) = -2374440.0;
[4912]757 }
[5343]758 else if (_crdTrafo == "DREF91") {
759 meanSta(1) = 3959579.0;
760 meanSta(2) = 721719.0;
761 meanSta(3) = 4931539.0;
762 }
[4912]763 else if (_crdTrafo == "Custom") {
764 meanSta(1) = 0.0; // TODO
765 meanSta(2) = 0.0; // TODO
766 meanSta(3) = 0.0; // TODO
767 }
[4908]768
[4912]769 // Clock correction proportional to topocentric distance to satellites
770 // -------------------------------------------------------------------
771 double rho = (xyz - meanSta).norm_Frobenius();
[4913]772 dc = rho * (sc - 1.0) / sc / t_CST::c;
[4908]773
[3222]774 Matrix rMat(3,3);
775 rMat(1,1) = 1.0;
776 rMat(1,2) = -oz;
777 rMat(1,3) = oy;
778 rMat(2,1) = oz;
779 rMat(2,2) = 1.0;
780 rMat(2,3) = -ox;
781 rMat(3,1) = -oy;
782 rMat(3,2) = ox;
783 rMat(3,3) = 1.0;
784
785 xyz = sc * rMat * xyz + dx;
786}
787
Note: See TracBrowser for help on using the repository browser.