source: ntrip/trunk/BNC/test_bnc_qt.cpp@ 1193

Last change on this file since 1193 was 1193, checked in by mervart, 15 years ago

* empty log message *

File size: 4.3 KB
Line 
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
50using namespace std;
51
52int 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 }
97 }
98 for (;;) {
99 int i2 = buffer.indexOf(endEpoch);
100 if (i2 == -1) {
101 break;
102 }
103 else {
104 buffer.remove(i2, endEpochNBytes);
105 }
106 }
107
108 // Interpret a portion of buffer as observation
109 // --------------------------------------------
110 t_obsInternal* obs;
111 const int obsSize = sizeof(t_obsInternal);
112
113
114 while (buffer.size() >= obsSize) {
115
116 cout << buffer.size() << " " << obsSize << endl;
117
118 obs = (t_obsInternal*) (buffer.left(obsSize).data());
119
120 outObs << obs->StatID << " "
121 << obs->satSys << obs->satNum << " "
122 << obs->GPSWeek << " "
123 << qSetRealNumberPrecision(2) << obs->GPSWeeks << " "
124 << qSetRealNumberPrecision(4) << obs->C1 << " "
125 << qSetRealNumberPrecision(4) << obs->C2 << " "
126 << qSetRealNumberPrecision(4) << obs->P1 << " "
127 << qSetRealNumberPrecision(4) << obs->P2 << " "
128 << qSetRealNumberPrecision(4) << obs->L1 << " "
129 << qSetRealNumberPrecision(4) << obs->L2 << " "
130 << qSetRealNumberPrecision(4) << obs->S1 << " "
131 << qSetRealNumberPrecision(4) << obs->S2 << " "
132 << obs->SNR1 << " "
133 << obs->SNR2 << endl;
134
135 buffer.remove(0,obsSize);
136 }
137 }
138 else {
139 socketObs.waitForReadyRead(1);
140 }
141 }
142
143 return 0;
144}
Note: See TracBrowser for help on using the repository browser.