[3172] | 1 | /* -------------------------------------------------------------------------
|
---|
| 2 | * BKG NTRIP Server
|
---|
| 3 | * -------------------------------------------------------------------------
|
---|
| 4 | *
|
---|
| 5 | * Class: bncUploadCaster
|
---|
| 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 "bncuploadcaster.h"
|
---|
| 19 | #include "bncsettings.h"
|
---|
| 20 | #include "bncversion.h"
|
---|
| 21 | #include "bncapp.h"
|
---|
[3182] | 22 | #include "bncclockrinex.h"
|
---|
| 23 | #include "bncsp3.h"
|
---|
[3172] | 24 |
|
---|
| 25 | using namespace std;
|
---|
| 26 |
|
---|
| 27 | // Constructor
|
---|
| 28 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 29 | bncUploadCaster::bncUploadCaster(const QString& mountpoint,
|
---|
| 30 | const QString& outHost, int outPort,
|
---|
[3174] | 31 | const QString& password,
|
---|
| 32 | const QString& crdTrafo, bool CoM,
|
---|
[3187] | 33 | const QString& sp3FileName,
|
---|
[3182] | 34 | const QString& rnxFileName,
|
---|
[3172] | 35 | const QString& outFileName) {
|
---|
| 36 | bncSettings settings;
|
---|
| 37 |
|
---|
[3182] | 38 | connect(this, SIGNAL(newMessage(QByteArray,bool)),
|
---|
| 39 | ((bncApp*)qApp), SLOT(slotMessage(const QByteArray,bool)));
|
---|
| 40 |
|
---|
[3172] | 41 | _mountpoint = mountpoint;
|
---|
| 42 | _outHost = outHost;
|
---|
| 43 | _outPort = outPort;
|
---|
| 44 | _password = password;
|
---|
[3174] | 45 | _crdTrafo = crdTrafo;
|
---|
| 46 | _CoM = CoM;
|
---|
[3172] | 47 |
|
---|
| 48 | _outSocket = 0;
|
---|
| 49 | _sOpenTrial = 0;
|
---|
| 50 |
|
---|
[3207] | 51 | _isToBeDeleted = false;
|
---|
| 52 |
|
---|
[3185] | 53 | // Raw Output
|
---|
| 54 | // ----------
|
---|
| 55 | if (!outFileName.isEmpty()) {
|
---|
| 56 | _outFile = new bncoutf(outFileName, "", 0);
|
---|
[3172] | 57 | }
|
---|
| 58 | else {
|
---|
[3185] | 59 | _outFile = 0;
|
---|
[3172] | 60 | }
|
---|
[3182] | 61 |
|
---|
| 62 | // RINEX writer
|
---|
| 63 | // ------------
|
---|
[3185] | 64 | if (!rnxFileName.isEmpty()) {
|
---|
| 65 | _rnx = new bncClockRinex(rnxFileName, "", 0);
|
---|
[3182] | 66 | }
|
---|
| 67 | else {
|
---|
[3185] | 68 | _rnx = 0;
|
---|
[3182] | 69 | }
|
---|
| 70 |
|
---|
| 71 | // SP3 writer
|
---|
| 72 | // ----------
|
---|
[3185] | 73 | if (!sp3FileName.isEmpty()) {
|
---|
| 74 | _sp3 = new bncSP3(sp3FileName, "", 0);
|
---|
[3182] | 75 | }
|
---|
| 76 | else {
|
---|
[3185] | 77 | _sp3 = 0;
|
---|
[3182] | 78 | }
|
---|
| 79 |
|
---|
| 80 | // Set Transformation Parameters
|
---|
| 81 | // -----------------------------
|
---|
| 82 | if (_crdTrafo == "ETRF2000") {
|
---|
| 83 | _dx = 0.0541;
|
---|
| 84 | _dy = 0.0502;
|
---|
| 85 | _dz = -0.0538;
|
---|
| 86 | _dxr = -0.0002;
|
---|
| 87 | _dyr = 0.0001;
|
---|
| 88 | _dzr = -0.0018;
|
---|
| 89 | _ox = 0.000891;
|
---|
| 90 | _oy = 0.005390;
|
---|
| 91 | _oz = -0.008712;
|
---|
| 92 | _oxr = 0.000081;
|
---|
| 93 | _oyr = 0.000490;
|
---|
| 94 | _ozr = -0.000792;
|
---|
| 95 | _sc = 0.40;
|
---|
| 96 | _scr = 0.08;
|
---|
| 97 | _t0 = 2000.0;
|
---|
| 98 | }
|
---|
| 99 | else if (_crdTrafo == "NAD83") {
|
---|
| 100 | _dx = 0.9963;
|
---|
| 101 | _dy = -1.9024;
|
---|
| 102 | _dz = -0.5210;
|
---|
| 103 | _dxr = 0.0005;
|
---|
| 104 | _dyr = -0.0006;
|
---|
| 105 | _dzr = -0.0013;
|
---|
| 106 | _ox = 0.025915;
|
---|
| 107 | _oy = 0.009426;
|
---|
| 108 | _oz = 0.011599;
|
---|
| 109 | _oxr = 0.000067;
|
---|
| 110 | _oyr = -0.000757;
|
---|
| 111 | _ozr = -0.000051;
|
---|
| 112 | _sc = 0.78;
|
---|
| 113 | _scr = -0.10;
|
---|
| 114 | _t0 = 1997.0;
|
---|
| 115 | }
|
---|
| 116 | else if (_crdTrafo == "GDA94") {
|
---|
| 117 | _dx = -0.07973;
|
---|
| 118 | _dy = -0.00686;
|
---|
| 119 | _dz = 0.03803;
|
---|
| 120 | _dxr = 0.00225;
|
---|
| 121 | _dyr = -0.00062;
|
---|
| 122 | _dzr = -0.00056;
|
---|
| 123 | _ox = 0.0000351;
|
---|
| 124 | _oy = -0.0021211;
|
---|
| 125 | _oz = -0.0021411;
|
---|
| 126 | _oxr = -0.0014707;
|
---|
| 127 | _oyr = -0.0011443;
|
---|
| 128 | _ozr = -0.0011701;
|
---|
| 129 | _sc = 6.636;
|
---|
| 130 | _scr = 0.294;
|
---|
| 131 | _t0 = 1994.0;
|
---|
| 132 | }
|
---|
| 133 | else if (_crdTrafo == "SIRGAS2000") {
|
---|
| 134 | _dx = -0.0051;
|
---|
| 135 | _dy = -0.0065;
|
---|
| 136 | _dz = -0.0099;
|
---|
| 137 | _dxr = 0.0000;
|
---|
| 138 | _dyr = 0.0000;
|
---|
| 139 | _dzr = 0.0000;
|
---|
| 140 | _ox = 0.000150;
|
---|
| 141 | _oy = 0.000020;
|
---|
| 142 | _oz = 0.000021;
|
---|
| 143 | _oxr = 0.000000;
|
---|
| 144 | _oyr = 0.000000;
|
---|
| 145 | _ozr = 0.000000;
|
---|
| 146 | _sc = 0.000;
|
---|
| 147 | _scr = 0.000;
|
---|
| 148 | _t0 = 0000.0;
|
---|
| 149 | }
|
---|
| 150 | else if (_crdTrafo == "SIRGAS95") {
|
---|
| 151 | _dx = 0.0077;
|
---|
| 152 | _dy = 0.0058;
|
---|
| 153 | _dz = -0.0138;
|
---|
| 154 | _dxr = 0.0000;
|
---|
| 155 | _dyr = 0.0000;
|
---|
| 156 | _dzr = 0.0000;
|
---|
| 157 | _ox = 0.000000;
|
---|
| 158 | _oy = 0.000000;
|
---|
| 159 | _oz = -0.000030;
|
---|
| 160 | _oxr = 0.000000;
|
---|
| 161 | _oyr = 0.000000;
|
---|
| 162 | _ozr = 0.000000;
|
---|
| 163 | _sc = 1.570;
|
---|
| 164 | _scr = 0.000;
|
---|
| 165 | _t0 = 0000.0;
|
---|
| 166 | }
|
---|
| 167 | else if (_crdTrafo == "Custom") {
|
---|
| 168 | _dx = settings.value("trafo_dx").toDouble();
|
---|
| 169 | _dy = settings.value("trafo_dy").toDouble();
|
---|
| 170 | _dz = settings.value("trafo_dz").toDouble();
|
---|
| 171 | _dxr = settings.value("trafo_dxr").toDouble();
|
---|
| 172 | _dyr = settings.value("trafo_dyr").toDouble();
|
---|
| 173 | _dzr = settings.value("trafo_dzr").toDouble();
|
---|
| 174 | _ox = settings.value("trafo_ox").toDouble();
|
---|
| 175 | _oy = settings.value("trafo_oy").toDouble();
|
---|
| 176 | _oz = settings.value("trafo_oz").toDouble();
|
---|
| 177 | _oxr = settings.value("trafo_oxr").toDouble();
|
---|
| 178 | _oyr = settings.value("trafo_oyr").toDouble();
|
---|
| 179 | _ozr = settings.value("trafo_ozr").toDouble();
|
---|
| 180 | _sc = settings.value("trafo_sc").toDouble();
|
---|
| 181 | _scr = settings.value("trafo_scr").toDouble();
|
---|
| 182 | _t0 = settings.value("trafo_t0").toDouble();
|
---|
| 183 | }
|
---|
[3209] | 184 |
|
---|
| 185 | // Member that receives the ephemeris
|
---|
| 186 | // ----------------------------------
|
---|
| 187 | _ephUser = new bncEphUser();
|
---|
[3172] | 188 | }
|
---|
| 189 |
|
---|
[3207] | 190 | // Safe Desctructor
|
---|
| 191 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 192 | void bncUploadCaster::deleteSafely() {
|
---|
| 193 | _isToBeDeleted = true;
|
---|
[3208] | 194 | if (!isRunning()) {
|
---|
| 195 | delete this;
|
---|
| 196 | }
|
---|
[3207] | 197 | }
|
---|
| 198 |
|
---|
[3172] | 199 | // Destructor
|
---|
| 200 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 201 | bncUploadCaster::~bncUploadCaster() {
|
---|
[3208] | 202 | if (isRunning()) {
|
---|
| 203 | wait();
|
---|
| 204 | }
|
---|
[3172] | 205 | delete _outFile;
|
---|
[3185] | 206 | delete _rnx;
|
---|
| 207 | delete _sp3;
|
---|
[3209] | 208 | delete _ephUser;
|
---|
[3172] | 209 | }
|
---|
| 210 |
|
---|
[3206] | 211 | // Endless Loop
|
---|
| 212 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 213 | void bncUploadCaster::run() {
|
---|
| 214 | while (true) {
|
---|
[3210] | 215 | if (_isToBeDeleted) {
|
---|
| 216 | QThread::quit();
|
---|
| 217 | deleteLater();
|
---|
| 218 | return;
|
---|
[3208] | 219 | }
|
---|
[3210] | 220 | open();
|
---|
[3206] | 221 | uploadClockOrbitBias();
|
---|
| 222 | msleep(10);
|
---|
| 223 | }
|
---|
| 224 | }
|
---|
| 225 |
|
---|
[3172] | 226 | // Start the Communication with NTRIP Caster
|
---|
| 227 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 228 | void bncUploadCaster::open() {
|
---|
| 229 |
|
---|
| 230 | if (_mountpoint.isEmpty()) {
|
---|
| 231 | return;
|
---|
| 232 | }
|
---|
| 233 |
|
---|
| 234 | if (_outSocket != 0 &&
|
---|
| 235 | _outSocket->state() == QAbstractSocket::ConnectedState) {
|
---|
| 236 | return;
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 | delete _outSocket; _outSocket = 0;
|
---|
| 240 |
|
---|
| 241 | double minDt = pow(2.0,_sOpenTrial);
|
---|
| 242 | if (++_sOpenTrial > 4) {
|
---|
| 243 | _sOpenTrial = 4;
|
---|
| 244 | }
|
---|
| 245 | if (_outSocketOpenTime.isValid() &&
|
---|
| 246 | _outSocketOpenTime.secsTo(QDateTime::currentDateTime()) < minDt) {
|
---|
| 247 | return;
|
---|
| 248 | }
|
---|
| 249 | else {
|
---|
| 250 | _outSocketOpenTime = QDateTime::currentDateTime();
|
---|
| 251 | }
|
---|
| 252 |
|
---|
| 253 | bncSettings settings;
|
---|
| 254 | _outSocket = new QTcpSocket();
|
---|
| 255 | _outSocket->connectToHost(_outHost, _outPort);
|
---|
| 256 |
|
---|
| 257 | const int timeOut = 5000; // 5 seconds
|
---|
| 258 | if (!_outSocket->waitForConnected(timeOut)) {
|
---|
| 259 | delete _outSocket;
|
---|
| 260 | _outSocket = 0;
|
---|
[3189] | 261 | emit(newMessage("Broadcaster: Connect timeout", true));
|
---|
[3172] | 262 | return;
|
---|
| 263 | }
|
---|
| 264 |
|
---|
| 265 | QByteArray msg = "SOURCE " + _password.toAscii() + " /" +
|
---|
| 266 | _mountpoint.toAscii() + "\r\n" +
|
---|
| 267 | "Source-Agent: NTRIP BNC/" BNCVERSION "\r\n\r\n";
|
---|
| 268 |
|
---|
| 269 | _outSocket->write(msg);
|
---|
| 270 | _outSocket->waitForBytesWritten();
|
---|
| 271 |
|
---|
| 272 | _outSocket->waitForReadyRead();
|
---|
| 273 | QByteArray ans = _outSocket->readLine();
|
---|
| 274 |
|
---|
| 275 | if (ans.indexOf("OK") == -1) {
|
---|
| 276 | delete _outSocket;
|
---|
| 277 | _outSocket = 0;
|
---|
[3189] | 278 | emit(newMessage("Broadcaster: Connection broken", true));
|
---|
[3172] | 279 | }
|
---|
| 280 | else {
|
---|
[3189] | 281 | emit(newMessage("Broadcaster: Connection opened", true));
|
---|
[3172] | 282 | _sOpenTrial = 0;
|
---|
| 283 | }
|
---|
| 284 | }
|
---|
| 285 |
|
---|
| 286 | // Write buffer
|
---|
| 287 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 288 | void bncUploadCaster::write(char* buffer, unsigned len) {
|
---|
[3210] | 289 | if (_outSocket && _outSocket->state() == QAbstractSocket::ConnectedState) {
|
---|
[3172] | 290 | _outSocket->write(buffer, len);
|
---|
| 291 | _outSocket->flush();
|
---|
| 292 | }
|
---|
| 293 | }
|
---|
| 294 |
|
---|
[3206] | 295 | //
|
---|
[3182] | 296 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3209] | 297 | void bncUploadCaster::decodeRtnetStream(char* buffer, int bufLen) {
|
---|
[3206] | 298 |
|
---|
| 299 | QMutexLocker locker(&_mutex);
|
---|
| 300 |
|
---|
| 301 | // Append to buffer
|
---|
| 302 | // ----------------
|
---|
[3212] | 303 | const int MAXBUFFSIZE = 100000;
|
---|
[3206] | 304 | _rtnetStreamBuffer.append(QByteArray(buffer, bufLen));
|
---|
[3210] | 305 | if (_rtnetStreamBuffer.size() > MAXBUFFSIZE) {
|
---|
| 306 | _rtnetStreamBuffer = _rtnetStreamBuffer.right(MAXBUFFSIZE);
|
---|
| 307 | }
|
---|
[3206] | 308 | }
|
---|
| 309 |
|
---|
| 310 | // Function called in separate thread
|
---|
| 311 | ////////////////////////////////////////////////////////////////////////
|
---|
| 312 | void bncUploadCaster::uploadClockOrbitBias() {
|
---|
| 313 |
|
---|
| 314 | QMutexLocker locker(&_mutex);
|
---|
| 315 |
|
---|
| 316 | // Prepare list of lines with satellite positions in SP3-like format
|
---|
| 317 | // -----------------------------------------------------------------
|
---|
| 318 | QStringList lines;
|
---|
| 319 | int iLast = _rtnetStreamBuffer.lastIndexOf('\n');
|
---|
| 320 | if (iLast != -1) {
|
---|
| 321 | QStringList hlpLines = _rtnetStreamBuffer.split('\n', QString::SkipEmptyParts);
|
---|
| 322 | _rtnetStreamBuffer = _rtnetStreamBuffer.mid(iLast+1);
|
---|
| 323 | for (int ii = 0; ii < hlpLines.size(); ii++) {
|
---|
| 324 | if (hlpLines[ii].indexOf('*') != -1) {
|
---|
[3210] | 325 | lines.clear();
|
---|
[3206] | 326 | QTextStream in(hlpLines[ii].toAscii());
|
---|
| 327 | QString hlp;
|
---|
| 328 | int year, month, day, hour, min;
|
---|
| 329 | double sec;
|
---|
| 330 | in >> hlp >> year >> month >> day >> hour >> min >> sec;
|
---|
| 331 | _epoTime.set( year, month, day, hour, min, sec);
|
---|
| 332 | }
|
---|
| 333 | else if (_epoTime.valid()) {
|
---|
| 334 | lines << hlpLines[ii];
|
---|
| 335 | }
|
---|
| 336 | }
|
---|
| 337 | }
|
---|
| 338 |
|
---|
| 339 | if (lines.size() == 0) {
|
---|
| 340 | return;
|
---|
| 341 | }
|
---|
| 342 |
|
---|
[3186] | 343 | unsigned year, month, day;
|
---|
[3206] | 344 | _epoTime.civil_date(year, month, day);
|
---|
[3182] | 345 |
|
---|
| 346 | struct ClockOrbit co;
|
---|
| 347 | memset(&co, 0, sizeof(co));
|
---|
[3206] | 348 | co.GPSEpochTime = static_cast<int>(_epoTime.gpssec());
|
---|
| 349 | co.GLONASSEpochTime = static_cast<int>(fmod(_epoTime.gpssec(), 86400.0))
|
---|
[3182] | 350 | + 3 * 3600 - gnumleap(year, month, day);
|
---|
| 351 | co.ClockDataSupplied = 1;
|
---|
| 352 | co.OrbitDataSupplied = 1;
|
---|
| 353 | co.SatRefDatum = DATUM_ITRF;
|
---|
| 354 |
|
---|
| 355 | struct Bias bias;
|
---|
| 356 | memset(&bias, 0, sizeof(bias));
|
---|
[3186] | 357 | bias.GPSEpochTime = co.GPSEpochTime;
|
---|
| 358 | bias.GLONASSEpochTime = co.GLONASSEpochTime;
|
---|
[3182] | 359 |
|
---|
| 360 | for (int ii = 0; ii < lines.size(); ii++) {
|
---|
| 361 |
|
---|
| 362 | QString prn;
|
---|
| 363 | ColumnVector xx(14); xx = 0.0;
|
---|
| 364 |
|
---|
| 365 | QTextStream in(lines[ii].toAscii());
|
---|
[3190] | 366 |
|
---|
[3182] | 367 | in >> prn;
|
---|
[3190] | 368 | if (prn[0] == 'P') {
|
---|
| 369 | prn.remove(0,1);
|
---|
| 370 | }
|
---|
| 371 |
|
---|
[3209] | 372 | const bncEphUser::t_ephPair* ephPair = _ephUser->ephPair(prn);
|
---|
| 373 | if (ephPair) {
|
---|
| 374 | t_eph* eph = ephPair->last;
|
---|
| 375 | if (ephPair->prev &&
|
---|
| 376 | eph->receptDateTime().secsTo(QDateTime::currentDateTime()) < 60) {
|
---|
| 377 | eph = ephPair->prev;
|
---|
| 378 | }
|
---|
[3206] | 379 |
|
---|
[3182] | 380 | in >> xx(1) >> xx(2) >> xx(3) >> xx(4) >> xx(5)
|
---|
| 381 | >> xx(6) >> xx(7) >> xx(8) >> xx(9) >> xx(10)
|
---|
| 382 | >> xx(11) >> xx(12) >> xx(13) >> xx(14);
|
---|
| 383 | xx(1) *= 1e3; // x-crd
|
---|
| 384 | xx(2) *= 1e3; // y-crd
|
---|
| 385 | xx(3) *= 1e3; // z-crd
|
---|
| 386 | xx(4) *= 1e-6; // clk
|
---|
| 387 | xx(5) *= 1e-6; // rel. corr.
|
---|
| 388 | // xx(6), xx(7), xx(8) ... PhaseCent - CoM
|
---|
| 389 | // xx(9) ... P1-C1 DCB in meters
|
---|
| 390 | // xx(10) ... P1-P2 DCB in meters
|
---|
| 391 | // xx(11) ... dT
|
---|
| 392 | xx(12) *= 1e3; // x-crd at time + dT
|
---|
| 393 | xx(13) *= 1e3; // y-crd at time + dT
|
---|
| 394 | xx(14) *= 1e3; // z-crd at time + dT
|
---|
| 395 |
|
---|
| 396 | struct ClockOrbit::SatData* sd = 0;
|
---|
| 397 | if (prn[0] == 'G') {
|
---|
| 398 | sd = co.Sat + co.NumberOfGPSSat;
|
---|
| 399 | ++co.NumberOfGPSSat;
|
---|
| 400 | }
|
---|
| 401 | else if (prn[0] == 'R') {
|
---|
| 402 | sd = co.Sat + CLOCKORBIT_NUMGPS + co.NumberOfGLONASSSat;
|
---|
| 403 | ++co.NumberOfGLONASSSat;
|
---|
| 404 | }
|
---|
| 405 | if (sd) {
|
---|
| 406 | QString outLine;
|
---|
[3209] | 407 | processSatellite(eph, _epoTime.gpsw(), _epoTime.gpssec(), prn,
|
---|
| 408 | xx, sd, outLine);
|
---|
[3185] | 409 | if (_outFile) {
|
---|
[3206] | 410 | _outFile->write(_epoTime.gpsw(), _epoTime.gpssec(), outLine);
|
---|
[3185] | 411 | }
|
---|
[3182] | 412 | }
|
---|
| 413 |
|
---|
| 414 | struct Bias::BiasSat* biasSat = 0;
|
---|
| 415 | if (prn[0] == 'G') {
|
---|
| 416 | biasSat = bias.Sat + bias.NumberOfGPSSat;
|
---|
| 417 | ++bias.NumberOfGPSSat;
|
---|
| 418 | }
|
---|
| 419 | else if (prn[0] == 'R') {
|
---|
| 420 | biasSat = bias.Sat + CLOCKORBIT_NUMGPS + bias.NumberOfGLONASSSat;
|
---|
| 421 | ++bias.NumberOfGLONASSSat;
|
---|
| 422 | }
|
---|
| 423 |
|
---|
| 424 | // Coefficient of Ionosphere-Free LC
|
---|
| 425 | // ---------------------------------
|
---|
| 426 | const static double a_L1_GPS = 2.54572778;
|
---|
| 427 | const static double a_L2_GPS = -1.54572778;
|
---|
| 428 | const static double a_L1_Glo = 2.53125000;
|
---|
| 429 | const static double a_L2_Glo = -1.53125000;
|
---|
| 430 |
|
---|
| 431 | if (biasSat) {
|
---|
| 432 | biasSat->ID = prn.mid(1).toInt();
|
---|
| 433 | biasSat->NumberOfCodeBiases = 3;
|
---|
| 434 | if (prn[0] == 'G') {
|
---|
| 435 | biasSat->Biases[0].Type = CODETYPEGPS_L1_Z;
|
---|
| 436 | biasSat->Biases[0].Bias = - a_L2_GPS * xx(10);
|
---|
| 437 | biasSat->Biases[1].Type = CODETYPEGPS_L1_CA;
|
---|
| 438 | biasSat->Biases[1].Bias = - a_L2_GPS * xx(10) + xx(9);
|
---|
| 439 | biasSat->Biases[2].Type = CODETYPEGPS_L2_Z;
|
---|
| 440 | biasSat->Biases[2].Bias = a_L1_GPS * xx(10);
|
---|
| 441 | }
|
---|
| 442 | else if (prn[0] == 'R') {
|
---|
| 443 | biasSat->Biases[0].Type = CODETYPEGLONASS_L1_P;
|
---|
| 444 | biasSat->Biases[0].Bias = - a_L2_Glo * xx(10);
|
---|
| 445 | biasSat->Biases[1].Type = CODETYPEGLONASS_L1_CA;
|
---|
| 446 | biasSat->Biases[1].Bias = - a_L2_Glo * xx(10) + xx(9);
|
---|
| 447 | biasSat->Biases[2].Type = CODETYPEGLONASS_L2_P;
|
---|
| 448 | biasSat->Biases[2].Bias = a_L1_Glo * xx(10);
|
---|
| 449 | }
|
---|
| 450 | }
|
---|
| 451 | }
|
---|
| 452 | }
|
---|
| 453 |
|
---|
[3210] | 454 | if (co.NumberOfGPSSat > 0 || co.NumberOfGLONASSSat > 0) {
|
---|
[3182] | 455 | char obuffer[CLOCKORBIT_BUFFERSIZE];
|
---|
| 456 |
|
---|
| 457 | int len = MakeClockOrbit(&co, COTYPE_AUTO, 0, obuffer, sizeof(obuffer));
|
---|
| 458 | if (len > 0) {
|
---|
| 459 | this->write(obuffer, len);
|
---|
| 460 | }
|
---|
| 461 | }
|
---|
| 462 |
|
---|
[3210] | 463 | if (bias.NumberOfGPSSat > 0 || bias.NumberOfGLONASSSat > 0) {
|
---|
[3182] | 464 | char obuffer[CLOCKORBIT_BUFFERSIZE];
|
---|
| 465 | int len = MakeBias(&bias, BTYPE_AUTO, 0, obuffer, sizeof(obuffer));
|
---|
| 466 | if (len > 0) {
|
---|
| 467 | this->write(obuffer, len);
|
---|
| 468 | }
|
---|
| 469 | }
|
---|
| 470 | }
|
---|
| 471 |
|
---|
| 472 | //
|
---|
| 473 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 474 | void bncUploadCaster::processSatellite(t_eph* eph, int GPSweek,
|
---|
| 475 | double GPSweeks, const QString& prn,
|
---|
| 476 | const ColumnVector& xx,
|
---|
| 477 | struct ClockOrbit::SatData* sd,
|
---|
| 478 | QString& outLine) {
|
---|
| 479 |
|
---|
| 480 | const double secPerWeek = 7.0 * 86400.0;
|
---|
| 481 |
|
---|
| 482 | ColumnVector rsw(3);
|
---|
| 483 | ColumnVector rsw2(3);
|
---|
| 484 | double dClk;
|
---|
| 485 |
|
---|
| 486 | for (int ii = 1; ii <= 2; ++ii) {
|
---|
| 487 |
|
---|
| 488 | int GPSweek12 = GPSweek;
|
---|
| 489 | double GPSweeks12 = GPSweeks;
|
---|
| 490 | if (ii == 2) {
|
---|
| 491 | GPSweeks12 += xx(11);
|
---|
| 492 | if (GPSweeks12 > secPerWeek) {
|
---|
| 493 | GPSweek12 += 1;
|
---|
| 494 | GPSweeks12 -= secPerWeek;
|
---|
| 495 | }
|
---|
| 496 | }
|
---|
| 497 |
|
---|
| 498 | ColumnVector xB(4);
|
---|
| 499 | ColumnVector vv(3);
|
---|
| 500 |
|
---|
| 501 | eph->position(GPSweek12, GPSweeks12, xB.data(), vv.data());
|
---|
| 502 |
|
---|
| 503 | ColumnVector xyz;
|
---|
| 504 | if (ii == 1) {
|
---|
| 505 | xyz = xx.Rows(1,3);
|
---|
| 506 | }
|
---|
| 507 | else {
|
---|
| 508 | xyz = xx.Rows(12,14);
|
---|
| 509 | }
|
---|
| 510 |
|
---|
| 511 | // Correction Center of Mass -> Antenna Phase Center
|
---|
| 512 | // -------------------------------------------------
|
---|
| 513 | if (! _CoM) {
|
---|
| 514 | xyz(1) += xx(6);
|
---|
| 515 | xyz(2) += xx(7);
|
---|
| 516 | xyz(3) += xx(8);
|
---|
| 517 | }
|
---|
| 518 |
|
---|
| 519 | if (_crdTrafo != "IGS05") {
|
---|
| 520 | crdTrafo(GPSweek12, xyz);
|
---|
| 521 | }
|
---|
| 522 |
|
---|
| 523 | ColumnVector dx = xB.Rows(1,3) - xyz ;
|
---|
| 524 |
|
---|
| 525 | if (ii == 1) {
|
---|
| 526 | XYZ_to_RSW(xB.Rows(1,3), vv, dx, rsw);
|
---|
| 527 | dClk = (xx(4) + xx(5) - xB(4)) * 299792458.0;
|
---|
| 528 | }
|
---|
| 529 | else {
|
---|
| 530 | XYZ_to_RSW(xB.Rows(1,3), vv, dx, rsw2);
|
---|
| 531 | }
|
---|
| 532 | }
|
---|
| 533 |
|
---|
| 534 | if (sd) {
|
---|
| 535 | sd->ID = prn.mid(1).toInt();
|
---|
| 536 | sd->IOD = eph->IOD();
|
---|
| 537 | sd->Clock.DeltaA0 = dClk;
|
---|
| 538 | sd->Orbit.DeltaRadial = rsw(1);
|
---|
| 539 | sd->Orbit.DeltaAlongTrack = rsw(2);
|
---|
| 540 | sd->Orbit.DeltaCrossTrack = rsw(3);
|
---|
| 541 | sd->Orbit.DotDeltaRadial = (rsw2(1) - rsw(1)) / xx(11);
|
---|
| 542 | sd->Orbit.DotDeltaAlongTrack = (rsw2(2) - rsw(2)) / xx(11);
|
---|
| 543 | sd->Orbit.DotDeltaCrossTrack = (rsw2(3) - rsw(3)) / xx(11);
|
---|
| 544 | }
|
---|
| 545 |
|
---|
| 546 | outLine.sprintf("%d %.1f %s %3d %10.3f %8.3f %8.3f %8.3f\n",
|
---|
| 547 | GPSweek, GPSweeks, eph->prn().c_str(),
|
---|
| 548 | eph->IOD(), dClk, rsw(1), rsw(2), rsw(3));
|
---|
| 549 |
|
---|
| 550 | if (_rnx) {
|
---|
| 551 | _rnx->write(GPSweek, GPSweeks, prn, xx);
|
---|
| 552 | }
|
---|
| 553 | if (_sp3) {
|
---|
[3185] | 554 | _sp3->write(GPSweek, GPSweeks, prn, xx);
|
---|
[3182] | 555 | }
|
---|
| 556 | }
|
---|
| 557 |
|
---|
| 558 | // Transform Coordinates
|
---|
| 559 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 560 | void bncUploadCaster::crdTrafo(int GPSWeek, ColumnVector& xyz) {
|
---|
| 561 |
|
---|
| 562 | // Current epoch minus 2000.0 in years
|
---|
| 563 | // ------------------------------------
|
---|
| 564 | double dt = (GPSWeek - (1042.0+6.0/7.0)) / 365.2422 * 7.0 + 2000.0 - _t0;
|
---|
| 565 |
|
---|
| 566 | ColumnVector dx(3);
|
---|
| 567 |
|
---|
| 568 | dx(1) = _dx + dt * _dxr;
|
---|
| 569 | dx(2) = _dy + dt * _dyr;
|
---|
| 570 | dx(3) = _dz + dt * _dzr;
|
---|
| 571 |
|
---|
| 572 | static const double arcSec = 180.0 * 3600.0 / M_PI;
|
---|
| 573 |
|
---|
| 574 | double ox = (_ox + dt * _oxr) / arcSec;
|
---|
| 575 | double oy = (_oy + dt * _oyr) / arcSec;
|
---|
| 576 | double oz = (_oz + dt * _ozr) / arcSec;
|
---|
| 577 |
|
---|
| 578 | double sc = 1.0 + _sc * 1e-9 + dt * _scr * 1e-9;
|
---|
| 579 |
|
---|
| 580 | Matrix rMat(3,3);
|
---|
| 581 | rMat(1,1) = 1.0;
|
---|
| 582 | rMat(1,2) = -oz;
|
---|
| 583 | rMat(1,3) = oy;
|
---|
| 584 | rMat(2,1) = oz;
|
---|
| 585 | rMat(2,2) = 1.0;
|
---|
| 586 | rMat(2,3) = -ox;
|
---|
| 587 | rMat(3,1) = -oy;
|
---|
| 588 | rMat(3,2) = ox;
|
---|
| 589 | rMat(3,3) = 1.0;
|
---|
| 590 |
|
---|
| 591 | xyz = sc * rMat * xyz + dx;
|
---|
| 592 | }
|
---|
[3206] | 593 |
|
---|