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 |
|
---|
24 | using namespace std;
|
---|
25 |
|
---|
26 | // Constructor
|
---|
27 | ////////////////////////////////////////////////////////////////////////////
|
---|
28 | bncRtnetUploadCaster::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.9963;
|
---|
113 | _dy = -1.9024;
|
---|
114 | _dz = -0.5210;
|
---|
115 | _dxr = 0.0005;
|
---|
116 | _dyr = -0.0006;
|
---|
117 | _dzr = -0.0013;
|
---|
118 | _ox = -0.025915;
|
---|
119 | _oy = -0.009426;
|
---|
120 | _oz = -0.011599;
|
---|
121 | _oxr = -0.000067;
|
---|
122 | _oyr = 0.000757;
|
---|
123 | _ozr = 0.000051;
|
---|
124 | _sc = 0.78;
|
---|
125 | _scr = -0.10;
|
---|
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 = 0.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 == "Custom") {
|
---|
180 | _dx = settings.value("trafo_dx").toDouble();
|
---|
181 | _dy = settings.value("trafo_dy").toDouble();
|
---|
182 | _dz = settings.value("trafo_dz").toDouble();
|
---|
183 | _dxr = settings.value("trafo_dxr").toDouble();
|
---|
184 | _dyr = settings.value("trafo_dyr").toDouble();
|
---|
185 | _dzr = settings.value("trafo_dzr").toDouble();
|
---|
186 | _ox = settings.value("trafo_ox").toDouble();
|
---|
187 | _oy = settings.value("trafo_oy").toDouble();
|
---|
188 | _oz = settings.value("trafo_oz").toDouble();
|
---|
189 | _oxr = settings.value("trafo_oxr").toDouble();
|
---|
190 | _oyr = settings.value("trafo_oyr").toDouble();
|
---|
191 | _ozr = settings.value("trafo_ozr").toDouble();
|
---|
192 | _sc = settings.value("trafo_sc").toDouble();
|
---|
193 | _scr = settings.value("trafo_scr").toDouble();
|
---|
194 | _t0 = settings.value("trafo_t0").toDouble();
|
---|
195 | }
|
---|
196 | }
|
---|
197 |
|
---|
198 | // Destructor
|
---|
199 | ////////////////////////////////////////////////////////////////////////////
|
---|
200 | bncRtnetUploadCaster::~bncRtnetUploadCaster() {
|
---|
201 | if (isRunning()) {
|
---|
202 | wait();
|
---|
203 | }
|
---|
204 | delete _rnx;
|
---|
205 | delete _sp3;
|
---|
206 | delete _ephUser;
|
---|
207 | delete _usedEph;
|
---|
208 | }
|
---|
209 |
|
---|
210 | //
|
---|
211 | ////////////////////////////////////////////////////////////////////////////
|
---|
212 | void bncRtnetUploadCaster::decodeRtnetStream(char* buffer, int bufLen) {
|
---|
213 |
|
---|
214 | QMutexLocker locker(&_mutex);
|
---|
215 |
|
---|
216 | // Append to internal buffer
|
---|
217 | // -------------------------
|
---|
218 | _rtnetStreamBuffer.append(QByteArray(buffer, bufLen));
|
---|
219 |
|
---|
220 | // Select buffer part that contains last epoch
|
---|
221 | // -------------------------------------------
|
---|
222 | QStringList lines;
|
---|
223 | int iEpoBeg = _rtnetStreamBuffer.lastIndexOf('*'); // begin of last epoch
|
---|
224 | if (iEpoBeg == -1) {
|
---|
225 | _rtnetStreamBuffer.clear();
|
---|
226 | return;
|
---|
227 | }
|
---|
228 | _rtnetStreamBuffer = _rtnetStreamBuffer.mid(iEpoBeg);
|
---|
229 |
|
---|
230 | int iEpoEnd = _rtnetStreamBuffer.lastIndexOf("EOE"); // end of last epoch
|
---|
231 | if (iEpoEnd == -1) {
|
---|
232 | return;
|
---|
233 | }
|
---|
234 | else {
|
---|
235 | lines = _rtnetStreamBuffer.left(iEpoEnd).split('\n', QString::SkipEmptyParts);
|
---|
236 | _rtnetStreamBuffer = _rtnetStreamBuffer.mid(iEpoEnd+3);
|
---|
237 | }
|
---|
238 |
|
---|
239 | if (lines.size() < 2) {
|
---|
240 | return;
|
---|
241 | }
|
---|
242 |
|
---|
243 | // Keep the last unfinished line in buffer
|
---|
244 | // ---------------------------------------
|
---|
245 | int iLastEOL = _rtnetStreamBuffer.lastIndexOf('\n');
|
---|
246 | if (iLastEOL != -1) {
|
---|
247 | _rtnetStreamBuffer = _rtnetStreamBuffer.mid(iLastEOL+1);
|
---|
248 | }
|
---|
249 |
|
---|
250 | // Read first line (with epoch time)
|
---|
251 | // ---------------------------------
|
---|
252 | QTextStream in(lines[0].toAscii());
|
---|
253 | QString hlp;
|
---|
254 | int year, month, day, hour, min;
|
---|
255 | double sec;
|
---|
256 | in >> hlp >> year >> month >> day >> hour >> min >> sec;
|
---|
257 | bncTime epoTime; epoTime.set( year, month, day, hour, min, sec);
|
---|
258 |
|
---|
259 | emit(newMessage("bncRtnetUploadCaster: decode " +
|
---|
260 | QByteArray(epoTime.datestr().c_str()) + " " +
|
---|
261 | QByteArray(epoTime.timestr().c_str()) + " " +
|
---|
262 | _casterID.toAscii(), false));
|
---|
263 |
|
---|
264 | struct ClockOrbit co;
|
---|
265 | memset(&co, 0, sizeof(co));
|
---|
266 | co.GPSEpochTime = static_cast<int>(epoTime.gpssec());
|
---|
267 | co.GLONASSEpochTime = static_cast<int>(fmod(epoTime.gpssec(), 86400.0))
|
---|
268 | + 3 * 3600 - gnumleap(year, month, day);
|
---|
269 | co.ClockDataSupplied = 1;
|
---|
270 | co.OrbitDataSupplied = 1;
|
---|
271 | co.SatRefDatum = DATUM_ITRF;
|
---|
272 | co.SSRIOD = _IOD;
|
---|
273 | co.SSRProviderID = _PID; // 256 .. BKG, 257 ... EUREF
|
---|
274 | co.SSRSolutionID = _SID;
|
---|
275 |
|
---|
276 | struct Bias bias;
|
---|
277 | memset(&bias, 0, sizeof(bias));
|
---|
278 | bias.GPSEpochTime = co.GPSEpochTime;
|
---|
279 | bias.GLONASSEpochTime = co.GLONASSEpochTime;
|
---|
280 |
|
---|
281 | // Default Update Interval
|
---|
282 | // -----------------------
|
---|
283 | int clkUpdInd = 2; // 5 sec
|
---|
284 | int ephUpdInd = clkUpdInd; // default
|
---|
285 | if (_samplRtcmEphCorr == 10.0) {
|
---|
286 | ephUpdInd = 3;
|
---|
287 | }
|
---|
288 | else if (_samplRtcmEphCorr == 15.0) {
|
---|
289 | ephUpdInd = 4;
|
---|
290 | }
|
---|
291 | else if (_samplRtcmEphCorr == 30.0) {
|
---|
292 | ephUpdInd = 5;
|
---|
293 | }
|
---|
294 | else if (_samplRtcmEphCorr == 60.0) {
|
---|
295 | ephUpdInd = 6;
|
---|
296 | }
|
---|
297 | else if (_samplRtcmEphCorr == 120.0) {
|
---|
298 | ephUpdInd = 7;
|
---|
299 | }
|
---|
300 | else if (_samplRtcmEphCorr == 240.0) {
|
---|
301 | ephUpdInd = 8;
|
---|
302 | }
|
---|
303 | else if (_samplRtcmEphCorr == 300.0) {
|
---|
304 | ephUpdInd = 9;
|
---|
305 | }
|
---|
306 | else if (_samplRtcmEphCorr == 600.0) {
|
---|
307 | ephUpdInd = 10;
|
---|
308 | }
|
---|
309 | else if (_samplRtcmEphCorr == 900.0) {
|
---|
310 | ephUpdInd = 11;
|
---|
311 | }
|
---|
312 |
|
---|
313 | co.UpdateInterval = clkUpdInd;
|
---|
314 | bias.UpdateInterval = clkUpdInd;
|
---|
315 |
|
---|
316 | for (int ii = 1; ii < lines.size(); ii++) {
|
---|
317 |
|
---|
318 | QString prn;
|
---|
319 | ColumnVector rtnAPC;
|
---|
320 | ColumnVector rtnVel;
|
---|
321 | ColumnVector rtnCoM;
|
---|
322 | double rtnClk;
|
---|
323 |
|
---|
324 | QTextStream in(lines[ii].toAscii());
|
---|
325 |
|
---|
326 | in >> prn;
|
---|
327 |
|
---|
328 | t_eph* eph = 0;
|
---|
329 | const bncEphUser::t_ephPair* ephPair = _ephUser->ephPair(prn);
|
---|
330 | if (ephPair) {
|
---|
331 |
|
---|
332 | eph = ephPair->last;
|
---|
333 |
|
---|
334 | // Use previous ephemeris if the last one is too recent
|
---|
335 | // ----------------------------------------------------
|
---|
336 | const int MINAGE = 60; // seconds
|
---|
337 | if (ephPair->prev && eph->receptDateTime().isValid() &&
|
---|
338 | eph->receptDateTime().secsTo(currentDateAndTimeGPS()) < MINAGE) {
|
---|
339 | eph = ephPair->prev;
|
---|
340 | }
|
---|
341 |
|
---|
342 | // Make sure the clock messages refer to same IOD as orbit messages
|
---|
343 | // ----------------------------------------------------------------
|
---|
344 | if (_usedEph) {
|
---|
345 | if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
|
---|
346 | (*_usedEph)[prn] = eph;
|
---|
347 | }
|
---|
348 | else {
|
---|
349 | eph = 0;
|
---|
350 | if (_usedEph->contains(prn)) {
|
---|
351 | t_eph* usedEph = _usedEph->value(prn);
|
---|
352 | if (usedEph == ephPair->last) {
|
---|
353 | eph = ephPair->last;
|
---|
354 | }
|
---|
355 | else if (usedEph == ephPair->prev) {
|
---|
356 | eph = ephPair->prev;
|
---|
357 | }
|
---|
358 | }
|
---|
359 | }
|
---|
360 | }
|
---|
361 | }
|
---|
362 |
|
---|
363 | if (eph) {
|
---|
364 |
|
---|
365 | while (true) {
|
---|
366 | QString key;
|
---|
367 | int numVal = 0;
|
---|
368 | in >> key >> numVal;
|
---|
369 | if (in.status() != QTextStream::Ok) {
|
---|
370 | break;
|
---|
371 | }
|
---|
372 | if (key == "APC") {
|
---|
373 | rtnAPC.ReSize(3);
|
---|
374 | in >> rtnAPC[0] >> rtnAPC[1] >> rtnAPC[2];
|
---|
375 | }
|
---|
376 | else if (key == "Clk") {
|
---|
377 | in >> rtnClk;
|
---|
378 | }
|
---|
379 | else if (key == "Vel") {
|
---|
380 | rtnVel.ReSize(3);
|
---|
381 | in >> rtnVel[0] >> rtnVel[1] >> rtnVel[2];
|
---|
382 | }
|
---|
383 | else if (key == "CoM") {
|
---|
384 | rtnCoM.ReSize(3);
|
---|
385 | in >> rtnCoM[0] >> rtnCoM[1] >> rtnCoM[2];
|
---|
386 | }
|
---|
387 | else {
|
---|
388 | for (int ii = 0; ii < numVal; ii++) {
|
---|
389 | double dummy;
|
---|
390 | in >> dummy;
|
---|
391 | }
|
---|
392 | }
|
---|
393 | }
|
---|
394 | struct ClockOrbit::SatData* sd = 0;
|
---|
395 | if (prn[0] == 'G') {
|
---|
396 | sd = co.Sat + co.NumberOfGPSSat;
|
---|
397 | ++co.NumberOfGPSSat;
|
---|
398 | }
|
---|
399 | else if (prn[0] == 'R') {
|
---|
400 | sd = co.Sat + CLOCKORBIT_NUMGPS + co.NumberOfGLONASSSat;
|
---|
401 | ++co.NumberOfGLONASSSat;
|
---|
402 | }
|
---|
403 | if (sd) {
|
---|
404 | QString outLine;
|
---|
405 | processSatellite(eph, epoTime.gpsw(), epoTime.gpssec(), prn,
|
---|
406 | rtnAPC, rtnClk, rtnVel, rtnCoM, sd, outLine);
|
---|
407 | }
|
---|
408 |
|
---|
409 | struct Bias::BiasSat* biasSat = 0;
|
---|
410 | if (prn[0] == 'G') {
|
---|
411 | biasSat = bias.Sat + bias.NumberOfGPSSat;
|
---|
412 | ++bias.NumberOfGPSSat;
|
---|
413 | }
|
---|
414 | else if (prn[0] == 'R') {
|
---|
415 | biasSat = bias.Sat + CLOCKORBIT_NUMGPS + bias.NumberOfGLONASSSat;
|
---|
416 | ++bias.NumberOfGLONASSSat;
|
---|
417 | }
|
---|
418 |
|
---|
419 | // Coefficient of Ionosphere-Free LC
|
---|
420 | // ---------------------------------
|
---|
421 | // const static double a_L1_GPS = 2.54572778;
|
---|
422 | // const static double a_L2_GPS = -1.54572778;
|
---|
423 | // const static double a_L1_Glo = 2.53125000;
|
---|
424 | // const static double a_L2_Glo = -1.53125000;
|
---|
425 |
|
---|
426 | if (biasSat) {
|
---|
427 | biasSat->ID = prn.mid(1).toInt();
|
---|
428 | biasSat->NumberOfCodeBiases = 3;
|
---|
429 | if (prn[0] == 'G') {
|
---|
430 | biasSat->Biases[0].Type = CODETYPEGPS_L1_Z;
|
---|
431 | // biasSat->Biases[0].Bias = - a_L2_GPS * xx(10);
|
---|
432 | biasSat->Biases[0].Bias = 0.0;
|
---|
433 | biasSat->Biases[1].Type = CODETYPEGPS_L1_CA;
|
---|
434 | // biasSat->Biases[1].Bias = - a_L2_GPS * xx(10) + xx(9);
|
---|
435 | biasSat->Biases[1].Bias = 0.0;
|
---|
436 | biasSat->Biases[2].Type = CODETYPEGPS_L2_Z;
|
---|
437 | // biasSat->Biases[2].Bias = a_L1_GPS * xx(10);
|
---|
438 | biasSat->Biases[2].Bias = 0.0;
|
---|
439 | }
|
---|
440 | else if (prn[0] == 'R') {
|
---|
441 | biasSat->Biases[0].Type = CODETYPEGLONASS_L1_P;
|
---|
442 | // biasSat->Biases[0].Bias = - a_L2_Glo * xx(10);
|
---|
443 | biasSat->Biases[0].Bias = 0.0;
|
---|
444 | biasSat->Biases[1].Type = CODETYPEGLONASS_L1_CA;
|
---|
445 | // biasSat->Biases[1].Bias = - a_L2_Glo * xx(10) + xx(9);
|
---|
446 | biasSat->Biases[1].Bias = 0.0;
|
---|
447 | biasSat->Biases[2].Type = CODETYPEGLONASS_L2_P;
|
---|
448 | // biasSat->Biases[2].Bias = a_L1_Glo * xx(10);
|
---|
449 | biasSat->Biases[2].Bias = 0.0;
|
---|
450 | }
|
---|
451 | }
|
---|
452 | }
|
---|
453 | }
|
---|
454 |
|
---|
455 | QByteArray hlpBufferCo;
|
---|
456 |
|
---|
457 | // Orbit and Clock Corrections together
|
---|
458 | // ------------------------------------
|
---|
459 | if (_samplRtcmEphCorr == 0.0) {
|
---|
460 | if (co.NumberOfGPSSat > 0 || co.NumberOfGLONASSSat > 0) {
|
---|
461 | char obuffer[CLOCKORBIT_BUFFERSIZE];
|
---|
462 | int len = MakeClockOrbit(&co, COTYPE_AUTO, 0, obuffer, sizeof(obuffer));
|
---|
463 | if (len > 0) {
|
---|
464 | hlpBufferCo = QByteArray(obuffer, len);
|
---|
465 | }
|
---|
466 | }
|
---|
467 | }
|
---|
468 |
|
---|
469 | // Orbit and Clock Corrections separately
|
---|
470 | // --------------------------------------
|
---|
471 | else {
|
---|
472 | if (co.NumberOfGPSSat > 0) {
|
---|
473 | char obuffer[CLOCKORBIT_BUFFERSIZE];
|
---|
474 | if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
|
---|
475 | co.UpdateInterval = ephUpdInd;
|
---|
476 | int len1 = MakeClockOrbit(&co, COTYPE_GPSORBIT, 1, obuffer, sizeof(obuffer));
|
---|
477 | co.UpdateInterval = clkUpdInd;
|
---|
478 | if (len1 > 0) {
|
---|
479 | hlpBufferCo += QByteArray(obuffer, len1);
|
---|
480 | }
|
---|
481 | }
|
---|
482 | int mmsg = (co.NumberOfGLONASSSat > 0) ? 1 : 0;
|
---|
483 | int len2 = MakeClockOrbit(&co, COTYPE_GPSCLOCK, mmsg, obuffer, sizeof(obuffer));
|
---|
484 | if (len2 > 0) {
|
---|
485 | hlpBufferCo += QByteArray(obuffer, len2);
|
---|
486 | }
|
---|
487 | }
|
---|
488 | if (co.NumberOfGLONASSSat > 0) {
|
---|
489 | char obuffer[CLOCKORBIT_BUFFERSIZE];
|
---|
490 | if (fmod(epoTime.gpssec(), _samplRtcmEphCorr) == 0.0) {
|
---|
491 | co.UpdateInterval = ephUpdInd;
|
---|
492 | int len1 = MakeClockOrbit(&co, COTYPE_GLONASSORBIT, 1, obuffer, sizeof(obuffer));
|
---|
493 | co.UpdateInterval = clkUpdInd;
|
---|
494 | if (len1 > 0) {
|
---|
495 | hlpBufferCo += QByteArray(obuffer, len1);
|
---|
496 | }
|
---|
497 | }
|
---|
498 | int len2 = MakeClockOrbit(&co, COTYPE_GLONASSCLOCK, 0, obuffer, sizeof(obuffer));
|
---|
499 | if (len2 > 0) {
|
---|
500 | hlpBufferCo += QByteArray(obuffer, len2);
|
---|
501 | }
|
---|
502 | }
|
---|
503 | }
|
---|
504 |
|
---|
505 | // Biases
|
---|
506 | // ------
|
---|
507 | QByteArray hlpBufferBias;
|
---|
508 | if (bias.NumberOfGPSSat > 0 || bias.NumberOfGLONASSSat > 0) {
|
---|
509 | char obuffer[CLOCKORBIT_BUFFERSIZE];
|
---|
510 | int len = MakeBias(&bias, BTYPE_AUTO, 0, obuffer, sizeof(obuffer));
|
---|
511 | if (len > 0) {
|
---|
512 | hlpBufferBias = QByteArray(obuffer, len);
|
---|
513 | }
|
---|
514 | }
|
---|
515 |
|
---|
516 | _outBuffer += hlpBufferCo + hlpBufferBias;
|
---|
517 | }
|
---|
518 |
|
---|
519 | //
|
---|
520 | ////////////////////////////////////////////////////////////////////////////
|
---|
521 | void bncRtnetUploadCaster::processSatellite(t_eph* eph, int GPSweek,
|
---|
522 | double GPSweeks, const QString& prn,
|
---|
523 | const ColumnVector& rtnAPC,
|
---|
524 | double rtnClk,
|
---|
525 | const ColumnVector& rtnVel,
|
---|
526 | const ColumnVector& rtnCoM,
|
---|
527 | struct ClockOrbit::SatData* sd,
|
---|
528 | QString& outLine) {
|
---|
529 |
|
---|
530 | // Broadcast Position and Velocity
|
---|
531 | // -------------------------------
|
---|
532 | ColumnVector xB(4);
|
---|
533 | ColumnVector vB(3);
|
---|
534 | eph->position(GPSweek, GPSweeks, xB.data(), vB.data());
|
---|
535 |
|
---|
536 | // Precise Position
|
---|
537 | // ----------------
|
---|
538 | ColumnVector xP = _CoM ? rtnCoM : rtnAPC;
|
---|
539 |
|
---|
540 | double dc = 0.0;
|
---|
541 | if (_crdTrafo != "IGS08") {
|
---|
542 | crdTrafo(GPSweek, xP, dc);
|
---|
543 | }
|
---|
544 |
|
---|
545 | // Difference in xyz
|
---|
546 | // -----------------
|
---|
547 | ColumnVector dx = xB.Rows(1,3) - xP;
|
---|
548 | ColumnVector dv = vB - rtnVel;
|
---|
549 |
|
---|
550 | // Difference in RSW
|
---|
551 | // -----------------
|
---|
552 | ColumnVector rsw(3);
|
---|
553 | XYZ_to_RSW(xB.Rows(1,3), vB, dx, rsw);
|
---|
554 |
|
---|
555 | ColumnVector dotRsw(3);
|
---|
556 | XYZ_to_RSW(xB.Rows(1,3), vB, dv, dotRsw);
|
---|
557 |
|
---|
558 | // Clock Correction
|
---|
559 | // ----------------
|
---|
560 | double dClk = rtnClk - (xB(4) - dc) * t_CST::c;
|
---|
561 |
|
---|
562 | if (sd) {
|
---|
563 | sd->ID = prn.mid(1).toInt();
|
---|
564 | sd->IOD = eph->IOD();
|
---|
565 | sd->Clock.DeltaA0 = dClk;
|
---|
566 | sd->Orbit.DeltaRadial = rsw(1);
|
---|
567 | sd->Orbit.DeltaAlongTrack = rsw(2);
|
---|
568 | sd->Orbit.DeltaCrossTrack = rsw(3);
|
---|
569 | sd->Orbit.DotDeltaRadial = dotRsw(1);
|
---|
570 | sd->Orbit.DotDeltaAlongTrack = dotRsw(2);
|
---|
571 | sd->Orbit.DotDeltaCrossTrack = dotRsw(3);
|
---|
572 | }
|
---|
573 |
|
---|
574 | outLine.sprintf("%d %.1f %s %3d %10.3f %8.3f %8.3f %8.3f\n",
|
---|
575 | GPSweek, GPSweeks, eph->prn().toAscii().data(),
|
---|
576 | eph->IOD(), dClk, rsw(1), rsw(2), rsw(3));
|
---|
577 |
|
---|
578 | double relativity = -2.0 * DotProduct(xP, rtnVel) / t_CST::c;
|
---|
579 | double sp3Clk = (rtnClk - relativity) / t_CST::c; // in seconds
|
---|
580 |
|
---|
581 | if (_rnx) {
|
---|
582 | _rnx->write(GPSweek, GPSweeks, prn, sp3Clk);
|
---|
583 | }
|
---|
584 | if (_sp3) {
|
---|
585 | _sp3->write(GPSweek, GPSweeks, prn, rtnCoM, sp3Clk);
|
---|
586 | }
|
---|
587 | }
|
---|
588 |
|
---|
589 | // Transform Coordinates
|
---|
590 | ////////////////////////////////////////////////////////////////////////////
|
---|
591 | void bncRtnetUploadCaster::crdTrafo(int GPSWeek, ColumnVector& xyz,
|
---|
592 | double& dc) {
|
---|
593 |
|
---|
594 | // Current epoch minus 2000.0 in years
|
---|
595 | // ------------------------------------
|
---|
596 | double dt = (GPSWeek - (1042.0+6.0/7.0)) / 365.2422 * 7.0 + 2000.0 - _t0;
|
---|
597 |
|
---|
598 | ColumnVector dx(3);
|
---|
599 |
|
---|
600 | dx(1) = _dx + dt * _dxr;
|
---|
601 | dx(2) = _dy + dt * _dyr;
|
---|
602 | dx(3) = _dz + dt * _dzr;
|
---|
603 |
|
---|
604 | static const double arcSec = 180.0 * 3600.0 / M_PI;
|
---|
605 |
|
---|
606 | double ox = (_ox + dt * _oxr) / arcSec;
|
---|
607 | double oy = (_oy + dt * _oyr) / arcSec;
|
---|
608 | double oz = (_oz + dt * _ozr) / arcSec;
|
---|
609 |
|
---|
610 | double sc = 1.0 + _sc * 1e-9 + dt * _scr * 1e-9;
|
---|
611 |
|
---|
612 | // Specify approximate center of area
|
---|
613 | // ----------------------------------
|
---|
614 | ColumnVector meanSta(3);
|
---|
615 |
|
---|
616 | if (_crdTrafo == "ETRF2000") {
|
---|
617 | meanSta(1) = 3661090.0;
|
---|
618 | meanSta(2) = 845230.0;
|
---|
619 | meanSta(3) = 5136850.0;
|
---|
620 | }
|
---|
621 | else if (_crdTrafo == "NAD83") {
|
---|
622 | meanSta(1) = -1092950.0;
|
---|
623 | meanSta(2) = -4383600.0;
|
---|
624 | meanSta(3) = 4487420.0;
|
---|
625 | }
|
---|
626 | else if (_crdTrafo == "GDA94") {
|
---|
627 | meanSta(1) = -4052050.0;
|
---|
628 | meanSta(2) = 4212840.0;
|
---|
629 | meanSta(3) = -2545110.0;
|
---|
630 | }
|
---|
631 | else if (_crdTrafo == "SIRGAS2000") {
|
---|
632 | meanSta(1) = 3740860.0;
|
---|
633 | meanSta(2) = -4964290.0;
|
---|
634 | meanSta(3) = -1425420.0;
|
---|
635 | }
|
---|
636 | else if (_crdTrafo == "SIRGAS95") {
|
---|
637 | meanSta(1) = 3135390.0;
|
---|
638 | meanSta(2) = -5017670.0;
|
---|
639 | meanSta(3) = -2374440.0;
|
---|
640 | }
|
---|
641 | else if (_crdTrafo == "Custom") {
|
---|
642 | meanSta(1) = 0.0; // TODO
|
---|
643 | meanSta(2) = 0.0; // TODO
|
---|
644 | meanSta(3) = 0.0; // TODO
|
---|
645 | }
|
---|
646 |
|
---|
647 | // Clock correction proportional to topocentric distance to satellites
|
---|
648 | // -------------------------------------------------------------------
|
---|
649 | double rho = (xyz - meanSta).norm_Frobenius();
|
---|
650 | dc = rho * (sc - 1.0) / sc / t_CST::c;
|
---|
651 |
|
---|
652 | Matrix rMat(3,3);
|
---|
653 | rMat(1,1) = 1.0;
|
---|
654 | rMat(1,2) = -oz;
|
---|
655 | rMat(1,3) = oy;
|
---|
656 | rMat(2,1) = oz;
|
---|
657 | rMat(2,2) = 1.0;
|
---|
658 | rMat(2,3) = -ox;
|
---|
659 | rMat(3,1) = -oy;
|
---|
660 | rMat(3,2) = ox;
|
---|
661 | rMat(3,3) = 1.0;
|
---|
662 |
|
---|
663 | xyz = sc * rMat * xyz + dx;
|
---|
664 | }
|
---|
665 |
|
---|