Changeset 1346 in ntrip


Ignore:
Timestamp:
Dec 27, 2008, 12:40:39 PM (15 years ago)
Author:
mervart
Message:

* empty log message *

Location:
trunk/BNC
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/bncgetthread.cpp

    r1345 r1346  
    301301}
    302302
    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 Socket
    312   // ------------------
    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 Request
    331   // ------------
    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 stream
    362   // --------------------------------
    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 
    418303// Init Run
    419304////////////////////////////////////////////////////////////////////////////
     
    425310    // -----------------
    426311    QString msg;
    427     _socket = this->request(_mountPoint, _latitude, _longitude,
    428                             _nmea, _timeOut, msg);
     312    _socket = bncSocket::request(_mountPoint, _latitude, _longitude,
     313                                 _nmea, _timeOut, msg);
    429314    if (!_socket) {
    430315      return failure;
  • trunk/BNC/bncgetthread.h

    r1345 r1346  
    5151
    5252   ~bncGetThread();
    53 
    54    static bncSocket* request(const QUrl& mountPoint, QByteArray& latitude, QByteArray& longitude,
    55                              QByteArray& nmea, int timeOut, QString& msg);
    5653
    5754   QByteArray staID() const {return _staID;}
  • trunk/BNC/bncrinex.cpp

    r1345 r1346  
    157157    QByteArray _longitude;
    158158    QByteArray _nmea;
    159     bncSocket* socket = bncGetThread::request(url, _latitude, _longitude, _nmea, timeOut, msg);
     159    bncSocket* socket = bncSocket::request(url, _latitude, _longitude, _nmea, timeOut, msg);
    160160
    161161    if (socket) {
  • trunk/BNC/bncsocket.cpp

    r1345 r1346  
    2222using namespace std;
    2323
     24#define BNCVERSION "1.7"
     25
    2426// Constructor
    2527////////////////////////////////////////////////////////////////////////////
     
    99101  return _socket->waitForBytesWritten(msecs);
    100102}
     103
     104// Connect to Caster, send the Request (static)
     105////////////////////////////////////////////////////////////////////////////
     106bncSocket* bncSocket::request(const QUrl& mountPoint,
     107                              QByteArray& latitude, QByteArray& longitude,
     108                              QByteArray& nmea, int timeOut,
     109                              QString& msg) {
     110
     111  // Connect the Socket
     112  // ------------------
     113  QSettings settings;
     114  QString proxyHost = settings.value("proxyHost").toString();
     115  int     proxyPort = settings.value("proxyPort").toInt();
     116 
     117  bncSocket* socket = new bncSocket(new QTcpSocket());
     118  if ( proxyHost.isEmpty() ) {
     119    socket->connectToHost(mountPoint.host(), mountPoint.port());
     120  }
     121  else {
     122    socket->connectToHost(proxyHost, proxyPort);
     123  }
     124  if (!socket->waitForConnected(timeOut)) {
     125    msg += "Connect timeout\n";
     126    delete socket;
     127    return 0;
     128  }
     129
     130  // Send Request
     131  // ------------
     132  QString uName = QUrl::fromPercentEncoding(mountPoint.userName().toAscii());
     133  QString passW = QUrl::fromPercentEncoding(mountPoint.password().toAscii());
     134  QByteArray userAndPwd;
     135
     136  if(!uName.isEmpty() || !passW.isEmpty())
     137  {
     138    userAndPwd = "Authorization: Basic " + (uName.toAscii() + ":" +
     139    passW.toAscii()).toBase64() + "\r\n";
     140  }
     141
     142  QUrl hlp;
     143  hlp.setScheme("http");
     144  hlp.setHost(mountPoint.host());
     145  hlp.setPort(mountPoint.port());
     146  hlp.setPath(mountPoint.path());
     147
     148  QByteArray reqStr;
     149  if ( proxyHost.isEmpty() ) {
     150    if (hlp.path().indexOf("/") != 0) hlp.setPath("/");
     151    reqStr = "GET " + hlp.path().toAscii() + " HTTP/1.0\r\n"
     152             + "User-Agent: NTRIP BNC/" BNCVERSION "\r\n"
     153             + userAndPwd + "\r\n";
     154  } else {
     155    reqStr = "GET " + hlp.toEncoded() + " HTTP/1.0\r\n"
     156             + "User-Agent: NTRIP BNC/" BNCVERSION "\r\n"
     157             + "Host: " + hlp.host().toAscii() + "\r\n"
     158             + userAndPwd + "\r\n";
     159  }
     160
     161  // NMEA string to handle VRS stream
     162  // --------------------------------
     163  double lat, lon;
     164
     165  lat = strtod(latitude,NULL);
     166  lon = strtod(longitude,NULL);
     167
     168  if ((nmea == "yes") && (hlp.path().length() > 2) && (hlp.path().indexOf(".skl") < 0)) {
     169    const char* flagN="N";
     170    const char* flagE="E";
     171    if (lon >180.) {lon=(lon-360.)*(-1.); flagE="W";}
     172    if ((lon < 0.) && (lon >= -180.))  {lon=lon*(-1.); flagE="W";}
     173    if (lon < -180.)  {lon=(lon+360.); flagE="E";}
     174    if (lat < 0.)  {lat=lat*(-1.); flagN="S";}
     175    QTime ttime(QDateTime::currentDateTime().toUTC().time());
     176    int lat_deg = (int)lat; 
     177    double lat_min=(lat-lat_deg)*60.;
     178    int lon_deg = (int)lon; 
     179    double lon_min=(lon-lon_deg)*60.;
     180    int hh = 0 , mm = 0;
     181    double ss = 0.0;
     182    hh=ttime.hour();
     183    mm=ttime.minute();
     184    ss=(double)ttime.second()+0.001*ttime.msec();
     185    QString gga;
     186    gga += "GPGGA,";
     187    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'));
     188    gga += QString("%1%2,").arg((int)lat_deg,2, 10, QLatin1Char('0')).arg(lat_min, 7, 'f', 4, QLatin1Char('0'));
     189    gga += flagN;
     190    gga += QString(",%1%2,").arg((int)lon_deg,3, 10, QLatin1Char('0')).arg(lon_min, 7, 'f', 4, QLatin1Char('0'));
     191    gga += flagE + QString(",1,05,1.00,+00100,M,10.000,M,,");
     192    int xori;
     193    char XOR = 0;
     194    char *Buff =gga.toAscii().data();
     195    int iLen = strlen(Buff);
     196    for (xori = 0; xori < iLen; xori++) {
     197      XOR ^= (char)Buff[xori];
     198    }
     199    gga += QString("*%1").arg(XOR, 2, 16, QLatin1Char('0'));
     200    reqStr += "$";
     201    reqStr += gga;
     202    reqStr += "\r\n";
     203  }
     204
     205  msg += reqStr;
     206
     207  socket->write(reqStr, reqStr.length());
     208
     209  if (!socket->waitForBytesWritten(timeOut)) {
     210    msg += "Write timeout\n";
     211    delete socket;
     212    return 0;
     213  }
     214
     215  return socket;
     216}
     217
  • trunk/BNC/bncsocket.h

    r1345 r1346  
    2323  QAbstractSocket::SocketState state() const;
    2424
     25 static bncSocket* request(const QUrl& mountPoint, QByteArray& latitude,
     26                           QByteArray& longitude, QByteArray& nmea,
     27                           int timeOut, QString& msg);
     28
     29
    2530 private:
    2631  QTcpSocket* _socket;
  • trunk/BNC/bnctabledlg.cpp

    r1345 r1346  
    163163  QByteArray _longitude;
    164164  QByteArray _nmea;
    165   bncSocket* socket = bncGetThread::request(url, _latitude, _longitude, _nmea, timeOut, msg);
     165  bncSocket* socket = bncSocket::request(url, _latitude, _longitude, _nmea, timeOut, msg);
    166166
    167167  if (!socket) {
  • trunk/BNC/serial/posix_qextserialport.cpp

    r1317 r1346  
    822822        /*open the port*/
    823823        Posix_File->setFileName(port);
    824         qDebug("Trying to open File");
     824        ////        qDebug("Trying to open File");
    825825        if (Posix_File->open(QIODevice::ReadWrite|QIODevice::Unbuffered)) {
    826             qDebug("Opened File succesfully");
     826          ///            qDebug("Opened File succesfully");
    827827            /*set open mode*/
    828828            QIODevice::open(mode);
Note: See TracChangeset for help on using the changeset viewer.