[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 |
|
---|
| 45 | using namespace std;
|
---|
| 46 |
|
---|
[305] | 47 | #undef L1
|
---|
| 48 | #undef L2
|
---|
| 49 |
|
---|
[661] | 50 | //
|
---|
| 51 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 52 | ephSenderRTIGS::ephSenderRTIGS() {
|
---|
| 53 | connect(this, SIGNAL(newGPSEph(gpsephemeris*)),
|
---|
[2585] | 54 | (bncApp*) qApp, SLOT(slotNewGPSEph(gpsephemeris*)));
|
---|
[661] | 55 | }
|
---|
| 56 |
|
---|
[293] | 57 | // Constructor
|
---|
| 58 | ////////////////////////////////////////////////////////////////////////////
|
---|
[306] | 59 | RTIGSDecoder::RTIGSDecoder() {
|
---|
[293] | 60 | }
|
---|
| 61 |
|
---|
| 62 | // Destructor
|
---|
| 63 | ////////////////////////////////////////////////////////////////////////////
|
---|
[306] | 64 | RTIGSDecoder::~RTIGSDecoder() {
|
---|
[293] | 65 | }
|
---|
| 66 |
|
---|
| 67 | //
|
---|
| 68 | ////////////////////////////////////////////////////////////////////////////
|
---|
[1218] | 69 | t_irc RTIGSDecoder::Decode(char* buffer, int bufLen, vector<string>& errmsg) {
|
---|
[293] | 70 |
|
---|
[1218] | 71 | errmsg.clear();
|
---|
| 72 |
|
---|
[293] | 73 | // Append the incomming data to the internal buffer
|
---|
| 74 | // ------------------------------------------------
|
---|
[457] | 75 | _buffer.append(buffer, bufLen);
|
---|
[293] | 76 |
|
---|
| 77 | // Find the beginning of the message
|
---|
| 78 | // ---------------------------------
|
---|
| 79 | bool found = false;
|
---|
[457] | 80 | for (unsigned ii = 0; ii < _buffer.size(); ii++) {
|
---|
[293] | 81 | unsigned short xx;
|
---|
[457] | 82 | memcpy( (void*) &xx, &_buffer[ii], sizeof(xx) );
|
---|
[305] | 83 | if (_GPSTrans.f_IsLittleEndian) {
|
---|
| 84 | SwitchBytes( (char*) &xx, sizeof(xx) );
|
---|
| 85 | }
|
---|
[661] | 86 | if (xx == 200 || xx == 300 ) { // 2/1/2008 SPG
|
---|
[457] | 87 | _buffer = _buffer.substr(ii);
|
---|
[293] | 88 | found = true;
|
---|
| 89 | break;
|
---|
| 90 | }
|
---|
| 91 | }
|
---|
[305] | 92 |
|
---|
[293] | 93 | if (! found) {
|
---|
| 94 | _buffer.clear();
|
---|
[649] | 95 | return failure;
|
---|
[293] | 96 | }
|
---|
| 97 |
|
---|
[305] | 98 | unsigned char* p_buf = (unsigned char*) _buffer.data();
|
---|
[293] | 99 |
|
---|
[305] | 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) {
|
---|
[652] | 106 | return success;
|
---|
[293] | 107 | }
|
---|
| 108 |
|
---|
[661] | 109 | // 2/1/2008 SPG Start
|
---|
[305] | 110 | // Decode the epoch
|
---|
| 111 | // ----------------
|
---|
| 112 | if (messType == 200) {
|
---|
[661] | 113 | // Decode Obs
|
---|
[305] | 114 | RTIGSO_T rtigs_obs;
|
---|
| 115 | short numObs = _GPSTrans.Decode_RTIGS_Obs(p_buf, numbytes, rtigs_obs);
|
---|
[293] | 116 |
|
---|
[305] | 117 | for (short ii = 0; ii < numObs; ii++) {
|
---|
[622] | 118 | p_obs obs = new t_obs();
|
---|
[627] | 119 | _obsList.push_back(obs);
|
---|
[622] | 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));
|
---|
[293] | 133 | }
|
---|
| 134 | }
|
---|
[661] | 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;
|
---|
[293] | 181 |
|
---|
[661] | 182 | // Pass back to parent class
|
---|
| 183 | // --------------------
|
---|
| 184 | emit _ephSender.newGPSEph(ep);
|
---|
| 185 | }
|
---|
| 186 | }
|
---|
| 187 |
|
---|
| 188 | // 2/1/2008 SPG End
|
---|
| 189 |
|
---|
[293] | 190 | // Unprocessed bytes remain in buffer
|
---|
| 191 | // ----------------------------------
|
---|
[457] | 192 | _buffer = _buffer.substr(numbytes);
|
---|
[649] | 193 | return success;
|
---|
[293] | 194 | }
|
---|