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 | #include "hassDecoder.h"
|
---|
20 | #include "bnctime.h"
|
---|
21 | #include "bncutils.h"
|
---|
22 | #include "RTCM3/RTCM3coDecoder.h"
|
---|
23 |
|
---|
24 | using namespace std;
|
---|
25 |
|
---|
26 | // Constructor
|
---|
27 | ////////////////////////////////////////////////////////////////////////////
|
---|
28 | hassDecoder::hassDecoder(const QString& staID) {
|
---|
29 | _GPSweeks = -1.0;
|
---|
30 | }
|
---|
31 |
|
---|
32 | // Destructor
|
---|
33 | ////////////////////////////////////////////////////////////////////////////
|
---|
34 | hassDecoder::~hassDecoder() {
|
---|
35 | }
|
---|
36 |
|
---|
37 | //
|
---|
38 | ////////////////////////////////////////////////////////////////////////////
|
---|
39 | t_irc hassDecoder::Decode(char* data, int dataLen, vector<string>& errmsg) {
|
---|
40 |
|
---|
41 | errmsg.clear();
|
---|
42 |
|
---|
43 | _buffer += QByteArray(data, dataLen);
|
---|
44 |
|
---|
45 | bool corrFound = false;
|
---|
46 | int indexEOL = -1;
|
---|
47 | while ( (indexEOL = _buffer.indexOf('\n')) != -1) {
|
---|
48 | QByteArray line = _buffer.left(indexEOL-1);
|
---|
49 | _buffer = _buffer.mid(indexEOL+1);
|
---|
50 |
|
---|
51 | if (QString(line).split(QRegExp("\\s+"), QString::SkipEmptyParts).count() != 11) {
|
---|
52 | continue;
|
---|
53 | }
|
---|
54 | else {
|
---|
55 | corrFound = true;
|
---|
56 | }
|
---|
57 |
|
---|
58 | QTextStream in(line, QIODevice::ReadOnly | QIODevice::Text);
|
---|
59 | int mjd, IOD;
|
---|
60 | double daySec;
|
---|
61 | ColumnVector dx(3);
|
---|
62 | ColumnVector dxRate(3);
|
---|
63 | double clkFull;
|
---|
64 |
|
---|
65 | QString prn;
|
---|
66 |
|
---|
67 | in >> mjd >> daySec >> prn >> IOD >> dx[0] >> dx[1] >> dx[2] >> clkFull
|
---|
68 | >> dxRate[0] >> dxRate[1] >> dxRate[2];
|
---|
69 |
|
---|
70 | // Correction Time
|
---|
71 | // ---------------
|
---|
72 | bncTime tt;
|
---|
73 | tt.setmjd(daySec, mjd);
|
---|
74 |
|
---|
75 | _GPSweeks = tt.gpssec();
|
---|
76 | long coTime = tt.gpsw() * 7*24*3600 + long(floor(_GPSweeks+0.5));
|
---|
77 |
|
---|
78 | // Transform Correction
|
---|
79 | // --------------------
|
---|
80 | dx = -dx;
|
---|
81 | dxRate = -dxRate;
|
---|
82 |
|
---|
83 | t_eph* eph = 0;
|
---|
84 | if (_eph.contains(prn)) {
|
---|
85 | if (_eph.value(prn)->last && _eph.value(prn)->last->IOD() == IOD) {
|
---|
86 | eph = _eph.value(prn)->last;
|
---|
87 | }
|
---|
88 | else if (_eph.value(prn)->prev && _eph.value(prn)->prev->IOD() == IOD) {
|
---|
89 | eph = _eph.value(prn)->prev;
|
---|
90 | }
|
---|
91 | }
|
---|
92 | if (!eph) {
|
---|
93 | continue;
|
---|
94 | }
|
---|
95 |
|
---|
96 | ColumnVector xc(4);
|
---|
97 | ColumnVector vv(3);
|
---|
98 | eph->position(tt.gpsw(), tt.gpssec(), xc.data(), vv.data());
|
---|
99 |
|
---|
100 | ColumnVector rao(3);
|
---|
101 | XYZ_to_RSW(xc.Rows(1,3), vv, dx, rao);
|
---|
102 |
|
---|
103 | ColumnVector dotRao(3);
|
---|
104 | XYZ_to_RSW(xc.Rows(1,3), vv, dxRate, dotRao);
|
---|
105 |
|
---|
106 | double dClk = clkFull - xc[3] * t_CST::c;
|
---|
107 |
|
---|
108 | // Print Correction Line
|
---|
109 | // ---------------------
|
---|
110 | QString corrLine;
|
---|
111 |
|
---|
112 | int updateInterval = 0;
|
---|
113 | int messageType = 0;
|
---|
114 | if (prn[0] == 'G') {
|
---|
115 | messageType = COTYPE_GPSCOMBINED;
|
---|
116 | }
|
---|
117 | else if (prn[0] == 'R') {
|
---|
118 | messageType = COTYPE_GLONASSCOMBINED;
|
---|
119 | }
|
---|
120 |
|
---|
121 | corrLine.sprintf("%d %d %d %.1f %s"
|
---|
122 | " %3d"
|
---|
123 | " %8.3f %8.3f %8.3f %8.3f"
|
---|
124 | " %10.5f %10.5f %10.5f %10.5f"
|
---|
125 | " %10.5f",
|
---|
126 | messageType, updateInterval, tt.gpsw(), _GPSweeks,
|
---|
127 | prn.toAscii().data(), IOD,
|
---|
128 | dClk, rao[0], rao[1], rao[2],
|
---|
129 | 0.0, dotRao[0], dotRao[1], dotRao[2], 0.0);
|
---|
130 |
|
---|
131 | RTCM3coDecoder::reopen(_fileNameSkl, _fileName, _out);
|
---|
132 | if (_out) {
|
---|
133 | *_out << corrLine.toAscii().data() << endl;
|
---|
134 | _out->flush();
|
---|
135 | }
|
---|
136 | emit newCorrLine(corrLine, _staID, coTime);
|
---|
137 | }
|
---|
138 |
|
---|
139 | if (corrFound) {
|
---|
140 | return success;
|
---|
141 | }
|
---|
142 | else {
|
---|
143 | return failure;
|
---|
144 | }
|
---|
145 | }
|
---|