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

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

* empty log message *

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