source: ntrip/trunk/BNC/src/GPSS/hassDecoder.cpp@ 5120

Last change on this file since 5120 was 5120, checked in by mervart, 11 years ago
File size: 4.1 KB
Line 
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 "bnccore.h"
22#include "bnctime.h"
23#include "bncutils.h"
24#include "bncsettings.h"
25#include "RTCM3/RTCM3coDecoder.h"
26
27using namespace std;
28
29// Constructor
30////////////////////////////////////////////////////////////////////////////
31hassDecoder::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, bncTime)),
49 BNC_CORE, SLOT(slotNewCorrLine(QString, QString, bncTime)));
50}
51
52// Destructor
53////////////////////////////////////////////////////////////////////////////
54hassDecoder::~hassDecoder() {
55 delete _out;
56}
57
58//
59////////////////////////////////////////////////////////////////////////////
60t_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 coTime; coTime.setmjd(daySec, mjd);
95
96 _GPSweeks = coTime.gpssec();
97
98 // Transform Correction
99 // --------------------
100 dx = -dx;
101 dxRate = -dxRate;
102
103 t_eph* eph = 0;
104 if (_eph.contains(prn)) {
105 if (_eph.value(prn)->last && _eph.value(prn)->last->IOD() == IOD) {
106 eph = _eph.value(prn)->last;
107 }
108 else if (_eph.value(prn)->prev && _eph.value(prn)->prev->IOD() == IOD) {
109 eph = _eph.value(prn)->prev;
110 }
111 }
112 if (!eph) {
113 continue;
114 }
115
116 ColumnVector xc(4);
117 ColumnVector vv(3);
118 eph->position(coTime.gpsw(), coTime.gpssec(), xc.data(), vv.data());
119
120 ColumnVector rao(3);
121 XYZ_to_RSW(xc.Rows(1,3), vv, dx, rao);
122
123 ColumnVector dotRao(3);
124 XYZ_to_RSW(xc.Rows(1,3), vv, dxRate, dotRao);
125
126 double dClk = clkFull - xc[3] * t_CST::c;
127
128 // Print Correction Line
129 // ---------------------
130 QString corrLine;
131
132 int updateInterval = 0;
133 int messageType = 0;
134 if (prn[0] == 'G') {
135 messageType = COTYPE_GPSCOMBINED;
136 }
137 else if (prn[0] == 'R') {
138 messageType = COTYPE_GLONASSCOMBINED;
139 }
140
141 corrLine.sprintf("%d %d %d %.1f %s"
142 " %3d"
143 " %8.3f %8.3f %8.3f %8.3f"
144 " %10.5f %10.5f %10.5f %10.5f"
145 " %10.5f",
146 messageType, updateInterval, coTime.gpsw(), _GPSweeks,
147 prn.toAscii().data(), IOD,
148 dClk, rao[0], rao[1], rao[2],
149 0.0, dotRao[0], dotRao[1], dotRao[2], 0.0);
150
151 RTCM3coDecoder::reopen(_fileNameSkl, _fileName, _out);
152 if (_out) {
153 *_out << corrLine.toAscii().data() << endl;
154 _out->flush();
155 }
156 emit newCorrLine(corrLine, _staID, coTime);
157 }
158
159 if (corrFound) {
160 return success;
161 }
162 else {
163 return failure;
164 }
165}
Note: See TracBrowser for help on using the repository browser.