[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 |
|
---|
[379] | 41 | #include <iostream>
|
---|
| 42 | #include <iomanip>
|
---|
| 43 |
|
---|
| 44 | #include "RTCM/GPSDecoder.h"
|
---|
| 45 |
|
---|
[599] | 46 | #include <QFile>
|
---|
| 47 | #include <QTextStream>
|
---|
[379] | 48 | #include <QTcpSocket>
|
---|
| 49 |
|
---|
| 50 | using namespace std;
|
---|
| 51 |
|
---|
| 52 | const char begEpoch = 'A';
|
---|
| 53 | const char begObs = 'B';
|
---|
| 54 | const char endEpoch = 'C';
|
---|
| 55 |
|
---|
| 56 | int main(int /* argc */, char** /* argv */) {
|
---|
| 57 |
|
---|
[599] | 58 | QTcpSocket socketObs;
|
---|
| 59 | QTcpSocket socketEph;
|
---|
| 60 |
|
---|
| 61 | QFile obsFile("obs.txt");
|
---|
| 62 | QFile ephFile("eph.txt");
|
---|
[379] | 63 |
|
---|
[599] | 64 | socketObs.connectToHost("127.0.0.1", 1968);
|
---|
| 65 | if (!socketObs.waitForConnected(10000)) {
|
---|
| 66 | cout << "socketObs: not connected" << endl;
|
---|
[388] | 67 | exit(1);
|
---|
[379] | 68 | }
|
---|
| 69 |
|
---|
[599] | 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 |
|
---|
[379] | 85 | // Receive Data
|
---|
| 86 | // ------------
|
---|
[627] | 87 | t_obsInternal obs;
|
---|
[379] | 88 | char flag = ' ';
|
---|
| 89 | cout.setf(ios::showpoint | ios::fixed);
|
---|
| 90 |
|
---|
| 91 | while (true) {
|
---|
[599] | 92 | if (socketObs.state() != QAbstractSocket::ConnectedState) {
|
---|
| 93 | cout << "socketObs: disconnected" << endl;
|
---|
| 94 | exit(0);
|
---|
| 95 | }
|
---|
| 96 | if (socketEph.state() != QAbstractSocket::ConnectedState) {
|
---|
| 97 | cout << "socketEph: disconnected" << endl;
|
---|
| 98 | exit(0);
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | if ( socketObs.bytesAvailable() ) {
|
---|
| 102 | int bytesRecv = socketObs.read(&flag, 1);
|
---|
[379] | 103 | if (flag == begObs) {
|
---|
[599] | 104 | if ( socketObs.bytesAvailable() >= sizeof(obs) ) {
|
---|
| 105 | bytesRecv = socketObs.read((char*) &obs, sizeof(obs));
|
---|
| 106 | outObs << obs.StatID << " "
|
---|
| 107 | << obs.satSys << obs.satNum << " "
|
---|
| 108 | << obs.GPSWeek << " "
|
---|
| 109 | << qSetRealNumberPrecision(2) << obs.GPSWeeks << " "
|
---|
| 110 | << qSetRealNumberPrecision(4) << obs.C1 << " "
|
---|
| 111 | << qSetRealNumberPrecision(4) << obs.C2 << " "
|
---|
| 112 | << qSetRealNumberPrecision(4) << obs.P1 << " "
|
---|
| 113 | << qSetRealNumberPrecision(4) << obs.P2 << " "
|
---|
| 114 | << qSetRealNumberPrecision(4) << obs.L1 << " "
|
---|
| 115 | << qSetRealNumberPrecision(4) << obs.L2 << " "
|
---|
| 116 | << qSetRealNumberPrecision(4) << obs.S1 << " "
|
---|
| 117 | << qSetRealNumberPrecision(4) << obs.S2 << " "
|
---|
| 118 | << obs.SNR1 << " "
|
---|
| 119 | << obs.SNR2 << endl;
|
---|
[379] | 120 | }
|
---|
| 121 | }
|
---|
| 122 | }
|
---|
[601] | 123 | else {
|
---|
[633] | 124 | socketObs.waitForReadyRead(1);
|
---|
[601] | 125 | }
|
---|
[599] | 126 |
|
---|
| 127 | if ( socketEph.bytesAvailable() ) {
|
---|
| 128 | QByteArray eph = socketEph.readAll();
|
---|
| 129 | outEph << eph.data() << endl;
|
---|
[380] | 130 | }
|
---|
[601] | 131 | else {
|
---|
[633] | 132 | socketEph.waitForReadyRead(1);
|
---|
[599] | 133 | }
|
---|
[379] | 134 | }
|
---|
| 135 |
|
---|
| 136 | return 0;
|
---|
| 137 | }
|
---|