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

Last change on this file since 1223 was 1223, 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 <stdlib.h>
42#include <iostream>
43#include <iomanip>
44
45#include "RTCM/GPSDecoder.h"
46
47#include <QFile>
48#include <QTextStream>
49#include <QTcpSocket>
50
51using namespace std;
52
53int main(int argc, char** argv) {
54
55 if (argc != 2) {
56 cerr << "Usage: test_bnc_qt port\n";
57 exit(1);
58 }
59
60 int port = atoi(argv[1]);
61
62 QTcpSocket socketObs;
63
64 socketObs.connectToHost("127.0.0.1", port);
65 if (!socketObs.waitForConnected(10000)) {
66 cerr << "socketObs: not connected on port " << port << endl;
67 exit(1);
68 }
69
70 cout.setf(ios::fixed);
71
72 // Receive Data
73 // ------------
74 const char begObs[] = "BEGOBS";
75 const char begEpoch[] = "BEGEPOCH";
76 const char endEpoch[] = "ENDEPOCH";
77 const unsigned begObsNBytes = sizeof(begObs) - 1;
78 const unsigned begEpochNBytes = sizeof(begEpoch) - 1;
79 const unsigned endEpochNBytes = sizeof(endEpoch) - 1;
80
81 QByteArray buffer;
82
83 while (true) {
84 if (socketObs.state() != QAbstractSocket::ConnectedState) {
85 cerr << "socketObs: disconnected" << endl;
86 exit(1);
87 }
88
89 if ( socketObs.bytesAvailable() ) {
90 buffer += socketObs.readAll();
91
92 // Skip begEpoch and endEpoch Marks
93 // --------------------------------
94 for (;;) {
95 int i1 = buffer.indexOf(begEpoch);
96 if (i1 == -1) {
97 break;
98 }
99 else {
100 buffer.remove(i1, begEpochNBytes);
101 cout << endl;
102 }
103 }
104 for (;;) {
105 int i2 = buffer.indexOf(endEpoch);
106 if (i2 == -1) {
107 break;
108 }
109 else {
110 buffer.remove(i2, endEpochNBytes);
111 }
112 }
113 for (;;) {
114 int i3 = buffer.indexOf(begObs);
115 if (i3 == -1) {
116 break;
117 }
118 else {
119 buffer.remove(i3, begObsNBytes);
120 }
121 }
122
123 // Interpret a portion of buffer as observation
124 // --------------------------------------------
125 t_obsInternal* obs;
126 const int obsSize = sizeof(t_obsInternal);
127
128
129 while (buffer.size() >= obsSize) {
130
131 obs = (t_obsInternal*) (buffer.left(obsSize).data());
132
133 cout << obs->StatID << " "
134 << obs->satSys << obs->satNum << " "
135 << obs->GPSWeek << " "
136 << setprecision(2) << obs->GPSWeeks << " "
137 << setprecision(4) << obs->C1 << " "
138 << setprecision(4) << obs->C2 << " "
139 << setprecision(4) << obs->P1 << " "
140 << setprecision(4) << obs->P2 << " "
141 << setprecision(4) << obs->L1 << " "
142 << setprecision(4) << obs->L2 << " "
143 << setprecision(4) << obs->S1 << " "
144 << setprecision(4) << obs->S2 << " "
145 << obs->SNR1 << " "
146 << obs->SNR2 << endl;
147
148 buffer.remove(0,obsSize);
149 }
150 }
151 else {
152 socketObs.waitForReadyRead(1);
153 }
154 }
155
156 return 0;
157}
Note: See TracBrowser for help on using the repository browser.