[3504] | 1 |
|
---|
| 2 | /* -------------------------------------------------------------------------
|
---|
| 3 | * BKG NTRIP Client
|
---|
| 4 | * -------------------------------------------------------------------------
|
---|
| 5 | *
|
---|
| 6 | * Class: hassDecoder
|
---|
| 7 | *
|
---|
| 8 | * Purpose: Decode Data (PPP Corrections) in HASS Format
|
---|
| 9 | *
|
---|
| 10 | * Author: L. Mervart
|
---|
| 11 | *
|
---|
| 12 | * Created: 19-Nov-2011
|
---|
| 13 | *
|
---|
| 14 | * Changes:
|
---|
| 15 | *
|
---|
| 16 | * -----------------------------------------------------------------------*/
|
---|
| 17 |
|
---|
[3512] | 18 | #include <iostream>
|
---|
[3579] | 19 |
|
---|
[3504] | 20 | #include "hassDecoder.h"
|
---|
[3579] | 21 | #include "bncapp.h"
|
---|
[3507] | 22 | #include "bnctime.h"
|
---|
[3520] | 23 | #include "bncutils.h"
|
---|
[3579] | 24 | #include "bncsettings.h"
|
---|
[3578] | 25 | #include "RTCM3/RTCM3coDecoder.h"
|
---|
[3504] | 26 |
|
---|
| 27 | using namespace std;
|
---|
| 28 |
|
---|
| 29 | // Constructor
|
---|
| 30 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3578] | 31 | hassDecoder::hassDecoder(const QString& staID) {
|
---|
[3579] | 32 | _staID = staID;
|
---|
| 33 |
|
---|
| 34 | // File Output
|
---|
| 35 | // -----------
|
---|
| 36 | bncSettings settings;
|
---|
| 37 | QString path = settings.value("corrPath").toString();
|
---|
| 38 | if (!path.isEmpty()) {
|
---|
| 39 | expandEnvVar(path);
|
---|
| 40 | if ( path.length() > 0 && path[path.length()-1] != QDir::separator() ) {
|
---|
| 41 | path += QDir::separator();
|
---|
| 42 | }
|
---|
| 43 | _fileNameSkl = path + staID;
|
---|
| 44 | }
|
---|
| 45 | _out = 0;
|
---|
[3506] | 46 | _GPSweeks = -1.0;
|
---|
[3579] | 47 |
|
---|
| 48 | connect(this, SIGNAL(newCorrLine(QString, QString, long)),
|
---|
| 49 | (bncApp*) qApp, SLOT(slotNewCorrLine(QString, QString, long)));
|
---|
[3504] | 50 | }
|
---|
| 51 |
|
---|
| 52 | // Destructor
|
---|
| 53 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 54 | hassDecoder::~hassDecoder() {
|
---|
[3579] | 55 | delete _out;
|
---|
[3504] | 56 | }
|
---|
| 57 |
|
---|
| 58 | //
|
---|
| 59 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 60 | t_irc hassDecoder::Decode(char* data, int dataLen, vector<string>& errmsg) {
|
---|
[3580] | 61 | QMutexLocker locker(&_mutex);
|
---|
[3504] | 62 |
|
---|
| 63 | errmsg.clear();
|
---|
| 64 |
|
---|
| 65 | _buffer += QByteArray(data, dataLen);
|
---|
| 66 |
|
---|
[3506] | 67 | bool corrFound = false;
|
---|
| 68 | int indexEOL = -1;
|
---|
| 69 | while ( (indexEOL = _buffer.indexOf('\n')) != -1) {
|
---|
| 70 | QByteArray line = _buffer.left(indexEOL-1);
|
---|
[3512] | 71 | _buffer = _buffer.mid(indexEOL+1);
|
---|
[3504] | 72 |
|
---|
[3512] | 73 | if (QString(line).split(QRegExp("\\s+"), QString::SkipEmptyParts).count() != 11) {
|
---|
[3506] | 74 | continue;
|
---|
| 75 | }
|
---|
| 76 | else {
|
---|
| 77 | corrFound = true;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | QTextStream in(line, QIODevice::ReadOnly | QIODevice::Text);
|
---|
| 81 | int mjd, IOD;
|
---|
| 82 | double daySec;
|
---|
[3520] | 83 | ColumnVector dx(3);
|
---|
| 84 | ColumnVector dxRate(3);
|
---|
| 85 | double clkFull;
|
---|
| 86 |
|
---|
[3506] | 87 | QString prn;
|
---|
| 88 |
|
---|
[3520] | 89 | in >> mjd >> daySec >> prn >> IOD >> dx[0] >> dx[1] >> dx[2] >> clkFull
|
---|
| 90 | >> dxRate[0] >> dxRate[1] >> dxRate[2];
|
---|
[3506] | 91 |
|
---|
[3520] | 92 | // Correction Time
|
---|
| 93 | // ---------------
|
---|
[3507] | 94 | bncTime tt;
|
---|
| 95 | tt.setmjd(daySec, mjd);
|
---|
| 96 |
|
---|
| 97 | _GPSweeks = tt.gpssec();
|
---|
| 98 | long coTime = tt.gpsw() * 7*24*3600 + long(floor(_GPSweeks+0.5));
|
---|
| 99 |
|
---|
[3520] | 100 | // Transform Correction
|
---|
| 101 | // --------------------
|
---|
| 102 | dx = -dx;
|
---|
| 103 | dxRate = -dxRate;
|
---|
| 104 |
|
---|
| 105 | t_eph* eph = 0;
|
---|
| 106 | if (_eph.contains(prn)) {
|
---|
| 107 | if (_eph.value(prn)->last && _eph.value(prn)->last->IOD() == IOD) {
|
---|
| 108 | eph = _eph.value(prn)->last;
|
---|
| 109 | }
|
---|
| 110 | else if (_eph.value(prn)->prev && _eph.value(prn)->prev->IOD() == IOD) {
|
---|
| 111 | eph = _eph.value(prn)->prev;
|
---|
| 112 | }
|
---|
| 113 | }
|
---|
| 114 | if (!eph) {
|
---|
| 115 | continue;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | ColumnVector xc(4);
|
---|
| 119 | ColumnVector vv(3);
|
---|
| 120 | eph->position(tt.gpsw(), tt.gpssec(), xc.data(), vv.data());
|
---|
| 121 |
|
---|
| 122 | ColumnVector rao(3);
|
---|
| 123 | XYZ_to_RSW(xc.Rows(1,3), vv, dx, rao);
|
---|
| 124 |
|
---|
| 125 | ColumnVector dotRao(3);
|
---|
| 126 | XYZ_to_RSW(xc.Rows(1,3), vv, dxRate, dotRao);
|
---|
| 127 |
|
---|
| 128 | double dClk = clkFull - xc[3] * t_CST::c;
|
---|
| 129 |
|
---|
| 130 | // Print Correction Line
|
---|
| 131 | // ---------------------
|
---|
[3507] | 132 | QString corrLine;
|
---|
| 133 |
|
---|
[3520] | 134 | int updateInterval = 0;
|
---|
| 135 | int messageType = 0;
|
---|
[3508] | 136 | if (prn[0] == 'G') {
|
---|
[3520] | 137 | messageType = COTYPE_GPSCOMBINED;
|
---|
[3508] | 138 | }
|
---|
| 139 | else if (prn[0] == 'R') {
|
---|
[3520] | 140 | messageType = COTYPE_GLONASSCOMBINED;
|
---|
[3508] | 141 | }
|
---|
[3507] | 142 |
|
---|
| 143 | corrLine.sprintf("%d %d %d %.1f %s"
|
---|
| 144 | " %3d"
|
---|
| 145 | " %8.3f %8.3f %8.3f %8.3f"
|
---|
| 146 | " %10.5f %10.5f %10.5f %10.5f"
|
---|
| 147 | " %10.5f",
|
---|
| 148 | messageType, updateInterval, tt.gpsw(), _GPSweeks,
|
---|
| 149 | prn.toAscii().data(), IOD,
|
---|
[3520] | 150 | dClk, rao[0], rao[1], rao[2],
|
---|
| 151 | 0.0, dotRao[0], dotRao[1], dotRao[2], 0.0);
|
---|
[3514] | 152 |
|
---|
[3578] | 153 | RTCM3coDecoder::reopen(_fileNameSkl, _fileName, _out);
|
---|
| 154 | if (_out) {
|
---|
| 155 | *_out << corrLine.toAscii().data() << endl;
|
---|
| 156 | _out->flush();
|
---|
| 157 | }
|
---|
| 158 | emit newCorrLine(corrLine, _staID, coTime);
|
---|
[3506] | 159 | }
|
---|
| 160 |
|
---|
| 161 | if (corrFound) {
|
---|
| 162 | return success;
|
---|
| 163 | }
|
---|
| 164 | else {
|
---|
| 165 | return failure;
|
---|
| 166 | }
|
---|
[3504] | 167 | }
|
---|