Main MRPT website > C++ reference
MRPT logo

CNTRIPClient.h

Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                   http://mrpt.sourceforge.net/                            |
00005    |                                                                           |
00006    |   Copyright (C) 2005-2011  University of Malaga                           |
00007    |                                                                           |
00008    |    This software was written by the Machine Perception and Intelligent    |
00009    |      Robotics Lab, University of Malaga (Spain).                          |
00010    |    Contact: Jose-Luis Blanco  <jlblanco@ctima.uma.es>                     |
00011    |                                                                           |
00012    |  This file is part of the MRPT project.                                   |
00013    |                                                                           |
00014    |     MRPT is free software: you can redistribute it and/or modify          |
00015    |     it under the terms of the GNU General Public License as published by  |
00016    |     the Free Software Foundation, either version 3 of the License, or     |
00017    |     (at your option) any later version.                                   |
00018    |                                                                           |
00019    |   MRPT is distributed in the hope that it will be useful,                 |
00020    |     but WITHOUT ANY WARRANTY; without even the implied warranty of        |
00021    |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |
00022    |     GNU General Public License for more details.                          |
00023    |                                                                           |
00024    |     You should have received a copy of the GNU General Public License     |
00025    |     along with MRPT.  If not, see <http://www.gnu.org/licenses/>.         |
00026    |                                                                           |
00027    +---------------------------------------------------------------------------+ */
00028 
00029 #ifndef CNTRIPClient_H
00030 #define CNTRIPClient_H
00031 
00032 #include <mrpt/utils/utils_defs.h>
00033 #include <mrpt/synch.h>
00034 #include <mrpt/system/threads.h>
00035 
00036 #include <mrpt/hwdrivers/link_pragmas.h>
00037 
00038 namespace mrpt
00039 {
00040         namespace hwdrivers
00041         {
00042                 using namespace std;
00043 
00044                 /** A client for NTRIP (HTTP) sources of differential GPS corrections from internet servers, or Global navigation satellite system (GNSS) internet radio.
00045                   *  Usage:
00046                   *             - To open the server, invoke "open" with the proper parameters. Then use "stream_data" to read the read data.
00047                   *             - To obtain a list of all the mountpoints available at a given NTRIP Caster, call "retrieveListOfMountpoints" (it's a static method).
00048                   *
00049                   *  It is not neccesary to call "close", the connection is ended at destruction.
00050                   *
00051                   * \note For a good reference of the NTRIP protocol, see http://gnss.itacyl.es/opencms/opencms/system/modules/es.jcyl.ita.site.gnss/resources/documentos_gnss/NtripDocumentation.pdf
00052                   *
00053                   */
00054                 class HWDRIVERS_IMPEXP CNTRIPClient
00055                 {
00056                 public:
00057 
00058                         /** A descriptor of one stream in an NTRIP Caster - See CNTRIPClient::retrieveListOfMountpoints
00059                          */
00060                         struct HWDRIVERS_IMPEXP TMountPoint
00061                         {
00062                                 string  mountpoint_name;
00063                                 string  id;  //!< City name
00064                                 string  format; //!< RTCM 2.3, RTCM 3, CMR+, etc...
00065                                 string  format_details;
00066                                 int             carrier; //!< 0: No carrier phase, 1: L1, 2: L1+L2
00067                                 string  nav_system;     //!< GPS, ...
00068                                 string  network;        //!< IGS, ...
00069                                 string  country_code;   //!< ITA, ESP, DEU,...
00070                                 double  latitude, longitude;
00071                                 bool    needs_nmea;
00072                                 bool    net_ref_stations;
00073                                 string  generator_model;
00074                                 string  compr_encryp;           //!< "none"
00075                                 char    authentication;         //!< "N": none, "B": basic, "D": digest
00076                                 bool    pay_service;
00077                                 int             stream_bitspersec;
00078                                 string  extra_info;
00079 
00080                                 TMountPoint() :
00081                                         carrier(0),
00082                                         latitude(0),
00083                                         longitude(0),
00084                                         needs_nmea(false),
00085                                         net_ref_stations(false),
00086                                         authentication('B'),
00087                                         pay_service(false),
00088                                         stream_bitspersec(0)
00089                                 {}
00090 
00091                         };
00092 
00093                         typedef list<TMountPoint> TListMountPoints; //!< Used in CNTRIPClient::retrieveListOfMountpoints
00094 
00095                         /**  The arguments for connecting to a NTRIP stream, used in CNTRIPClient::open
00096                           */
00097                         struct HWDRIVERS_IMPEXP NTRIPArgs
00098                         {
00099                                 string  server;
00100                                 int             port;
00101                                 string  user;
00102                                 string  password;
00103                                 string  mountpoint;
00104 
00105                                 /** Default params */
00106                                 NTRIPArgs() :
00107                                         server          ( "www.euref-ip.net" ),
00108                                         port            ( 2101 ),
00109                                         user            ( "" ),
00110                                         password        ( "" ),
00111                                         mountpoint      ( )
00112                                 {
00113                                 }
00114                         };
00115 
00116                 protected:
00117                         void private_ntrip_thread(); //!< The working thread
00118 
00119                         mrpt::system::TThreadHandle  m_thread;
00120                         mrpt::synch::CSemaphore  m_sem_sock_closed;
00121                         mrpt::synch::CSemaphore  m_sem_first_connect_done;
00122 
00123                         mutable bool m_thread_exit;
00124                         mutable bool m_thread_do_process; //!< Will be "true" between "open" and "close"
00125                         mutable bool m_waiting_answer_connection;
00126 
00127                         enum TConnResult {
00128                                 connOk = 0,
00129                                 connError,
00130                                 connUnauthorized
00131                         };
00132 
00133                         mutable TConnResult m_answer_connection;
00134                         mutable NTRIPArgs  m_args;  //!< All the parameters for the NTRIP connection
00135 
00136                 public:
00137                         CNTRIPClient();   //!< Default constructor
00138                         virtual ~CNTRIPClient();   //!< Default destructor
00139 
00140                         /** Tries to open a given NTRIP stream and, if successful, launches a thread for continuously reading from it.
00141                           * \sa close, stream_data
00142                           *
00143                           * \return false On any kind of error, with a description of the error in errmsg, if provided.
00144                           */
00145                         bool open(const NTRIPArgs &params, string &out_errmsg);
00146 
00147                         /** Closes the connection.
00148                           * \sa open
00149                           */
00150                         void close();
00151 
00152                         /** The buffer with all the bytes so-far read from the NTRIP server stream.
00153                           * Call its "readAndClear" method in a timely fashion to get the stream contents.
00154                           * \sa open, close
00155                           */
00156                         mrpt::synch::MT_buffer   stream_data;
00157 
00158                         /** Connect to a given NTRIP caster and get the list of all available mountpoints and their parameters.
00159                           *  Note that the authentication parameters "auth_user" and "auth_pass" will be left empty in most situations, since LISTING the Caster normally doesn't require special rights.
00160                           *
00161                           * Example:
00162                           * \code
00163                           *      CNTRIPClient::TListMountPoints lst;
00164                           *      std::string errMsg;
00165                           *      bool ret = CNTRIPClient::retrieveListOfMountpoints(lst,errMsg,"www.euref-ip.net", 2101);
00166                           * \endcode
00167                           *
00168                           * \return False on any error, then "errmsg" holds the reason.
00169                           */
00170                         static bool retrieveListOfMountpoints(
00171                                 TListMountPoints        &out_list,
00172                                 string                          &out_errmsg,
00173                                 const string            &server,
00174                                 int                                     port = 2101,
00175                                 const string            &auth_user = string(),
00176                                 const string            &auth_pass = string()
00177                                 );
00178 
00179 
00180                 };      // End of class
00181 
00182         } // End of namespace
00183 
00184 } // End of namespace
00185 
00186 #endif



Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN:exported at Tue Jan 25 21:56:31 UTC 2011