Changeset 1783 in ntrip
- Timestamp:
- Apr 8, 2009, 1:14:21 PM (16 years ago)
- Location:
- trunk/BNC
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/bncnetqueryudp0.cpp
r1779 r1783 30 30 //////////////////////////////////////////////////////////////////////////// 31 31 bncNetQueryUdp0::bncNetQueryUdp0() { 32 _port = 0;33 32 _udpSocket = 0; 34 _eventLoop = new QEventLoop(this);35 36 _keepAlive[ 0] = 128;37 _keepAlive[ 1] = 96;38 for (int ii = 2; ii <=11; ii++) {39 _keepAlive[ii] = 0;40 }41 33 } 42 34 … … 44 36 //////////////////////////////////////////////////////////////////////////// 45 37 bncNetQueryUdp0::~bncNetQueryUdp0() { 46 delete _eventLoop;47 38 delete _udpSocket; 48 39 } … … 51 42 //////////////////////////////////////////////////////////////////////////// 52 43 void bncNetQueryUdp0::stop() { 53 _eventLoop->quit(); 44 #ifndef sparc 45 if (_udpSocket) { 46 _udpSocket->abort(); 47 } 48 #endif 54 49 _status = finished; 55 }56 57 //58 ////////////////////////////////////////////////////////////////////////////59 void bncNetQueryUdp0::slotKeepAlive() {60 if (_udpSocket) {61 _udpSocket->writeDatagram(_keepAlive, 12, _address, _port);62 }63 QTimer::singleShot(15000, this, SLOT(slotKeepAlive()));64 50 } 65 51 … … 72 58 //////////////////////////////////////////////////////////////////////////// 73 59 void bncNetQueryUdp0::waitForReadyRead(QByteArray& outData) { 74 75 // Wait Loop76 // ---------77 if (!_udpSocket->hasPendingDatagrams()) {78 _eventLoop->exec();79 }80 81 // Append Data82 // -----------83 QByteArray datagram;84 datagram.resize(_udpSocket->pendingDatagramSize());85 _udpSocket->readDatagram(datagram.data(), datagram.size());86 87 if (datagram.size() > 12) {88 outData.append(datagram.mid(12));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 } 89 75 } 90 76 } … … 92 78 // Connect to Caster, send the Request 93 79 //////////////////////////////////////////////////////////////////////////// 94 void bncNetQueryUdp0::startRequest(const QUrl& url, const QByteArray& gga) {80 void bncNetQueryUdp0::startRequest(const QUrl& url, const QByteArray& /* gga */) { 95 81 96 82 _status = running; … … 106 92 } 107 93 108 _port = _url.port();109 110 94 delete _udpSocket; 111 95 _udpSocket = new QUdpSocket(); 112 _udpSocket->bind(0); 113 connect(_udpSocket, SIGNAL(readyRead()), _eventLoop, SLOT(quit())); 114 115 QHostInfo hInfo = QHostInfo::fromName(url.host()); 116 117 if (!hInfo.addresses().isEmpty()) { 118 119 _address = hInfo.addresses().first(); 120 121 // Send Request 122 // ------------ 123 QString uName = QUrl::fromPercentEncoding(_url.userName().toAscii()); 124 QString passW = QUrl::fromPercentEncoding(_url.password().toAscii()); 125 QByteArray userAndPwd; 126 127 if(!uName.isEmpty() || !passW.isEmpty()) { 128 userAndPwd = "Authorization: Basic " + (uName.toAscii() + ":" + 129 passW.toAscii()).toBase64() + "\r\n"; 130 } 131 132 QByteArray reqStr = "GET " + _url.path().toAscii() + " HTTP/1.1\r\n" 133 + "Host: " + _url.host().toAscii() + "\r\n" 134 + "Ntrip-Version: Ntrip/2.0\r\n" 135 + "User-Agent: NTRIP BNC/" BNCVERSION "\r\n"; 136 if (!gga.isEmpty()) { 137 reqStr += "Ntrip-GGA: " + gga + "\r\n"; 138 } 139 reqStr += userAndPwd + "Connection: close\r\n\r\n"; 140 141 char rtpbuffer[12 + reqStr.size()]; 142 rtpbuffer[0] = 128; 143 rtpbuffer[1] = 97; 144 for (int jj = 2; jj <= 11; jj++) { 145 rtpbuffer[jj] = _keepAlive[jj]; 146 } 147 for (int ii = 0; ii < reqStr.size(); ii++) { 148 rtpbuffer[12+ii] = reqStr[ii]; 149 } 150 151 _udpSocket->writeDatagram(rtpbuffer, 12 + reqStr.size(), _address, _port); 152 153 // Wait for Reply, read Session Number 154 // ----------------------------------- 155 QByteArray repl; 156 waitForReadyRead(repl); 157 158 QTextStream in(repl); 159 QString line = in.readLine(); 160 while (!line.isEmpty()) { 161 if (line.indexOf("Session:") == 0) { 162 _session = line.mid(9).toInt(); 163 _keepAlive[ 8] = (_session >> 24) & 0xFF; 164 _keepAlive[ 9] = (_session >> 16) & 0xFF; 165 _keepAlive[10] = (_session >> 8) & 0xFF; 166 _keepAlive[11] = (_session) & 0xFF; 167 break; 168 } 169 line = in.readLine(); 170 } 171 172 QTimer::singleShot(15000, this, SLOT(slotKeepAlive())); 173 } 96 _udpSocket->connectToHost(_url.host(), _url.port()); 174 97 } 175 98 -
trunk/BNC/bncnetqueryudp0.h
r1779 r1783 14 14 virtual void startRequest(const QUrl& url, const QByteArray& gga); 15 15 virtual void waitForReadyRead(QByteArray& outData); 16 17 private slots:18 void slotKeepAlive();19 20 16 private: 21 17 QUdpSocket* _udpSocket; 22 QEventLoop* _eventLoop;23 QHostAddress _address;24 int _port;25 char _keepAlive[12];26 int _session;27 18 }; 28 19 -
trunk/BNC/bncnetqueryv0.cpp
r1716 r1783 77 77 // Connect to Caster, send the Request 78 78 //////////////////////////////////////////////////////////////////////////// 79 void bncNetQueryV0::startRequest(const QUrl& url, const QByteArray& gga) {79 void bncNetQueryV0::startRequest(const QUrl& url, const QByteArray& /* gga */) { 80 80 81 81 _status = running; 82 QByteArray dummy = gga;83 82 84 83 delete _socket;
Note:
See TracChangeset
for help on using the changeset viewer.