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

Last change on this file since 599 was 599, checked in by mervart, 16 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
52const char begEpoch = 'A';
53const char begObs = 'B';
54const char endEpoch = 'C';
55
56int main(int /* argc */, char** /* argv */) {
57
58 QTcpSocket socketObs;
59 QTcpSocket socketEph;
60
61 QFile obsFile("obs.txt");
62 QFile ephFile("eph.txt");
63
64 socketObs.connectToHost("127.0.0.1", 1968);
65 if (!socketObs.waitForConnected(10000)) {
66 cout << "socketObs: not connected" << endl;
67 exit(1);
68 }
69
70 socketEph.connectToHost("127.0.0.1", 1969);
71 if (!socketEph.waitForConnected(10000)) {
72 cout << "socketEph: not connected" << endl;
73 exit(1);
74 }
75
76 obsFile.open(QIODevice::WriteOnly | QIODevice::Unbuffered);
77 ephFile.open(QIODevice::WriteOnly | QIODevice::Unbuffered);
78
79 QTextStream outObs(&obsFile);
80 outObs.setRealNumberNotation(QTextStream::FixedNotation);
81
82 QTextStream outEph(&ephFile);
83 outEph.setRealNumberNotation(QTextStream::FixedNotation);
84
85 // Receive Data
86 // ------------
87 Observation obs;
88 char flag = ' ';
89 cout.setf(ios::showpoint | ios::fixed);
90
91 while (true) {
92 bool somethingRead = false;
93
94 if (socketObs.state() != QAbstractSocket::ConnectedState) {
95 cout << "socketObs: disconnected" << endl;
96 exit(0);
97 }
98 if (socketEph.state() != QAbstractSocket::ConnectedState) {
99 cout << "socketEph: disconnected" << endl;
100 exit(0);
101 }
102
103 if ( socketObs.bytesAvailable() ) {
104 somethingRead = true;
105 int bytesRecv = socketObs.read(&flag, 1);
106 if (flag == begObs) {
107 if ( socketObs.bytesAvailable() >= sizeof(obs) ) {
108 bytesRecv = socketObs.read((char*) &obs, sizeof(obs));
109 outObs << obs.StatID << " "
110 << obs.satSys << obs.satNum << " "
111 << obs.GPSWeek << " "
112 << qSetRealNumberPrecision(2) << obs.GPSWeeks << " "
113 << qSetRealNumberPrecision(4) << obs.C1 << " "
114 << qSetRealNumberPrecision(4) << obs.C2 << " "
115 << qSetRealNumberPrecision(4) << obs.P1 << " "
116 << qSetRealNumberPrecision(4) << obs.P2 << " "
117 << qSetRealNumberPrecision(4) << obs.L1 << " "
118 << qSetRealNumberPrecision(4) << obs.L2 << " "
119 << qSetRealNumberPrecision(4) << obs.S1 << " "
120 << qSetRealNumberPrecision(4) << obs.S2 << " "
121 << obs.SNR1 << " "
122 << obs.SNR2 << endl;
123 }
124 }
125 }
126
127 if ( socketEph.bytesAvailable() ) {
128 somethingRead = true;
129 QByteArray eph = socketEph.readAll();
130 outEph << eph.data() << endl;
131 }
132
133 if (!somethingRead) {
134 socketObs.waitForReadyRead(100);
135 }
136 }
137
138 return 0;
139}
Note: See TracBrowser for help on using the repository browser.