8 #include <boost/asio.hpp> 12 using boost::asio::ip::tcp;
14 int main(
int argc,
char** argv)
18 std::cerr <<
"USAGE: tcp_client <host> <port>\n";
22 boost::asio::io_service io;
24 tcp::resolver resolver(io);
25 tcp::resolver::query query(tcp::v4(), argv[1], argv[2]);
26 tcp::resolver::iterator iterator = resolver.resolve(query);
28 std::cout <<
"Connecting to TCP server " << argv[1] <<
" on port " << argv[2] <<
'\n';
30 tcp::socket socket{io};
34 boost::asio::connect(socket, iterator);
36 catch(
const boost::system::system_error& e)
38 std::cerr <<
"Failed to connect to the socket: " << e.what();
42 std::array<uint8_t, 9000> recvBuffer;
44 auto lastPrint = std::chrono::steady_clock::now();
49 const auto bytesRead = socket.read_some(boost::asio::buffer(recvBuffer));
51 decoder.
addNewData(recvBuffer.data(), bytesRead);
54 if((std::chrono::steady_clock::now() - lastPrint) >
55 std::chrono::seconds{1})
58 if(nav.position.is_initialized())
60 std::cout <<
"Position: \n" 61 << std::fixed << std::setprecision(9)
62 <<
" lat: " << nav.
position->latitude_deg <<
" deg\n" 63 <<
" lon: " << nav.position->longitude_deg <<
" deg\n" 64 << std::setprecision(2)
65 <<
" alt: " << nav.position->altitude_m <<
" m\n";
66 lastPrint = std::chrono::steady_clock::now();
71 <<
"Last nav frame received does not contain position\n";
77 catch(
const std::runtime_error& e)
79 std::cerr <<
"Parser error: " << e.what() <<
'\n';
void addNewData(const uint8_t *data, std::size_t length)
Add new binary data to the parser internal buffer The new data can only be a part of a frame...
boost::optional< Position > position
Data::BinaryNav getLastNavData(void) const
bool parseNextFrame()
Try to parse a frame from the parser internal buffer. Some binary data must have been added with the ...
Parser of a STDBIN IXblue message. This is the entry point of the library. Usage of this class is as ...
int main(int argc, char **argv)