Go to the documentation of this file.
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);
168 std::vector<uint8_t> buf;
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";
201 std::vector<uint8_t>
v(auth_str.size());
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);
277 std::vector<uint8_t> buf;
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);
296 std::vector<uint8_t> upload_data;
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);
344 std::stringstream ss(content);
346 while (std::getline(ss, lin,
'\n'))
348 if (lin.size() < 5)
continue;
349 if (0 != ::strncmp(
"STR;", lin.c_str(), 4))
continue;
352 deque<string> fields;
355 if (fields.size() < 13)
continue;
363 mnt.
carrier = atoi(fields[5].c_str());
367 mnt.
latitude = atof(fields[9].c_str());
368 mnt.
longitude = atof(fields[10].c_str());
373 mnt.
needs_nmea = atoi(fields[11].c_str()) != 0;
376 if (fields.size() >= 19) mnt.
extra_info = fields[18];
378 out_list.push_back(mnt);
387 if (
data.empty())
return;
389 std::vector<uint8_t> d(
data.size());
A TCP socket that can be connected to a TCP server, implementing MRPT's CStream interface for passing...
bool m_waiting_answer_connection
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.
bool m_thread_do_process
Will be "true" between "open" and "close".
std::string mountpoint_name
void private_ntrip_thread()
The working thread.
void clear()
Empty the buffer.
mrpt::containers::MT_buffer stream_data
The buffer with all the bytes so-far read from the NTRIP server stream.
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.
Contains classes for various device interfaces.
Serial and networking devices and utilities.
void readAndClear(std::vector< uint8_t > &d)
Read the whole buffer and empty it.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
double RAD2DEG(const double x)
Radians to degrees.
void close()
Closes the connection.
The arguments for connecting to a NTRIP stream, used in CNTRIPClient::open.
std::string format
RTCM 2.3, RTCM 3, CMR+, etc...
std::string network
IGS, ...
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.
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...
void sendString(const std::string &str)
Writes a string to the socket.
std::string country_code
ITA, ESP, DEU,...
NTRIPArgs m_args
All the parameters for the NTRIP connection.
int carrier
0: No carrier phase, 1: L1, 2: L1+L2
GLsizei GLsizei GLenum GLenum const GLvoid * data
T wrapToPi(T a)
Modifies the given angle to translate it into the ]-pi,pi] range.
ERRORCODE_HTTP
Possible returns from a HTTP request.
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
For usage when passing a dynamic number of (numeric) arguments to a function, by name.
size_t size()
Return the number of available bytes at this moment.
std::promise< void > m_sem_first_connect_done
void connect(const std::string &remotePartAddress, unsigned short remotePartTCPPort, unsigned int timeout_ms=0)
Establishes a connection with a remote part.
virtual ~CNTRIPClient()
Default destructor.
mrpt::containers::MT_buffer m_upload_data
Buffer for data to be sent back to the server.
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.
TConnResult m_answer_connection
void close()
Closes the connection.
std::string format_details
std::string nav_system
GPS, ...
void appendData(const std::vector< uint8_t > &d)
Append new data to the stream.
void encodeBase64(const std::vector< uint8_t > &inputData, std::string &outString)
Encode a sequence of bytes as a string in base-64.
std::promise< void > m_sem_sock_closed
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>)
This base provides a set of functions for maths stuff.
GLsizei const GLchar ** string
bool isConnected()
Returns true if this objects represents a successfully connected socket.
This namespace provides a OS-independent interface to many useful functions: filenames manipulation,...
GLenum const GLfloat * params
A descriptor of one stream in an NTRIP Caster - See CNTRIPClient::retrieveListOfMountpoints.
void sendBackToServer(const std::string &data)
Enqueues a string to be sent back to the NTRIP server (e.g.
std::list< TMountPoint > TListMountPoints
Used in CNTRIPClient::retrieveListOfMountpoints.
void memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) noexcept
An OS and compiler independent version of "memcpy".
double DEG2RAD(const double x)
Degrees to radians.
Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST | |