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

Last change on this file since 684 was 661, checked in by mervart, 17 years ago

* empty log message *

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