Main MRPT website > C++ reference for MRPT 1.9.9
test.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
11 #include <mrpt/system/os.h>
12 #include <cstdio>
13 #include <iostream>
14 
15 using namespace std;
16 using namespace mrpt;
17 using namespace mrpt::hwdrivers;
18 using namespace mrpt::system;
19 
20 // ------------------------------------------------------
21 // TestNTRIP
22 // ------------------------------------------------------
23 void TestNTRIP()
24 {
25  const string server = "www.euref-ip.net";
26  const int server_port = 2101;
27 
29  string errMsg;
30 
31  bool ret = CNTRIPClient::retrieveListOfMountpoints(
32  lst, errMsg, server, server_port);
33 
34  if (!ret)
35  {
36  cout << "Error: " << errMsg << endl;
37  return;
38  }
39 
40  if (lst.empty())
41  {
42  cout << "Zero streams listed in caster...?" << endl;
43  return;
44  }
45 
46  // List:
47  // -----------------------------------
49  it != lst.end(); it++)
50  {
51  const CNTRIPClient::TMountPoint& m = *it;
52  cout << "MOUNT: " << m.mountpoint_name
53  << " | COUNTRY: " << m.country_code
54  << " | NMEA?: " << m.needs_nmea << " | FORMAT: " << m.format
55  << " (" << m.id << ") " << m.extra_info << endl;
56  }
57 
58  // Now connect to a random server:
59  // -----------------------------------
60  CNTRIPClient ntrip;
62 
64  // std::advance(it,8);
65 
66  cout << "Connecting to: " << it->mountpoint_name << " - " << it->id << endl;
67  params.mountpoint = it->mountpoint_name;
68  params.server = server;
69  params.port = server_port;
70 
71  params.user = "";
72  params.password = "";
73 
74  string msgerr;
75 
76  if (!ntrip.open(params, msgerr))
77  {
78  cout << "ERROR: " << msgerr << endl;
79  }
80  else
81  {
82  cout << "Reading stream... press any key to finish." << endl;
83 
84  std::vector<uint8_t> dat;
85  while (!mrpt::system::os::kbhit())
86  {
87  ntrip.stream_data.readAndClear(dat);
88  cout << "Read " << dat.size() << " bytes." << endl;
89  std::this_thread::sleep_for(1000ms);
90  }
91  }
92 }
93 
94 void TestNTRIP2()
95 {
96  // const string server = "www.euref-ip.net";
97  const string server = "193.144.251.13";
98  const int server_port = 2101;
99 
100  // Now connect to a random server:
101  // -----------------------------------
102  CNTRIPClient ntrip;
104 
105  params.mountpoint = "ACOR0";
106  params.server = server;
107  params.port = server_port;
108  params.user = "";
109  params.password = "";
110 
111  string msgerr;
112 
113  if (!ntrip.open(params, msgerr))
114  {
115  cout << "ERROR: " << msgerr << endl;
116  }
117  else
118  {
119  cout << "Reading stream... press any key to finish." << endl;
120 
121  std::vector<uint8_t> dat;
122  while (!mrpt::system::os::kbhit())
123  {
124  ntrip.stream_data.readAndClear(dat);
125  cout << "Read " << dat.size() << " bytes." << endl;
126  std::this_thread::sleep_for(1000ms);
127  }
128  }
129 }
130 
131 // ------------------------------------------------------
132 // MAIN
133 // ------------------------------------------------------
134 int main()
135 {
136  try
137  {
138  TestNTRIP();
139  // TestNTRIP2();
140 
141  return 0;
142  }
143  catch (std::exception& e)
144  {
145  std::cout << "MRPT exception caught: " << e.what() << std::endl;
146  return -1;
147  }
148  catch (...)
149  {
150  printf("Untyped exception!!");
151  return -1;
152  }
153 }
mrpt::system::os::kbhit
bool kbhit() noexcept
An OS-independent version of kbhit, which returns true if a key has been pushed.
Definition: os.cpp:390
os.h
const_iterator
const Scalar * const_iterator
Definition: eigen_plugins.h:27
mrpt::hwdrivers::CNTRIPClient
A client for NTRIP (HTTP) sources of differential GPS corrections from internet servers,...
Definition: CNTRIPClient.h:39
mrpt::hwdrivers::CNTRIPClient::TMountPoint::mountpoint_name
std::string mountpoint_name
Definition: CNTRIPClient.h:47
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:163
mrpt::hwdrivers
Contains classes for various device interfaces.
Definition: C2DRangeFinderAbstract.h:22
mrpt::containers::MT_buffer::readAndClear
void readAndClear(std::vector< uint8_t > &d)
Read the whole buffer and empty it.
Definition: MT_buffer.h:62
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
TestNTRIP2
void TestNTRIP2()
Definition: vision_stereo_rectify/test.cpp:94
mrpt::hwdrivers::CNTRIPClient::NTRIPArgs
The arguments for connecting to a NTRIP stream, used in CNTRIPClient::open.
Definition: CNTRIPClient.h:92
mrpt::hwdrivers::CNTRIPClient::TMountPoint::format
std::string format
RTCM 2.3, RTCM 3, CMR+, etc...
Definition: CNTRIPClient.h:51
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:69
mrpt::hwdrivers::CNTRIPClient::TMountPoint::needs_nmea
bool needs_nmea
Definition: CNTRIPClient.h:62
CNTRIPClient.h
main
int main()
Definition: vision_stereo_rectify/test.cpp:78
mrpt::hwdrivers::CNTRIPClient::TMountPoint::country_code
std::string country_code
ITA, ESP, DEU,...
Definition: CNTRIPClient.h:60
mrpt::hwdrivers::CNTRIPClient::TMountPoint::extra_info
std::string extra_info
Definition: CNTRIPClient.h:71
mrpt::hwdrivers::CNTRIPClient::TMountPoint::id
std::string id
City name.
Definition: CNTRIPClient.h:49
TestNTRIP
void TestNTRIP()
Definition: vision_stereo_rectify/test.cpp:23
iterator
Scalar * iterator
Definition: eigen_plugins.h:26
mrpt::system
This namespace provides a OS-independent interface to many useful functions: filenames manipulation,...
Definition: math_frwds.h:25
params
GLenum const GLfloat * params
Definition: glext.h:3534
mrpt::hwdrivers::CNTRIPClient::TMountPoint
A descriptor of one stream in an NTRIP Caster - See CNTRIPClient::retrieveListOfMountpoints.
Definition: CNTRIPClient.h:45
mrpt::hwdrivers::CNTRIPClient::TListMountPoints
std::list< TMountPoint > TListMountPoints
Used in CNTRIPClient::retrieveListOfMountpoints.
Definition: CNTRIPClient.h:87



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