source: ntrip/trunk/BNC/RTIGS/RTIGSDecoder.cpp@ 2013

Last change on this file since 2013 was 1218, checked in by mervart, 15 years ago

Zdenek Lukes:
a) changed logic how the ephemerides are stored for decoding of message 20/21 RTCM 2.3
b) added some debugging output (enabled is macro DEBUG_RTCM2_2021 is defined)

File size: 6.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: RTIGSDecoder
30 *
31 * Purpose: RTIGS Decoder
32 *
33 * Author: L. Mervart
34 *
35 * Created: 24-Aug-2006
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include "RTIGSDecoder.h"
42#include "bncconst.h"
43#include "bncapp.h"
44
45using namespace std;
46
47#undef L1
48#undef L2
49
50//
51////////////////////////////////////////////////////////////////////////////
52ephSenderRTIGS::ephSenderRTIGS() {
53 connect(this, SIGNAL(newGPSEph(gpsephemeris*)),
54 (bncApp*) qApp, SLOT(slotNewGPSEph(gpsephemeris*)));
55 //connect(this, SIGNAL(newGlonassEph(glonassephemeris*)),
56 // (bncApp*) qApp, SLOT(slotNewGlonassEph(glonassephemeris*)));
57}
58
59// Constructor
60////////////////////////////////////////////////////////////////////////////
61RTIGSDecoder::RTIGSDecoder() {
62}
63
64// Destructor
65////////////////////////////////////////////////////////////////////////////
66RTIGSDecoder::~RTIGSDecoder() {
67}
68
69//
70////////////////////////////////////////////////////////////////////////////
71t_irc RTIGSDecoder::Decode(char* buffer, int bufLen, vector<string>& errmsg) {
72
73 errmsg.clear();
74
75 // Append the incomming data to the internal buffer
76 // ------------------------------------------------
77 _buffer.append(buffer, bufLen);
78
79 // Find the beginning of the message
80 // ---------------------------------
81 bool found = false;
82 for (unsigned ii = 0; ii < _buffer.size(); ii++) {
83 unsigned short xx;
84 memcpy( (void*) &xx, &_buffer[ii], sizeof(xx) );
85 if (_GPSTrans.f_IsLittleEndian) {
86 SwitchBytes( (char*) &xx, sizeof(xx) );
87 }
88 if (xx == 200 || xx == 300 ) { // 2/1/2008 SPG
89 _buffer = _buffer.substr(ii);
90 found = true;
91 break;
92 }
93 }
94
95 if (! found) {
96 _buffer.clear();
97 return failure;
98 }
99
100 unsigned char* p_buf = (unsigned char*) _buffer.data();
101
102 unsigned short messType = _GPSTrans.GetRTIGSHdrRecType(p_buf);
103 unsigned short numbytes = _GPSTrans.GetRTIGSHdrRecBytes(p_buf);
104
105 // Not enough new data, return
106 // ---------------------------
107 if (_buffer.size() < numbytes) {
108 return success;
109 }
110
111 // 2/1/2008 SPG Start
112 // Decode the epoch
113 // ----------------
114 if (messType == 200) {
115 // Decode Obs
116 RTIGSO_T rtigs_obs;
117 short numObs = _GPSTrans.Decode_RTIGS_Obs(p_buf, numbytes, rtigs_obs);
118
119 for (short ii = 0; ii < numObs; ii++) {
120 p_obs obs = new t_obs();
121 _obsList.push_back(obs);
122 obs->_o.satSys = 'G';
123 obs->_o.satNum = _GPSTrans.DecObs.Obs[ii].sat_prn;
124 obs->_o.GPSWeek = _GPSTrans.DecObs.Obs[ii].GPSTime / (7 * 86400);
125 obs->_o.GPSWeeks = _GPSTrans.DecObs.Obs[ii].GPSTime % (7 * 86400);
126 obs->_o.C1 = _GPSTrans.DecObs.Obs[ii].l1_pseudo_range;
127 obs->_o.P1 = _GPSTrans.DecObs.Obs[ii].p1_pseudo_range;
128 obs->_o.P2 = _GPSTrans.DecObs.Obs[ii].p2_pseudo_range;
129 obs->_o.L1 = _GPSTrans.DecObs.Obs[ii].p1_phase;
130 obs->_o.L2 = _GPSTrans.DecObs.Obs[ii].p2_phase;
131 obs->_o.S1 = _GPSTrans.DecObs.Obs[ii].l1_sn;
132 obs->_o.S2 = _GPSTrans.DecObs.Obs[ii].l2_sn;
133 obs->_o.SNR1 = int(ceil(_GPSTrans.DecObs.Obs[ii].l1_sn / 60.0 * 9.0));
134 obs->_o.SNR2 = int(ceil(_GPSTrans.DecObs.Obs[ii].l2_sn / 60.0 * 9.0));
135 }
136 }
137 if(messType==300){
138 // Decode Ephemeris
139 RTIGSE_T rtigs_eph;
140 BEPH_T new_eph;
141 short PRN;
142 // To TNAV_T
143 // ---------
144 short retval = _GPSTrans.Decode_RTIGS_Eph(p_buf, numbytes , rtigs_eph, PRN);
145 // Ensure it was decoded ok.
146 // ------------------------
147 if(retval==1){
148 // TNAV To BEPH (decodes subframes)
149 // --------------------------------
150 _GPSTrans.TNAV_To_BEPH(&_GPSTrans.TNAV_Eph.Eph[PRN-1],&new_eph);
151 gpsephemeris* ep = new gpsephemeris();
152 // Match datatypes
153 // ---------------
154 ep->flags = (int)new_eph.l2pflag;
155 ep->satellite = (int)new_eph.satellite;
156 ep->IODE = (int)new_eph.issue_of_eph;
157 ep->URAindex = (int)new_eph.user_range_acc;
158 ep->SVhealth = (int)new_eph.sat_health;
159 ep->GPSweek = (int)new_eph.gps_week;
160 ep->IODC = (int)new_eph.issue_of_clock;
161 ep->TOW = (int)new_eph.transmit_time;
162 ep->TOC = (int)new_eph.clock_ref_time;
163 ep->TOE = (int)new_eph.eph_ref_time;
164 ep->clock_bias = new_eph.a0;
165 ep->clock_drift = new_eph.a1;
166 ep->clock_driftrate = new_eph.a2;
167 ep->Crs = new_eph.orbit_sin_corr;
168 ep->Delta_n = new_eph.mean_mot_diff ;
169 ep->M0 = new_eph.ref_mean_anmly;
170 ep->Cuc = new_eph.lat_cos_corr;
171 ep->e = new_eph.orbit_ecc;
172 ep->Cus = new_eph.lat_sin_corr;
173 ep->sqrt_A = new_eph.orbit_semimaj;
174 ep->Cic = new_eph.incl_cos_corr;
175 ep->OMEGA0 = new_eph.right_asc;
176 ep->Cis = new_eph.incl_sin_corr;
177 ep->i0 = new_eph.orbit_incl;
178 ep->Crc = new_eph.orbit_cos_corr;
179 ep->omega = new_eph.arg_of_perigee;
180 ep->OMEGADOT = new_eph.right_asc_rate;
181 ep->IDOT = new_eph.incl_rate;
182 ep->TGD = new_eph.group_delay;
183
184 // Pass back to parent class
185 // --------------------
186 emit _ephSender.newGPSEph(ep);
187 }
188 }
189
190 // 2/1/2008 SPG End
191
192 // Unprocessed bytes remain in buffer
193 // ----------------------------------
194 _buffer = _buffer.substr(numbytes);
195 return success;
196}
Note: See TracBrowser for help on using the repository browser.