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

Last change on this file since 6109 was 6109, checked in by mervart, 10 years ago
File size: 24.3 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 "bncsp3.h"
23
24using namespace std;
25
26// Constructor
27////////////////////////////////////////////////////////////////////////////
28bncRtnetUploadCaster::bncRtnetUploadCaster(const QString& mountpoint,
29 const QString& outHost, int outPort,
30 const QString& password,
31 const QString& crdTrafo, bool CoM,
32 const QString& sp3FileName,
33 const QString& rnxFileName,
34 int PID, int SID, int IOD, int iRow) :
35 bncUploadCaster(mountpoint, outHost, outPort, password, iRow, 0) {
36
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
50 _crdTrafo = crdTrafo;
51 _CoM = CoM;
52 _PID = PID;
53 _SID = SID;
54 _IOD = IOD;
55
56 // Member that receives the ephemeris
57 // ----------------------------------
58 _ephUser = new bncEphUser();
59
60 bncSettings settings;
61 QString intr = settings.value("uploadIntr").toString();
62
63 _samplRtcmEphCorr = settings.value("uploadSamplRtcmEphCorr").toDouble();
64 int samplClkRnx = settings.value("uploadSamplClkRnx").toInt();
65 int samplSp3 = settings.value("uploadSamplSp3").toInt() * 60;
66
67 if (_samplRtcmEphCorr == 0.0) {
68 _usedEph = 0;
69 }
70 else {
71 _usedEph = new QMap<QString, t_eph*>;
72 }
73
74 // RINEX writer
75 // ------------
76 if (!rnxFileName.isEmpty()) {
77 _rnx = new bncClockRinex(rnxFileName, intr, samplClkRnx);
78 }
79 else {
80 _rnx = 0;
81 }
82
83 // SP3 writer
84 // ----------
85 if (!sp3FileName.isEmpty()) {
86 _sp3 = new bncSP3(sp3FileName, intr, samplSp3);
87 }
88 else {
89 _sp3 = 0;
90 }
91
92 // Set Transformation Parameters
93 // -----------------------------
94 if (_crdTrafo == "ETRF2000") {
95 _dx = 0.0521;
96 _dy = 0.0493;
97 _dz = -0.0585;
98 _dxr = 0.0001;
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;
107 _sc = 1.34;
108 _scr = 0.08;
109 _t0 = 2000.0;
110 }
111 else if (_crdTrafo == "NAD83") {
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;
125 _scr = -0.10201;
126 _t0 = 1997.0;
127 }
128 else if (_crdTrafo == "GDA94") {
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;
143 _t0 = 1994.0;
144 }
145 else if (_crdTrafo == "SIRGAS2000") {
146 _dx = 0.0020;
147 _dy = 0.0041;
148 _dz = 0.0039;
149 _dxr = 0.0000;
150 _dyr = 0.0000;
151 _dzr = 0.0000;
152 _ox = 0.000170;
153 _oy = -0.000030;
154 _oz = 0.000070;
155 _oxr = 0.000000;
156 _oyr = 0.000000;
157 _ozr = 0.000000;
158 _sc = -1.000;
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 }
179 else if (_crdTrafo == "DREF91") {
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 }
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////////////////////////////////////////////////////////////////////////////
217bncRtnetUploadCaster::~bncRtnetUploadCaster() {
218 if (isRunning()) {
219 wait();
220 }
221 delete _rnx;
222 delete _sp3;
223 delete _ephUser;
224 delete _usedEph;
225}
226
227//
228////////////////////////////////////////////////////////////////////////////
229void bncRtnetUploadCaster::decodeRtnetStream(char* buffer, int bufLen) {
230
231 QMutexLocker locker(&_mutex);
232
233 // Append to internal buffer
234 // -------------------------
235 _rtnetStreamBuffer.append(QByteArray(buffer, bufLen));
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) {
242 _rtnetStreamBuffer.clear();
243 return;
244 }
245 _rtnetStreamBuffer = _rtnetStreamBuffer.mid(iEpoBeg);
246
247 int iEpoEnd = _rtnetStreamBuffer.lastIndexOf("EOE"); // end of last epoch
248 if (iEpoEnd == -1) {
249 return;
250 }
251 else {
252 lines = _rtnetStreamBuffer.left(iEpoEnd).split('\n', QString::SkipEmptyParts);
253 _rtnetStreamBuffer = _rtnetStreamBuffer.mid(iEpoEnd+3);
254 }
255
256 if (lines.size() < 2) {
257 return;
258 }
259
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
276 emit(newMessage("bncRtnetUploadCaster: decode " +
277 QByteArray(epoTime.datestr().c_str()) + " " +
278 QByteArray(epoTime.timestr().c_str()) + " " +
279 _casterID.toAscii(), false));
280
281 struct ClockOrbit co;
282 memset(&co, 0, sizeof(co));
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
287 co.Supplied[COBOFS_CLOCK] = 1;
288 co.Supplied[COBOFS_ORBIT] = 1;
289 co.SatRefDatum = DATUM_ITRF;
290 co.SSRIOD = _IOD;
291 co.SSRProviderID = _PID; // 256 .. BKG, 257 ... EUREF
292 co.SSRSolutionID = _SID;
293
294 struct CodeBias bias;
295 memset(&bias, 0, sizeof(bias));
296 bias.EpochTime[CLOCKORBIT_SATGPS] = co.EpochTime[CLOCKORBIT_SATGPS];
297 bias.EpochTime[CLOCKORBIT_SATGLONASS] = co.EpochTime[CLOCKORBIT_SATGLONASS];
298
299 // Default Update Interval
300 // -----------------------
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 }
330
331 co.UpdateInterval = clkUpdInd;
332 bias.UpdateInterval = clkUpdInd;
333
334 for (int ii = 1; ii < lines.size(); ii++) {
335
336 QString prn;
337 ColumnVector rtnAPC;
338 ColumnVector rtnVel;
339 ColumnVector rtnCoM;
340 double rtnClk;
341
342 QTextStream in(lines[ii].toAscii());
343
344 in >> prn;
345
346 t_eph* eph = 0;
347 const bncEphUser::t_ephPair* ephPair = _ephUser->ephPair(prn);
348 if (ephPair) {
349
350 eph = ephPair->last;
351
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 }
359
360 // Make sure the clock messages refer to same IOD as orbit messages
361 // ----------------------------------------------------------------
362 if (_usedEph) {
363 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
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
383 QMap<QString, double> codeBiases;
384
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 }
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 }
415 else {
416 for (int ii = 0; ii < numVal; ii++) {
417 double dummy;
418 in >> dummy;
419 }
420 }
421 }
422 struct ClockOrbit::SatData* sd = 0;
423 if (prn[0] == 'G') {
424 sd = co.Sat + co.NumberOfSat[CLOCKORBIT_SATGPS];
425 ++co.NumberOfSat[CLOCKORBIT_SATGPS];
426 }
427 else if (prn[0] == 'R') {
428 sd = co.Sat + CLOCKORBIT_NUMGPS + co.NumberOfSat[CLOCKORBIT_SATGLONASS];
429 ++co.NumberOfSat[CLOCKORBIT_SATGLONASS];
430 }
431 if (sd) {
432 QString outLine;
433 processSatellite(eph, epoTime.gpsw(), epoTime.gpssec(), prn,
434 rtnAPC, rtnClk, rtnVel, rtnCoM, sd, outLine);
435 }
436
437 struct CodeBias::BiasSat* biasSat = 0;
438 if (prn[0] == 'G') {
439 biasSat = bias.Sat + bias.NumberOfSat[CLOCKORBIT_SATGPS];
440 ++bias.NumberOfSat[CLOCKORBIT_SATGPS];
441 }
442 else if (prn[0] == 'R') {
443 biasSat = bias.Sat + CLOCKORBIT_NUMGPS + bias.NumberOfSat[CLOCKORBIT_SATGLONASS];
444 ++bias.NumberOfSat[CLOCKORBIT_SATGLONASS];
445 }
446
447 // Code Biases
448 // -----------
449 if (biasSat) {
450 biasSat->ID = prn.mid(1).toInt();
451 biasSat->NumberOfCodeBiases = 0;
452 if (prn[0] == 'G') {
453 QMapIterator<QString, double> it(codeBiases);
454 while (it.hasNext()) {
455 it.next();
456 if (it.key() == "1C") {
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 }
462 else if (it.key() == "1C") {
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 }
468 else if (it.key() == "1P") {
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 }
474 else if (it.key() == "1W") {
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 }
480 else if (it.key() == "2C") {
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 }
486 else if (it.key() == "2D") {
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 }
492 else if (it.key() == "2S") {
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 }
498 else if (it.key() == "2L") {
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 }
504 else if (it.key() == "2X") {
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 }
510 else if (it.key() == "2P") {
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 }
516 else if (it.key() == "2W") {
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 }
522 else if (it.key() == "5I") {
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 }
528 else if (it.key() == "5Q") {
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 }
535 }
536 else if (prn[0] == 'R') {
537 QMapIterator<QString, double> it(codeBiases);
538 while (it.hasNext()) {
539 it.next();
540 if (it.key() == "1C") {
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 }
546 else if (it.key() == "1P") {
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 }
552 else if (it.key() == "2C") {
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 }
558 else if (it.key() == "2P") {
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 }
565 }
566 }
567 }
568 }
569
570 QByteArray hlpBufferCo;
571
572 // Orbit and Clock Corrections together
573 // ------------------------------------
574 if (_samplRtcmEphCorr == 0.0) {
575 if (co.NumberOfSat[CLOCKORBIT_SATGPS] > 0 || co.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0) {
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 }
581 }
582 }
583
584 // Orbit and Clock Corrections separately
585 // --------------------------------------
586 else {
587 if (co.NumberOfSat[CLOCKORBIT_SATGPS] > 0) {
588 char obuffer[CLOCKORBIT_BUFFERSIZE];
589 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
590 co.UpdateInterval = ephUpdInd;
591 int len1 = MakeClockOrbit(&co, COTYPE_GPSORBIT, 1, obuffer, sizeof(obuffer));
592 co.UpdateInterval = clkUpdInd;
593 if (len1 > 0) {
594 hlpBufferCo += QByteArray(obuffer, len1);
595 }
596 }
597 int mmsg = (co.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0) ? 1 : 0;
598 int len2 = MakeClockOrbit(&co, COTYPE_GPSCLOCK, mmsg, obuffer, sizeof(obuffer));
599 if (len2 > 0) {
600 hlpBufferCo += QByteArray(obuffer, len2);
601 }
602 }
603 if (co.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0) {
604 char obuffer[CLOCKORBIT_BUFFERSIZE];
605 if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
606 co.UpdateInterval = ephUpdInd;
607 int len1 = MakeClockOrbit(&co, COTYPE_GLONASSORBIT, 1, obuffer, sizeof(obuffer));
608 co.UpdateInterval = clkUpdInd;
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 }
619
620 // Biases
621 // ------
622 QByteArray hlpBufferBias;
623 if (bias.NumberOfSat[CLOCKORBIT_SATGPS] > 0 || bias.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0) {
624 char obuffer[CLOCKORBIT_BUFFERSIZE];
625 int len = MakeCodeBias(&bias, BTYPE_AUTO, 0, obuffer, sizeof(obuffer));
626 if (len > 0) {
627 hlpBufferBias = QByteArray(obuffer, len);
628 }
629 }
630
631 _outBuffer += hlpBufferCo + hlpBufferBias;
632}
633
634//
635////////////////////////////////////////////////////////////////////////////
636void bncRtnetUploadCaster::processSatellite(t_eph* eph, int GPSweek,
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) {
644
645 // Broadcast Position and Velocity
646 // -------------------------------
647 ColumnVector xB(4);
648 ColumnVector vB(3);
649 eph->getCrd(bncTime(GPSweek, GPSweeks), xB, vB, false);
650
651 // Precise Position
652 // ----------------
653 ColumnVector xP = _CoM ? rtnCoM : rtnAPC;
654
655 double dc = 0.0;
656 if (_crdTrafo != "IGS08") {
657 crdTrafo(GPSweek, xP, dc);
658 }
659
660 // Difference in xyz
661 // -----------------
662 ColumnVector dx = xB.Rows(1,3) - xP;
663 ColumnVector dv = vB - rtnVel;
664
665 // Difference in RSW
666 // -----------------
667 ColumnVector rsw(3);
668 XYZ_to_RSW(xB.Rows(1,3), vB, dx, rsw);
669
670 ColumnVector dotRsw(3);
671 XYZ_to_RSW(xB.Rows(1,3), vB, dv, dotRsw);
672
673 // Clock Correction
674 // ----------------
675 double dClk = rtnClk - (xB(4) - dc) * t_CST::c;
676
677 if (sd) {
678 sd->ID = prn.mid(1).toInt();
679 sd->IOD = eph->IOD();
680 sd->Clock.DeltaA0 = dClk;
681 sd->Clock.DeltaA1 = 0.0; // TODO
682 sd->Clock.DeltaA2 = 0.0; // TODO
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);
689 }
690
691 outLine.sprintf("%d %.1f %s %3d %10.3f %8.3f %8.3f %8.3f\n",
692 GPSweek, GPSweeks, eph->prn().toString().c_str(),
693 eph->IOD(), dClk, rsw(1), rsw(2), rsw(3));
694
695 double relativity = -2.0 * DotProduct(xP, rtnVel) / t_CST::c;
696 double sp3Clk = (rtnClk - relativity) / t_CST::c; // in seconds
697
698 if (_rnx) {
699 _rnx->write(GPSweek, GPSweeks, prn, sp3Clk);
700 }
701 if (_sp3) {
702 _sp3->write(GPSweek, GPSweeks, prn, rtnCoM, sp3Clk);
703 }
704}
705
706// Transform Coordinates
707////////////////////////////////////////////////////////////////////////////
708void bncRtnetUploadCaster::crdTrafo(int GPSWeek, ColumnVector& xyz,
709 double& dc) {
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
729 // Specify approximate center of area
730 // ----------------------------------
731 ColumnVector meanSta(3);
732
733 if (_crdTrafo == "ETRF2000") {
734 meanSta(1) = 3661090.0;
735 meanSta(2) = 845230.0;
736 meanSta(3) = 5136850.0;
737 }
738 else if (_crdTrafo == "NAD83") {
739 meanSta(1) = -1092950.0;
740 meanSta(2) = -4383600.0;
741 meanSta(3) = 4487420.0;
742 }
743 else if (_crdTrafo == "GDA94") {
744 meanSta(1) = -4052050.0;
745 meanSta(2) = 4212840.0;
746 meanSta(3) = -2545110.0;
747 }
748 else if (_crdTrafo == "SIRGAS2000") {
749 meanSta(1) = 3740860.0;
750 meanSta(2) = -4964290.0;
751 meanSta(3) = -1425420.0;
752 }
753 else if (_crdTrafo == "SIRGAS95") {
754 meanSta(1) = 3135390.0;
755 meanSta(2) = -5017670.0;
756 meanSta(3) = -2374440.0;
757 }
758 else if (_crdTrafo == "DREF91") {
759 meanSta(1) = 3959579.0;
760 meanSta(2) = 721719.0;
761 meanSta(3) = 4931539.0;
762 }
763 else if (_crdTrafo == "Custom") {
764 meanSta(1) = 0.0; // TODO
765 meanSta(2) = 0.0; // TODO
766 meanSta(3) = 0.0; // TODO
767 }
768
769 // Clock correction proportional to topocentric distance to satellites
770 // -------------------------------------------------------------------
771 double rho = (xyz - meanSta).norm_Frobenius();
772 dc = rho * (sc - 1.0) / sc / t_CST::c;
773
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.