source: ntrip/branches/BNC_2.11.0/src/GPSS/hassDecoder.cpp@ 6478

Last change on this file since 6478 was 5576, checked in by mervart, 11 years ago
File size: 4.2 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 qRegisterMetaType<bncTime>("bncTime");
49
50 connect(this, SIGNAL(newCorrLine(QString, QString, bncTime)),
51 BNC_CORE, SLOT(slotNewCorrLine(QString, QString, bncTime)));
52}
53
54// Destructor
55////////////////////////////////////////////////////////////////////////////
56hassDecoder::~hassDecoder() {
57 delete _out;
58}
59
60//
61////////////////////////////////////////////////////////////////////////////
62t_irc hassDecoder::Decode(char* data, int dataLen, vector<string>& errmsg) {
63 QMutexLocker locker(&_mutex);
64
65 errmsg.clear();
66
67 _buffer += QByteArray(data, dataLen);
68
69 bool corrFound = false;
70 int indexEOL = -1;
71 while ( (indexEOL = _buffer.indexOf('\n')) != -1) {
72 QByteArray line = _buffer.left(indexEOL-1);
73 _buffer = _buffer.mid(indexEOL+1);
74
75 if (QString(line).split(QRegExp("\\s+"), QString::SkipEmptyParts).count() != 11) {
76 continue;
77 }
78 else {
79 corrFound = true;
80 }
81
82 QTextStream in(line, QIODevice::ReadOnly | QIODevice::Text);
83 int mjd, IOD;
84 double daySec;
85 ColumnVector dx(3);
86 ColumnVector dxRate(3);
87 double clkFull;
88
89 QString prn;
90
91 in >> mjd >> daySec >> prn >> IOD >> dx[0] >> dx[1] >> dx[2] >> clkFull
92 >> dxRate[0] >> dxRate[1] >> dxRate[2];
93
94 // Correction Time
95 // ---------------
96 bncTime coTime; coTime.setmjd(daySec, mjd);
97
98 _GPSweeks = coTime.gpssec();
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(coTime.gpsw(), coTime.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, coTime.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}
Note: See TracBrowser for help on using the repository browser.