Ignore:
Timestamp:
Mar 31, 2011, 5:15:47 PM (13 years ago)
Author:
mervart
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/upload/bncrtnetuploadcaster.cpp

    r3222 r3224  
    33 * -------------------------------------------------------------------------
    44 *
    5  * Class:      bncUploadCaster
     5 * Class:      bncRtnetUploadCaster
    66 *
    77 * Purpose:    Connection to NTRIP Caster
     
    1616
    1717#include <math.h>
    18 #include "bncuploadcaster.h"
     18#include "bncrtnetuploadcaster.h"
    1919#include "bncsettings.h"
    20 #include "bncversion.h"
    21 #include "bncapp.h"
     20#include "bncephuser.h"
    2221#include "bncclockrinex.h"
    2322#include "bncsp3.h"
     
    2726// Constructor
    2827////////////////////////////////////////////////////////////////////////////
    29 bncUploadCaster::bncUploadCaster(const QString& mountpoint,
     28bncRtnetUploadCaster::bncRtnetUploadCaster(const QString& mountpoint,
    3029                                 const QString& outHost, int outPort,
    3130                                 const QString& password,
     
    3332                                 const QString& sp3FileName,
    3433                                 const QString& rnxFileName,
    35                                  const QString& outFileName) {
     34                                 const QString& outFileName) :
     35                      bncUploadCaster(mountpoint, outHost, outPort, password) {
     36
    3637  bncSettings settings;
    37 
    38   connect(this, SIGNAL(newMessage(QByteArray,bool)),
    39           ((bncApp*)qApp), SLOT(slotMessage(const QByteArray,bool)));
    40 
    41   _mountpoint = mountpoint;
    42   _outHost    = outHost;
    43   _outPort    = outPort;
    44   _password   = password;
    4538  _crdTrafo   = crdTrafo;
    4639  _CoM        = CoM;
    4740
    48   _outSocket  = 0;
    49   _sOpenTrial = 0;
    50 
    51   _isToBeDeleted = false;
     41  // Member that receives the ephemeris
     42  // ----------------------------------
     43  _ephUser = new bncEphUser();
    5244
    5345  // Raw Output
     
    182174    _t0  = settings.value("trafo_t0").toDouble();
    183175  }
    184 
    185   // Member that receives the ephemeris
    186   // ----------------------------------
    187   _ephUser = new bncEphUser();
    188 }
    189 
    190 // Safe Desctructor
    191 ////////////////////////////////////////////////////////////////////////////
    192 void bncUploadCaster::deleteSafely() {
    193   _isToBeDeleted = true;
    194   if (!isRunning()) {
    195     delete this;
    196   }
    197176}
    198177
    199178// Destructor
    200179////////////////////////////////////////////////////////////////////////////
    201 bncUploadCaster::~bncUploadCaster() {
     180bncRtnetUploadCaster::~bncRtnetUploadCaster() {
    202181  if (isRunning()) {
    203182    wait();
     
    211190// Endless Loop
    212191////////////////////////////////////////////////////////////////////////////
    213 void bncUploadCaster::run() {
     192void bncRtnetUploadCaster::run() {
    214193  while (true) {
    215194    if (_isToBeDeleted) {
     
    224203}
    225204
    226 // Start the Communication with NTRIP Caster
    227 ////////////////////////////////////////////////////////////////////////////
    228 void bncUploadCaster::open() {
    229 
    230   if (_mountpoint.isEmpty()) {
    231     return;
    232   }
    233 
    234   if (_outSocket != 0 &&
    235       _outSocket->state() == QAbstractSocket::ConnectedState) {
    236     return;
    237   }
    238 
    239   delete _outSocket; _outSocket = 0;
    240 
    241   double minDt = pow(2.0,_sOpenTrial);
    242   if (++_sOpenTrial > 4) {
    243     _sOpenTrial = 4;
    244   }
    245   if (_outSocketOpenTime.isValid() &&
    246       _outSocketOpenTime.secsTo(QDateTime::currentDateTime()) < minDt) {
    247     return;
    248   }
    249   else {
    250     _outSocketOpenTime = QDateTime::currentDateTime();
    251   }
    252 
    253   bncSettings settings;
    254   _outSocket = new QTcpSocket();
    255   _outSocket->connectToHost(_outHost, _outPort);
    256 
    257   const int timeOut = 5000;  // 5 seconds
    258   if (!_outSocket->waitForConnected(timeOut)) {
    259     delete _outSocket;
    260     _outSocket = 0;
    261     emit(newMessage("Broadcaster: Connect timeout", true));
    262     return;
    263   }
    264 
    265   QByteArray msg = "SOURCE " + _password.toAscii() + " /" +
    266                    _mountpoint.toAscii() + "\r\n" +
    267                    "Source-Agent: NTRIP BNC/" BNCVERSION "\r\n\r\n";
    268 
    269   _outSocket->write(msg);
    270   _outSocket->waitForBytesWritten();
    271 
    272   _outSocket->waitForReadyRead();
    273   QByteArray ans = _outSocket->readLine();
    274 
    275   if (ans.indexOf("OK") == -1) {
    276     delete _outSocket;
    277     _outSocket = 0;
    278     emit(newMessage("Broadcaster: Connection broken", true));
    279   }
    280   else {
    281     emit(newMessage("Broadcaster: Connection opened", true));
    282     _sOpenTrial = 0;
    283   }
    284 }
    285 
    286 // Write buffer
    287 ////////////////////////////////////////////////////////////////////////////
    288 void bncUploadCaster::write(char* buffer, unsigned len) {
    289   if (_outSocket && _outSocket->state() == QAbstractSocket::ConnectedState) {
    290     _outSocket->write(buffer, len);
    291     _outSocket->flush();
    292   }
    293 }
    294 
    295205//
    296206////////////////////////////////////////////////////////////////////////////
    297 void bncUploadCaster::decodeRtnetStream(char* buffer, int bufLen) {
     207void bncRtnetUploadCaster::decodeRtnetStream(char* buffer, int bufLen) {
    298208                                       
    299209  QMutexLocker locker(&_mutex);
     
    310220// Function called in separate thread
    311221////////////////////////////////////////////////////////////////////////
    312 void bncUploadCaster::uploadClockOrbitBias() {
     222void bncRtnetUploadCaster::uploadClockOrbitBias() {
    313223
    314224  QMutexLocker locker(&_mutex);
     
    472382//
    473383////////////////////////////////////////////////////////////////////////////
    474 void bncUploadCaster::processSatellite(t_eph* eph, int GPSweek,
     384void bncRtnetUploadCaster::processSatellite(t_eph* eph, int GPSweek,
    475385                                       double GPSweeks, const QString& prn,
    476386                                       const ColumnVector& xx,
     
    558468// Transform Coordinates
    559469////////////////////////////////////////////////////////////////////////////
    560 void bncUploadCaster::crdTrafo(int GPSWeek, ColumnVector& xyz) {
     470void bncRtnetUploadCaster::crdTrafo(int GPSWeek, ColumnVector& xyz) {
    561471
    562472  // Current epoch minus 2000.0 in years
Note: See TracChangeset for help on using the changeset viewer.