33 CNTRIPClient::CNTRIPClient() :
35 m_sem_sock_closed(0,1),
36 m_sem_first_connect_done(0,1),
37 m_thread_exit (false),
38 m_thread_do_process(false),
39 m_waiting_answer_connection(false),
40 m_answer_connection(connError),
81 out_errmsg=
"MOUNTPOINT cannot be empty.";
86 out_errmsg=
"Server address cannot be empty.";
101 out_errmsg =
"Timeout waiting thread response";
110 out_errmsg =
format(
"Error trying to connect to server '%s'",
params.server.c_str());
113 out_errmsg =
format(
"Authentication failed for server '%s'",
params.server.c_str());
117 out_errmsg =
"UNKNOWN m_answer_connection!!";
150 if (last_thread_do_process)
185 req+=
"User-Agent: NTRIP MRPT Library\r\n";
186 req+=
"Accept: */*\r\n";
187 req+=
"Connection: close\r\n";
200 req+=
"Authorization: Basic ";
213 size_t to_read_now = 30;
214 buf.resize(to_read_now);
215 size_t len = my_sock.
readAsync(&buf[0],to_read_now, 4000,200);
222 catch(std::exception &)
232 resp.resize(buf.size());
233 ::memcpy(&resp[0],&buf[0],buf.size());
235 if (resp.find(
" 200 ")==string::npos)
241 if (resp.find(
" 401 ")!=string::npos)
271 size_t to_read_now = 1000;
272 buf.resize(to_read_now);
273 size_t len = my_sock.
readAsync(&buf[0],to_read_now,10,5);
291 if (!upload_data.empty())
293 const size_t N = upload_data.size();
294 const size_t nWritten = my_sock.
writeAsync( &upload_data[0],N, 1000);
296 cerr <<
"*ERROR*: Couldn't write back " << N <<
" bytes to NTRIP server!.\n";
306 cerr <<
"[CNTRIPClient] Exception in working thread: " << endl << e.what() << endl;
310 cerr <<
"[CNTRIPClient] Runtime exception in working thread." << endl;
322 const string &server,
324 const string &auth_user,
325 const string &auth_pass)
334 string(
"http://")+server,
339 &http_code,&my_headers,NULL,
348 for (
size_t i=0;i<lstLines.
size();i++)
350 const string &lin = lstLines(i);
351 if (lin.size()<5)
continue;
352 if (0!=::strncmp(
"STR;",lin.c_str(),4))
continue;
355 deque<string> fields;
358 if (fields.size()<13)
367 mnt.
carrier = atoi(fields[5].c_str());
371 mnt.
latitude = atof(fields[9].c_str());
372 mnt.
longitude = atof(fields[10].c_str());
380 if (fields.size()>=19)
383 out_list.push_back(mnt);
393 if (
data.empty())
return;
void BASE_IMPEXP memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) MRPT_NO_THROWS
An OS and compiler independent version of "memcpy".
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...
ERRORCODE_HTTP
Possible returns from a HTTP request.
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.
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
std::string mountpoint_name
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 BASE_IMPEXP encodeBase64(const vector_byte &inputData, std::string &outString)
Encode a sequence of bytes as a string in base-64.
Contains classes for various device interfaces.
void close()
Closes the connection.
void sendString(const std::string &str)
Writes a string to the socket.
void readAndClear(vector_byte &d)
std::string network
IGS, ...
A descriptor of one stream in an NTRIP Caster - See CNTRIPClient::retrieveListOfMountpoints.
virtual ~CNTRIPClient()
Default destructor.
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.
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.
mrpt::synch::MT_buffer m_upload_data
Buffer for data to be sent back to the server.
void close()
Closes the connection.
ERRORCODE_HTTP BASE_IMPEXP 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=NULL, mrpt::utils::TParameters< string > *extra_headers=NULL, mrpt::utils::TParameters< string > *out_headers=NULL, int timeout_ms=1000)
Perform an HTTP GET operation (version for retrieving the data as a vector_byte)
mrpt::system::TThreadHandle m_thread
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...
NTRIPArgs m_args
All the parameters for the NTRIP connection.
void BASE_IMPEXP sleep(int time_ms) MRPT_NO_THROWS
An OS-independent method for sending the current thread to "sleep" for a given period of time...
bool isConnected()
Returns true if this objects represents a successfully connected socket.
std::string country_code
ITA, ESP, DEU,...
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
void release(unsigned int increaseCount=1)
Increments the count of the semaphore by a given amount.
int carrier
0: No carrier phase, 1: L1, 2: L1+L2
bool m_thread_do_process
Will be "true" between "open" and "close".
bool isClear() const
Returns true if the handle is uninitialized.
This namespace provides multitask, synchronization utilities.
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.
TThreadHandle createThreadFromObjectMethod(CLASS *obj, void(CLASS::*func)(PARAM), PARAM param)
Creates a new thread running a non-static method (so it will have access to "this") from another meth...
std::string nav_system
GPS, ...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void connect(const std::string &remotePartAddress, unsigned short remotePartTCPPort, unsigned int timeout_ms=0)
Establishes a connection with a remote part.
void appendData(const vector_byte &d)
std::string format_details
TConnResult m_answer_connection
bool waitForSignal(unsigned int timeout_ms=0)
Blocks until the count of the semaphore to be non-zero.
mrpt::synch::CSemaphore m_sem_first_connect_done
A TCP socket that can be connected to a TCP server, implementing MRPT's CStream interface for passing...
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.
mrpt::synch::CSemaphore m_sem_sock_closed
GLsizei GLsizei GLenum GLenum const GLvoid * data
void BASE_IMPEXP tokenize(const std::string &inString, const std::string &inDelimiters, std::deque< std::string > &outTokens, bool skipBlankTokens=true) MRPT_NO_THROWS
Tokenizes a string according to a set of delimiting characters.
GLenum const GLfloat * params
The arguments for connecting to a NTRIP stream, used in CNTRIPClient::open.
void BASE_IMPEXP joinThread(const TThreadHandle &threadHandle)
Waits until the given thread ends.
void sendBackToServer(const std::string &data)
Enqueues a string to be sent back to the NTRIP server (e.g.