31 CNTRIPClient::CNTRIPClient() : m_thread(), m_args()
69 out_errmsg =
"MOUNTPOINT cannot be empty.";
74 out_errmsg =
"Server address cannot be empty.";
88 std::future_status::timeout)
90 out_errmsg =
"Timeout waiting thread response";
100 "Error trying to connect to server '%s'",
105 "Authentication failed for server '%s'",
params.server.c_str());
109 out_errmsg =
"UNKNOWN m_answer_connection!!";
145 if (last_thread_do_process)
150 std::this_thread::sleep_for(100ms);
162 std::vector<uint8_t> buf;
170 "[CNTRIPClient] Trying to connect to %s:%i\n",
184 req +=
"User-Agent: NTRIP MRPT Library\r\n";
185 req +=
"Accept: */*\r\n";
186 req +=
"Connection: close\r\n";
195 std::vector<uint8_t>
v(auth_str.size());
196 ::memcpy(&
v[0], &auth_str[0], auth_str.size());
201 req +=
"Authorization: Basic ";
214 size_t to_read_now = 30;
215 buf.resize(to_read_now);
217 my_sock.
readAsync(&buf[0], to_read_now, 4000, 200);
224 catch (std::exception&)
235 resp.resize(buf.size());
236 ::memcpy(&resp[0], &buf[0], buf.size());
238 if (resp.find(
" 200 ") == string::npos)
244 if (resp.find(
" 401 ") != string::npos)
265 std::this_thread::sleep_for(500ms);
271 std::vector<uint8_t> buf;
272 size_t to_read_now = 1000;
273 buf.resize(to_read_now);
274 size_t len = my_sock.
readAsync(&buf[0], to_read_now, 10, 5);
290 std::vector<uint8_t> upload_data;
292 if (!upload_data.empty())
294 const size_t N = upload_data.size();
295 const size_t nWritten =
298 cerr <<
"*ERROR*: Couldn't write back " << N
299 <<
" bytes to NTRIP server!.\n";
302 std::this_thread::sleep_for(10ms);
308 cerr <<
"[CNTRIPClient] Exception in working thread: " << endl
313 cerr <<
"[CNTRIPClient] Runtime exception in working thread." << endl;
323 int port,
const string& auth_user,
const string& auth_pass)
332 string(
"http://") + server, content, out_errmsg, port, auth_user,
333 auth_pass, &http_code, &my_headers,
nullptr, 6000);
338 std::stringstream ss(content);
340 while (std::getline(ss, lin,
'\n'))
342 if (lin.size() < 5)
continue;
343 if (0 != ::strncmp(
"STR;", lin.c_str(), 4))
continue;
346 deque<string> fields;
349 if (fields.size() < 13)
continue;
357 mnt.
carrier = atoi(fields[5].c_str());
361 mnt.
latitude = atof(fields[9].c_str());
362 mnt.
longitude = atof(fields[10].c_str());
367 mnt.
needs_nmea = atoi(fields[11].c_str()) != 0;
370 if (fields.size() >= 19) mnt.
extra_info = fields[18];
372 out_list.push_back(mnt);
381 if (
data.empty())
return;
383 std::vector<uint8_t> d(
data.size());
std::promise< void > m_sem_sock_closed
bool open(const NTRIPArgs ¶ms, std::string &out_errmsg)
Tries to open a given NTRIP stream and, if successful, launches a thread for continuously reading fro...
bool m_waiting_answer_connection
double RAD2DEG(const double x)
Radians to degrees.
void appendData(const std::vector< uint8_t > &d)
Append new data to the stream.
void connect(const std::string &remotePartAddress, unsigned short remotePartTCPPort, unsigned int timeout_ms=0)
Establishes a connection with a remote part.
std::string mountpoint_name
bool isConnected()
Returns true if this objects represents a successfully connected socket.
double DEG2RAD(const double x)
Degrees to radians.
void private_ntrip_thread()
The working thread.
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...
Contains classes for various device interfaces.
void close()
Closes the connection.
std::string network
IGS, ...
A descriptor of one stream in an NTRIP Caster - See CNTRIPClient::retrieveListOfMountpoints.
ERRORCODE_HTTP http_get(const string &url, std::vector< uint8_t > &out_content, string &out_errormsg, int port=80, const string &auth_user=string(), const string &auth_pass=string(), int *out_http_responsecode=nullptr, mrpt::system::TParameters< string > *extra_headers=nullptr, mrpt::system::TParameters< string > *out_headers=nullptr, int timeout_ms=1000)
Perform an HTTP GET operation (version for retrieving the data as a std::vector<uint8_t>) ...
virtual ~CNTRIPClient()
Default destructor.
void tokenize(const std::string &inString, const std::string &inDelimiters, OUT_CONTAINER &outTokens, bool skipBlankTokens=true) noexcept
Tokenizes a string according to a set of delimiting characters.
This base provides a set of functions for maths stuff.
std::string format
RTCM 2.3, RTCM 3, CMR+, etc...
ERRORCODE_HTTP
Possible returns from a HTTP request.
NTRIPArgs m_args
All the parameters for the NTRIP connection.
std::string country_code
ITA, ESP, DEU,...
int carrier
0: No carrier phase, 1: L1, 2: L1+L2
bool m_thread_do_process
Will be "true" between "open" and "close".
GLsizei const GLchar ** string
T wrapToPi(T a)
Modifies the given angle to translate it into the ]-pi,pi] range.
std::string nav_system
GPS, ...
size_t writeAsync(const void *Buffer, const size_t Count, const int timeout_ms=-1)
A method for writing to the socket with optional timeouts.
mrpt::containers::MT_buffer m_upload_data
Buffer for data to be sent back to the server.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
std::promise< void > m_sem_first_connect_done
void encodeBase64(const std::vector< uint8_t > &inputData, std::string &outString)
Encode a sequence of bytes as a string in base-64.
std::string format_details
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
TConnResult m_answer_connection
A TCP socket that can be connected to a TCP server, implementing MRPT's CStream interface for passing...
void close()
Closes the connection.
void readAndClear(std::vector< uint8_t > &d)
Read the whole buffer and empty it.
void clear()
Empty the buffer.
Serial and networking devices and utilities.
size_t readAsync(void *Buffer, const size_t Count, const int timeoutStart_ms=-1, const int timeoutBetween_ms=-1)
A method for reading from the socket with an optional timeout.
std::list< TMountPoint > TListMountPoints
Used in CNTRIPClient::retrieveListOfMountpoints.
For usage when passing a dynamic number of (numeric) arguments to a function, by name.
GLsizei GLsizei GLenum GLenum const GLvoid * data
GLenum const GLfloat * params
The arguments for connecting to a NTRIP stream, used in CNTRIPClient::open.
mrpt::containers::MT_buffer stream_data
The buffer with all the bytes so-far read from the NTRIP server stream.
void sendString(const std::string &str)
Writes a string to the socket.
void memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) noexcept
An OS and compiler independent version of "memcpy".
size_t size()
Return the number of available bytes at this moment.
void sendBackToServer(const std::string &data)
Enqueues a string to be sent back to the NTRIP server (e.g.