diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index c9b4d3f33..d09b0a274 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -16,11 +16,13 @@ All notable changes to GNSS-SDR will be documented in this file. ### Improvements in Usability: -- Added a new monitor to extract the raw data bits in the navigation message and - send them elsewhere via UDP. Activated by setting +- Added a new monitor to extract the decoded data bits of the navigation + messages and send them elsewhere via UDP. Activated by setting `NavDataMonitor.enable_monitor=true`, `NavDataMonitor.client_addresses=127.0.0.1` and `NavDataMonitor.port=1237` in - the configuration file. Format described in the `nav_message.proto` file. + the configuration file. Format described in the `nav_message.proto` file. A + simple listener application written in C++ is included in + `src/utils/nav-listener` as a example. ## [GNSS-SDR v0.0.15](https://github.com/gnss-sdr/gnss-sdr/releases/tag/v0.0.15) - 2021-08-23 diff --git a/src/utils/nav-listener/CMakeLists.txt b/src/utils/nav-listener/CMakeLists.txt new file mode 100644 index 000000000..618866b82 --- /dev/null +++ b/src/utils/nav-listener/CMakeLists.txt @@ -0,0 +1,38 @@ +# GNSS-SDR is a Global Navigation Satellite System software-defined receiver. +# This file is part of GNSS-SDR. +# +# SPDX-FileCopyrightText: 2021 C. Fernandez-Prades cfernandez(at)cttc.es +# SPDX-License-Identifier: BSD-3-Clause + +cmake_minimum_required (VERSION 3.9...3.21) +project (nav-msg-listener CXX) + +set(CMAKE_CXX_STANDARD 11) + +set(Boost_USE_STATIC_LIBS OFF) +find_package(Boost COMPONENTS system REQUIRED) + +find_package(Protobuf REQUIRED) +if(${Protobuf_VERSION} VERSION_LESS "3.0.0") + message(FATAL_ERROR "Fatal error: Protocol Buffers >= v3.0.0 required.") +endif() + +protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${CMAKE_SOURCE_DIR}/nav_message.proto) + +add_library(navmsg_lib ${CMAKE_SOURCE_DIR}/nav_msg_udp_listener.cc ${PROTO_SRCS}) + +target_link_libraries(navmsg_lib + PUBLIC + Boost::boost + Boost::system + protobuf::libprotobuf +) + +target_include_directories(navmsg_lib + PUBLIC + ${CMAKE_BINARY_DIR} +) + +add_executable(nav_msg_listener ${CMAKE_SOURCE_DIR}/main.cc) + +target_link_libraries(nav_msg_listener PUBLIC navmsg_lib) diff --git a/src/utils/nav-listener/README.md b/src/utils/nav-listener/README.md new file mode 100644 index 000000000..d4a6f744a --- /dev/null +++ b/src/utils/nav-listener/README.md @@ -0,0 +1,83 @@ +# nav_msg_listener + +Simple application that retrieves decoded navigation messages produced by +GNSS-SDR and prints them in a terminal. This is only for demonstration purposes, +as a example on how to retrieve data using the `nav_message.proto` file. + + +# Build the software + +This software requires [Boost](https://www.boost.org/) and [Protocol +Buffers](https://developers.google.com/protocol-buffers). + +In a terminal, type: + +``` +$ mkdir build && cd build +$ cmake .. +$ make +``` + + +## Usage + +In order to tell GNSS-SDR to generate those messages, you need to include the +lines: + +``` +NavDataMonitor.enable_monitor=true +NavDataMonitor.client_addresses=127.0.0.1 ; destination IP +NavDataMonitor.port=1237 ; destination port +``` + +in your gnss-sdr configuration file. You can specify multiple destination +addresses, separated by underscores: + +``` +NavDataMonitor.client_addresses=79.154.253.31_79.154.253.32 +``` + +Run gnss-sdr with your configuration, and at the same time, from the computer of +the client address (or another terminal from the same computer that is executing +gnss-sdr if you are using `127.0.0.1`), execute the binary as: + +``` +$ ./nav_msg_listener 1237 +``` + +where `1237` needs to be the same port as in `NavDataMonitor.port`. As soon as +gnss-sdr starts to decode navigation messages, you will see them in your +terminal: + +``` +$ ./nav_msg_listener 1237 + +New Data received: +System: E +Signal: 1B +PRN: 11 +TOW of last symbol [ms]: 75869044 +Nav message: 000000001001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010011100101110001000000 + +New Data received: +System: G +Signal: 1C +PRN: 16 +TOW of last symbol [ms]: 75870000 +Nav message: 100010111010101010101000101111000110001011001010010100011100010001000000000000000000000011010100000000101101100001000011000000000000000000000000111111101000010000110110011011000100000101111100000111100110110101000100110100100010011011101001001010011001011111111110000110000000000000000000000010001100 + +New Data received: +System: E +Signal: 5X +PRN: 18 +TOW of last symbol [ms]: 75870260 +Nav message: 0000100001111110010000010111110100011010010000100000000000000000000000000000000000000000000000000000000010101010000001001011010010100100100100100110101110110101010000100000000000000000111001011100010010100001010100001110101001001101111000000000 + +New Data received: +System: G +Signal: L5 +PRN: 6 +TOW of last symbol [ms]: 75871320 +Nav message: 100010110001100011110001100010110010100111100001110100001000000110110101100101011100110111001101100001011001110110010100101110001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000000010000000100000001000001010101010111110000000 + +``` diff --git a/src/utils/nav-listener/main.cc b/src/utils/nav-listener/main.cc new file mode 100644 index 000000000..a96cbef48 --- /dev/null +++ b/src/utils/nav-listener/main.cc @@ -0,0 +1,46 @@ +/*! + * \file main.cc + * \author Carles Fernandez-Prades, 2021. cfernandez(at)cttc.es + * + * ----------------------------------------------------------------------------- + * + * GNSS-SDR is a Global Navigation Satellite System software-defined receiver. + * This file is part of GNSS-SDR. + * + * Copyright (C) 2010-2021 (see AUTHORS file for a list of contributors) + * SPDX-License-Identifier: BSD-3-Clause + * + * ----------------------------------------------------------------------------- + */ + +#include "nav_msg_udp_listener.h" +#include +#include + +int main(int argc, char *argv[]) +{ + try + { + // Check command line arguments. + if (argc != 2) + { + // Print help. + std::cerr << "Usage: nav_msg_listener \n"; + return 1; + } + + unsigned short port = boost::lexical_cast(argv[1]); + Nav_Msg_Udp_Listener udp_listener(port); + + while (true) + { + udp_listener.print_content(); + } + } + catch (std::exception &e) + { + std::cerr << e.what() << '\n'; + } + + return 0; +} diff --git a/src/utils/nav-listener/nav_message.proto b/src/utils/nav-listener/nav_message.proto new file mode 100644 index 000000000..923b60872 --- /dev/null +++ b/src/utils/nav-listener/nav_message.proto @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: BSD-3-Clause +// SPDX-FileCopyrightText: 2021 Carles Fernandez-Prades +syntax = "proto3"; + +package gnss_sdr; + +message navMsg { + string system = 1; // GNSS constellation: "G" for GPS, "R" for Glonass, "E" for Galileo, and "C" for Beidou. + string signal = 2; // GNSS signal: "1C" for GPS L1 C/A, "1B" for Galileo E1b/c, "1G" for Glonass L1 C/A, "2S" for GPS L2 L2C(M), "2G" for Glonass L2 C/A, "L5" for GPS L5, and "5X" for Galileo E5a + int32 prn = 3; // SV ID + int32 tow_at_current_symbol_ms = 4; // Time of week of the last symbol received, in ms + string nav_message = 5; // for Galileo I/NAV: decoded half page (even or odd), 120 bits, as described in OS SIS ICD 2.0, paragraph 4.3.2.3. I/NAV Page Part + // for Galileo F/NAV: decoded word, 244 bits, as described in OS SIS ICD 2.0, paragraph 4.2.2. F/NAV Page Layout + // For GPS LNAV: decoded subframe, 300 bits, as described in IS-GPS-200M paragraph 20.3.2 Message Structure. + // For GPS CNAV: decoded subframe, 300 bits, as described in IS-GPS-200M paragraph 30.3.3 Message Content. +} diff --git a/src/utils/nav-listener/nav_msg_udp_listener.cc b/src/utils/nav-listener/nav_msg_udp_listener.cc new file mode 100644 index 000000000..646b332fe --- /dev/null +++ b/src/utils/nav-listener/nav_msg_udp_listener.cc @@ -0,0 +1,60 @@ +/*! + * \file nav_msg_udp_listener.cc + * \author Carles Fernandez-Prades, 2021. cfernandez(at)cttc.es + * + * ----------------------------------------------------------------------------- + * + * GNSS-SDR is a Global Navigation Satellite System software-defined receiver. + * This file is part of GNSS-SDR. + * + * Copyright (C) 2010-2021 (see AUTHORS file for a list of contributors) + * SPDX-License-Identifier: BSD-3-Clause + * + * ----------------------------------------------------------------------------- + */ + +#include "nav_msg_udp_listener.h" +#include + +Nav_Msg_Udp_Listener::Nav_Msg_Udp_Listener(unsigned short port) + : socket{io_service}, endpoint{boost::asio::ip::udp::v4(), port} +{ + socket.open(endpoint.protocol(), error); // Open socket. + socket.bind(endpoint, error); // Bind the socket to the given local endpoint. +} + + +bool Nav_Msg_Udp_Listener::read_nav_message(gnss_sdr::navMsg &message) +{ + char buff[1500]; // Buffer for storing the received data. + + message_ = message; + // This call will block until one or more bytes of data has been received. + int bytes = socket.receive(boost::asio::buffer(buff)); + + std::string data(&buff[0], bytes); + // Deserialize a stock of Nav_Msg objects from the binary string. + return message_.ParseFromString(data); +} + + +bool Nav_Msg_Udp_Listener::print_content() +{ + if (read_nav_message(message_)) + { + std::cout << "\nNew Data received:\n"; + std::cout << "System: " << message_.system() << '\n'; + std::cout << "Signal: " << message_.signal() << '\n'; + std::cout << "PRN: " << message_.prn() << '\n'; + std::cout << "TOW of last symbol [ms]: " + << message_.tow_at_current_symbol_ms() << '\n'; + std::cout << "Nav message: " << message_.nav_message() << "\n\n"; + } + else + { + std::cout << "Error: the message cannot be parsed.\n"; + return false; + } + + return true; +} diff --git a/src/utils/nav-listener/nav_msg_udp_listener.h b/src/utils/nav-listener/nav_msg_udp_listener.h new file mode 100644 index 000000000..80dd080f4 --- /dev/null +++ b/src/utils/nav-listener/nav_msg_udp_listener.h @@ -0,0 +1,37 @@ +/*! + * \file nav_msg_udp_listener.h + * \author Carles Fernandez-Prades, 2021. cfernandez(at)cttc.es + * + * ----------------------------------------------------------------------------- + * + * GNSS-SDR is a Global Navigation Satellite System software-defined receiver. + * This file is part of GNSS-SDR. + * + * Copyright (C) 2010-2021 (see AUTHORS file for a list of contributors) + * SPDX-License-Identifier: BSD-3-Clause + * + * ----------------------------------------------------------------------------- + */ + +#ifndef GNSS_SDR_NAV_MSG_UDP_LISTENER_H +#define GNSS_SDR_NAV_MSG_UDP_LISTENER_H + +#include "nav_message.pb.h" +#include + +class Nav_Msg_Udp_Listener +{ +public: + Nav_Msg_Udp_Listener(unsigned short port); + bool print_content(); + +private: + bool read_nav_message(gnss_sdr::navMsg &message); + boost::asio::io_service io_service; + boost::asio::ip::udp::socket socket; + boost::system::error_code error; + boost::asio::ip::udp::endpoint endpoint; + gnss_sdr::navMsg message_; +}; + +#endif