31 CNTRIPClient::CNTRIPClient()
34 m_thread_do_process(false),
35 m_waiting_answer_connection(false),
36 m_answer_connection(connError),
75 out_errmsg =
"MOUNTPOINT cannot be empty.";
80 out_errmsg =
"Server address cannot be empty.";
94 std::future_status::timeout)
96 out_errmsg =
"Timeout waiting thread response";
106 "Error trying to connect to server '%s'",
111 "Authentication failed for server '%s'",
params.server.c_str());
115 out_errmsg =
"UNKNOWN m_answer_connection!!";
151 if (last_thread_do_process)
156 std::this_thread::sleep_for(100ms);
176 "[CNTRIPClient] Trying to connect to %s:%i\n",
190 req +=
"User-Agent: NTRIP MRPT Library\r\n";
191 req +=
"Accept: */*\r\n";
192 req +=
"Connection: close\r\n";
202 ::memcpy(&
v[0], &auth_str[0], auth_str.size());
207 req +=
"Authorization: Basic ";
220 size_t to_read_now = 30;
221 buf.resize(to_read_now);
223 my_sock.
readAsync(&buf[0], to_read_now, 4000, 200);
230 catch (std::exception&)
241 resp.resize(buf.size());
242 ::memcpy(&resp[0], &buf[0], buf.size());
244 if (resp.find(
" 200 ") == string::npos)
250 if (resp.find(
" 401 ") != string::npos)
271 std::this_thread::sleep_for(500ms);
278 size_t to_read_now = 1000;
279 buf.resize(to_read_now);
280 size_t len = my_sock.
readAsync(&buf[0], to_read_now, 10, 5);
298 if (!upload_data.empty())
300 const size_t N = upload_data.size();
301 const size_t nWritten =
304 cerr <<
"*ERROR*: Couldn't write back " << N
305 <<
" bytes to NTRIP server!.\n";
308 std::this_thread::sleep_for(10ms);
314 cerr <<
"[CNTRIPClient] Exception in working thread: " << endl
319 cerr <<
"[CNTRIPClient] Runtime exception in working thread." << endl;
329 int port,
const string& auth_user,
const string& auth_pass)
338 string(
"http://") + server, content, out_errmsg, port, auth_user,
339 auth_pass, &http_code, &my_headers,
nullptr, 6000);
346 for (
size_t i = 0; i < lstLines.
size(); i++)
348 const string& lin = lstLines(i);
349 if (lin.size() < 5)
continue;
350 if (0 != ::strncmp(
"STR;", lin.c_str(), 4))
continue;
353 deque<string> fields;
356 if (fields.size() < 13)
continue;
364 mnt.
carrier = atoi(fields[5].c_str());
368 mnt.
latitude = atof(fields[9].c_str());
369 mnt.
longitude = atof(fields[10].c_str());
374 mnt.
needs_nmea = atoi(fields[11].c_str()) != 0;
377 if (fields.size() >= 19) mnt.
extra_info = fields[18];
379 out_list.push_back(mnt);
388 if (
data.empty())
return;
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
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
For usage when passing a dynamic number of (numeric) arguments to a function, by name.
std::vector< uint8_t > vector_byte
std::list< TMountPoint > TListMountPoints
Used in CNTRIPClient::retrieveListOfMountpoints.
void connect(const std::string &remotePartAddress, unsigned short remotePartTCPPort, unsigned int timeout_ms=0)
Establishes a connection with a remote part.
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
std::string mountpoint_name
bool isConnected()
Returns true if this objects represents a successfully connected socket.
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...
void encodeBase64(const vector_byte &inputData, std::string &outString)
Encode a sequence of bytes as a string in base-64.
ERRORCODE_HTTP http_get(const string &url, vector_byte &out_content, string &out_errormsg, int port=80, const string &auth_user=string(), const string &auth_pass=string(), int *out_http_responsecode=nullptr, mrpt::utils::TParameters< string > *extra_headers=nullptr, mrpt::utils::TParameters< string > *out_headers=nullptr, int timeout_ms=1000)
Perform an HTTP GET operation (version for retrieving the data as a vector_byte)
Contains classes for various device interfaces.
void close()
Closes the connection.
void readAndClear(vector_byte &d)
Read the whole buffer and empty it.
std::string network
IGS, ...
A descriptor of one stream in an NTRIP Caster - See CNTRIPClient::retrieveListOfMountpoints.
virtual ~CNTRIPClient()
Default destructor.
void clear()
Empty the buffer.
mrpt::synch::MT_buffer m_upload_data
Buffer for data to be sent back to the server.
A class for storing a list of text lines.
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.
size_t size()
Return the number of available bytes at this moment.
NTRIPArgs m_args
All the parameters for the NTRIP connection.
std::string country_code
ITA, ESP, DEU,...
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
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.
size_t size() const
Returns the number of text lines in the list.
void tokenize(const std::string &inString, const std::string &inDelimiters, std::deque< std::string > &outTokens, bool skipBlankTokens=true) noexcept
Tokenizes a string according to a set of delimiting characters.
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.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
std::promise< void > m_sem_first_connect_done
void appendData(const vector_byte &d)
Append new data to the stream.
std::string format_details
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.
Serial and networking devices and utilities.
std::vector< uint8_t > vector_byte
mrpt::synch::MT_buffer stream_data
The buffer with all the bytes so-far read from the NTRIP server stream.
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.
GLsizei GLsizei GLenum GLenum const GLvoid * data
GLenum const GLfloat * params
The arguments for connecting to a NTRIP stream, used in CNTRIPClient::open.
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".
void sendBackToServer(const std::string &data)
Enqueues a string to be sent back to the NTRIP server (e.g.