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

Last change on this file since 920 was 920, checked in by weber, 16 years ago

* empty log message *

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