source: ntrip/trunk/BNC/bncnetrequest.cpp@ 1350

Last change on this file since 1350 was 1345, checked in by mervart, 16 years ago

* empty log message *

File size: 3.8 KB
Line 
1/* -------------------------------------------------------------------------
2 * BKG NTRIP Client
3 * -------------------------------------------------------------------------
4 *
5 * Class: bncNetRequest
6 *
7 * Purpose: Prepare and submit network request
8 *
9 * Author: L. Mervart
10 *
11 * Created: 09-Dec-2008
12 *
13 * Changes:
14 *
15 * -----------------------------------------------------------------------*/
16
17#include <iostream>
18#include <iomanip>
19
20#include "bncnetrequest.h"
21#include "RTCM3/RTCM3Decoder.h"
22
23using namespace std;
24
25// Constructor
26////////////////////////////////////////////////////////////////////////////
27bncNetRequest::bncNetRequest() {
28 _manager = 0;
29 _reply = 0;
30 _decoder = new RTCM3Decoder("TEST1");
31 connect((RTCM3Decoder*) _decoder, SIGNAL(newMessage(QByteArray,bool)),
32 this, SIGNAL(slotNewMessage(QByteArray,bool)));
33}
34
35// Destructor
36////////////////////////////////////////////////////////////////////////////
37bncNetRequest::~bncNetRequest() {
38 cout << "~bncNetRequest" << endl;
39 delete _reply;
40 delete _manager;
41}
42
43// Network Request
44////////////////////////////////////////////////////////////////////////////
45t_irc bncNetRequest::request(const QUrl& url) {
46
47 // Network Access Manager
48 // ----------------------
49 if (_manager == 0) {
50 _manager = new QNetworkAccessManager(this);
51 }
52 else {
53 return failure;
54 }
55
56 // Network Request
57 // ---------------
58 QNetworkRequest request;
59 request.setUrl(url);
60 request.setRawHeader("Host" , url.host().toAscii());
61 request.setRawHeader("Ntrip-Version", "NTRIP/2.0");
62 request.setRawHeader("User-Agent" , "NTRIP BNC/1.7");
63 if (!url.userName().isEmpty()) {
64 request.setRawHeader("Authorization", "Basic " +
65 (url.userName() + ":" + url.password()).toAscii().toBase64());
66 }
67 request.setRawHeader("Connection" , "close");
68
69 _reply = _manager->get(request);
70
71 connect(_reply, SIGNAL(finished()), this, SLOT(slotReplyFinished()));
72 connect(_reply, SIGNAL(readyRead()), this, SLOT(slotReadyRead()));
73 connect(_reply, SIGNAL(error(QNetworkReply::NetworkError)),
74 this, SLOT(slotError(QNetworkReply::NetworkError)));
75 connect(_reply, SIGNAL(sslErrors(const QList<QSslError>&)),
76 this, SLOT(slotSslErrors(const QList<QSslError>&)));
77
78
79 return success;
80}
81
82//
83////////////////////////////////////////////////////////////////////////////
84void bncNetRequest::slotReplyFinished() {
85 cout << "slotReplyFinished" << endl;
86 this->deleteLater();
87}
88
89//
90////////////////////////////////////////////////////////////////////////////
91void bncNetRequest::slotReadyRead() {
92 cout << "slotReadyRead" << endl;
93 QByteArray buffer = _reply->readAll();
94
95 vector<string> errmsg;
96 _decoder->Decode(buffer.data(), buffer.length(), errmsg);
97
98 QListIterator<p_obs> it(_decoder->_obsList);
99 while (it.hasNext()) {
100 p_obs obs = it.next();
101 cout << obs->_o.satSys << obs->_o.satNum << " "
102 << obs->_o.GPSWeek << " "
103 << obs->_o.GPSWeeks << " "
104 << obs->_o.C1 << " "
105 << obs->_o.C2 << " "
106 << obs->_o.P1 << " "
107 << obs->_o.P2 << " "
108 << obs->_o.L1 << " "
109 << obs->_o.L2 << endl;
110 delete obs;
111 }
112 _decoder->_obsList.clear();
113}
114
115//
116////////////////////////////////////////////////////////////////////////////
117void bncNetRequest::slotError(QNetworkReply::NetworkError) {
118 cout << "slotError " << _reply->error() << endl
119 << _reply->errorString().toAscii().data() << endl;
120}
121
122//
123////////////////////////////////////////////////////////////////////////////
124void bncNetRequest::slotSslErrors(const QList<QSslError>&) {
125 cout << "slotSslError" << endl;
126}
127
128//
129////////////////////////////////////////////////////////////////////////////
130void bncNetRequest::slotNewMessage(QByteArray msg, bool) {
131 cout << "Message: " << msg.data() << endl;
132}
Note: See TracBrowser for help on using the repository browser.