Changeset 1346 in ntrip for trunk/BNC/bncgetthread.cpp
- Timestamp:
- Dec 27, 2008, 12:40:39 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/bncgetthread.cpp
r1345 r1346 301 301 } 302 302 303 #define AGENTVERSION "1.7"304 // Connect to Caster, send the Request (static)305 ////////////////////////////////////////////////////////////////////////////306 bncSocket* bncGetThread::request(const QUrl& mountPoint,307 QByteArray& latitude, QByteArray& longitude,308 QByteArray& nmea, int timeOut,309 QString& msg) {310 311 // Connect the Socket312 // ------------------313 QSettings settings;314 QString proxyHost = settings.value("proxyHost").toString();315 int proxyPort = settings.value("proxyPort").toInt();316 317 bncSocket* socket = new bncSocket(new QTcpSocket());318 if ( proxyHost.isEmpty() ) {319 socket->connectToHost(mountPoint.host(), mountPoint.port());320 }321 else {322 socket->connectToHost(proxyHost, proxyPort);323 }324 if (!socket->waitForConnected(timeOut)) {325 msg += "Connect timeout\n";326 delete socket;327 return 0;328 }329 330 // Send Request331 // ------------332 QString uName = QUrl::fromPercentEncoding(mountPoint.userName().toAscii());333 QString passW = QUrl::fromPercentEncoding(mountPoint.password().toAscii());334 QByteArray userAndPwd;335 336 if(!uName.isEmpty() || !passW.isEmpty())337 {338 userAndPwd = "Authorization: Basic " + (uName.toAscii() + ":" +339 passW.toAscii()).toBase64() + "\r\n";340 }341 342 QUrl hlp;343 hlp.setScheme("http");344 hlp.setHost(mountPoint.host());345 hlp.setPort(mountPoint.port());346 hlp.setPath(mountPoint.path());347 348 QByteArray reqStr;349 if ( proxyHost.isEmpty() ) {350 if (hlp.path().indexOf("/") != 0) hlp.setPath("/");351 reqStr = "GET " + hlp.path().toAscii() + " HTTP/1.0\r\n"352 + "User-Agent: NTRIP BNC/" AGENTVERSION "\r\n"353 + userAndPwd + "\r\n";354 } else {355 reqStr = "GET " + hlp.toEncoded() + " HTTP/1.0\r\n"356 + "User-Agent: NTRIP BNC/" AGENTVERSION "\r\n"357 + "Host: " + hlp.host().toAscii() + "\r\n"358 + userAndPwd + "\r\n";359 }360 361 // NMEA string to handle VRS stream362 // --------------------------------363 double lat, lon;364 365 lat = strtod(latitude,NULL);366 lon = strtod(longitude,NULL);367 368 if ((nmea == "yes") && (hlp.path().length() > 2) && (hlp.path().indexOf(".skl") < 0)) {369 const char* flagN="N";370 const char* flagE="E";371 if (lon >180.) {lon=(lon-360.)*(-1.); flagE="W";}372 if ((lon < 0.) && (lon >= -180.)) {lon=lon*(-1.); flagE="W";}373 if (lon < -180.) {lon=(lon+360.); flagE="E";}374 if (lat < 0.) {lat=lat*(-1.); flagN="S";}375 QTime ttime(QDateTime::currentDateTime().toUTC().time());376 int lat_deg = (int)lat;377 double lat_min=(lat-lat_deg)*60.;378 int lon_deg = (int)lon;379 double lon_min=(lon-lon_deg)*60.;380 int hh = 0 , mm = 0;381 double ss = 0.0;382 hh=ttime.hour();383 mm=ttime.minute();384 ss=(double)ttime.second()+0.001*ttime.msec();385 QString gga;386 gga += "GPGGA,";387 gga += QString("%1%2%3,").arg((int)hh, 2, 10, QLatin1Char('0')).arg((int)mm, 2, 10, QLatin1Char('0')).arg((int)ss, 2, 10, QLatin1Char('0'));388 gga += QString("%1%2,").arg((int)lat_deg,2, 10, QLatin1Char('0')).arg(lat_min, 7, 'f', 4, QLatin1Char('0'));389 gga += flagN;390 gga += QString(",%1%2,").arg((int)lon_deg,3, 10, QLatin1Char('0')).arg(lon_min, 7, 'f', 4, QLatin1Char('0'));391 gga += flagE + QString(",1,05,1.00,+00100,M,10.000,M,,");392 int xori;393 char XOR = 0;394 char *Buff =gga.toAscii().data();395 int iLen = strlen(Buff);396 for (xori = 0; xori < iLen; xori++) {397 XOR ^= (char)Buff[xori];398 }399 gga += QString("*%1").arg(XOR, 2, 16, QLatin1Char('0'));400 reqStr += "$";401 reqStr += gga;402 reqStr += "\r\n";403 }404 405 msg += reqStr;406 407 socket->write(reqStr, reqStr.length());408 409 if (!socket->waitForBytesWritten(timeOut)) {410 msg += "Write timeout\n";411 delete socket;412 return 0;413 }414 415 return socket;416 }417 418 303 // Init Run 419 304 //////////////////////////////////////////////////////////////////////////// … … 425 310 // ----------------- 426 311 QString msg; 427 _socket = this->request(_mountPoint, _latitude, _longitude,428 _nmea, _timeOut, msg);312 _socket = bncSocket::request(_mountPoint, _latitude, _longitude, 313 _nmea, _timeOut, msg); 429 314 if (!_socket) { 430 315 return failure;
Note:
See TracChangeset
for help on using the changeset viewer.