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 <iostream>
|
---|
42 | #include <iomanip>
|
---|
43 |
|
---|
44 | #include "RTCM/GPSDecoder.h"
|
---|
45 |
|
---|
46 | #include <QFile>
|
---|
47 | #include <QTextStream>
|
---|
48 | #include <QTcpSocket>
|
---|
49 |
|
---|
50 | using namespace std;
|
---|
51 |
|
---|
52 | int main(int /* argc */, char** /* argv */) {
|
---|
53 |
|
---|
54 | QTcpSocket socketObs;
|
---|
55 |
|
---|
56 | QFile obsFile("obs.txt");
|
---|
57 |
|
---|
58 | socketObs.connectToHost("127.0.0.1", 1968);
|
---|
59 | if (!socketObs.waitForConnected(10000)) {
|
---|
60 | cout << "socketObs: not connected" << endl;
|
---|
61 | exit(1);
|
---|
62 | }
|
---|
63 |
|
---|
64 | obsFile.open(QIODevice::WriteOnly | QIODevice::Unbuffered);
|
---|
65 |
|
---|
66 | QTextStream outObs(&obsFile);
|
---|
67 | outObs.setRealNumberNotation(QTextStream::FixedNotation);
|
---|
68 |
|
---|
69 | // Receive Data
|
---|
70 | // ------------
|
---|
71 | const char begEpoch[] = "BEGEPOCH";
|
---|
72 | const char endEpoch[] = "ENDEPOCH";
|
---|
73 | const unsigned begEpochNBytes = sizeof(begEpoch) - 1;
|
---|
74 | const unsigned endEpochNBytes = sizeof(endEpoch) - 1;
|
---|
75 |
|
---|
76 | QByteArray buffer;
|
---|
77 |
|
---|
78 | while (true) {
|
---|
79 | if (socketObs.state() != QAbstractSocket::ConnectedState) {
|
---|
80 | cout << "socketObs: disconnected" << endl;
|
---|
81 | exit(0);
|
---|
82 | }
|
---|
83 |
|
---|
84 | if ( socketObs.bytesAvailable() ) {
|
---|
85 | buffer += socketObs.readAll();
|
---|
86 |
|
---|
87 | // Skip begEpoch and endEpoch Marks
|
---|
88 | // --------------------------------
|
---|
89 | for (;;) {
|
---|
90 | int i1 = buffer.indexOf(begEpoch);
|
---|
91 | if (i1 == -1) {
|
---|
92 | break;
|
---|
93 | }
|
---|
94 | else {
|
---|
95 | buffer.remove(i1, begEpochNBytes);
|
---|
96 | outObs << endl;
|
---|
97 | }
|
---|
98 | }
|
---|
99 | for (;;) {
|
---|
100 | int i2 = buffer.indexOf(endEpoch);
|
---|
101 | if (i2 == -1) {
|
---|
102 | break;
|
---|
103 | }
|
---|
104 | else {
|
---|
105 | buffer.remove(i2, endEpochNBytes);
|
---|
106 | }
|
---|
107 | }
|
---|
108 |
|
---|
109 | // Interpret a portion of buffer as observation
|
---|
110 | // --------------------------------------------
|
---|
111 | t_obsInternal* obs;
|
---|
112 | const int obsSize = sizeof(t_obsInternal);
|
---|
113 |
|
---|
114 |
|
---|
115 | while (buffer.size() >= obsSize) {
|
---|
116 |
|
---|
117 | obs = (t_obsInternal*) (buffer.left(obsSize).data());
|
---|
118 |
|
---|
119 | outObs << obs->StatID << " "
|
---|
120 | << obs->satSys << obs->satNum << " "
|
---|
121 | << obs->GPSWeek << " "
|
---|
122 | << qSetRealNumberPrecision(2) << obs->GPSWeeks << " "
|
---|
123 | << qSetRealNumberPrecision(4) << obs->C1 << " "
|
---|
124 | << qSetRealNumberPrecision(4) << obs->C2 << " "
|
---|
125 | << qSetRealNumberPrecision(4) << obs->P1 << " "
|
---|
126 | << qSetRealNumberPrecision(4) << obs->P2 << " "
|
---|
127 | << qSetRealNumberPrecision(4) << obs->L1 << " "
|
---|
128 | << qSetRealNumberPrecision(4) << obs->L2 << " "
|
---|
129 | << qSetRealNumberPrecision(4) << obs->S1 << " "
|
---|
130 | << qSetRealNumberPrecision(4) << obs->S2 << " "
|
---|
131 | << obs->SNR1 << " "
|
---|
132 | << obs->SNR2 << endl;
|
---|
133 |
|
---|
134 | buffer.remove(0,obsSize);
|
---|
135 | }
|
---|
136 | }
|
---|
137 | else {
|
---|
138 | socketObs.waitForReadyRead(1);
|
---|
139 | }
|
---|
140 | }
|
---|
141 |
|
---|
142 | return 0;
|
---|
143 | }
|
---|