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

Last change on this file since 1023 was 1023, checked in by mervart, 16 years ago

* empty log message *

File size: 6.1 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
49using namespace std;
50
51// Constructor
52////////////////////////////////////////////////////////////////////////////
53RTCM3coDecoder::RTCM3coDecoder(const QString& staID) {
54
55 _staID = staID;
56
57 // File Output
58 // -----------
59 QSettings settings;
60 QString path = settings.value("corrPath").toString();
61 if (!path.isEmpty()) {
62 expandEnvVar(path);
63 if ( path.length() > 0 && path[path.length()-1] != QDir::separator() ) {
64 path += QDir::separator();
65 }
66 _fileNameSkl = path + staID;
67 }
68 _out = 0;
69
70 connect(this, SIGNAL(newCorrLine(QString, QString, long)),
71 (bncApp*) qApp, SLOT(slotNewCorrLine(QString, QString, long)));
72}
73
74// Destructor
75////////////////////////////////////////////////////////////////////////////
76RTCM3coDecoder::~RTCM3coDecoder() {
77 delete _out;
78}
79
80// Reopen Output File
81////////////////////////////////////////////////////////////////////////
82void RTCM3coDecoder::reopen() {
83
84 if (!_fileNameSkl.isEmpty()) {
85
86 QSettings settings;
87
88 QDateTime datTim = QDateTime::currentDateTime().toUTC();
89
90 QString hlpStr = bncRinex::nextEpochStr(datTim,
91 settings.value("corrIntr").toString());
92
93 QString fileName = _fileNameSkl
94 + QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0'))
95 + hlpStr + datTim.toString(".yyC");
96
97 if (_fileName == fileName) {
98 return;
99 }
100 else {
101 _fileName = fileName;
102 }
103
104 delete _out;
105 _out = new ofstream( _fileName.toAscii().data() );
106 }
107}
108
109//
110////////////////////////////////////////////////////////////////////////////
111t_irc RTCM3coDecoder::Decode(char* buffer, int bufLen) {
112
113 _buffer.append(buffer, bufLen);
114
115 t_irc retCode = failure;
116
117 while (true) {
118
119 memset(&_co, 0, sizeof(_co));
120
121 int bytesused = 0;
122 GCOB_RETURN irc = GetClockOrbitBias(&_co, &_bias, _buffer.data(),
123 _buffer.size(), &bytesused);
124
125 // Not enough Data
126 // ---------------
127 if (irc == GCOBR_SHORTBUFFER ||
128 irc == GCOBR_MESSAGEEXCEEDSBUFFER) {
129 return retCode;
130 }
131
132 // Message correctly decoded
133 // -------------------------
134 else if ( (irc == GCOBR_OK || irc == GCOBR_MESSAGEFOLLOWS) &&
135 bytesused > 0) {
136 reopen();
137
138 int GPSweek;
139 double GPSweeks;
140 currentGPSWeeks(GPSweek, GPSweeks);
141
142 if (_co.NumberOfGPSSat > 0) {
143 if (GPSweeks > _co.GPSEpochTime + 86400.0) {
144 GPSweek += 1;
145 }
146 else if (GPSweeks < _co.GPSEpochTime - 86400.0) {
147 GPSweek -= 1;
148 }
149 GPSweeks = _co.GPSEpochTime;
150 }
151 else {
152 double GPSdaysec = fmod(GPSweeks, 86400.0);
153 int weekDay = int((GPSweeks - GPSdaysec) / 86400.0);
154 if (GPSdaysec > _co.GLONASSEpochTime + 3600.0) {
155 weekDay += 1;
156 if (weekDay > 6) {
157 weekDay = 0;
158 GPSweek += 1;
159 }
160 }
161 else if (GPSdaysec < _co.GLONASSEpochTime - 3600.0) {
162 weekDay -= 1;
163 if (weekDay < 0) {
164 weekDay = 6;
165 GPSweek -= 1;
166 }
167 }
168 GPSweeks = weekDay * 86400.0 + _co.GLONASSEpochTime;
169 }
170
171 for(int ii = 0; ii < _co.NumberOfGPSSat; ++ii) {
172 QString line;
173 line.sprintf("%d %.1f G%2.2d %3d %8.3f %8.3f %8.3f %8.3f",
174 GPSweek, GPSweeks, _co.Sat[ii].ID, _co.Sat[ii].IOD,
175 _co.Sat[ii].Clock.DeltaA0,
176 _co.Sat[ii].Orbit.DeltaRadial,
177 _co.Sat[ii].Orbit.DeltaAlongTrack,
178 _co.Sat[ii].Orbit.DeltaCrossTrack);
179 long coTime = GPSweek * 7*24*3600 + long(floor(GPSweeks+0.5));
180 printLine(line, coTime);
181 }
182 for(int ii = CLOCKORBIT_NUMGPS;
183 ii < CLOCKORBIT_NUMGPS + _co.NumberOfGLONASSSat; ++ii) {
184 QString line;
185 line.sprintf("%d %.1f R%2.2d %3d %8.3f %8.3f %8.3f %8.3f",
186 GPSweek, GPSweeks, _co.Sat[ii].ID, _co.Sat[ii].IOD,
187 _co.Sat[ii].Clock.DeltaA0,
188 _co.Sat[ii].Orbit.DeltaRadial,
189 _co.Sat[ii].Orbit.DeltaAlongTrack,
190 _co.Sat[ii].Orbit.DeltaCrossTrack);
191 long coTime = GPSweek * 7*24*3600 + long(floor(GPSweeks+0.5));
192 printLine(line, coTime);
193 }
194 _buffer = _buffer.substr(bytesused);
195 retCode = success;
196 }
197
198 // All other Cases
199 // ---------------
200 else {
201 _buffer = _buffer.substr(1);
202 }
203 }
204}
205
206//
207////////////////////////////////////////////////////////////////////////////
208void RTCM3coDecoder::printLine(const QString& line, long coTime) {
209 if (_out) {
210 *_out << line.toAscii().data() << endl;
211 _out->flush();
212 }
213
214 emit newCorrLine(line, _staID, coTime);
215}
Note: See TracBrowser for help on using the repository browser.