MRPT  2.0.4
CNTRIPClient.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #pragma once
11 
13 
14 #include <future>
15 #include <list>
16 
17 namespace mrpt::hwdrivers
18 {
19 /** A client for NTRIP (HTTP) sources of differential GPS corrections from
20  *internet servers, or Global navigation satellite system (GNSS) internet
21  *radio.
22  * Usage:
23  * - To open the server, invoke "open" with the proper parameters. Then use
24  *"stream_data" to read the read data.
25  * - To obtain a list of all the mountpoints available at a given NTRIP
26  *Caster, call "retrieveListOfMountpoints" (it's a static method).
27  *
28  * It is not neccesary to call "close", the connection is ended at
29  *destruction.
30  *
31  * \note For a good reference of the NTRIP protocol, see
32  *http://gnss.itacyl.es/opencms/opencms/system/modules/es.jcyl.ita.site.gnss/resources/documentos_gnss/NtripDocumentation.pdf
33  * \ingroup mrpt_hwdrivers_grp
34  *
35  */
37 {
38  public:
39  /** A descriptor of one stream in an NTRIP Caster - See
40  * CNTRIPClient::retrieveListOfMountpoints
41  */
42  struct TMountPoint
43  {
44  std::string mountpoint_name;
45  /** City name */
46  std::string id;
47  /** RTCM 2.3, RTCM 3, CMR+, etc... */
48  std::string format;
49  std::string format_details;
50  /** 0: No carrier phase, 1: L1, 2: L1+L2 */
51  int carrier{0};
52  /** GPS, ... */
53  std::string nav_system;
54  /** IGS, ... */
55  std::string network;
56  /** ITA, ESP, DEU,... */
57  std::string country_code;
58  double latitude{0}, longitude{0};
59  bool needs_nmea{false};
60  bool net_ref_stations{false};
61  std::string generator_model;
62  /** "none" */
63  std::string compr_encryp;
64  /** "N": none, "B": basic, "D": digest */
65  char authentication{'B'};
66  bool pay_service{false};
68  std::string extra_info;
69 
70  TMountPoint() = default;
71  };
72 
73  /** Used in CNTRIPClient::retrieveListOfMountpoints */
74  using TListMountPoints = std::list<TMountPoint>;
75 
76  /** The arguments for connecting to a NTRIP stream, used in
77  * CNTRIPClient::open
78  */
79  struct NTRIPArgs
80  {
81  std::string server{"www.euref-ip.net"};
82  int port{2101};
83  std::string user;
84  std::string password;
85  std::string mountpoint;
86 
87  /** Default params */
88  NTRIPArgs() = default;
89  };
90 
91  protected:
92  /** The working thread */
93  void private_ntrip_thread();
94 
95  std::thread m_thread;
96  std::promise<void> m_sem_sock_closed;
97  std::promise<void> m_sem_first_connect_done;
98 
99  mutable bool m_thread_exit{false};
100  /** Will be "true" between "open" and "close" */
101  mutable bool m_thread_do_process{false};
102  mutable bool m_waiting_answer_connection{false};
103 
105  {
106  connOk = 0,
109  };
110 
112  /** All the parameters for the NTRIP connection */
113  mutable NTRIPArgs m_args;
114 
115  /** Buffer for data to be sent back to the server */
117 
118  public:
119  /** Default constructor */
120  CNTRIPClient();
121  /** Default destructor */
122  virtual ~CNTRIPClient();
123 
124  /** Tries to open a given NTRIP stream and, if successful, launches a thread
125  * for continuously reading from it.
126  * \sa close, stream_data
127  *
128  * \return false On any kind of error, with a description of the error in
129  * errmsg, if provided.
130  */
131  bool open(const NTRIPArgs& params, std::string& out_errmsg);
132 
133  /** Closes the connection.
134  * \sa open
135  */
136  void close();
137 
138  /** The buffer with all the bytes so-far read from the NTRIP server stream.
139  * Call its "readAndClear" method in a timely fashion to get the stream
140  * contents.
141  * \sa open, close
142  */
144 
145  /** Connect to a given NTRIP caster and get the list of all available
146  *mountpoints and their parameters.
147  * Note that the authentication parameters "auth_user" and "auth_pass"
148  *will be left empty in most situations, since LISTING the Caster normally
149  *doesn't require special rights.
150  *
151  * Example:
152  * \code
153  * CNTRIPClient::TListMountPoints lst;
154  * std::string errMsg;
155  * bool ret =
156  *CNTRIPClient::retrieveListOfMountpoints(lst,errMsg,"www.euref-ip.net",
157  *2101);
158  * \endcode
159  *
160  * \return False on any error, then "errmsg" holds the reason.
161  */
162  static bool retrieveListOfMountpoints(
163  TListMountPoints& out_list, std::string& out_errmsg,
164  const std::string& server, int port = 2101,
165  const std::string& auth_user = std::string(),
166  const std::string& auth_pass = std::string());
167 
168  /** Enqueues a string to be sent back to the NTRIP server (e.g. GGA frames)
169  */
170  void sendBackToServer(const std::string& data);
171 
172 }; // End of class
173 
174 } // namespace mrpt::hwdrivers
mrpt::opengl::internal::data
static struct FontData data
Definition: gltext.cpp:144
mrpt::hwdrivers::CNTRIPClient::m_waiting_answer_connection
bool m_waiting_answer_connection
Definition: CNTRIPClient.h:102
mrpt::hwdrivers::CNTRIPClient::connOk
@ connOk
Definition: CNTRIPClient.h:106
mrpt::hwdrivers::CNTRIPClient::NTRIPArgs::NTRIPArgs
NTRIPArgs()=default
Default params.
mrpt::hwdrivers::CNTRIPClient
A client for NTRIP (HTTP) sources of differential GPS corrections from internet servers,...
Definition: CNTRIPClient.h:36
mrpt::hwdrivers::CNTRIPClient::retrieveListOfMountpoints
static bool retrieveListOfMountpoints(TListMountPoints &out_list, std::string &out_errmsg, const std::string &server, int port=2101, const std::string &auth_user=std::string(), const std::string &auth_pass=std::string())
Connect to a given NTRIP caster and get the list of all available mountpoints and their parameters.
Definition: CNTRIPClient.cpp:322
mrpt::hwdrivers::CNTRIPClient::m_thread_do_process
bool m_thread_do_process
Will be "true" between "open" and "close".
Definition: CNTRIPClient.h:101
mrpt::hwdrivers::CNTRIPClient::TMountPoint::generator_model
std::string generator_model
Definition: CNTRIPClient.h:61
mrpt::hwdrivers::CNTRIPClient::TMountPoint::mountpoint_name
std::string mountpoint_name
Definition: CNTRIPClient.h:44
mrpt::hwdrivers::CNTRIPClient::private_ntrip_thread
void private_ntrip_thread()
The working thread.
Definition: CNTRIPClient.cpp:118
mrpt::hwdrivers::CNTRIPClient::connError
@ connError
Definition: CNTRIPClient.h:107
mrpt::hwdrivers::CNTRIPClient::stream_data
mrpt::containers::MT_buffer stream_data
The buffer with all the bytes so-far read from the NTRIP server stream.
Definition: CNTRIPClient.h:143
mrpt::hwdrivers::CNTRIPClient::TMountPoint::latitude
double latitude
Definition: CNTRIPClient.h:58
mrpt::hwdrivers::CNTRIPClient::TMountPoint::pay_service
bool pay_service
Definition: CNTRIPClient.h:66
mrpt::hwdrivers::CNTRIPClient::NTRIPArgs::server
std::string server
Definition: CNTRIPClient.h:81
mrpt::hwdrivers
Contains classes for various device interfaces.
Definition: C2DRangeFinderAbstract.h:19
mrpt::hwdrivers::CNTRIPClient::NTRIPArgs::mountpoint
std::string mountpoint
Definition: CNTRIPClient.h:85
mrpt::hwdrivers::CNTRIPClient::NTRIPArgs::password
std::string password
Definition: CNTRIPClient.h:84
mrpt::hwdrivers::CNTRIPClient::TMountPoint::compr_encryp
std::string compr_encryp
"none"
Definition: CNTRIPClient.h:63
mrpt::hwdrivers::CNTRIPClient::NTRIPArgs
The arguments for connecting to a NTRIP stream, used in CNTRIPClient::open.
Definition: CNTRIPClient.h:79
mrpt::hwdrivers::CNTRIPClient::TMountPoint::format
std::string format
RTCM 2.3, RTCM 3, CMR+, etc...
Definition: CNTRIPClient.h:48
mrpt::hwdrivers::CNTRIPClient::TMountPoint::network
std::string network
IGS, ...
Definition: CNTRIPClient.h:55
mrpt::hwdrivers::CNTRIPClient::open
bool open(const NTRIPArgs &params, std::string &out_errmsg)
Tries to open a given NTRIP stream and, if successful, launches a thread for continuously reading fro...
Definition: CNTRIPClient.cpp:64
mrpt::hwdrivers::CNTRIPClient::TMountPoint::needs_nmea
bool needs_nmea
Definition: CNTRIPClient.h:59
mrpt::hwdrivers::CNTRIPClient::TMountPoint::country_code
std::string country_code
ITA, ESP, DEU,...
Definition: CNTRIPClient.h:57
mrpt::hwdrivers::CNTRIPClient::TMountPoint::longitude
double longitude
Definition: CNTRIPClient.h:58
mrpt::hwdrivers::CNTRIPClient::NTRIPArgs::user
std::string user
Definition: CNTRIPClient.h:83
mrpt::hwdrivers::CNTRIPClient::m_args
NTRIPArgs m_args
All the parameters for the NTRIP connection.
Definition: CNTRIPClient.h:113
mrpt::hwdrivers::CNTRIPClient::TMountPoint::extra_info
std::string extra_info
Definition: CNTRIPClient.h:68
mrpt::hwdrivers::CNTRIPClient::TMountPoint::carrier
int carrier
0: No carrier phase, 1: L1, 2: L1+L2
Definition: CNTRIPClient.h:51
mrpt::hwdrivers::CNTRIPClient::TMountPoint::id
std::string id
City name.
Definition: CNTRIPClient.h:46
mrpt::hwdrivers::CNTRIPClient::TMountPoint::net_ref_stations
bool net_ref_stations
Definition: CNTRIPClient.h:60
mrpt::hwdrivers::CNTRIPClient::m_sem_first_connect_done
std::promise< void > m_sem_first_connect_done
Definition: CNTRIPClient.h:97
mrpt::hwdrivers::CNTRIPClient::~CNTRIPClient
virtual ~CNTRIPClient()
Default destructor.
Definition: CNTRIPClient.cpp:40
MT_buffer.h
mrpt::hwdrivers::CNTRIPClient::m_thread
std::thread m_thread
Definition: CNTRIPClient.h:95
mrpt::hwdrivers::CNTRIPClient::m_upload_data
mrpt::containers::MT_buffer m_upload_data
Buffer for data to be sent back to the server.
Definition: CNTRIPClient.h:116
mrpt::hwdrivers::CNTRIPClient::m_answer_connection
TConnResult m_answer_connection
Definition: CNTRIPClient.h:111
mrpt::hwdrivers::CNTRIPClient::close
void close()
Closes the connection.
Definition: CNTRIPClient.cpp:53
mrpt::hwdrivers::CNTRIPClient::TMountPoint::TMountPoint
TMountPoint()=default
params
mrpt::vision::TStereoCalibParams params
Definition: chessboard_stereo_camera_calib_unittest.cpp:24
mrpt::hwdrivers::CNTRIPClient::TMountPoint::format_details
std::string format_details
Definition: CNTRIPClient.h:49
mrpt::hwdrivers::CNTRIPClient::TMountPoint::nav_system
std::string nav_system
GPS, ...
Definition: CNTRIPClient.h:53
mrpt::hwdrivers::CNTRIPClient::TMountPoint::stream_bitspersec
int stream_bitspersec
Definition: CNTRIPClient.h:67
mrpt::hwdrivers::CNTRIPClient::TConnResult
TConnResult
Definition: CNTRIPClient.h:104
mrpt::hwdrivers::CNTRIPClient::m_sem_sock_closed
std::promise< void > m_sem_sock_closed
Definition: CNTRIPClient.h:96
mrpt::hwdrivers::CNTRIPClient::connUnauthorized
@ connUnauthorized
Definition: CNTRIPClient.h:108
mrpt::hwdrivers::CNTRIPClient::NTRIPArgs::port
int port
Definition: CNTRIPClient.h:82
mrpt::containers::MT_buffer
This class is a bulk sequence of bytes with MultiThread (MT)-safe read and write operations.
Definition: MT_buffer.h:22
mrpt::hwdrivers::CNTRIPClient::TMountPoint::authentication
char authentication
"N": none, "B": basic, "D": digest
Definition: CNTRIPClient.h:65
mrpt::hwdrivers::CNTRIPClient::m_thread_exit
bool m_thread_exit
Definition: CNTRIPClient.h:99
mrpt::hwdrivers::CNTRIPClient::TMountPoint
A descriptor of one stream in an NTRIP Caster - See CNTRIPClient::retrieveListOfMountpoints.
Definition: CNTRIPClient.h:42
mrpt::hwdrivers::CNTRIPClient::sendBackToServer
void sendBackToServer(const std::string &data)
Enqueues a string to be sent back to the NTRIP server (e.g.
Definition: CNTRIPClient.cpp:380
mrpt::hwdrivers::CNTRIPClient::CNTRIPClient
CNTRIPClient()
Default constructor.
Definition: CNTRIPClient.cpp:32
mrpt::hwdrivers::CNTRIPClient::TListMountPoints
std::list< TMountPoint > TListMountPoints
Used in CNTRIPClient::retrieveListOfMountpoints.
Definition: CNTRIPClient.h:74



Page generated by Doxygen 1.8.17 for MRPT 2.0.4 at Fri Jul 17 08:43:33 UTC 2020