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

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

* empty log message *

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