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

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

* empty log message *

File size: 4.5 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
43#include "RTCM3coDecoder.h"
44#include "bncutils.h"
45
46using namespace std;
47
48// Constructor
49////////////////////////////////////////////////////////////////////////////
50RTCM3coDecoder::RTCM3coDecoder(const QString& fileName)
51 : bncZeroDecoder(fileName) {
52}
53
54// Destructor
55////////////////////////////////////////////////////////////////////////////
56RTCM3coDecoder::~RTCM3coDecoder() {
57}
58
59//
60////////////////////////////////////////////////////////////////////////////
61t_irc RTCM3coDecoder::Decode(char* buffer, int bufLen) {
62
63 _buffer.append(buffer, bufLen);
64
65 while (true) {
66
67 memset(&_co, 0, sizeof(_co));
68
69 int bytesused = 0;
70 GCOB_RETURN irc = GetClockOrbitBias(&_co, &_bias, _buffer.data(),
71 _buffer.size(), &bytesused);
72
73 // Not enough Data
74 // ---------------
75 if (irc == GCOBR_SHORTBUFFER ||
76 irc == GCOBR_MESSAGEEXCEEDSBUFFER) {
77 return failure;
78 }
79
80 // Message correctly decoded
81 // -------------------------
82 else if ( (irc == GCOBR_OK || irc == GCOBR_MESSAGEFOLLOWS) &&
83 bytesused > 0) {
84 reopen();
85
86 int GPSweek;
87 double GPSweeks;
88 currentGPSWeeks(GPSweek, GPSweeks);
89
90 if (_co.NumberOfGPSSat > 0) {
91 if (GPSweeks > _co.GPSEpochTime + 86400.0) {
92 GPSweek += 1;
93 }
94 else if (GPSweeks < _co.GPSEpochTime - 86400.0) {
95 GPSweek -= 1;
96 }
97 GPSweeks = _co.GPSEpochTime;
98 }
99 else {
100 double GPSdaysec = fmod(GPSweeks, 86400.0);
101 int weekDay = int((GPSweeks - GPSdaysec) / 86400.0);
102 if (GPSdaysec > _co.GLONASSEpochTime + 3600.0) {
103 weekDay += 1;
104 if (weekDay > 6) {
105 weekDay = 0;
106 GPSweek += 1;
107 }
108 }
109 else if (GPSdaysec < _co.GLONASSEpochTime - 3600.0) {
110 weekDay -= 1;
111 if (weekDay < 0) {
112 weekDay = 6;
113 GPSweek -= 1;
114 }
115 }
116 GPSweeks = weekDay * 86400.0 + _co.GLONASSEpochTime;
117 }
118
119 for(int ii = 0; ii < _co.NumberOfGPSSat; ++ii) {
120 QString line;
121 line.sprintf("%d %.1f G%2.2d %3d %8.3f %8.3f %8.3f %8.3f\n",
122 GPSweek, GPSweeks, _co.Sat[ii].ID, _co.Sat[ii].IOD,
123 _co.Sat[ii].Clock.DeltaA0,
124 _co.Sat[ii].Orbit.DeltaRadial,
125 _co.Sat[ii].Orbit.DeltaAlongTrack,
126 _co.Sat[ii].Orbit.DeltaCrossTrack);
127 *_out << line.toAscii().data();
128 }
129 for(int ii = CLOCKORBIT_NUMGPS;
130 ii < CLOCKORBIT_NUMGPS + _co.NumberOfGLONASSSat; ++ii) {
131 QString line;
132 line.sprintf("%d %.1f R%2.2d %3d %8.3f %8.3f %8.3f %8.3f\n",
133 GPSweek, GPSweeks, _co.Sat[ii].ID, _co.Sat[ii].IOD,
134 _co.Sat[ii].Clock.DeltaA0,
135 _co.Sat[ii].Orbit.DeltaRadial,
136 _co.Sat[ii].Orbit.DeltaAlongTrack,
137 _co.Sat[ii].Orbit.DeltaCrossTrack);
138 *_out << line.toAscii().data();
139 }
140 _out->flush();
141 _buffer = _buffer.substr(bytesused);
142 return success;
143 }
144
145 // All other Cases
146 // ---------------
147 else {
148 _buffer = _buffer.substr(1);
149 }
150 }
151}
Note: See TracBrowser for help on using the repository browser.