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 |
|
---|
18 | #include <iostream>
|
---|
19 |
|
---|
20 | #include "hassDecoder.h"
|
---|
21 | #include "bncapp.h"
|
---|
22 | #include "bnctime.h"
|
---|
23 | #include "bncutils.h"
|
---|
24 | #include "bncsettings.h"
|
---|
25 | #include "RTCM3/RTCM3coDecoder.h"
|
---|
26 |
|
---|
27 | using namespace std;
|
---|
28 |
|
---|
29 | // Constructor
|
---|
30 | ////////////////////////////////////////////////////////////////////////////
|
---|
31 | hassDecoder::hassDecoder(const QString& staID) {
|
---|
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;
|
---|
46 | _GPSweeks = -1.0;
|
---|
47 |
|
---|
48 | connect(this, SIGNAL(newCorrLine(QString, QString, long)),
|
---|
49 | (bncApp*) qApp, SLOT(slotNewCorrLine(QString, QString, long)));
|
---|
50 | }
|
---|
51 |
|
---|
52 | // Destructor
|
---|
53 | ////////////////////////////////////////////////////////////////////////////
|
---|
54 | hassDecoder::~hassDecoder() {
|
---|
55 | delete _out;
|
---|
56 | }
|
---|
57 |
|
---|
58 | //
|
---|
59 | ////////////////////////////////////////////////////////////////////////////
|
---|
60 | t_irc hassDecoder::Decode(char* data, int dataLen, vector<string>& errmsg) {
|
---|
61 | QMutexLocker locker(&_mutex);
|
---|
62 |
|
---|
63 | errmsg.clear();
|
---|
64 |
|
---|
65 | _buffer += QByteArray(data, dataLen);
|
---|
66 |
|
---|
67 | bool corrFound = false;
|
---|
68 | int indexEOL = -1;
|
---|
69 | while ( (indexEOL = _buffer.indexOf('\n')) != -1) {
|
---|
70 | QByteArray line = _buffer.left(indexEOL-1);
|
---|
71 | _buffer = _buffer.mid(indexEOL+1);
|
---|
72 |
|
---|
73 | if (QString(line).split(QRegExp("\\s+"), QString::SkipEmptyParts).count() != 11) {
|
---|
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;
|
---|
83 | ColumnVector dx(3);
|
---|
84 | ColumnVector dxRate(3);
|
---|
85 | double clkFull;
|
---|
86 |
|
---|
87 | QString prn;
|
---|
88 |
|
---|
89 | in >> mjd >> daySec >> prn >> IOD >> dx[0] >> dx[1] >> dx[2] >> clkFull
|
---|
90 | >> dxRate[0] >> dxRate[1] >> dxRate[2];
|
---|
91 |
|
---|
92 | // Correction Time
|
---|
93 | // ---------------
|
---|
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 |
|
---|
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 | // ---------------------
|
---|
132 | QString corrLine;
|
---|
133 |
|
---|
134 | int updateInterval = 0;
|
---|
135 | int messageType = 0;
|
---|
136 | if (prn[0] == 'G') {
|
---|
137 | messageType = COTYPE_GPSCOMBINED;
|
---|
138 | }
|
---|
139 | else if (prn[0] == 'R') {
|
---|
140 | messageType = COTYPE_GLONASSCOMBINED;
|
---|
141 | }
|
---|
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,
|
---|
150 | dClk, rao[0], rao[1], rao[2],
|
---|
151 | 0.0, dotRao[0], dotRao[1], dotRao[2], 0.0);
|
---|
152 |
|
---|
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);
|
---|
159 | }
|
---|
160 |
|
---|
161 | if (corrFound) {
|
---|
162 | return success;
|
---|
163 | }
|
---|
164 | else {
|
---|
165 | return failure;
|
---|
166 | }
|
---|
167 | }
|
---|