source: ntrip/trunk/BNC/RTCM3/RTCM3coDecoder.cpp@ 1535

Last change on this file since 1535 was 1535, checked in by mervart, 15 years ago

* empty log message *

File size: 6.3 KB
Line 
1// Part of BNC, a utility for retrieving decoding and
2// converting GNSS data streams from NTRIP broadcasters.
3//
4// Copyright (C) 2007
5// German Federal Agency for Cartography and Geodesy (BKG)
6// http://www.bkg.bund.de
7// Czech Technical University Prague, Department of Geodesy
8// http://www.fsv.cvut.cz
9//
10// Email: euref-ip@bkg.bund.de
11//
12// This program is free software; you can redistribute it and/or
13// modify it under the terms of the GNU General Public License
14// as published by the Free Software Foundation, version 2.
15//
16// This program is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program; if not, write to the Free Software
23// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25/* -------------------------------------------------------------------------
26 * BKG NTRIP Client
27 * -------------------------------------------------------------------------
28 *
29 * Class: RTCM3coDecoder
30 *
31 * Purpose: RTCM3 Clock Orbit Decoder
32 *
33 * Author: L. Mervart
34 *
35 * Created: 05-May-2008
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <stdio.h>
42#include <math.h>
43
44#include "RTCM3coDecoder.h"
45#include "bncutils.h"
46#include "bncrinex.h"
47#include "bncapp.h"
48#include "bncsettings.h"
49
50using namespace std;
51
52// Constructor
53////////////////////////////////////////////////////////////////////////////
54RTCM3coDecoder::RTCM3coDecoder(const QString& staID) {
55
56 _staID = staID;
57
58 // File Output
59 // -----------
60 bncSettings settings;
61 QString path = settings.value("corrPath").toString();
62 if (!path.isEmpty()) {
63 expandEnvVar(path);
64 if ( path.length() > 0 && path[path.length()-1] != QDir::separator() ) {
65 path += QDir::separator();
66 }
67 _fileNameSkl = path + staID;
68 }
69 _out = 0;
70
71 connect(this, SIGNAL(newCorrLine(QString, QString, long)),
72 (bncApp*) qApp, SLOT(slotNewCorrLine(QString, QString, long)));
73}
74
75// Destructor
76////////////////////////////////////////////////////////////////////////////
77RTCM3coDecoder::~RTCM3coDecoder() {
78 delete _out;
79}
80
81// Reopen Output File
82////////////////////////////////////////////////////////////////////////
83void RTCM3coDecoder::reopen() {
84
85 if (!_fileNameSkl.isEmpty()) {
86
87 bncSettings settings;
88
89 QDateTime datTim = currentDateAndTimeGPS();
90
91 QString hlpStr = bncRinex::nextEpochStr(datTim,
92 settings.value("corrIntr").toString());
93
94 QString fileName = _fileNameSkl
95 + QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0'))
96 + hlpStr + datTim.toString(".yyC");
97
98 if (_fileName == fileName) {
99 return;
100 }
101 else {
102 _fileName = fileName;
103 }
104
105 delete _out;
106 _out = new ofstream( _fileName.toAscii().data() );
107 }
108}
109
110//
111////////////////////////////////////////////////////////////////////////////
112t_irc RTCM3coDecoder::Decode(char* buffer, int bufLen, vector<string>& errmsg) {
113
114 errmsg.clear();
115
116 _buffer.append(QByteArray(buffer,bufLen));
117
118 t_irc retCode = failure;
119
120 while (true) {
121
122 memset(&_co, 0, sizeof(_co));
123
124 int bytesused = 0;
125 GCOB_RETURN irc = GetClockOrbitBias(&_co, &_bias, _buffer.data(),
126 _buffer.size(), &bytesused);
127
128 // Not enough Data
129 // ---------------
130 if (irc == GCOBR_SHORTBUFFER ||
131 irc == GCOBR_MESSAGEEXCEEDSBUFFER) {
132 return retCode;
133 }
134
135 // Message correctly decoded
136 // -------------------------
137 else if ( (irc == GCOBR_OK || irc == GCOBR_MESSAGEFOLLOWS) &&
138 bytesused > 0) {
139 reopen();
140
141 int GPSweek;
142 double GPSweeks;
143 currentGPSWeeks(GPSweek, GPSweeks);
144
145 for (int kk = 0; kk < _co.epochSize; kk++) {
146 _epochList.push_back(_co.epochGPS[kk]); /* Weber, for latency */
147 }
148
149 if (_co.NumberOfGPSSat > 0) {
150 if (GPSweeks > _co.GPSEpochTime + 86400.0) {
151 GPSweek += 1;
152 }
153 else if (GPSweeks < _co.GPSEpochTime - 86400.0) {
154 GPSweek -= 1;
155 }
156 GPSweeks = _co.GPSEpochTime;
157 }
158 else {
159 double GPSdaysec = fmod(GPSweeks, 86400.0);
160 int weekDay = int((GPSweeks - GPSdaysec) / 86400.0);
161 if (GPSdaysec > _co.GLONASSEpochTime + 3600.0) {
162 weekDay += 1;
163 if (weekDay > 6) {
164 weekDay = 0;
165 GPSweek += 1;
166 }
167 }
168 else if (GPSdaysec < _co.GLONASSEpochTime - 3600.0) {
169 weekDay -= 1;
170 if (weekDay < 0) {
171 weekDay = 6;
172 GPSweek -= 1;
173 }
174 }
175 GPSweeks = weekDay * 86400.0 + _co.GLONASSEpochTime;
176 }
177
178 for(int ii = 0; ii < _co.NumberOfGPSSat; ++ii) {
179 QString line;
180 line.sprintf("%d %.1f G%2.2d %3d %8.3f %8.3f %8.3f %8.3f",
181 GPSweek, GPSweeks, _co.Sat[ii].ID, _co.Sat[ii].IOD,
182 _co.Sat[ii].Clock.DeltaA0,
183 _co.Sat[ii].Orbit.DeltaRadial,
184 _co.Sat[ii].Orbit.DeltaAlongTrack,
185 _co.Sat[ii].Orbit.DeltaCrossTrack);
186 long coTime = GPSweek * 7*24*3600 + long(floor(GPSweeks+0.5));
187 printLine(line, coTime);
188 }
189 for(int ii = CLOCKORBIT_NUMGPS;
190 ii < CLOCKORBIT_NUMGPS + _co.NumberOfGLONASSSat; ++ii) {
191 QString line;
192 line.sprintf("%d %.1f R%2.2d %3d %8.3f %8.3f %8.3f %8.3f",
193 GPSweek, GPSweeks, _co.Sat[ii].ID, _co.Sat[ii].IOD,
194 _co.Sat[ii].Clock.DeltaA0,
195 _co.Sat[ii].Orbit.DeltaRadial,
196 _co.Sat[ii].Orbit.DeltaAlongTrack,
197 _co.Sat[ii].Orbit.DeltaCrossTrack);
198 long coTime = GPSweek * 7*24*3600 + long(floor(GPSweeks+0.5));
199 printLine(line, coTime);
200 }
201 _buffer = _buffer.mid(bytesused);
202 retCode = success;
203 }
204
205 // All other Cases
206 // ---------------
207 else {
208 _buffer = _buffer.mid(1);
209 }
210 }
211}
212
213//
214////////////////////////////////////////////////////////////////////////////
215void RTCM3coDecoder::printLine(const QString& line, long coTime) {
216 if (_out) {
217 *_out << line.toAscii().data() << endl;
218 _out->flush();
219 }
220
221 emit newCorrLine(line, _staID, coTime);
222}
Note: See TracBrowser for help on using the repository browser.