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

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

* empty log message *

File size: 4.4 KB
RevLine 
[464]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.
[379]24
[464]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
[1223]41#include <stdlib.h>
[379]42#include <iostream>
43#include <iomanip>
44
45#include "RTCM/GPSDecoder.h"
46
47#include <QTcpSocket>
48
49using namespace std;
50
[1223]51int main(int argc, char** argv) {
[379]52
[1223]53 if (argc != 2) {
54 cerr << "Usage: test_bnc_qt port\n";
55 exit(1);
56 }
57
58 int port = atoi(argv[1]);
59
[599]60 QTcpSocket socketObs;
61
[1223]62 socketObs.connectToHost("127.0.0.1", port);
[599]63 if (!socketObs.waitForConnected(10000)) {
[1223]64 cerr << "socketObs: not connected on port " << port << endl;
[388]65 exit(1);
[379]66 }
67
[1223]68 cout.setf(ios::fixed);
[599]69
[379]70 // Receive Data
71 // ------------
[1223]72 const char begObs[] = "BEGOBS";
[1193]73 const char begEpoch[] = "BEGEPOCH";
74 const char endEpoch[] = "ENDEPOCH";
[1223]75 const unsigned begObsNBytes = sizeof(begObs) - 1;
[1193]76 const unsigned begEpochNBytes = sizeof(begEpoch) - 1;
77 const unsigned endEpochNBytes = sizeof(endEpoch) - 1;
[379]78
[1193]79 QByteArray buffer;
80
[379]81 while (true) {
[599]82 if (socketObs.state() != QAbstractSocket::ConnectedState) {
[1223]83 cerr << "socketObs: disconnected" << endl;
84 exit(1);
[599]85 }
86
[1193]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);
[1223]99 cout << endl;
[1193]100 }
[379]101 }
[1193]102 for (;;) {
103 int i2 = buffer.indexOf(endEpoch);
104 if (i2 == -1) {
105 break;
106 }
107 else {
108 buffer.remove(i2, endEpochNBytes);
109 }
110 }
[1223]111 for (;;) {
112 int i3 = buffer.indexOf(begObs);
113 if (i3 == -1) {
114 break;
115 }
116 else {
117 buffer.remove(i3, begObsNBytes);
118 }
119 }
[1193]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
[1223]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 << " "
[1232]141 << obs->slip_cnt_L1 << " "
142 << obs->slip_cnt_L2 << " "
[1223]143 << setprecision(4) << obs->S1 << " "
144 << setprecision(4) << obs->S2 << " "
145 << obs->SNR1 << " "
146 << obs->SNR2 << endl;
[1193]147
148 buffer.remove(0,obsSize);
149 }
[379]150 }
[601]151 else {
[633]152 socketObs.waitForReadyRead(1);
[601]153 }
[379]154 }
155
156 return 0;
157}
Note: See TracBrowser for help on using the repository browser.