diff --git a/src/algorithms/telemetry_decoder/gnuradio_blocks/galileo_telemetry_decoder_gs.cc b/src/algorithms/telemetry_decoder/gnuradio_blocks/galileo_telemetry_decoder_gs.cc index 60b83efc8..0868ab5e9 100644 --- a/src/algorithms/telemetry_decoder/gnuradio_blocks/galileo_telemetry_decoder_gs.cc +++ b/src/algorithms/telemetry_decoder/gnuradio_blocks/galileo_telemetry_decoder_gs.cc @@ -511,8 +511,8 @@ void galileo_telemetry_decoder_gs::decode_INAV_word(float *page_part_symbols, in if (d_band == '1' && d_inav_nav.have_new_nma() == true) { const std::shared_ptr tmp_obj = std::make_shared(d_inav_nav.get_osnma_msg()); - this->message_port_pub(pmt::mp("OSNMA_from_TLM"), pmt::make_any(tmp_obj)); uint8_t nma_status = (tmp_obj->hkroot[0] & 0xC0) >> 6; + this->message_port_pub(pmt::mp("OSNMA_from_TLM"), pmt::make_any(tmp_obj)); std::string nma_status_string; if (nma_status == 0) { diff --git a/src/core/libs/osnma_msg_receiver.cc b/src/core/libs/osnma_msg_receiver.cc index afa3eb746..41ab86aac 100644 --- a/src/core/libs/osnma_msg_receiver.cc +++ b/src/core/libs/osnma_msg_receiver.cc @@ -19,7 +19,7 @@ #include "osnma_msg_receiver.h" #include "Galileo_OSNMA.h" -#include "gnss_sdr_make_unique.h" // for std::make_unique in C++11 +#include "osnma_dsm_reader.h" // for OSNMA_DSM_Reader #include // for DLOG #include // for gr::io_signature::make #include @@ -67,6 +67,7 @@ osnma_msg_receiver::osnma_msg_receiver() : gr::block("osnma_msg_receiver", gr::io_signature::make(0, 0, 0), gr::io_signature::make(0, 0, 0)) { + d_dsm_reader = std::make_unique(); // register OSNMA input message port from telemetry blocks this->message_port_register_in(pmt::mp("OSNMA_from_TLM")); // register OSNMA output message port to PVT block @@ -130,17 +131,17 @@ void osnma_msg_receiver::process_osnma_message(const std::shared_ptr& void osnma_msg_receiver::read_nma_header(uint8_t nma_header) { - d_osnma_data.d_nma_header.nmas = get_nmas(nma_header); - d_osnma_data.d_nma_header.cid = get_cid(nma_header); - d_osnma_data.d_nma_header.cpks = get_cpks(nma_header); - d_osnma_data.d_nma_header.reserved = get_nma_header_reserved(nma_header); + d_osnma_data.d_nma_header.nmas = d_dsm_reader->get_nmas(nma_header); + d_osnma_data.d_nma_header.cid = d_dsm_reader->get_cid(nma_header); + d_osnma_data.d_nma_header.cpks = d_dsm_reader->get_cpks(nma_header); + d_osnma_data.d_nma_header.reserved = d_dsm_reader->get_nma_header_reserved(nma_header); } void osnma_msg_receiver::read_dsm_header(uint8_t dsm_header) { - d_osnma_data.d_dsm_header.dsm_id = get_dsm_id(dsm_header); - d_osnma_data.d_dsm_header.dsm_block_id = get_dsm_block_id(dsm_header); // BID + d_osnma_data.d_dsm_header.dsm_id = d_dsm_reader->get_dsm_id(dsm_header); + d_osnma_data.d_dsm_header.dsm_block_id = d_dsm_reader->get_dsm_block_id(dsm_header); // BID LOG(WARNING) << "OSNMA: DSM_ID=" << static_cast(d_osnma_data.d_dsm_header.dsm_id); LOG(WARNING) << "OSNMA: DSM_BID=" << static_cast(d_osnma_data.d_dsm_header.dsm_block_id); } @@ -158,7 +159,7 @@ void osnma_msg_receiver::read_dsm_block(const std::shared_ptr& osnma_ if (d_osnma_data.d_dsm_header.dsm_block_id == 0) { // Get number of blocks in message - uint8_t nb = get_number_blocks_index(d_dsm_message[d_osnma_data.d_dsm_header.dsm_id][0]); + uint8_t nb = d_dsm_reader->get_number_blocks_index(d_dsm_message[d_osnma_data.d_dsm_header.dsm_id][0]); uint16_t number_of_blocks = 0; if (d_osnma_data.d_dsm_header.dsm_id < 12) { @@ -217,19 +218,19 @@ void osnma_msg_receiver::process_dsm_message(const std::vector& dsm_msg { LOG(WARNING) << "OSNMA: DSM-KROOT message received."; // DSM-KROOT message - d_osnma_data.d_dsm_kroot_message.nb_dk = get_number_blocks_index(dsm_msg[0]); - d_osnma_data.d_dsm_kroot_message.pkid = get_pkid(dsm_msg); - d_osnma_data.d_dsm_kroot_message.cidkr = get_cidkr(dsm_msg); - d_osnma_data.d_dsm_kroot_message.reserved1 = get_dsm_reserved1(dsm_msg); - d_osnma_data.d_dsm_kroot_message.hf = get_hf(dsm_msg); - d_osnma_data.d_dsm_kroot_message.mf = get_mf(dsm_msg); - d_osnma_data.d_dsm_kroot_message.ks = get_ks(dsm_msg); - d_osnma_data.d_dsm_kroot_message.ts = get_ts(dsm_msg); - d_osnma_data.d_dsm_kroot_message.maclt = get_maclt(dsm_msg); - d_osnma_data.d_dsm_kroot_message.reserved = get_dsm_reserved(dsm_msg); - d_osnma_data.d_dsm_kroot_message.wn_k = get_wn_k(dsm_msg); - d_osnma_data.d_dsm_kroot_message.towh_k = get_towh_k(dsm_msg); - d_osnma_data.d_dsm_kroot_message.alpha = get_alpha(dsm_msg); + d_osnma_data.d_dsm_kroot_message.nb_dk = d_dsm_reader->get_number_blocks_index(dsm_msg[0]); + d_osnma_data.d_dsm_kroot_message.pkid = d_dsm_reader->get_pkid(dsm_msg); + d_osnma_data.d_dsm_kroot_message.cidkr = d_dsm_reader->get_cidkr(dsm_msg); + d_osnma_data.d_dsm_kroot_message.reserved1 = d_dsm_reader->get_dsm_reserved1(dsm_msg); + d_osnma_data.d_dsm_kroot_message.hf = d_dsm_reader->get_hf(dsm_msg); + d_osnma_data.d_dsm_kroot_message.mf = d_dsm_reader->get_mf(dsm_msg); + d_osnma_data.d_dsm_kroot_message.ks = d_dsm_reader->get_ks(dsm_msg); + d_osnma_data.d_dsm_kroot_message.ts = d_dsm_reader->get_ts(dsm_msg); + d_osnma_data.d_dsm_kroot_message.maclt = d_dsm_reader->get_maclt(dsm_msg); + d_osnma_data.d_dsm_kroot_message.reserved = d_dsm_reader->get_dsm_reserved(dsm_msg); + d_osnma_data.d_dsm_kroot_message.wn_k = d_dsm_reader->get_wn_k(dsm_msg); + d_osnma_data.d_dsm_kroot_message.towh_k = d_dsm_reader->get_towh_k(dsm_msg); + d_osnma_data.d_dsm_kroot_message.alpha = d_dsm_reader->get_alpha(dsm_msg); LOG(WARNING) << "nb_dk=" << static_cast(d_osnma_data.d_dsm_kroot_message.nb_dk); LOG(WARNING) << "pkid=" << static_cast(d_osnma_data.d_dsm_kroot_message.pkid); @@ -245,12 +246,12 @@ void osnma_msg_receiver::process_dsm_message(const std::vector& dsm_msg LOG(WARNING) << "towh_k=" << static_cast(d_osnma_data.d_dsm_kroot_message.towh_k); LOG(WARNING) << "alpha=" << d_osnma_data.d_dsm_kroot_message.alpha; - uint16_t bytes_lk = get_lk_bits(d_osnma_data.d_dsm_kroot_message.ks) / 8; - d_osnma_data.d_dsm_kroot_message.kroot = get_kroot(dsm_msg, bytes_lk); - LOG(WARNING) << "lk_bits=" << static_cast(get_lk_bits(d_osnma_data.d_dsm_kroot_message.ks)); + uint16_t bytes_lk = d_dsm_reader->get_lk_bits(d_osnma_data.d_dsm_kroot_message.ks) / 8; + d_osnma_data.d_dsm_kroot_message.kroot = d_dsm_reader->get_kroot(dsm_msg, bytes_lk); + LOG(WARNING) << "lk_bits=" << static_cast(d_dsm_reader->get_lk_bits(d_osnma_data.d_dsm_kroot_message.ks)); LOG(WARNING) << "lk_bytes=" << static_cast(bytes_lk); - std::string hash_function = get_hash_function(d_osnma_data.d_dsm_kroot_message.hf); + std::string hash_function = d_dsm_reader->get_hash_function(d_osnma_data.d_dsm_kroot_message.hf); uint16_t l_ds_bits = 0; const auto it4 = OSNMA_TABLE_15.find(hash_function); @@ -266,7 +267,7 @@ void osnma_msg_receiver::process_dsm_message(const std::vector& dsm_msg { d_osnma_data.d_dsm_kroot_message.ds[k] = dsm_msg[13 + bytes_lk + k]; } - uint16_t l_dk_bits = get_l_dk_bits(d_osnma_data.d_dsm_kroot_message.nb_dk); + uint16_t l_dk_bits = d_dsm_reader->get_l_dk_bits(d_osnma_data.d_dsm_kroot_message.nb_dk); uint16_t l_dk_bytes = l_dk_bits / 8; LOG(WARNING) << "dk_bits=" << static_cast(l_dk_bits); LOG(WARNING) << "dk_bytes=" << static_cast(l_dk_bytes); @@ -300,7 +301,7 @@ void osnma_msg_receiver::process_dsm_message(const std::vector& dsm_msg } for (uint16_t k = 0; k < l_ds_bytes; k++) { - MSG.push_back(dsm_msg[13 + bytes_lk + k]); + MSG.push_back(d_osnma_data.d_dsm_kroot_message.ds[k]); } std::vector hash = computeSHA256(MSG); @@ -334,14 +335,14 @@ void osnma_msg_receiver::process_dsm_message(const std::vector& dsm_msg { LOG(WARNING) << "OSNMA: DSM-PKR message received."; // DSM-PKR message - d_osnma_data.d_dsm_pkr_message.nb_dp = get_number_blocks_index(dsm_msg[0]); - d_osnma_data.d_dsm_pkr_message.mid = get_mid(dsm_msg); + d_osnma_data.d_dsm_pkr_message.nb_dp = d_dsm_reader->get_number_blocks_index(dsm_msg[0]); + d_osnma_data.d_dsm_pkr_message.mid = d_dsm_reader->get_mid(dsm_msg); for (int k = 0; k > 128; k++) { d_osnma_data.d_dsm_pkr_message.itn[k] = dsm_msg[k + 1]; } - d_osnma_data.d_dsm_pkr_message.npkt = get_npkt(dsm_msg); - d_osnma_data.d_dsm_pkr_message.npktid = get_npktid(dsm_msg); + d_osnma_data.d_dsm_pkr_message.npkt = d_dsm_reader->get_npkt(dsm_msg); + d_osnma_data.d_dsm_pkr_message.npktid = d_dsm_reader->get_npktid(dsm_msg); uint32_t l_npk = 0; const auto it = OSNMA_TABLE_5.find(d_osnma_data.d_dsm_pkr_message.npkt); @@ -396,9 +397,8 @@ void osnma_msg_receiver::process_dsm_message(const std::vector& dsm_msg void osnma_msg_receiver::read_mack_block(const std::shared_ptr& osnma_msg) { uint32_t index = 0; - for (size_t i = 0; i < osnma_msg->mack.size(); i++) + for (uint32_t value : osnma_msg->mack) { - uint32_t value = osnma_msg->mack[i]; d_mack_message[index] = static_cast((value & 0xFF000000) >> 6); d_mack_message[index + 1] = static_cast((value & 0x00FF0000) >> 4); d_mack_message[index + 2] = static_cast((value & 0x0000FF00) >> 2); @@ -453,21 +453,21 @@ std::vector osnma_msg_receiver::computeSHA256(const std::vector // for gr::block #include // for pmt::pmt_t @@ -33,6 +34,7 @@ /** \addtogroup Core_Receiver_Library * \{ */ +class OSNMA_DSM_Reader; class osnma_msg_receiver; using osnma_msg_receiver_sptr = gnss_shared_ptr; @@ -69,6 +71,8 @@ private: std::vector computeSHA256(const std::vector& input); + std::unique_ptr d_dsm_reader; + std::array, 16> d_dsm_message{}; std::array, 16> d_dsm_id_received{}; std::array d_number_of_blocks{}; diff --git a/src/core/system_parameters/CMakeLists.txt b/src/core/system_parameters/CMakeLists.txt index 81fd4318a..3f2e2a167 100644 --- a/src/core/system_parameters/CMakeLists.txt +++ b/src/core/system_parameters/CMakeLists.txt @@ -27,8 +27,9 @@ set(SYSTEM_PARAMETERS_SOURCES glonass_gnav_ephemeris.cc glonass_gnav_utc_model.cc glonass_gnav_navigation_message.cc - osnma_data.cc reed_solomon.cc + osnma_data.cc + osnma_dsm_reader.cc ) set(SYSTEM_PARAMETERS_HEADERS @@ -92,6 +93,7 @@ set(SYSTEM_PARAMETERS_HEADERS galileo_has_page.h Galileo_OSNMA.h osnma_data.h + osnma_dsm_reader.h ) list(SORT SYSTEM_PARAMETERS_HEADERS) diff --git a/src/core/system_parameters/Galileo_OSNMA.h b/src/core/system_parameters/Galileo_OSNMA.h index 62df5ccb1..7d3010308 100644 --- a/src/core/system_parameters/Galileo_OSNMA.h +++ b/src/core/system_parameters/Galileo_OSNMA.h @@ -149,209 +149,6 @@ const std::unordered_map OSNMA_TABLE_15 = { {std::string("SHA-256"), 512}, {std::string("SHA-512"), 1056}}; // key: ECDSA Curve and hash function, value: {l_ds_bits} -#if __cplusplus == 201103L -constexpr std::uint8_t mask_nmas{0xC0}; -constexpr std::uint8_t mask_cid{0x30}; -constexpr std::uint8_t mask_cpks{0x07}; -constexpr std::uint8_t mask_nma_header_reserved{0x01}; -constexpr std::uint8_t mask_dsm_id{0xF0}; -constexpr std::uint8_t mask_dsm_block_id{0x0F}; -constexpr std::uint8_t mask_dsm_number_blocks{0xF0}; -constexpr std::uint8_t mask_dsm_pkid{0x0F}; -constexpr std::uint8_t mask_dsm_cidkr{0xC0}; -constexpr std::uint8_t mask_dsm_reserved1{0x30}; -constexpr std::uint8_t mask_dsm_hf{0x0C}; -constexpr std::uint8_t mask_dsm_mf{0x03}; -constexpr std::uint8_t mask_dsm_ks{0xF0}; -constexpr std::uint8_t mask_dsm_ts{0x0F}; -constexpr std::uint8_t mask_dsm_reserved{0xF0}; -constexpr std::uint8_t mask_dsm_wk_k_msbyte{0x0F}; -constexpr std::uint8_t mask_dsm_mid{0x0F}; -constexpr std::uint8_t mask_dsm_npkt{0xF0}; -constexpr std::uint8_t mask_dsm_npktid{0x0F}; -#else -constexpr std::uint8_t mask_nmas{0b1100'0000}; -constexpr std::uint8_t mask_cid{0b0011'0000}; -constexpr std::uint8_t mask_cpks{0b0000'1110}; -constexpr std::uint8_t mask_nma_header_reserved{0b0000'0001}; -constexpr std::uint8_t mask_dsm_id{0b1111'0000}; -constexpr std::uint8_t mask_dsm_block_id{0b0000'1111}; -constexpr std::uint8_t mask_dsm_number_blocks{0b1111'0000}; -constexpr std::uint8_t mask_dsm_pkid{0b0000'1111}; -constexpr std::uint8_t mask_dsm_cidkr{0b1100'0000}; -constexpr std::uint8_t mask_dsm_reserved1{0b0011'0000}; -constexpr std::uint8_t mask_dsm_hf{0b0000'1100}; -constexpr std::uint8_t mask_dsm_mf{0b0000'0011}; -constexpr std::uint8_t mask_dsm_ks{0b1111'0000}; -constexpr std::uint8_t mask_dsm_ts{0b0000'1111}; -constexpr std::uint8_t mask_dsm_reserved{0b1111'0000}; -constexpr std::uint8_t mask_dsm_wk_k_msbyte{0b0000'1111}; -constexpr std::uint8_t mask_dsm_mid{0b0000'1111}; -constexpr std::uint8_t mask_dsm_npkt{0b1111'0000}; -constexpr std::uint8_t mask_dsm_npktid{0b0000'1111}; -#endif - -// // hf = (dsm_msg[1] & 0b00001100) >> 2; -uint8_t get_nmas(uint8_t nma_header) -{ - return (nma_header & mask_nmas) >> 6; -} - -uint8_t get_cid(uint8_t nma_header) -{ - return (nma_header & mask_cid) >> 4; -} - -uint8_t get_cpks(uint8_t nma_header) -{ - return (nma_header & mask_cpks) >> 1; -} - -bool get_nma_header_reserved(uint8_t nma_header) -{ - return ((nma_header & mask_nma_header_reserved) ? true : false); -} - -uint8_t get_dsm_id(uint8_t dsm_header) -{ - return (dsm_header & mask_dsm_id) >> 4; -} - -uint8_t get_dsm_block_id(uint8_t dsm_header) -{ - return dsm_header & mask_dsm_block_id; -} - -uint8_t get_number_blocks_index(uint8_t dsm_msg_0) -{ - return (dsm_msg_0 & mask_dsm_number_blocks) >> 4; -} - -uint8_t get_pkid(const std::vector& dsm_msg) -{ - return (dsm_msg[0] & mask_dsm_pkid); -} - -uint8_t get_cidkr(const std::vector& dsm_msg) -{ - return (dsm_msg[1] & mask_dsm_cidkr) >> 6; -} - -uint8_t get_dsm_reserved1(const std::vector& dsm_msg) -{ - return (dsm_msg[1] & mask_dsm_reserved1) >> 4; -} - -uint8_t get_hf(const std::vector& dsm_msg) -{ - return (dsm_msg[1] & mask_dsm_hf) >> 2; -} - -uint8_t get_mf(const std::vector& dsm_msg) -{ - return (dsm_msg[1] & mask_dsm_mf); -} - -uint8_t get_ks(const std::vector& dsm_msg) -{ - return (dsm_msg[2] & mask_dsm_ks) >> 4; -} - -uint8_t get_ts(const std::vector& dsm_msg) -{ - return (dsm_msg[2] & mask_dsm_ts); -} - -uint8_t get_maclt(const std::vector& dsm_msg) -{ - return dsm_msg[3]; -} - -uint8_t get_dsm_reserved(const std::vector& dsm_msg) -{ - return (dsm_msg[4] & mask_dsm_reserved) >> 4; -} - -uint16_t get_wn_k(const std::vector& dsm_msg) -{ - return (static_cast((dsm_msg[4] & mask_dsm_wk_k_msbyte) << 8) + static_cast(dsm_msg[5])); -} - -uint8_t get_towh_k(const std::vector& dsm_msg) -{ - return dsm_msg[6]; -} - -uint64_t get_alpha(const std::vector& dsm_msg) -{ - uint64_t alpha = (static_cast(dsm_msg[8]) << 32) + - (static_cast(dsm_msg[9]) << 24) + - (static_cast(dsm_msg[10]) << 16) + - (static_cast(dsm_msg[11]) << 8) + - static_cast(dsm_msg[12]); - return alpha; -} - -uint16_t get_l_dk_bits(uint8_t nb_dk) -{ - const auto it = OSNMA_TABLE_7.find(nb_dk); - if (it != OSNMA_TABLE_7.cend()) - { - return it->second.second; - } - return 0; -} - -uint16_t get_lk_bits(uint8_t ks) -{ - const auto it = OSNMA_TABLE_10.find(ks); - if (it != OSNMA_TABLE_10.cend()) - { - return it->second; - } - return 0; -} - -std::vector get_kroot(const std::vector& dsm_msg, uint16_t bytes_lk) -{ - std::vector kroot = std::vector(bytes_lk, 0); - if (dsm_msg.size() > static_cast(13 + bytes_lk)) - { - for (uint16_t k = 0; k < bytes_lk; k++) - { - kroot[k] = dsm_msg[13 + k]; - } - } - return kroot; -} - -std::string get_hash_function(uint8_t hf) -{ - std::string hash_; - const auto it = OSNMA_TABLE_8.find(hf); - if (it != OSNMA_TABLE_8.cend()) - { - hash_ = it->second; - } - return hash_; -} - -uint8_t get_mid(const std::vector& dsm_msg) -{ - return (dsm_msg[0] & mask_dsm_mid); -} - -uint8_t get_npkt(const std::vector& dsm_msg) -{ - return ((dsm_msg[129] & mask_dsm_npkt) >> 4); -} - -uint8_t get_npktid(const std::vector& dsm_msg) -{ - return (dsm_msg[129] & mask_dsm_npktid); -} - - /** \} */ /** \} */ #endif // GNSS_SDR_GALILEO_OSNMA_H \ No newline at end of file diff --git a/src/core/system_parameters/osnma_dsm_reader.cc b/src/core/system_parameters/osnma_dsm_reader.cc new file mode 100644 index 000000000..baf873bbb --- /dev/null +++ b/src/core/system_parameters/osnma_dsm_reader.cc @@ -0,0 +1,204 @@ +/*! + * \file osnma_dsm_reader.cc + * \brief Class for reading OSNMA DSM messages + * \author Carles Fernandez-Prades, 2023 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-2023 (see AUTHORS file for a list of contributors) + * SPDX-License-Identifier: GPL-3.0-or-later + * + * ----------------------------------------------------------------------------- + */ + +#include "osnma_dsm_reader.h" +#include "Galileo_OSNMA.h" + + +uint8_t OSNMA_DSM_Reader::get_nmas(uint8_t nma_header) const +{ + return (nma_header & mask_nmas) >> 6; +} + + +uint8_t OSNMA_DSM_Reader::get_cid(uint8_t nma_header) const +{ + return (nma_header & mask_cid) >> 4; +} + + +uint8_t OSNMA_DSM_Reader::get_cpks(uint8_t nma_header) const +{ + return (nma_header & mask_cpks) >> 1; +} + + +bool OSNMA_DSM_Reader::get_nma_header_reserved(uint8_t nma_header) const +{ + return ((nma_header & mask_nma_header_reserved) ? true : false); +} + + +uint8_t OSNMA_DSM_Reader::get_dsm_id(uint8_t dsm_header) const +{ + return (dsm_header & mask_dsm_id) >> 4; +} + + +uint8_t OSNMA_DSM_Reader::get_dsm_block_id(uint8_t dsm_header) const +{ + return dsm_header & mask_dsm_block_id; +} + + +uint8_t OSNMA_DSM_Reader::get_number_blocks_index(uint8_t dsm_msg_0) const +{ + return (dsm_msg_0 & mask_dsm_number_blocks) >> 4; +} + + +uint8_t OSNMA_DSM_Reader::get_pkid(const std::vector& dsm_msg) const +{ + return (dsm_msg[0] & mask_dsm_pkid); +} + + +uint8_t OSNMA_DSM_Reader::get_cidkr(const std::vector& dsm_msg) const +{ + return (dsm_msg[1] & mask_dsm_cidkr) >> 6; +} + + +uint8_t OSNMA_DSM_Reader::get_dsm_reserved1(const std::vector& dsm_msg) const +{ + return (dsm_msg[1] & mask_dsm_reserved1) >> 4; +} + + +uint8_t OSNMA_DSM_Reader::get_hf(const std::vector& dsm_msg) const +{ + return (dsm_msg[1] & mask_dsm_hf) >> 2; +} + + +uint8_t OSNMA_DSM_Reader::get_mf(const std::vector& dsm_msg) const +{ + return (dsm_msg[1] & mask_dsm_mf); +} + + +uint8_t OSNMA_DSM_Reader::get_ks(const std::vector& dsm_msg) const +{ + return (dsm_msg[2] & mask_dsm_ks) >> 4; +} + + +uint8_t OSNMA_DSM_Reader::get_ts(const std::vector& dsm_msg) const +{ + return (dsm_msg[2] & mask_dsm_ts); +} + + +uint8_t OSNMA_DSM_Reader::get_maclt(const std::vector& dsm_msg) const +{ + return dsm_msg[3]; +} + + +uint8_t OSNMA_DSM_Reader::get_dsm_reserved(const std::vector& dsm_msg) const +{ + return (dsm_msg[4] & mask_dsm_reserved) >> 4; +} + + +uint16_t OSNMA_DSM_Reader::get_wn_k(const std::vector& dsm_msg) const +{ + return (static_cast((dsm_msg[4] & mask_dsm_wk_k_msbyte) << 8) + static_cast(dsm_msg[5])); +} + + +uint8_t OSNMA_DSM_Reader::get_towh_k(const std::vector& dsm_msg) const +{ + return dsm_msg[6]; +} + + +uint64_t OSNMA_DSM_Reader::get_alpha(const std::vector& dsm_msg) const +{ + uint64_t alpha = (static_cast(dsm_msg[8]) << 40) + + (static_cast(dsm_msg[9]) << 32) + + (static_cast(dsm_msg[10]) << 24) + + (static_cast(dsm_msg[11]) << 16) + + (static_cast(dsm_msg[12]) << 8) + + (static_cast(dsm_msg[13])); + return alpha; +} + + +uint16_t OSNMA_DSM_Reader::get_l_dk_bits(uint8_t nb_dk) const +{ + const auto it = OSNMA_TABLE_7.find(nb_dk); + if (it != OSNMA_TABLE_7.cend()) + { + return it->second.second; + } + return 0; +} + + +uint16_t OSNMA_DSM_Reader::get_lk_bits(uint8_t ks) const +{ + const auto it = OSNMA_TABLE_10.find(ks); + if (it != OSNMA_TABLE_10.cend()) + { + return it->second; + } + return 0; +} + + +std::vector OSNMA_DSM_Reader::get_kroot(const std::vector& dsm_msg, uint16_t bytes_lk) const +{ + std::vector kroot = std::vector(bytes_lk, 0); + if (dsm_msg.size() > static_cast(13 + bytes_lk)) + { + for (uint16_t k = 0; k < bytes_lk; k++) + { + kroot[k] = dsm_msg[13 + k]; + } + } + return kroot; +} + + +std::string OSNMA_DSM_Reader::get_hash_function(uint8_t hf) const +{ + std::string hash_; + const auto it = OSNMA_TABLE_8.find(hf); + if (it != OSNMA_TABLE_8.cend()) + { + hash_ = it->second; + } + return hash_; +} + + +uint8_t OSNMA_DSM_Reader::get_mid(const std::vector& dsm_msg) const +{ + return (dsm_msg[0] & mask_dsm_mid); +} + + +uint8_t OSNMA_DSM_Reader::get_npkt(const std::vector& dsm_msg) const +{ + return ((dsm_msg[129] & mask_dsm_npkt) >> 4); +} + + +uint8_t OSNMA_DSM_Reader::get_npktid(const std::vector& dsm_msg) const +{ + return (dsm_msg[129] & mask_dsm_npktid); +} diff --git a/src/core/system_parameters/osnma_dsm_reader.h b/src/core/system_parameters/osnma_dsm_reader.h new file mode 100644 index 000000000..f90bd531b --- /dev/null +++ b/src/core/system_parameters/osnma_dsm_reader.h @@ -0,0 +1,109 @@ +/*! + * \file osnma_dsm_reader.h + * \brief Class for reading OSNMA DSM messages + * \author Carles Fernandez-Prades, 2023 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-2023 (see AUTHORS file for a list of contributors) + * SPDX-License-Identifier: GPL-3.0-or-later + * + * ----------------------------------------------------------------------------- + */ + +#ifndef GNSS_SDR_OSNMA_DSM_READER_H +#define GNSS_SDR_OSNMA_DSM_READER_H + +#include +#include +#include + +/** \addtogroup Core + * \{ */ +/** \addtogroup System_Parameters + * \{ */ + +class OSNMA_DSM_Reader +{ +public: + OSNMA_DSM_Reader() = default; + uint8_t get_nmas(uint8_t nma_header) const; + uint8_t get_cid(uint8_t nma_header) const; + uint8_t get_cpks(uint8_t nma_header) const; + bool get_nma_header_reserved(uint8_t nma_header) const; + + uint8_t get_dsm_id(uint8_t dsm_header) const; + uint8_t get_dsm_block_id(uint8_t dsm_header) const; + + uint8_t get_number_blocks_index(uint8_t dsm_msg_0) const; + uint8_t get_pkid(const std::vector& dsm_msg) const; + uint8_t get_cidkr(const std::vector& dsm_msg) const; + uint8_t get_dsm_reserved1(const std::vector& dsm_msg) const; + uint8_t get_hf(const std::vector& dsm_msg) const; + uint8_t get_mf(const std::vector& dsm_msg) const; + uint8_t get_ks(const std::vector& dsm_msg) const; + uint8_t get_ts(const std::vector& dsm_msg) const; + uint8_t get_maclt(const std::vector& dsm_msg) const; + uint8_t get_dsm_reserved(const std::vector& dsm_msg) const; + uint16_t get_wn_k(const std::vector& dsm_msg) const; + uint8_t get_towh_k(const std::vector& dsm_msg) const; + uint64_t get_alpha(const std::vector& dsm_msg) const; + uint16_t get_l_dk_bits(uint8_t nb_dk) const; + uint16_t get_lk_bits(uint8_t ks) const; + std::vector get_kroot(const std::vector& dsm_msg, uint16_t bytes_lk) const; + std::string get_hash_function(uint8_t hf) const; + + uint8_t get_mid(const std::vector& dsm_msg) const; + uint8_t get_npkt(const std::vector& dsm_msg) const; + uint8_t get_npktid(const std::vector& dsm_msg) const; + +private: +#if __cplusplus == 201103L + static constexpr std::uint8_t mask_nmas{0xC0}; + static constexpr std::uint8_t mask_cid{0x30}; + static constexpr std::uint8_t mask_cpks{0x07}; + static constexpr std::uint8_t mask_nma_header_reserved{0x01}; + static constexpr std::uint8_t mask_dsm_id{0xF0}; + static constexpr std::uint8_t mask_dsm_block_id{0x0F}; + static constexpr std::uint8_t mask_dsm_number_blocks{0xF0}; + static constexpr std::uint8_t mask_dsm_pkid{0x0F}; + static constexpr std::uint8_t mask_dsm_cidkr{0xC0}; + static constexpr std::uint8_t mask_dsm_reserved1{0x30}; + static constexpr std::uint8_t mask_dsm_hf{0x0C}; + static constexpr std::uint8_t mask_dsm_mf{0x03}; + static constexpr std::uint8_t mask_dsm_ks{0xF0}; + static constexpr std::uint8_t mask_dsm_ts{0x0F}; + static constexpr std::uint8_t mask_dsm_reserved{0xF0}; + static constexpr std::uint8_t mask_dsm_wk_k_msbyte{0x0F}; + static constexpr std::uint8_t mask_dsm_mid{0x0F}; + static constexpr std::uint8_t mask_dsm_npkt{0xF0}; + static constexpr std::uint8_t mask_dsm_npktid{0x0F}; +#else + static constexpr std::uint8_t mask_nmas{0b1100'0000}; + static constexpr std::uint8_t mask_cid{0b0011'0000}; + static constexpr std::uint8_t mask_cpks{0b0000'1110}; + static constexpr std::uint8_t mask_nma_header_reserved{0b0000'0001}; + static constexpr std::uint8_t mask_dsm_id{0b1111'0000}; + static constexpr std::uint8_t mask_dsm_block_id{0b0000'1111}; + static constexpr std::uint8_t mask_dsm_number_blocks{0b1111'0000}; + static constexpr std::uint8_t mask_dsm_pkid{0b0000'1111}; + static constexpr std::uint8_t mask_dsm_cidkr{0b1100'0000}; + static constexpr std::uint8_t mask_dsm_reserved1{0b0011'0000}; + static constexpr std::uint8_t mask_dsm_hf{0b0000'1100}; + static constexpr std::uint8_t mask_dsm_mf{0b0000'0011}; + static constexpr std::uint8_t mask_dsm_ks{0b1111'0000}; + static constexpr std::uint8_t mask_dsm_ts{0b0000'1111}; + static constexpr std::uint8_t mask_dsm_reserved{0b1111'0000}; + static constexpr std::uint8_t mask_dsm_wk_k_msbyte{0b0000'1111}; + static constexpr std::uint8_t mask_dsm_mid{0b0000'1111}; + static constexpr std::uint8_t mask_dsm_npkt{0b1111'0000}; + static constexpr std::uint8_t mask_dsm_npktid{0b0000'1111}; +#endif +}; + +/** \} */ +/** \} */ +#endif // GNSS_SDR_OSNMA_DSM_READER_H \ No newline at end of file