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_obsOld {
|
---|
49 | public:
|
---|
50 | int flags;
|
---|
51 | char StatID[20+1]; // Station ID
|
---|
52 | char satSys; // Satellite System ('G' or 'R')
|
---|
53 | int satNum; // Satellite Number (PRN for GPS NAVSTAR)
|
---|
54 | int slot; // Slot (Channel) Number (for Glonass)
|
---|
55 | int GPSWeek; // Week of GPS-Time
|
---|
56 | double GPSWeeks; // Second of Week (GPS-Time)
|
---|
57 | double C1; // CA-code pseudorange (meters)
|
---|
58 | double C2; // CA-code pseudorange (meters)
|
---|
59 | double P1; // P1-code pseudorange (meters)
|
---|
60 | double P2; // P2-code pseudorange (meters)
|
---|
61 | double L1; // L1 carrier phase (cycles)
|
---|
62 | double L2; // L2 carrier phase (cycles)
|
---|
63 | int slip_cnt_L1; // L1 cumulative loss of continuity indicator (negative value = undefined)
|
---|
64 | int slip_cnt_L2; // L2 cumulative loss of continuity indicator (negative value = undefined)
|
---|
65 | int lock_timei_L1; // L1 last lock time indicator (negative value = undefined)
|
---|
66 | int lock_timei_L2; // L2 last lock time indicator (negative value = undefined)
|
---|
67 | double S1; // L1 signal-to noise ratio
|
---|
68 | double S2; // L2 signal-to noise ratio
|
---|
69 | int SNR1; // L1 signal-to noise ratio (mapped to integer)
|
---|
70 | int SNR2; // L2 signal-to noise ratio (mapped to integer)
|
---|
71 | };
|
---|
72 |
|
---|
73 | int main(int argc, char** argv) {
|
---|
74 |
|
---|
75 | if (argc != 2) {
|
---|
76 | cerr << "Usage: test_bnc_qt port\n";
|
---|
77 | exit(1);
|
---|
78 | }
|
---|
79 |
|
---|
80 | int port = atoi(argv[1]);
|
---|
81 |
|
---|
82 | QTcpSocket socketObs;
|
---|
83 |
|
---|
84 | socketObs.connectToHost("127.0.0.1", port);
|
---|
85 | if (!socketObs.waitForConnected(10000)) {
|
---|
86 | cerr << "socketObs: not connected on port " << port << endl;
|
---|
87 | exit(1);
|
---|
88 | }
|
---|
89 |
|
---|
90 | cout.setf(ios::fixed);
|
---|
91 |
|
---|
92 | // Receive Data
|
---|
93 | // ------------
|
---|
94 | const char begObs[] = "BEGOBS";
|
---|
95 | const char begEpoch[] = "BEGEPOCH";
|
---|
96 | const char endEpoch[] = "ENDEPOCH";
|
---|
97 | const unsigned begObsNBytes = sizeof(begObs) - 1;
|
---|
98 | const unsigned begEpochNBytes = sizeof(begEpoch) - 1;
|
---|
99 | const unsigned endEpochNBytes = sizeof(endEpoch) - 1;
|
---|
100 |
|
---|
101 | QByteArray buffer;
|
---|
102 |
|
---|
103 | while (true) {
|
---|
104 | if (socketObs.state() != QAbstractSocket::ConnectedState) {
|
---|
105 | cerr << "socketObs: disconnected" << endl;
|
---|
106 | exit(1);
|
---|
107 | }
|
---|
108 |
|
---|
109 | if ( socketObs.bytesAvailable() ) {
|
---|
110 | buffer += socketObs.readAll();
|
---|
111 |
|
---|
112 | // Skip begEpoch and endEpoch Marks
|
---|
113 | // --------------------------------
|
---|
114 | for (;;) {
|
---|
115 | int i1 = buffer.indexOf(begEpoch);
|
---|
116 | if (i1 == -1) {
|
---|
117 | break;
|
---|
118 | }
|
---|
119 | else {
|
---|
120 | buffer.remove(i1, begEpochNBytes);
|
---|
121 | cout << endl;
|
---|
122 | }
|
---|
123 | }
|
---|
124 | for (;;) {
|
---|
125 | int i2 = buffer.indexOf(endEpoch);
|
---|
126 | if (i2 == -1) {
|
---|
127 | break;
|
---|
128 | }
|
---|
129 | else {
|
---|
130 | buffer.remove(i2, endEpochNBytes);
|
---|
131 | }
|
---|
132 | }
|
---|
133 | for (;;) {
|
---|
134 | int i3 = buffer.indexOf(begObs);
|
---|
135 | if (i3 == -1) {
|
---|
136 | break;
|
---|
137 | }
|
---|
138 | else {
|
---|
139 | buffer.remove(i3, begObsNBytes);
|
---|
140 | }
|
---|
141 | }
|
---|
142 |
|
---|
143 | // Interpret a portion of buffer as observation
|
---|
144 | // --------------------------------------------
|
---|
145 | t_obsOld* obs;
|
---|
146 | const int obsSize = sizeof(t_obsOld);
|
---|
147 |
|
---|
148 |
|
---|
149 | while (buffer.size() >= obsSize) {
|
---|
150 |
|
---|
151 | obs = (t_obsOld*) (buffer.left(obsSize).data());
|
---|
152 |
|
---|
153 | cout << obs->StatID << " "
|
---|
154 | << obs->satSys << obs->satNum << " "
|
---|
155 | << obs->GPSWeek << " "
|
---|
156 | << setprecision(2) << obs->GPSWeeks << " "
|
---|
157 | << setprecision(4) << obs->C1 << " "
|
---|
158 | << setprecision(4) << obs->C2 << " "
|
---|
159 | << setprecision(4) << obs->P1 << " "
|
---|
160 | << setprecision(4) << obs->P2 << " "
|
---|
161 | << setprecision(4) << obs->L1 << " "
|
---|
162 | << obs->slip_cnt_L1 << " "
|
---|
163 | << setprecision(4) << obs->L2 << " "
|
---|
164 | << obs->slip_cnt_L2 << " "
|
---|
165 | << setprecision(4) << obs->S1 << " "
|
---|
166 | << setprecision(4) << obs->S2 << endl;
|
---|
167 |
|
---|
168 | buffer.remove(0,obsSize);
|
---|
169 | }
|
---|
170 | }
|
---|
171 | else {
|
---|
172 | socketObs.waitForReadyRead(1);
|
---|
173 | }
|
---|
174 | }
|
---|
175 |
|
---|
176 | return 0;
|
---|
177 | }
|
---|