1 | /* -------------------------------------------------------------------------
|
---|
2 | * BKG NTRIP Client
|
---|
3 | * -------------------------------------------------------------------------
|
---|
4 | *
|
---|
5 | * Class: bncNetQueryUdp0
|
---|
6 | *
|
---|
7 | * Purpose: Blocking Network Requests (plain UDP, no NTRIP)
|
---|
8 | *
|
---|
9 | * Author: L. Mervart
|
---|
10 | *
|
---|
11 | * Created: 04-Feb-2009
|
---|
12 | *
|
---|
13 | * Changes:
|
---|
14 | *
|
---|
15 | * -----------------------------------------------------------------------*/
|
---|
16 |
|
---|
17 | #include <iostream>
|
---|
18 | #include <iomanip>
|
---|
19 | #include <time.h>
|
---|
20 |
|
---|
21 | #include "bncnetqueryudp0.h"
|
---|
22 | #include "bncsettings.h"
|
---|
23 |
|
---|
24 | using namespace std;
|
---|
25 |
|
---|
26 | #define BNCVERSION "1.7"
|
---|
27 | #define TIME_RESOLUTION 125
|
---|
28 |
|
---|
29 | // Constructor
|
---|
30 | ////////////////////////////////////////////////////////////////////////////
|
---|
31 | bncNetQueryUdp0::bncNetQueryUdp0() {
|
---|
32 | _udpSocket = 0;
|
---|
33 | }
|
---|
34 |
|
---|
35 | // Destructor
|
---|
36 | ////////////////////////////////////////////////////////////////////////////
|
---|
37 | bncNetQueryUdp0::~bncNetQueryUdp0() {
|
---|
38 | delete _udpSocket;
|
---|
39 | }
|
---|
40 |
|
---|
41 | //
|
---|
42 | ////////////////////////////////////////////////////////////////////////////
|
---|
43 | void bncNetQueryUdp0::stop() {
|
---|
44 | #ifndef sparc
|
---|
45 | if (_udpSocket) {
|
---|
46 | _udpSocket->abort();
|
---|
47 | }
|
---|
48 | #endif
|
---|
49 | _status = finished;
|
---|
50 | }
|
---|
51 |
|
---|
52 | //
|
---|
53 | ////////////////////////////////////////////////////////////////////////////
|
---|
54 | void bncNetQueryUdp0::waitForRequestResult(const QUrl&, QByteArray&) {
|
---|
55 | }
|
---|
56 |
|
---|
57 | //
|
---|
58 | ////////////////////////////////////////////////////////////////////////////
|
---|
59 | void bncNetQueryUdp0::waitForReadyRead(QByteArray& outData) {
|
---|
60 | if (_udpSocket) {
|
---|
61 | while (true) {
|
---|
62 | int nBytes = _udpSocket->bytesAvailable();
|
---|
63 | if (nBytes > 0) {
|
---|
64 | outData = _udpSocket->readAll();
|
---|
65 | return;
|
---|
66 | }
|
---|
67 | else if (!_udpSocket->waitForReadyRead(_timeOut)) {
|
---|
68 | delete _udpSocket;
|
---|
69 | _udpSocket = 0;
|
---|
70 | _status = error;
|
---|
71 | emit newMessage(_url.path().toAscii() + " read timeout", true);
|
---|
72 | return;
|
---|
73 | }
|
---|
74 | }
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | // Connect to Caster, send the Request
|
---|
79 | ////////////////////////////////////////////////////////////////////////////
|
---|
80 | void bncNetQueryUdp0::startRequest(const QUrl& url, const QByteArray& /* gga */) {
|
---|
81 |
|
---|
82 | _status = running;
|
---|
83 |
|
---|
84 | // Default scheme and path
|
---|
85 | // -----------------------
|
---|
86 | _url = url;
|
---|
87 | if (_url.scheme().isEmpty()) {
|
---|
88 | _url.setScheme("http");
|
---|
89 | }
|
---|
90 | if (_url.path().isEmpty()) {
|
---|
91 | _url.setPath("/");
|
---|
92 | }
|
---|
93 |
|
---|
94 | delete _udpSocket;
|
---|
95 | _udpSocket = new QUdpSocket();
|
---|
96 | _udpSocket->connectToHost(_url.host(), _url.port());
|
---|
97 | }
|
---|
98 |
|
---|