00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://www.mrpt.org/ | 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 #include <list> 00039 00040 namespace mrpt 00041 { 00042 namespace hwdrivers 00043 { 00044 using namespace std; 00045 00046 /** A client for NTRIP (HTTP) sources of differential GPS corrections from internet servers, or Global navigation satellite system (GNSS) internet radio. 00047 * Usage: 00048 * - To open the server, invoke "open" with the proper parameters. Then use "stream_data" to read the read data. 00049 * - To obtain a list of all the mountpoints available at a given NTRIP Caster, call "retrieveListOfMountpoints" (it's a static method). 00050 * 00051 * It is not neccesary to call "close", the connection is ended at destruction. 00052 * 00053 * \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 00054 * \ingroup mrpt_hwdrivers_grp 00055 * 00056 */ 00057 class HWDRIVERS_IMPEXP CNTRIPClient 00058 { 00059 public: 00060 00061 /** A descriptor of one stream in an NTRIP Caster - See CNTRIPClient::retrieveListOfMountpoints 00062 */ 00063 struct HWDRIVERS_IMPEXP TMountPoint 00064 { 00065 string mountpoint_name; 00066 string id; //!< City name 00067 string format; //!< RTCM 2.3, RTCM 3, CMR+, etc... 00068 string format_details; 00069 int carrier; //!< 0: No carrier phase, 1: L1, 2: L1+L2 00070 string nav_system; //!< GPS, ... 00071 string network; //!< IGS, ... 00072 string country_code; //!< ITA, ESP, DEU,... 00073 double latitude, longitude; 00074 bool needs_nmea; 00075 bool net_ref_stations; 00076 string generator_model; 00077 string compr_encryp; //!< "none" 00078 char authentication; //!< "N": none, "B": basic, "D": digest 00079 bool pay_service; 00080 int stream_bitspersec; 00081 string extra_info; 00082 00083 TMountPoint() : 00084 carrier(0), 00085 latitude(0), 00086 longitude(0), 00087 needs_nmea(false), 00088 net_ref_stations(false), 00089 authentication('B'), 00090 pay_service(false), 00091 stream_bitspersec(0) 00092 {} 00093 00094 }; 00095 00096 typedef list<TMountPoint> TListMountPoints; //!< Used in CNTRIPClient::retrieveListOfMountpoints 00097 00098 /** The arguments for connecting to a NTRIP stream, used in CNTRIPClient::open 00099 */ 00100 struct HWDRIVERS_IMPEXP NTRIPArgs 00101 { 00102 string server; 00103 int port; 00104 string user; 00105 string password; 00106 string mountpoint; 00107 00108 /** Default params */ 00109 NTRIPArgs() : 00110 server ( "www.euref-ip.net" ), 00111 port ( 2101 ), 00112 user ( "" ), 00113 password ( "" ), 00114 mountpoint ( ) 00115 { 00116 } 00117 }; 00118 00119 protected: 00120 void private_ntrip_thread(); //!< The working thread 00121 00122 mrpt::system::TThreadHandle m_thread; 00123 mrpt::synch::CSemaphore m_sem_sock_closed; 00124 mrpt::synch::CSemaphore m_sem_first_connect_done; 00125 00126 mutable bool m_thread_exit; 00127 mutable bool m_thread_do_process; //!< Will be "true" between "open" and "close" 00128 mutable bool m_waiting_answer_connection; 00129 00130 enum TConnResult { 00131 connOk = 0, 00132 connError, 00133 connUnauthorized 00134 }; 00135 00136 mutable TConnResult m_answer_connection; 00137 mutable NTRIPArgs m_args; //!< All the parameters for the NTRIP connection 00138 00139 public: 00140 CNTRIPClient(); //!< Default constructor 00141 virtual ~CNTRIPClient(); //!< Default destructor 00142 00143 /** Tries to open a given NTRIP stream and, if successful, launches a thread for continuously reading from it. 00144 * \sa close, stream_data 00145 * 00146 * \return false On any kind of error, with a description of the error in errmsg, if provided. 00147 */ 00148 bool open(const NTRIPArgs ¶ms, string &out_errmsg); 00149 00150 /** Closes the connection. 00151 * \sa open 00152 */ 00153 void close(); 00154 00155 /** The buffer with all the bytes so-far read from the NTRIP server stream. 00156 * Call its "readAndClear" method in a timely fashion to get the stream contents. 00157 * \sa open, close 00158 */ 00159 mrpt::synch::MT_buffer stream_data; 00160 00161 /** Connect to a given NTRIP caster and get the list of all available mountpoints and their parameters. 00162 * 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. 00163 * 00164 * Example: 00165 * \code 00166 * CNTRIPClient::TListMountPoints lst; 00167 * std::string errMsg; 00168 * bool ret = CNTRIPClient::retrieveListOfMountpoints(lst,errMsg,"www.euref-ip.net", 2101); 00169 * \endcode 00170 * 00171 * \return False on any error, then "errmsg" holds the reason. 00172 */ 00173 static bool retrieveListOfMountpoints( 00174 TListMountPoints &out_list, 00175 string &out_errmsg, 00176 const string &server, 00177 int port = 2101, 00178 const string &auth_user = string(), 00179 const string &auth_pass = string() 00180 ); 00181 00182 00183 }; // End of class 00184 00185 } // End of namespace 00186 00187 } // End of namespace 00188 00189 #endif
| Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011 |