1 | /* -------------------------------------------------------------------------
|
---|
2 | * BKG NTRIP Client
|
---|
3 | * -------------------------------------------------------------------------
|
---|
4 | *
|
---|
5 | * Class: bncNetQueryUdp
|
---|
6 | *
|
---|
7 | * Purpose: Blocking Network Requests (NTRIP Version 2 with plain UDP)
|
---|
8 | *
|
---|
9 | * Author: L. Mervart
|
---|
10 | *
|
---|
11 | * Created: 04-Feb-2009
|
---|
12 | *
|
---|
13 | * Changes:
|
---|
14 | *
|
---|
15 | * -----------------------------------------------------------------------*/
|
---|
16 |
|
---|
17 | #include <iostream>
|
---|
18 | #include <iomanip>
|
---|
19 |
|
---|
20 | #include "bncnetqueryudp.h"
|
---|
21 | #include "bncsettings.h"
|
---|
22 |
|
---|
23 | using namespace std;
|
---|
24 |
|
---|
25 | #define BNCVERSION "1.7"
|
---|
26 |
|
---|
27 | // Constructor
|
---|
28 | ////////////////////////////////////////////////////////////////////////////
|
---|
29 | bncNetQueryUdp::bncNetQueryUdp() {
|
---|
30 | _udpSocket = 0;
|
---|
31 | _eventLoop = new QEventLoop(this);
|
---|
32 | }
|
---|
33 |
|
---|
34 | // Destructor
|
---|
35 | ////////////////////////////////////////////////////////////////////////////
|
---|
36 | bncNetQueryUdp::~bncNetQueryUdp() {
|
---|
37 | delete _eventLoop;
|
---|
38 | delete _udpSocket;
|
---|
39 | }
|
---|
40 |
|
---|
41 | //
|
---|
42 | ////////////////////////////////////////////////////////////////////////////
|
---|
43 | void bncNetQueryUdp::stop() {
|
---|
44 | _eventLoop->quit();
|
---|
45 | _status = finished;
|
---|
46 | }
|
---|
47 |
|
---|
48 | //
|
---|
49 | ////////////////////////////////////////////////////////////////////////////
|
---|
50 | void bncNetQueryUdp::slotKeepAlive() {
|
---|
51 | }
|
---|
52 |
|
---|
53 | //
|
---|
54 | ////////////////////////////////////////////////////////////////////////////
|
---|
55 | void bncNetQueryUdp::waitForRequestResult(const QUrl&, QByteArray&) {
|
---|
56 | }
|
---|
57 |
|
---|
58 | //
|
---|
59 | ////////////////////////////////////////////////////////////////////////////
|
---|
60 | void bncNetQueryUdp::waitForReadyRead(QByteArray& outData) {
|
---|
61 |
|
---|
62 | // Wait Loop
|
---|
63 | // ---------
|
---|
64 | if (!_udpSocket->hasPendingDatagrams()) {
|
---|
65 | _eventLoop->exec();
|
---|
66 | }
|
---|
67 |
|
---|
68 | // Append Data
|
---|
69 | // -----------
|
---|
70 | QByteArray datagram;
|
---|
71 | datagram.resize(_udpSocket->pendingDatagramSize());
|
---|
72 | _udpSocket->readDatagram(datagram.data(), datagram.size());
|
---|
73 |
|
---|
74 | if (datagram.size() > 12) {
|
---|
75 | outData.append(datagram.mid(12));
|
---|
76 | }
|
---|
77 | }
|
---|
78 |
|
---|
79 | // Connect to Caster, send the Request
|
---|
80 | ////////////////////////////////////////////////////////////////////////////
|
---|
81 | void bncNetQueryUdp::startRequest(const QUrl& url, const QByteArray& gga) {
|
---|
82 |
|
---|
83 | _status = running;
|
---|
84 |
|
---|
85 | delete _udpSocket;
|
---|
86 | _udpSocket = new QUdpSocket();
|
---|
87 | _udpSocket->bind(0);
|
---|
88 | connect(_udpSocket, SIGNAL(readyRead()), _eventLoop, SLOT(quit()));
|
---|
89 | QByteArray clientPort = QString("%1").arg(_udpSocket->localPort()).toAscii();
|
---|
90 |
|
---|
91 | // Send initial RTP packet for firewall handling
|
---|
92 | // ---------------------------------------------
|
---|
93 | char rtpbuffer[12];
|
---|
94 | rtpbuffer[0] = (2<<6);
|
---|
95 | rtpbuffer[1] = 96;
|
---|
96 | rtpbuffer[2] = 0;
|
---|
97 | rtpbuffer[3] = 0;
|
---|
98 | rtpbuffer[4] = 0;
|
---|
99 | rtpbuffer[5] = 0;
|
---|
100 | rtpbuffer[6] = 0;
|
---|
101 | rtpbuffer[7] = 0;
|
---|
102 | rtpbuffer[8] = 0;
|
---|
103 | rtpbuffer[9] = 0;
|
---|
104 | rtpbuffer[10] = 0;
|
---|
105 | rtpbuffer[11] = 0;
|
---|
106 |
|
---|
107 | QHostInfo hInfo = QHostInfo::fromName(url.host());
|
---|
108 |
|
---|
109 | QHostAddress address;
|
---|
110 | if (!hInfo.addresses().isEmpty()) {
|
---|
111 | address = hInfo.addresses().first();
|
---|
112 | _udpSocket->writeDatagram(rtpbuffer, 12, address, url.port());
|
---|
113 | }
|
---|
114 |
|
---|
115 | }
|
---|
116 |
|
---|