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

Last change on this file since 2710 was 2710, checked in by mervart, 13 years ago
File size: 6.3 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}
56
57// Constructor
58////////////////////////////////////////////////////////////////////////////
59RTIGSDecoder::RTIGSDecoder() {
60}
61
62// Destructor
63////////////////////////////////////////////////////////////////////////////
64RTIGSDecoder::~RTIGSDecoder() {
65}
66
67//
68////////////////////////////////////////////////////////////////////////////
69t_irc RTIGSDecoder::Decode(char* buffer, int bufLen, vector<string>& errmsg) {
70
71 errmsg.clear();
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 t_obs* obs = new t_obs();
119 _obsList.push_back(obs);
120 obs->satSys = 'G';
121 obs->satNum = _GPSTrans.DecObs.Obs[ii].sat_prn;
122 obs->GPSWeek = _GPSTrans.DecObs.Obs[ii].GPSTime / (7 * 86400);
123 obs->GPSWeeks = _GPSTrans.DecObs.Obs[ii].GPSTime % (7 * 86400);
124 obs->C1 = _GPSTrans.DecObs.Obs[ii].l1_pseudo_range;
125 obs->P1 = _GPSTrans.DecObs.Obs[ii].p1_pseudo_range;
126 obs->P2 = _GPSTrans.DecObs.Obs[ii].p2_pseudo_range;
127 obs->L1P = _GPSTrans.DecObs.Obs[ii].p1_phase;
128 obs->L2P = _GPSTrans.DecObs.Obs[ii].p2_phase;
129 obs->S1P = _GPSTrans.DecObs.Obs[ii].l1_sn;
130 obs->S2P = _GPSTrans.DecObs.Obs[ii].l2_sn;
131 }
132 }
133 if(messType==300){
134 // Decode Ephemeris
135 RTIGSE_T rtigs_eph;
136 BEPH_T new_eph;
137 short PRN;
138 // To TNAV_T
139 // ---------
140 short retval = _GPSTrans.Decode_RTIGS_Eph(p_buf, numbytes , rtigs_eph, PRN);
141 // Ensure it was decoded ok.
142 // ------------------------
143 if(retval==1){
144 // TNAV To BEPH (decodes subframes)
145 // --------------------------------
146 _GPSTrans.TNAV_To_BEPH(&_GPSTrans.TNAV_Eph.Eph[PRN-1],&new_eph);
147 gpsephemeris* ep = new gpsephemeris();
148 // Match datatypes
149 // ---------------
150 ep->flags = (int)new_eph.l2pflag;
151 ep->satellite = (int)new_eph.satellite;
152 ep->IODE = (int)new_eph.issue_of_eph;
153 ep->URAindex = (int)new_eph.user_range_acc;
154 ep->SVhealth = (int)new_eph.sat_health;
155 ep->GPSweek = (int)new_eph.gps_week;
156 ep->IODC = (int)new_eph.issue_of_clock;
157 ep->TOW = (int)new_eph.transmit_time;
158 ep->TOC = (int)new_eph.clock_ref_time;
159 ep->TOE = (int)new_eph.eph_ref_time;
160 ep->clock_bias = new_eph.a0;
161 ep->clock_drift = new_eph.a1;
162 ep->clock_driftrate = new_eph.a2;
163 ep->Crs = new_eph.orbit_sin_corr;
164 ep->Delta_n = new_eph.mean_mot_diff ;
165 ep->M0 = new_eph.ref_mean_anmly;
166 ep->Cuc = new_eph.lat_cos_corr;
167 ep->e = new_eph.orbit_ecc;
168 ep->Cus = new_eph.lat_sin_corr;
169 ep->sqrt_A = new_eph.orbit_semimaj;
170 ep->Cic = new_eph.incl_cos_corr;
171 ep->OMEGA0 = new_eph.right_asc;
172 ep->Cis = new_eph.incl_sin_corr;
173 ep->i0 = new_eph.orbit_incl;
174 ep->Crc = new_eph.orbit_cos_corr;
175 ep->omega = new_eph.arg_of_perigee;
176 ep->OMEGADOT = new_eph.right_asc_rate;
177 ep->IDOT = new_eph.incl_rate;
178 ep->TGD = new_eph.group_delay;
179
180 // Pass back to parent class
181 // --------------------
182 emit _ephSender.newGPSEph(ep);
183 }
184 }
185
186 // 2/1/2008 SPG End
187
188 // Unprocessed bytes remain in buffer
189 // ----------------------------------
190 _buffer = _buffer.substr(numbytes);
191 return success;
192}
Note: See TracBrowser for help on using the repository browser.