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



Page generated by Doxygen 1.8.14 for MRPT 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020