From 7587490c960c2f73f8ff892a99571387d1d4dd1e Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Sun, 19 Apr 2020 15:36:24 +0200 Subject: [PATCH] npdsch_ue: fix compilation on Ubuntu 16.04 --- lib/examples/CMakeLists.txt | 2 +- lib/examples/npdsch_ue.c | 10 +------ lib/examples/npdsch_ue_helper.cc | 26 ++++++++++-------- lib/examples/npdsch_ue_helper.h | 46 ++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 21 deletions(-) create mode 100644 lib/examples/npdsch_ue_helper.h diff --git a/lib/examples/CMakeLists.txt b/lib/examples/CMakeLists.txt index eca027944..b904d2a83 100644 --- a/lib/examples/CMakeLists.txt +++ b/lib/examples/CMakeLists.txt @@ -53,7 +53,7 @@ else(RF_FOUND) add_executable(npdsch_enodeb npdsch_enodeb.c) target_link_libraries(npdsch_enodeb srslte_phy pthread) - add_executable(npdsch_ue npdsch_ue.c) + add_executable(npdsch_ue npdsch_ue.c npdsch_ue_helper.cc) target_link_libraries(npdsch_ue srslte_common srslte_phy pthread rrc_asn1) endif(RF_FOUND) diff --git a/lib/examples/npdsch_ue.c b/lib/examples/npdsch_ue.c index 1615e30cc..907799ba2 100644 --- a/lib/examples/npdsch_ue.c +++ b/lib/examples/npdsch_ue.c @@ -31,6 +31,7 @@ #include #include +#include "npdsch_ue_helper.h" #include "srslte/phy/ch_estimation/chest_dl_nbiot.h" #include "srslte/phy/channel/ch_awgn.h" #include "srslte/phy/io/filesink.h" @@ -78,15 +79,6 @@ bool plot_track = true; //#define CORRECT_SAMPLE_OFFSET static srslte_nbiot_si_params_t sib2_params; -extern int get_sib2_params(const uint8_t* sib1_payload, const uint32_t len, srslte_nbiot_si_params_t* sib2_params); -extern int bcch_bch_to_pretty_string(const uint8_t* bcch_bch_payload, - const uint32_t input_len, - char* output, - const uint32_t max_output_len); -extern int bcch_dl_sch_to_pretty_string(const uint8_t* bcch_dl_sch_payload, - const uint32_t input_len, - char* output, - const uint32_t max_output_len); /********************************************************************** * Program arguments processing diff --git a/lib/examples/npdsch_ue_helper.cc b/lib/examples/npdsch_ue_helper.cc index 0d7b5b0be..7c82643fe 100644 --- a/lib/examples/npdsch_ue_helper.cc +++ b/lib/examples/npdsch_ue_helper.cc @@ -19,13 +19,9 @@ * */ +#include "npdsch_ue_helper.h" #include "srslte/asn1/rrc_asn1_nbiot.h" -#include "srslte/phy/phch/ra_nbiot.h" -#include "srslte/phy/utils/vector.h" - -#ifdef __cplusplus -extern "C" { -#endif +#include "srslte/phy/utils/vector.h" // for SRSLTE_MIN int get_sib2_params(const uint8_t* sib1_payload, const uint32_t len, srslte_nbiot_si_params_t* sib2_params) { @@ -35,6 +31,10 @@ int get_sib2_params(const uint8_t* sib1_payload, const uint32_t len, srslte_nbio asn1::rrc::bcch_dl_sch_msg_nb_s dlsch_msg; asn1::cbit_ref dlsch_bref(sib1_payload, len); asn1::SRSASN_CODE err = dlsch_msg.unpack(dlsch_bref); + if (err != asn1::SRSASN_SUCCESS) { + fprintf(stderr, "Error unpacking DL-SCH message\n"); + return SRSLTE_ERROR; + } // set SIB2-NB parameters sib2_params->n = 1; @@ -61,6 +61,10 @@ int bcch_bch_to_pretty_string(const uint8_t* bcch_bch_payload, asn1::rrc::bcch_bch_msg_nb_s bch_msg; asn1::cbit_ref bch_bref(bcch_bch_payload, input_len); asn1::SRSASN_CODE err = bch_msg.unpack(bch_bref); + if (err != asn1::SRSASN_SUCCESS) { + fprintf(stderr, "Error unpacking BCCH message\n"); + return SRSLTE_ERROR; + } asn1::json_writer json_writer; bch_msg.to_json(json_writer); @@ -82,6 +86,10 @@ int bcch_dl_sch_to_pretty_string(const uint8_t* bcch_dl_sch_payload, asn1::rrc::bcch_dl_sch_msg_nb_s dlsch_msg; asn1::cbit_ref dlsch_bref(bcch_dl_sch_payload, input_len); asn1::SRSASN_CODE err = dlsch_msg.unpack(dlsch_bref); + if (err != asn1::SRSASN_SUCCESS) { + fprintf(stderr, "Error unpacking DL-SCH message\n"); + return SRSLTE_ERROR; + } asn1::json_writer json_writer; dlsch_msg.to_json(json_writer); @@ -90,8 +98,4 @@ int bcch_dl_sch_to_pretty_string(const uint8_t* bcch_dl_sch_payload, memcpy(output, json_writer.to_string().c_str(), output_len); return SRSLTE_SUCCESS; -} - -#ifdef __cplusplus -} -#endif +} \ No newline at end of file diff --git a/lib/examples/npdsch_ue_helper.h b/lib/examples/npdsch_ue_helper.h new file mode 100644 index 000000000..bedcb5718 --- /dev/null +++ b/lib/examples/npdsch_ue_helper.h @@ -0,0 +1,46 @@ +/* + * Copyright 2013-2020 Software Radio Systems Limited + * + * This file is part of srsLTE. + * + * srsLTE is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * srsLTE is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * A copy of the GNU Affero General Public License can be found in + * the LICENSE file in the top-level directory of this distribution + * and at http://www.gnu.org/licenses/. + * + */ + +#ifndef SRSLTE_NPDSCH_UE_HELPER_H +#define SRSLTE_NPDSCH_UE_HELPER_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "srslte/phy/phch/ra_nbiot.h" +#include + +int get_sib2_params(const uint8_t* sib1_payload, const uint32_t len, srslte_nbiot_si_params_t* sib2_params); +int bcch_bch_to_pretty_string(const uint8_t* bcch_bch_payload, + const uint32_t input_len, + char* output, + const uint32_t max_output_len); +int bcch_dl_sch_to_pretty_string(const uint8_t* bcch_dl_sch_payload, + const uint32_t input_len, + char* output, + const uint32_t max_output_len); + +#ifdef __cplusplus +} +#endif + +#endif // SRSLTE_NPDSCH_UE_HELPER_H