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

Last change on this file since 1747 was 1218, checked in by mervart, 16 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
RevLine 
[306]1// Part of BNC, a utility for retrieving decoding and
[464]2// converting GNSS data streams from NTRIP broadcasters.
[306]3//
[464]4// Copyright (C) 2007
[306]5// German Federal Agency for Cartography and Geodesy (BKG)
6// http://www.bkg.bund.de
[464]7// Czech Technical University Prague, Department of Geodesy
[306]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.
[293]24
25/* -------------------------------------------------------------------------
26 * BKG NTRIP Client
27 * -------------------------------------------------------------------------
28 *
[306]29 * Class: RTIGSDecoder
[293]30 *
31 * Purpose: RTIGS Decoder
32 *
33 * Author: L. Mervart
34 *
35 * Created: 24-Aug-2006
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
[306]41#include "RTIGSDecoder.h"
[293]42#include "bncconst.h"
[661]43#include "bncapp.h"
[293]44
45using namespace std;
46
[305]47#undef L1
48#undef L2
49
[661]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
[293]59// Constructor
60////////////////////////////////////////////////////////////////////////////
[306]61RTIGSDecoder::RTIGSDecoder() {
[293]62}
63
64// Destructor
65////////////////////////////////////////////////////////////////////////////
[306]66RTIGSDecoder::~RTIGSDecoder() {
[293]67}
68
69//
70////////////////////////////////////////////////////////////////////////////
[1218]71t_irc RTIGSDecoder::Decode(char* buffer, int bufLen, vector<string>& errmsg) {
[293]72
[1218]73 errmsg.clear();
74
[293]75 // Append the incomming data to the internal buffer
76 // ------------------------------------------------
[457]77 _buffer.append(buffer, bufLen);
[293]78
79 // Find the beginning of the message
80 // ---------------------------------
81 bool found = false;
[457]82 for (unsigned ii = 0; ii < _buffer.size(); ii++) {
[293]83 unsigned short xx;
[457]84 memcpy( (void*) &xx, &_buffer[ii], sizeof(xx) );
[305]85 if (_GPSTrans.f_IsLittleEndian) {
86 SwitchBytes( (char*) &xx, sizeof(xx) );
87 }
[661]88 if (xx == 200 || xx == 300 ) { // 2/1/2008 SPG
[457]89 _buffer = _buffer.substr(ii);
[293]90 found = true;
91 break;
92 }
93 }
[305]94
[293]95 if (! found) {
96 _buffer.clear();
[649]97 return failure;
[293]98 }
99
[305]100 unsigned char* p_buf = (unsigned char*) _buffer.data();
[293]101
[305]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) {
[652]108 return success;
[293]109 }
110
[661]111 // 2/1/2008 SPG Start
[305]112 // Decode the epoch
113 // ----------------
114 if (messType == 200) {
[661]115 // Decode Obs
[305]116 RTIGSO_T rtigs_obs;
117 short numObs = _GPSTrans.Decode_RTIGS_Obs(p_buf, numbytes, rtigs_obs);
[293]118
[305]119 for (short ii = 0; ii < numObs; ii++) {
[622]120 p_obs obs = new t_obs();
[627]121 _obsList.push_back(obs);
[622]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));
[293]135 }
136 }
[661]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;
[293]183
[661]184 // Pass back to parent class
185 // --------------------
186 emit _ephSender.newGPSEph(ep);
187 }
188 }
189
190 // 2/1/2008 SPG End
191
[293]192 // Unprocessed bytes remain in buffer
193 // ----------------------------------
[457]194 _buffer = _buffer.substr(numbytes);
[649]195 return success;
[293]196}
Note: See TracBrowser for help on using the repository browser.