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

Last change on this file since 2029 was 1232, checked in by mervart, 16 years ago

* empty log message *

File size: 4.4 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 <QTcpSocket>
48
49using namespace std;
50
51int main(int argc, char** argv) {
52
53 if (argc != 2) {
54 cerr << "Usage: test_bnc_qt port\n";
55 exit(1);
56 }
57
58 int port = atoi(argv[1]);
59
60 QTcpSocket socketObs;
61
62 socketObs.connectToHost("127.0.0.1", port);
63 if (!socketObs.waitForConnected(10000)) {
64 cerr << "socketObs: not connected on port " << port << endl;
65 exit(1);
66 }
67
68 cout.setf(ios::fixed);
69
70 // Receive Data
71 // ------------
72 const char begObs[] = "BEGOBS";
73 const char begEpoch[] = "BEGEPOCH";
74 const char endEpoch[] = "ENDEPOCH";
75 const unsigned begObsNBytes = sizeof(begObs) - 1;
76 const unsigned begEpochNBytes = sizeof(begEpoch) - 1;
77 const unsigned endEpochNBytes = sizeof(endEpoch) - 1;
78
79 QByteArray buffer;
80
81 while (true) {
82 if (socketObs.state() != QAbstractSocket::ConnectedState) {
83 cerr << "socketObs: disconnected" << endl;
84 exit(1);
85 }
86
87 if ( socketObs.bytesAvailable() ) {
88 buffer += socketObs.readAll();
89
90 // Skip begEpoch and endEpoch Marks
91 // --------------------------------
92 for (;;) {
93 int i1 = buffer.indexOf(begEpoch);
94 if (i1 == -1) {
95 break;
96 }
97 else {
98 buffer.remove(i1, begEpochNBytes);
99 cout << endl;
100 }
101 }
102 for (;;) {
103 int i2 = buffer.indexOf(endEpoch);
104 if (i2 == -1) {
105 break;
106 }
107 else {
108 buffer.remove(i2, endEpochNBytes);
109 }
110 }
111 for (;;) {
112 int i3 = buffer.indexOf(begObs);
113 if (i3 == -1) {
114 break;
115 }
116 else {
117 buffer.remove(i3, begObsNBytes);
118 }
119 }
120
121 // Interpret a portion of buffer as observation
122 // --------------------------------------------
123 t_obsInternal* obs;
124 const int obsSize = sizeof(t_obsInternal);
125
126
127 while (buffer.size() >= obsSize) {
128
129 obs = (t_obsInternal*) (buffer.left(obsSize).data());
130
131 cout << obs->StatID << " "
132 << obs->satSys << obs->satNum << " "
133 << obs->GPSWeek << " "
134 << setprecision(2) << obs->GPSWeeks << " "
135 << setprecision(4) << obs->C1 << " "
136 << setprecision(4) << obs->C2 << " "
137 << setprecision(4) << obs->P1 << " "
138 << setprecision(4) << obs->P2 << " "
139 << setprecision(4) << obs->L1 << " "
140 << setprecision(4) << obs->L2 << " "
141 << obs->slip_cnt_L1 << " "
142 << obs->slip_cnt_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.