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