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: test_bnc_qt
|
---|
30 | *
|
---|
31 | * Purpose: Example program to read BNC output from IP port.
|
---|
32 | *
|
---|
33 | * Author: L. Mervart
|
---|
34 | *
|
---|
35 | * Created: 24-Jan-2007
|
---|
36 | *
|
---|
37 | * Changes:
|
---|
38 | *
|
---|
39 | * -----------------------------------------------------------------------*/
|
---|
40 |
|
---|
41 | #include <stdlib.h>
|
---|
42 | #include <iostream>
|
---|
43 | #include <iomanip>
|
---|
44 | #include <QTcpSocket>
|
---|
45 |
|
---|
46 | using namespace std;
|
---|
47 |
|
---|
48 | class t_obs {
|
---|
49 | public:
|
---|
50 | double L1() const {return (L1P != 0.0 ? L1P : L1C);}
|
---|
51 | double L2() const {return (L2P != 0.0 ? L2P : L2C);}
|
---|
52 | double S1() const {return (L1P != 0.0 ? S1P : S1C);}
|
---|
53 | double S2() const {return (L2P != 0.0 ? S2P : S2C);}
|
---|
54 |
|
---|
55 | char StatID[20+1]; // Station ID
|
---|
56 | char satSys; // Satellite System ('G' or 'R')
|
---|
57 | int satNum; // Satellite Number (PRN for GPS NAVSTAR)
|
---|
58 | int slotNum; // Slot Number (for Glonass)
|
---|
59 | int GPSWeek; // Week of GPS-Time
|
---|
60 | double GPSWeeks; // Second of Week (GPS-Time)
|
---|
61 |
|
---|
62 | double C1; // CA-code pseudorange (meters)
|
---|
63 | double P1; // P1-code pseudorange (meters)
|
---|
64 | double L1C; // L1 carrier phase (cycles)
|
---|
65 | double D1C; // Doppler L1
|
---|
66 | double S1C; // raw L1 signal strength
|
---|
67 | double L1P; // L1 carrier phase (cycles)
|
---|
68 | double D1P; // Doppler L1
|
---|
69 | double S1P; // raw L1 signal strength
|
---|
70 |
|
---|
71 | double C2; // CA-code pseudorange (meters)
|
---|
72 | double P2; // P2-code pseudorange (meters)
|
---|
73 | double L2C; // L2 carrier phase (cycles)
|
---|
74 | double D2C; // Doppler L2
|
---|
75 | double S2C; // raw L2 signal strength
|
---|
76 | double L2P; // L2 carrier phase (cycles)
|
---|
77 | double D2P; // Doppler L2
|
---|
78 | double S2P; // raw L2 signal strength
|
---|
79 |
|
---|
80 | double C5; // Pseudorange (meters)
|
---|
81 | double L5; // L5 carrier phase (cycles)
|
---|
82 | double D5; // Doppler L5
|
---|
83 | double S5; // raw L5 signal strength
|
---|
84 |
|
---|
85 | int slip_cnt_L1; // L1 cumulative loss of continuity indicator (negative value = undefined)
|
---|
86 | int slip_cnt_L2; // L2 cumulative loss of continuity indicator (negative value = undefined)
|
---|
87 | int slip_cnt_L5; // L5 cumulative loss of continuity indicator (negative value = undefined)
|
---|
88 | };
|
---|
89 |
|
---|
90 | int main(int argc, char** argv) {
|
---|
91 |
|
---|
92 | if (argc != 2) {
|
---|
93 | cerr << "Usage: test_bnc_qt port\n";
|
---|
94 | exit(1);
|
---|
95 | }
|
---|
96 |
|
---|
97 | int port = atoi(argv[1]);
|
---|
98 |
|
---|
99 | QTcpSocket socketObs;
|
---|
100 |
|
---|
101 | socketObs.connectToHost("127.0.0.1", port);
|
---|
102 | if (!socketObs.waitForConnected(10000)) {
|
---|
103 | cerr << "socketObs: not connected on port " << port << endl;
|
---|
104 | exit(1);
|
---|
105 | }
|
---|
106 |
|
---|
107 | cout.setf(ios::fixed);
|
---|
108 |
|
---|
109 | // Receive Data
|
---|
110 | // ------------
|
---|
111 | const char begObs[] = "BEGOBS";
|
---|
112 | const char begEpoch[] = "BEGEPOCH";
|
---|
113 | const char endEpoch[] = "ENDEPOCH";
|
---|
114 | const unsigned begObsNBytes = sizeof(begObs) - 1;
|
---|
115 | const unsigned begEpochNBytes = sizeof(begEpoch) - 1;
|
---|
116 | const unsigned endEpochNBytes = sizeof(endEpoch) - 1;
|
---|
117 |
|
---|
118 | QByteArray buffer;
|
---|
119 |
|
---|
120 | while (true) {
|
---|
121 | if (socketObs.state() != QAbstractSocket::ConnectedState) {
|
---|
122 | cerr << "socketObs: disconnected" << endl;
|
---|
123 | exit(1);
|
---|
124 | }
|
---|
125 |
|
---|
126 | if ( socketObs.bytesAvailable() ) {
|
---|
127 | buffer += socketObs.readAll();
|
---|
128 |
|
---|
129 | // Skip begEpoch and endEpoch Marks
|
---|
130 | // --------------------------------
|
---|
131 | for (;;) {
|
---|
132 | int i1 = buffer.indexOf(begEpoch);
|
---|
133 | if (i1 == -1) {
|
---|
134 | break;
|
---|
135 | }
|
---|
136 | else {
|
---|
137 | buffer.remove(i1, begEpochNBytes);
|
---|
138 | cout << endl;
|
---|
139 | }
|
---|
140 | }
|
---|
141 | for (;;) {
|
---|
142 | int i2 = buffer.indexOf(endEpoch);
|
---|
143 | if (i2 == -1) {
|
---|
144 | break;
|
---|
145 | }
|
---|
146 | else {
|
---|
147 | buffer.remove(i2, endEpochNBytes);
|
---|
148 | }
|
---|
149 | }
|
---|
150 | for (;;) {
|
---|
151 | int i3 = buffer.indexOf(begObs);
|
---|
152 | if (i3 == -1) {
|
---|
153 | break;
|
---|
154 | }
|
---|
155 | else {
|
---|
156 | buffer.remove(i3, begObsNBytes);
|
---|
157 | }
|
---|
158 | }
|
---|
159 |
|
---|
160 | // Interpret a portion of buffer as observation
|
---|
161 | // --------------------------------------------
|
---|
162 | t_obs* obs;
|
---|
163 | const int obsSize = sizeof(t_obs);
|
---|
164 |
|
---|
165 |
|
---|
166 | while (buffer.size() >= obsSize) {
|
---|
167 |
|
---|
168 | obs = (t_obs*) (buffer.left(obsSize).data());
|
---|
169 |
|
---|
170 | cout << obs->StatID << " "
|
---|
171 | << obs->satSys << obs->satNum << " "
|
---|
172 | << obs->GPSWeek << " "
|
---|
173 | << setprecision(2) << obs->GPSWeeks << " "
|
---|
174 | << setprecision(4) << obs->C1 << " "
|
---|
175 | << setprecision(4) << obs->C2 << " "
|
---|
176 | << setprecision(4) << obs->P1 << " "
|
---|
177 | << setprecision(4) << obs->P2 << " "
|
---|
178 | << setprecision(4) << obs->L1() << " "
|
---|
179 | << obs->slip_cnt_L1 << " "
|
---|
180 | << setprecision(4) << obs->L2() << " "
|
---|
181 | << obs->slip_cnt_L2 << " "
|
---|
182 | << setprecision(4) << obs->S1() << " "
|
---|
183 | << setprecision(4) << obs->S2() << endl;
|
---|
184 |
|
---|
185 | buffer.remove(0,obsSize);
|
---|
186 | }
|
---|
187 | }
|
---|
188 | else {
|
---|
189 | socketObs.waitForReadyRead(1);
|
---|
190 | }
|
---|
191 | }
|
---|
192 |
|
---|
193 | return 0;
|
---|
194 | }
|
---|