mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2025-01-18 21:23:02 +00:00
Merge branch 'next' of https://github.com/gnss-sdr/gnss-sdr into ssr
This commit is contained in:
commit
4d775f2afe
@ -34,7 +34,15 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
udp_listener.print_content();
|
gnss_sdr::navMsg message;
|
||||||
|
if (udp_listener.receive_and_parse_nav_message(message))
|
||||||
|
{
|
||||||
|
udp_listener.print_message(message);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << "Error: the message cannot be parsed." << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (std::exception &e)
|
catch (std::exception &e)
|
||||||
|
@ -25,44 +25,40 @@ Nav_Msg_Udp_Listener::Nav_Msg_Udp_Listener(unsigned short port)
|
|||||||
socket.bind(endpoint, error); // Bind the socket to the given local endpoint.
|
socket.bind(endpoint, error); // Bind the socket to the given local endpoint.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
bool Nav_Msg_Udp_Listener::read_nav_message(gnss_sdr::navMsg &message)
|
* !\brief blocking call to read nav_message from UDP port
|
||||||
|
* \param[out] message navigation message class to contain parsed output
|
||||||
|
* \return true if message parsed succesfully, false ow
|
||||||
|
*/
|
||||||
|
bool Nav_Msg_Udp_Listener::receive_and_parse_nav_message(gnss_sdr::navMsg &message)
|
||||||
{
|
{
|
||||||
char buff[8192]; // Buffer for storing the received data.
|
char buff[8192]; // Buffer for storing the received data.
|
||||||
|
|
||||||
message_ = message;
|
|
||||||
// This call will block until one or more bytes of data has been received.
|
// This call will block until one or more bytes of data has been received.
|
||||||
int bytes = socket.receive(boost::asio::buffer(buff));
|
int bytes = socket.receive(boost::asio::buffer(buff));
|
||||||
|
|
||||||
std::string data(&buff[0], bytes);
|
std::string data(&buff[0], bytes);
|
||||||
// Deserialize a stock of Nav_Msg objects from the binary string.
|
// Deserialize a stock of Nav_Msg objects from the binary string.
|
||||||
return message_.ParseFromString(data);
|
return message.ParseFromString(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
bool Nav_Msg_Udp_Listener::print_content()
|
* !\brief prints navigation message content
|
||||||
|
* \param[in] message nav message to be printed
|
||||||
|
*/
|
||||||
|
void Nav_Msg_Udp_Listener::print_message(gnss_sdr::navMsg &message) const
|
||||||
{
|
{
|
||||||
if (read_nav_message(message_))
|
std::string system = message.system();
|
||||||
{
|
std::string signal = message.signal();
|
||||||
std::string system = message_.system();
|
int prn = message.prn();
|
||||||
std::string signal = message_.signal();
|
int tow_at_current_symbol_ms = message.tow_at_current_symbol_ms();
|
||||||
int prn = message_.prn();
|
std::string nav_message = message.nav_message();
|
||||||
int tow_at_current_symbol_ms = message_.tow_at_current_symbol_ms();
|
|
||||||
std::string nav_message = message_.nav_message();
|
|
||||||
|
|
||||||
std::cout << "\nNew Data received:\n";
|
std::cout << "\nNew Data received:\n";
|
||||||
std::cout << "System: " << system << '\n';
|
std::cout << "System: " << system << '\n';
|
||||||
std::cout << "Signal: " << signal << '\n';
|
std::cout << "Signal: " << signal << '\n';
|
||||||
std::cout << "PRN: " << prn << '\n';
|
std::cout << "PRN: " << prn << '\n';
|
||||||
std::cout << "TOW of last symbol [ms]: "
|
std::cout << "TOW of last symbol [ms]: "
|
||||||
<< tow_at_current_symbol_ms << '\n';
|
<< tow_at_current_symbol_ms << '\n';
|
||||||
std::cout << "Nav message: " << nav_message << "\n\n";
|
std::cout << "Nav message: " << nav_message << "\n\n";
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cout << "Error: the message cannot be parsed.\n";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
@ -23,15 +23,14 @@ class Nav_Msg_Udp_Listener
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit Nav_Msg_Udp_Listener(unsigned short port);
|
explicit Nav_Msg_Udp_Listener(unsigned short port);
|
||||||
bool print_content();
|
void print_message(gnss_sdr::navMsg &message) const;
|
||||||
|
bool receive_and_parse_nav_message(gnss_sdr::navMsg &message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool read_nav_message(gnss_sdr::navMsg &message);
|
|
||||||
boost::asio::io_service io_service;
|
boost::asio::io_service io_service;
|
||||||
boost::asio::ip::udp::socket socket;
|
boost::asio::ip::udp::socket socket;
|
||||||
boost::system::error_code error;
|
boost::system::error_code error;
|
||||||
boost::asio::ip::udp::endpoint endpoint;
|
boost::asio::ip::udp::endpoint endpoint;
|
||||||
gnss_sdr::navMsg message_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user