1 | // Part of BNC, a utility for retrieving decoding and
|
---|
2 | // converting GNSS data streams from NTRIP broadcasters,
|
---|
3 | // written by Leos Mervart.
|
---|
4 | //
|
---|
5 | // Copyright (C) 2006
|
---|
6 | // German Federal Agency for Cartography and Geodesy (BKG)
|
---|
7 | // http://www.bkg.bund.de
|
---|
8 | // Czech Technical University Prague, Department of Advanced Geodesy
|
---|
9 | // http://www.fsv.cvut.cz
|
---|
10 | //
|
---|
11 | // Email: euref-ip@bkg.bund.de
|
---|
12 | //
|
---|
13 | // This program is free software; you can redistribute it and/or
|
---|
14 | // modify it under the terms of the GNU General Public License
|
---|
15 | // as published by the Free Software Foundation, version 2.
|
---|
16 | //
|
---|
17 | // This program is distributed in the hope that it will be useful,
|
---|
18 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
20 | // GNU General Public License for more details.
|
---|
21 | //
|
---|
22 | // You should have received a copy of the GNU General Public License
|
---|
23 | // along with this program; if not, write to the Free Software
|
---|
24 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
---|
25 |
|
---|
26 | /* -------------------------------------------------------------------------
|
---|
27 | * BKG NTRIP Client
|
---|
28 | * -------------------------------------------------------------------------
|
---|
29 | *
|
---|
30 | * Class: RTIGSDecoder
|
---|
31 | *
|
---|
32 | * Purpose: RTIGS Decoder
|
---|
33 | *
|
---|
34 | * Author: L. Mervart
|
---|
35 | *
|
---|
36 | * Created: 24-Aug-2006
|
---|
37 | *
|
---|
38 | * Changes:
|
---|
39 | *
|
---|
40 | * -----------------------------------------------------------------------*/
|
---|
41 |
|
---|
42 | #include "RTIGSDecoder.h"
|
---|
43 | #include "bncconst.h"
|
---|
44 | #include "rtigs.h"
|
---|
45 |
|
---|
46 | using namespace std;
|
---|
47 |
|
---|
48 | // Constructor
|
---|
49 | ////////////////////////////////////////////////////////////////////////////
|
---|
50 | RTIGSDecoder::RTIGSDecoder() {
|
---|
51 | }
|
---|
52 |
|
---|
53 | // Destructor
|
---|
54 | ////////////////////////////////////////////////////////////////////////////
|
---|
55 | RTIGSDecoder::~RTIGSDecoder() {
|
---|
56 | }
|
---|
57 |
|
---|
58 | //
|
---|
59 | ////////////////////////////////////////////////////////////////////////////
|
---|
60 | void RTIGSDecoder::Decode(char* buffer, int bufLen) {
|
---|
61 |
|
---|
62 | // Append the incomming data to the internal buffer
|
---|
63 | // ------------------------------------------------
|
---|
64 | _buffer.append( QByteArray(buffer, bufLen) );
|
---|
65 |
|
---|
66 | // Find the beginning of the message
|
---|
67 | // ---------------------------------
|
---|
68 | bool found = false;
|
---|
69 | for (int ii = 0; ii < _buffer.size(); ii++) {
|
---|
70 | unsigned short xx;
|
---|
71 | memcpy( (void*) &xx, &_buffer.data()[ii], sizeof(xx) );
|
---|
72 | revbytes( (unsigned char*) &xx, sizeof(xx) );
|
---|
73 | if (xx == 200) {
|
---|
74 | _buffer = _buffer.mid(ii);
|
---|
75 | found = true;
|
---|
76 | break;
|
---|
77 | }
|
---|
78 | }
|
---|
79 | if (! found) {
|
---|
80 | _buffer.clear();
|
---|
81 | return;
|
---|
82 | }
|
---|
83 |
|
---|
84 | // Read the Header
|
---|
85 | // ---------------
|
---|
86 | if (_buffer.size() < (int) sizeof(RTIGSH)) {
|
---|
87 | return;
|
---|
88 | }
|
---|
89 | RTIGSH rtigs_header;
|
---|
90 | bytes_to_rtigsh(&rtigs_header, (unsigned char*) _buffer.data());
|
---|
91 |
|
---|
92 | // Read the Observations
|
---|
93 | // ---------------------
|
---|
94 | int numBytes = sizeof(RTIGSH) + rtigs_header.num_bytes;
|
---|
95 | if (_buffer.size() < numBytes) {
|
---|
96 | return;
|
---|
97 | }
|
---|
98 |
|
---|
99 | if (rtigs_header.rec_id == 200) {
|
---|
100 | RTIGSO rtigs_obs;
|
---|
101 | memcpy(&rtigs_obs, &rtigs_header, sizeof(RTIGSH));
|
---|
102 | memcpy((unsigned char*) &rtigs_obs.data, _buffer.data(),
|
---|
103 | rtigs_header.num_bytes - sizeof(RTIGSH));
|
---|
104 |
|
---|
105 | GPSEpoch epoch;
|
---|
106 | rtigso_to_raw(&rtigs_obs, &epoch);
|
---|
107 |
|
---|
108 | for (short ii = 0; ii < epoch.num_sv; ii++) {
|
---|
109 | Observation* obs = new Observation();
|
---|
110 |
|
---|
111 | obs->SVPRN = epoch.sv[ii].prn;
|
---|
112 | obs->GPSWeek = epoch.GPSTime / (7 * 86400);
|
---|
113 | obs->GPSWeeks = epoch.GPSTime % (7 * 86400);
|
---|
114 | obs->C1 = epoch.sv[ii].CARange;
|
---|
115 | obs->P1 = epoch.sv[ii].P1Range;
|
---|
116 | obs->P2 = epoch.sv[ii].P2Range;
|
---|
117 | obs->L1 = epoch.sv[ii].L1Phase;
|
---|
118 | obs->L2 = epoch.sv[ii].L2Phase;
|
---|
119 | obs->SNR1 = int(epoch.sv[ii].L1Snr * 10);
|
---|
120 | obs->SNR2 = int(epoch.sv[ii].L2Snr * 10);
|
---|
121 |
|
---|
122 | _obsList.push_back(obs);
|
---|
123 | }
|
---|
124 | }
|
---|
125 |
|
---|
126 | // Unprocessed bytes remain in buffer
|
---|
127 | // ----------------------------------
|
---|
128 | _buffer = _buffer.mid(numBytes);
|
---|
129 | }
|
---|