From fc34bb4d98dd49df3f5861ff239b4ff3c0d8a52a Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Sat, 7 Apr 2018 14:15:48 +0200 Subject: [PATCH 1/4] Get rid of gr::random so it can be compiled with c++17 The error was: In file included from /Users/carlesfernandez/git/cttc/src/algorithms/signal_generator/gnuradio_blocks/signal_generator_c.cc:31: In file included from /Users/carlesfernandez/git/cttc/src/algorithms/signal_generator/gnuradio_blocks/signal_generator_c.h:36: In file included from /opt/local/include/gnuradio/random.h:30: In file included from /opt/local/include/boost/random.hpp:83: /opt/local/include/boost/random/uniform_on_sphere.hpp:229:37: error: no member named 'bind2nd' in namespace 'std' std::bind2nd(std::multiplies(), 1/sqrt(sqsum))); ~~~~~^ 1 error generated. --- .../signal_generator/gnuradio_blocks/signal_generator_c.cc | 5 ++--- .../signal_generator/gnuradio_blocks/signal_generator_c.h | 6 ++++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/algorithms/signal_generator/gnuradio_blocks/signal_generator_c.cc b/src/algorithms/signal_generator/gnuradio_blocks/signal_generator_c.cc index 3cd4c92d9..bfb1eb48a 100644 --- a/src/algorithms/signal_generator/gnuradio_blocks/signal_generator_c.cc +++ b/src/algorithms/signal_generator/gnuradio_blocks/signal_generator_c.cc @@ -133,8 +133,8 @@ void signal_generator_c::init() } } } - random_ = new gr::random(); std::default_random_engine e1(r()); + std::default_random_engine e2(r()); std::uniform_int_distribution uniform_dist(0, RAND_MAX); } @@ -271,7 +271,6 @@ signal_generator_c::~signal_generator_c() } } */ volk_gnsssdr_free(complex_phase_); - delete random_; } @@ -433,7 +432,7 @@ int signal_generator_c::general_work(int noutput_items __attribute__((unused)), { for (out_idx = 0; out_idx < vector_length_; out_idx++) { - out[out_idx] += gr_complex(random_->gasdev(), random_->gasdev()); + out[out_idx] += gr_complex(normal_dist(e1), normal_dist(e2)); } } diff --git a/src/algorithms/signal_generator/gnuradio_blocks/signal_generator_c.h b/src/algorithms/signal_generator/gnuradio_blocks/signal_generator_c.h index c01b6c8e0..1dce88924 100644 --- a/src/algorithms/signal_generator/gnuradio_blocks/signal_generator_c.h +++ b/src/algorithms/signal_generator/gnuradio_blocks/signal_generator_c.h @@ -33,7 +33,7 @@ #include "gnss_signal.h" #include -#include +//#include #include #include #include @@ -120,13 +120,15 @@ private: boost::scoped_array sampled_code_data_; boost::scoped_array sampled_code_pilot_; - gr::random *random_; + //gr::random *random_; gr_complex *complex_phase_; unsigned int work_counter_; std::random_device r; std::default_random_engine e1; + std::default_random_engine e2; std::uniform_int_distribution uniform_dist; + std::normal_distribution normal_dist; public: ~signal_generator_c(); // public destructor From 795ac97e12704ca360f752ae72de4a6d652dfa59 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Sat, 7 Apr 2018 17:03:25 +0200 Subject: [PATCH 2/4] Set -std=c++11, -std=c++14 or -std=c++17 where appropriate --- CMakeLists.txt | 42 +++++---- .../volk_gnsssdr/CMakeLists.txt | 86 ++++++++++++++++++- 2 files changed, 111 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 563adfc03..b74802213 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -360,7 +360,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") endif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${GNSSSDR_GCC_MIN_VERSION}) endif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") -if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") execute_process(COMMAND ${CMAKE_CXX_COMPILER} -v RESULT_VARIABLE _res ERROR_VARIABLE _err @@ -387,7 +387,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") else(${_res} STREQUAL "0") message(WARNING "\nCannot determine the version of the compiler selected to build GNSS-SDR (${APPLE_STR}Clang : ${CMAKE_CXX_COMPILER}). This build may or not work. We highly recommend using Apple Clang version ${APPLECLANG_MIN_VERSION} or more recent, or Clang version ${CLANG_MIN_VERSION} or more recent.") endif(${_res} STREQUAL "0") -endif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") +endif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") @@ -783,7 +783,7 @@ if (NOT GLOG_FOUND OR ${LOCAL_GFLAGS}) set(GFLAGS_LIBRARY_DIR_TO_LINK ${GFlags_LIBRARY_DIRS}) endif(${LOCAL_GFLAGS}) - if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/glog-${GNSSSDR_GLOG_LOCAL_VERSION}/tmp/configure_with_gflags "#!/bin/sh export CPPFLAGS=-I${GFlags_INCLUDE_DIRS} @@ -799,7 +799,7 @@ autoreconf -vfi cd ${CMAKE_CURRENT_BINARY_DIR}/glog-${GNSSSDR_GLOG_LOCAL_VERSION} ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/glog/glog-${GNSSSDR_GLOG_LOCAL_VERSION}/configure") - else("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + else(CMAKE_CXX_COMPILER_ID MATCHES "Clang") file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/glog-${GNSSSDR_GLOG_LOCAL_VERSION}/tmp/configure_with_gflags "#!/bin/sh export CPPFLAGS=-I${GFlags_INCLUDE_DIRS} @@ -812,7 +812,7 @@ autoreconf -vfi cd ${CMAKE_CURRENT_BINARY_DIR}/glog-${GNSSSDR_GLOG_LOCAL_VERSION} ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/glog/glog-${GNSSSDR_GLOG_LOCAL_VERSION}/configure") - endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + endif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") file(COPY ${CMAKE_CURRENT_BINARY_DIR}/glog-${GNSSSDR_GLOG_LOCAL_VERSION}/tmp/configure_with_gflags DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/glog-${GNSSSDR_GLOG_LOCAL_VERSION} @@ -1458,39 +1458,51 @@ endif(ENABLE_GPROF) ######################################################################## # Set compiler flags ######################################################################## -# Enable C++14 support in GCC / Fallback to C++11 when using GCC < 6.1.1 +# Enable C++17 support in GCC >= 8.0.0 +# Enable C++14 support in 8.0.0 > GCC >= 6.1.1 +# Fallback to C++11 when using GCC < 6.1.1 if(CMAKE_COMPILER_IS_GNUCXX AND NOT WIN32) if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.1.1") set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -std=c++11") else(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.1.1") - set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -std=c++14") + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.0.0") + set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -std=c++14") + else(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.0.0") + set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -std=c++17") + endif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.0.0") endif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.1.1") set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -Wall -Wextra") #Add warning flags: For "-Wall" see http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html endif(CMAKE_COMPILER_IS_GNUCXX AND NOT WIN32) -# Enable C++14 support in Clang from 3.5 / Fallback to C++11 if older version and use lib++ if working in macOS +# Enable C++17 support in Clang >= 6.0.0 or AppleClang >= 900 +# Enable C++14 support in 6.0.0 > Clang >= 3.5.0 or 900 > AppleClang >= 600 +# Fallback to C++11 if older version if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") if(OS_IS_MACOSX) # See https://trac.macports.org/wiki/XcodeVersionInfo for Apple Clang version equivalences if(CLANG_VERSION VERSION_LESS "600") set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -std=c++11") else(CLANG_VERSION VERSION_LESS "600") - set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -std=c++14") + if(CLANG_VERSION VERSION_LESS "900") + set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -std=c++14") + else(CLANG_VERSION VERSION_LESS "900") + set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -std=c++17") + endif(CLANG_VERSION VERSION_LESS "900") endif(CLANG_VERSION VERSION_LESS "600") - set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -Wno-deprecated-declarations") else(OS_IS_MACOSX) if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.5.0") set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -std=c++11") else(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.5.0") - set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -std=c++14") + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.0.0") + set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -std=c++14") + else(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.0.0") + set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -std=c++17") + endif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.0.0") endif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.5.0") endif(OS_IS_MACOSX) - if(CMAKE_BUILD_TYPE MATCHES "Release") - set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -Wno-unused-private-field") - endif(CMAKE_BUILD_TYPE MATCHES "Release") if(OS_IS_MACOSX) - set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -stdlib=libc++") + set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -stdlib=libc++") endif(OS_IS_MACOSX) endif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") diff --git a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/CMakeLists.txt b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/CMakeLists.txt index 0534fa62b..d4ea0c46f 100644 --- a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/CMakeLists.txt +++ b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/CMakeLists.txt @@ -27,9 +27,91 @@ enable_language(CXX) enable_language(C) enable_testing() -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall") +# Set compiler flags +set(GNSSSDR_CLANG_MIN_VERSION "3.4.0") +set(GNSSSDR_APPLECLANG_MIN_VERSION "500") +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + execute_process(COMMAND + ${CMAKE_CXX_COMPILER} -v + RESULT_VARIABLE _res ERROR_VARIABLE _err + ERROR_STRIP_TRAILING_WHITESPACE) + if(${_res} STREQUAL "0") + # output is in error stream + string(REGEX MATCH "^Apple.*" IS_APPLE ${_err}) + if("${IS_APPLE}" STREQUAL "") + set(MIN_VERSION ${GNSSSDR_CLANG_MIN_VERSION}) + set(APPLE_STR "") + # retrieve the compiler's version from it + string(REGEX MATCH "clang version [0-9.]+" CLANG_OTHER_VERSION ${_err}) + string(REGEX MATCH "[0-9.]+" CLANG_VERSION ${CLANG_OTHER_VERSION}) + else("${IS_APPLE}" STREQUAL "") + set(MIN_VERSION ${GNSSSDR_APPLECLANG_MIN_VERSION}) + set(APPLE_STR "Apple ") + # retrieve the compiler's version from it + string(REGEX MATCH "(clang-[0-9.]+)" CLANG_APPLE_VERSION ${_err}) + string(REGEX MATCH "[0-9.]+" CLANG_VERSION ${CLANG_APPLE_VERSION}) + endif("${IS_APPLE}" STREQUAL "") + if(${CLANG_VERSION} VERSION_LESS "${MIN_VERSION}") + message(WARNING "\nThe compiler selected to build VOLK-GNSSSDR (${APPLE_STR}Clang version ${CLANG_VERSION} : ${CMAKE_CXX_COMPILER}) is older than that officially supported (${MIN_VERSION} minimum). This build may or not work. We highly recommend using Apple Clang version ${APPLECLANG_MIN_VERSION} or more recent, or Clang version ${CLANG_MIN_VERSION} or more recent.") + endif(${CLANG_VERSION} VERSION_LESS "${MIN_VERSION}") + else(${_res} STREQUAL "0") + message(WARNING "\nCannot determine the version of the compiler selected to build VOLK-GNSSSDR (${APPLE_STR}Clang : ${CMAKE_CXX_COMPILER}). This build may or not work. We highly recommend using Apple Clang version ${APPLECLANG_MIN_VERSION} or more recent, or Clang version ${CLANG_MIN_VERSION} or more recent.") + endif(${_res} STREQUAL "0") +endif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + +# Enable C++17 support in GCC >= 8.0.0 +# Enable C++14 support in 8.0.0 > GCC >= 6.1.1 +# Fallback to C++11 when using GCC < 6.1.1 +if(CMAKE_COMPILER_IS_GNUCXX AND NOT WIN32) + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.1.1") + set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -std=c++11") + else(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.1.1") + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.0.0") + set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -std=c++14") + else(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.0.0") + set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -std=c++17") + endif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.0.0") + endif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.1.1") + set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -Wall -Wextra") #Add warning flags: For "-Wall" see http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html +endif(CMAKE_COMPILER_IS_GNUCXX AND NOT WIN32) + +# Enable C++17 support in Clang >= 6.0.0 or AppleClang >= 900 +# Enable C++14 support in 6.0.0 > Clang >= 3.5.0 or 900 > AppleClang >= 600 +# Fallback to C++11 if older version +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + if(CMAKE_SYSTEM_NAME MATCHES "Darwin") + # See https://trac.macports.org/wiki/XcodeVersionInfo for Apple Clang version equivalences + if(CLANG_VERSION VERSION_LESS "600") + set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -std=c++11") + else(CLANG_VERSION VERSION_LESS "600") + if(CLANG_VERSION VERSION_LESS "900") + set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -std=c++14") + else(CLANG_VERSION VERSION_LESS "900") + set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -std=c++17") + endif(CLANG_VERSION VERSION_LESS "900") + endif(CLANG_VERSION VERSION_LESS "600") + else(CMAKE_SYSTEM_NAME MATCHES "Darwin") + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.5.0") + set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -std=c++11") + else(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.5.0") + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.0.0") + set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -std=c++14") + else(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.0.0") + set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -std=c++17") + endif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.0.0") + endif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.5.0") + endif(CMAKE_SYSTEM_NAME MATCHES "Darwin") +endif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + +if(NOT (CMAKE_COMPILER_IS_GNUCXX AND NOT WIN32) AND NOT (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) + if(NOT (CMAKE_VERSION VERSION_LESS "3.1")) + set(CMAKE_C_STANDARD 11) + set(CMAKE_CXX_STANDARD 11) + endif(NOT (CMAKE_VERSION VERSION_LESS "3.1")) +endif(NOT (CMAKE_COMPILER_IS_GNUCXX AND NOT WIN32) AND NOT (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MY_CXX_FLAGS} -Wall") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") -add_definitions(-D_GLIBCXX_USE_CXX11_ABI=1) if(CMAKE_VERSION VERSION_GREATER "3.0") cmake_policy(SET CMP0042 NEW) From 204aef99d0c674fbaa0f131d4df2053d697324dc Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Sun, 8 Apr 2018 23:48:35 +0200 Subject: [PATCH 3/4] Hold back c++17 until GNU Radio allows for it (already in next, so 3.8 will do) --- CMakeLists.txt | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b74802213..789a19974 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1458,24 +1458,24 @@ endif(ENABLE_GPROF) ######################################################################## # Set compiler flags ######################################################################## -# Enable C++17 support in GCC >= 8.0.0 -# Enable C++14 support in 8.0.0 > GCC >= 6.1.1 +# Support of C++17 is still not possible due to pm_remez.h (solved in GNU Radio 3.8) +# Enable C++14 support in GCC >= 6.1.1 # Fallback to C++11 when using GCC < 6.1.1 if(CMAKE_COMPILER_IS_GNUCXX AND NOT WIN32) if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.1.1") set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -std=c++11") else(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.1.1") - if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.0.0") + # if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.0.0") set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -std=c++14") - else(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.0.0") - set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -std=c++17") - endif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.0.0") + # else(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.0.0") + # set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -std=c++17") + # endif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.0.0") endif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.1.1") set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -Wall -Wextra") #Add warning flags: For "-Wall" see http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html endif(CMAKE_COMPILER_IS_GNUCXX AND NOT WIN32) -# Enable C++17 support in Clang >= 6.0.0 or AppleClang >= 900 -# Enable C++14 support in 6.0.0 > Clang >= 3.5.0 or 900 > AppleClang >= 600 +# Support of C++17 is still not possible due to pm_remez.h (solved in GNU Radio 3.8) +# Enable C++14 support in Clang >= 3.5.0 or AppleClang >= 600 # Fallback to C++11 if older version if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") if(OS_IS_MACOSX) @@ -1483,21 +1483,21 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") if(CLANG_VERSION VERSION_LESS "600") set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -std=c++11") else(CLANG_VERSION VERSION_LESS "600") - if(CLANG_VERSION VERSION_LESS "900") + # if(CLANG_VERSION VERSION_LESS "900") set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -std=c++14") - else(CLANG_VERSION VERSION_LESS "900") - set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -std=c++17") - endif(CLANG_VERSION VERSION_LESS "900") + # else(CLANG_VERSION VERSION_LESS "900") + # set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -std=c++17") + # endif(CLANG_VERSION VERSION_LESS "900") endif(CLANG_VERSION VERSION_LESS "600") else(OS_IS_MACOSX) if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.5.0") set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -std=c++11") else(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.5.0") - if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.0.0") + # if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.0.0") set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -std=c++14") - else(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.0.0") - set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -std=c++17") - endif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.0.0") + # else(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.0.0") + # set(MY_CXX_FLAGS "${MY_CXX_FLAGS} -std=c++17") + # endif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "6.0.0") endif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.5.0") endif(OS_IS_MACOSX) From d42d6b2ed4e4f4975f9172f32b4ce2b8468fc76e Mon Sep 17 00:00:00 2001 From: Antonio Ramos Date: Mon, 9 Apr 2018 16:16:50 +0200 Subject: [PATCH 4/4] Change std::vector> by gnss_circular_deque --- src/algorithms/libs/gnss_circular_deque.h | 213 ++++++++++++++++++ .../observables/adapters/CMakeLists.txt | 1 + .../gnuradio_blocks/CMakeLists.txt | 6 +- .../gnuradio_blocks/hybrid_observables_cc.cc | 122 +++++++--- .../gnuradio_blocks/hybrid_observables_cc.h | 11 +- 5 files changed, 312 insertions(+), 41 deletions(-) create mode 100644 src/algorithms/libs/gnss_circular_deque.h diff --git a/src/algorithms/libs/gnss_circular_deque.h b/src/algorithms/libs/gnss_circular_deque.h new file mode 100644 index 000000000..f453be3d2 --- /dev/null +++ b/src/algorithms/libs/gnss_circular_deque.h @@ -0,0 +1,213 @@ +/*! + * \file gnss_circular_deque.h + * \brief This class implements a circular deque for Gnss_Synchro + * + * \author Luis Esteve, 2018. antonio.ramos(at)cttc.es + * + * Detailed description of the file here if needed. + * + * ------------------------------------------------------------------------- + * + * Copyright (C) 2010-2018 (see AUTHORS file for a list of contributors) + * + * GNSS-SDR is a software defined Global Navigation + * Satellite Systems receiver + * + * This file is part of GNSS-SDR. + * + * GNSS-SDR is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GNSS-SDR 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNSS-SDR. If not, see . + * + * ------------------------------------------------------------------------- + */ + +#ifndef GNSS_SDR_CIRCULAR_DEQUE_H_ +#define GNSS_SDR_CIRCULAR_DEQUE_H_ + +template +class Gnss_circular_deque +{ +public: + Gnss_circular_deque(); + Gnss_circular_deque(const unsigned int max_size, const unsigned int nchann); + ~Gnss_circular_deque(); + unsigned int size(const unsigned int ch); + T& at(const unsigned int ch, const unsigned int pos); + T& front(const unsigned int ch); + T& back(const unsigned int ch); + void push_back(const unsigned int ch, const T& new_data); + T pop_front(const unsigned int ch); + void clear(const unsigned int ch); + T* get_vector(const unsigned int ch); + +private: + T** d_history; + T d_return_void; // Void object for avoid compiler errors + unsigned int* d_index_pop; + unsigned int* d_index_push; + unsigned int* d_size; + unsigned int d_max_size; + unsigned int d_nchannels; +}; + + +template +Gnss_circular_deque::Gnss_circular_deque() +{ + d_max_size = 0; + d_nchannels = 0; + d_size = nullptr; + d_index_pop = nullptr; + d_index_push = nullptr; + d_history = nullptr; +} + +template +Gnss_circular_deque::Gnss_circular_deque(const unsigned int max_size, const unsigned int nchann) +{ + d_max_size = max_size; + d_nchannels = nchann; + if (d_max_size > 0 and d_nchannels > 0) + { + d_size = new unsigned int[d_nchannels]; + d_index_pop = new unsigned int[d_nchannels]; + d_index_push = new unsigned int[d_nchannels]; + d_history = new T*[d_nchannels]; + for (unsigned int i = 0; i < d_nchannels; i++) + { + d_size[i] = 0; + d_index_pop[i] = 0; + d_index_push[i] = 0; + d_history[i] = new T[d_max_size]; + } + } +} + +template +Gnss_circular_deque::~Gnss_circular_deque() +{ + if (d_max_size > 0 and d_nchannels > 0) + { + delete[] d_size; + delete[] d_index_pop; + delete[] d_index_push; + for (unsigned int i = 0; i < d_nchannels; i++) + { + delete[] d_history[i]; + } + delete[] d_history; + } +} + +template +unsigned int Gnss_circular_deque::size(const unsigned int ch) +{ + return d_size[ch]; +} + +template +T& Gnss_circular_deque::back(const unsigned int ch) +{ + if (d_size[ch] > 0) + { + unsigned int index = 0; + if (d_index_push[ch] > 0) + { + index = d_index_push[ch] - 1; + } + else + { + index = d_max_size; + } + return d_history[ch][index]; + } + else + { + return d_return_void; + } +} + +template +T& Gnss_circular_deque::front(const unsigned int ch) +{ + if (d_size[ch] > 0) + { + return d_history[ch][d_index_pop[ch]]; + } + else + { + return d_return_void; + } +} + +template +T& Gnss_circular_deque::at(const unsigned int ch, const unsigned int pos) +{ + if (d_size[ch] > 0 and pos < d_size[ch]) + { + unsigned int index = (d_index_pop[ch] + pos) % d_max_size; + return d_history[ch][index]; + } + else + { + return d_return_void; + } +} + +template +void Gnss_circular_deque::clear(const unsigned int ch) +{ + d_size[ch] = 0; + d_index_pop[ch] = 0; + d_index_push[ch] = 0; +} + +template +T Gnss_circular_deque::pop_front(const unsigned int ch) +{ + T result; + if (d_size[ch] > 0) + { + d_size[ch]--; + result = d_history[ch][d_index_pop[ch]]; + d_index_pop[ch]++; + d_index_pop[ch] %= d_max_size; + } + return result; +} + +template +void Gnss_circular_deque::push_back(const unsigned int ch, const T& new_data) +{ + d_history[ch][d_index_push[ch]] = new_data; + d_index_push[ch]++; + d_index_push[ch] %= d_max_size; + if (d_size[ch] < d_max_size) + { + d_size[ch]++; + } + else + { + d_index_pop[ch]++; + d_index_pop[ch] %= d_max_size; + } +} + +template +T* Gnss_circular_deque::get_vector(const unsigned int ch) +{ + return d_history[ch]; +} + + +#endif /* GNSS_SDR_CIRCULAR_DEQUE_H_ */ diff --git a/src/algorithms/observables/adapters/CMakeLists.txt b/src/algorithms/observables/adapters/CMakeLists.txt index 5129e4157..882b22d83 100644 --- a/src/algorithms/observables/adapters/CMakeLists.txt +++ b/src/algorithms/observables/adapters/CMakeLists.txt @@ -26,6 +26,7 @@ include_directories( ${CMAKE_SOURCE_DIR}/src/core/interfaces ${CMAKE_SOURCE_DIR}/src/core/receiver ${CMAKE_SOURCE_DIR}/src/algorithms/observables/gnuradio_blocks + ${CMAKE_SOURCE_DIR}/src/algorithms/libs ${CMAKE_SOURCE_DIR}/src/algorithms/PVT/libs ${GLOG_INCLUDE_DIRS} ${GFlags_INCLUDE_DIRS} diff --git a/src/algorithms/observables/gnuradio_blocks/CMakeLists.txt b/src/algorithms/observables/gnuradio_blocks/CMakeLists.txt index 98b8213d8..e3db8ebcf 100644 --- a/src/algorithms/observables/gnuradio_blocks/CMakeLists.txt +++ b/src/algorithms/observables/gnuradio_blocks/CMakeLists.txt @@ -39,8 +39,8 @@ list(SORT OBS_GR_BLOCKS_HEADERS) add_library(obs_gr_blocks ${OBS_GR_BLOCKS_SOURCES} ${OBS_GR_BLOCKS_HEADERS}) source_group(Headers FILES ${OBS_GR_BLOCKS_HEADERS}) if(MATIO_FOUND) - add_dependencies(obs_gr_blocks glog-${glog_RELEASE} armadillo-${armadillo_RELEASE}) + add_dependencies(obs_gr_blocks gnss_sp_libs glog-${glog_RELEASE} armadillo-${armadillo_RELEASE}) else(MATIO_FOUND) - add_dependencies(obs_gr_blocks glog-${glog_RELEASE} armadillo-${armadillo_RELEASE} matio-${GNSSSDR_MATIO_LOCAL_VERSION}) + add_dependencies(obs_gr_blocks gnss_sp_libs glog-${glog_RELEASE} armadillo-${armadillo_RELEASE} matio-${GNSSSDR_MATIO_LOCAL_VERSION}) endif(MATIO_FOUND) -target_link_libraries(obs_gr_blocks ${GNURADIO_RUNTIME_LIBRARIES} ${ARMADILLO_LIBRARIES} ${MATIO_LIBRARIES}) +target_link_libraries(obs_gr_blocks gnss_sp_libs ${GNURADIO_RUNTIME_LIBRARIES} ${ARMADILLO_LIBRARIES} ${MATIO_LIBRARIES}) diff --git a/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc b/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc index 6e95da824..4b03988aa 100644 --- a/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc +++ b/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc @@ -66,11 +66,7 @@ hybrid_observables_cc::hybrid_observables_cc(unsigned int nchannels_in, max_delta = 0.15; // 150 ms valid_channels.resize(d_nchannels, false); d_num_valid_channels = 0; - - for (unsigned int i = 0; i < d_nchannels; i++) - { - d_gnss_synchro_history.push_back(std::deque()); - } + d_gnss_synchro_history = Gnss_circular_deque(200, d_nchannels); // ############# ENABLE DATA FILE LOG ################# if (d_dump) @@ -302,15 +298,37 @@ int hybrid_observables_cc::save_matfile() } -bool hybrid_observables_cc::interpolate_data(Gnss_Synchro &out, std::deque &data, const double &ti) +bool hybrid_observables_cc::interpolate_data(Gnss_Synchro &out, const unsigned int &ch, const double &ti) { - if ((ti < data.front().RX_time) or (ti > data.back().RX_time)) + if ((ti < d_gnss_synchro_history.front(ch).RX_time) or (ti > d_gnss_synchro_history.back(ch).RX_time)) { return false; } - std::deque::iterator it; + std::pair ind = find_interp_elements(ch, ti); - arma::vec t = arma::vec(data.size()); + double m = 0.0; + double c = 0.0; + + // CARRIER PHASE INTERPOLATION + + m = (d_gnss_synchro_history.at(ch, ind.first).Carrier_phase_rads - d_gnss_synchro_history.at(ch, ind.second).Carrier_phase_rads) / (d_gnss_synchro_history.at(ch, ind.first).RX_time - d_gnss_synchro_history.at(ch, ind.second).RX_time); + c = d_gnss_synchro_history.at(ch, ind.first).Carrier_phase_rads - m * d_gnss_synchro_history.at(ch, ind.first).RX_time; + out.Carrier_phase_rads = m * ti + c; + + // CARRIER DOPPLER INTERPOLATION + m = (d_gnss_synchro_history.at(ch, ind.first).Carrier_Doppler_hz - d_gnss_synchro_history.at(ch, ind.second).Carrier_Doppler_hz) / (d_gnss_synchro_history.at(ch, ind.first).RX_time - d_gnss_synchro_history.at(ch, ind.second).RX_time); + c = d_gnss_synchro_history.at(ch, ind.first).Carrier_Doppler_hz - m * d_gnss_synchro_history.at(ch, ind.first).RX_time; + out.Carrier_Doppler_hz = m * ti + c; + + // TOW INTERPOLATION + m = (d_gnss_synchro_history.at(ch, ind.first).TOW_at_current_symbol_s - d_gnss_synchro_history.at(ch, ind.second).TOW_at_current_symbol_s) / (d_gnss_synchro_history.at(ch, ind.first).RX_time - d_gnss_synchro_history.at(ch, ind.second).RX_time); + c = d_gnss_synchro_history.at(ch, ind.first).TOW_at_current_symbol_s - m * d_gnss_synchro_history.at(ch, ind.first).RX_time; + out.TOW_at_current_symbol_s = m * ti + c; + + return true; + + /* + arma::vec t = arma::vec(d_gnss_synchro_history.size(ch)); arma::vec dop = t; arma::vec cph = t; arma::vec tow = t; @@ -336,6 +354,7 @@ bool hybrid_observables_cc::interpolate_data(Gnss_Synchro &out, std::deque hybrid_observables_cc::find_interp_elements(const unsigned int &ch, const double &ti) +{ + unsigned int closest = 0; + double dif = std::numeric_limits::max(); + double dt = 0.0; + for (unsigned int i = 0; i < d_gnss_synchro_history.size(ch); i++) + { + dt = std::fabs(ti - d_gnss_synchro_history.at(ch, i).RX_time); + if (dt < dif) + { + dif = dt; + closest = i; + } + } + unsigned int index1; + unsigned int index2; + if (closest == 0) + { + index1 = 0; + index2 = 1; + } + else if (closest == (d_gnss_synchro_history.size(ch) - 1)) + { + index1 = d_gnss_synchro_history.size(ch) - 2; + index2 = d_gnss_synchro_history.size(ch) - 1; + } + else + { + if (d_gnss_synchro_history.at(ch, closest).RX_time < ti) + { + index1 = closest; + index2 = closest + 1; + } + else + { + index1 = closest - 1; + index2 = closest; + } + } + return std::pair(index1, index2); +} + void hybrid_observables_cc::forecast(int noutput_items __attribute__((unused)), gr_vector_int &ninput_items_required) @@ -363,13 +424,13 @@ void hybrid_observables_cc::forecast(int noutput_items __attribute__((unused)), } -void hybrid_observables_cc::clean_history(std::deque &data) +void hybrid_observables_cc::clean_history(Gnss_circular_deque &data, unsigned int pos) { - while (data.size() > 0) + while (data.size(pos) > 0) { - if ((T_rx_s - data.front().RX_time) > max_delta) + if ((T_rx_s - data.front(pos).RX_time) > max_delta) { - data.pop_front(); + data.pop_front(pos); } else { @@ -454,11 +515,9 @@ int hybrid_observables_cc::general_work(int noutput_items __attribute__((unused) } ////////////////////////////////////////////////////////////////////////// - std::vector>::iterator it; if (total_input_items > 0) { - i = 0; - for (it = d_gnss_synchro_history.begin(); it != d_gnss_synchro_history.end(); it++) + for (unsigned int i = 0; i < d_nchannels; i++) { if (ninput_items[i] > 0) { @@ -467,26 +526,25 @@ int hybrid_observables_cc::general_work(int noutput_items __attribute__((unused) { if (in[i][aux].Flag_valid_word) { - it->push_back(in[i][aux]); - it->back().RX_time = compute_T_rx_s(in[i][aux]); + d_gnss_synchro_history.push_back(i, in[i][aux]); + d_gnss_synchro_history.back(i).RX_time = compute_T_rx_s(in[i][aux]); // Check if the last Gnss_Synchro comes from the same satellite as the previous ones - if (it->size() > 1) + if (d_gnss_synchro_history.size(i) > 1) { - if (it->front().PRN != it->back().PRN) + if (d_gnss_synchro_history.front(i).PRN != d_gnss_synchro_history.back(i).PRN) { - it->clear(); + d_gnss_synchro_history.clear(i); } } } } consume(i, ninput_items[i]); } - i++; } } for (i = 0; i < d_nchannels; i++) { - if (d_gnss_synchro_history.at(i).size() > 2) + if (d_gnss_synchro_history.size(i) > 2) { valid_channels[i] = true; } @@ -506,8 +564,8 @@ int hybrid_observables_cc::general_work(int noutput_items __attribute__((unused) { if (valid_channels[i]) { - clean_history(d_gnss_synchro_history.at(i)); - if (d_gnss_synchro_history.at(i).size() < 2) + clean_history(d_gnss_synchro_history, i); + if (d_gnss_synchro_history.size(i) < 2) { valid_channels[i] = false; } @@ -523,13 +581,12 @@ int hybrid_observables_cc::general_work(int noutput_items __attribute__((unused) } std::vector epoch_data; - i = 0; - for (it = d_gnss_synchro_history.begin(); it != d_gnss_synchro_history.end(); it++) + for (unsigned int i = 0; i < d_nchannels; i++) { if (valid_channels[i]) { - Gnss_Synchro interpolated_gnss_synchro = it->back(); - if (interpolate_data(interpolated_gnss_synchro, *it, T_rx_s_out)) + Gnss_Synchro interpolated_gnss_synchro = d_gnss_synchro_history.back(i); + if (interpolate_data(interpolated_gnss_synchro, i, T_rx_s_out)) { epoch_data.push_back(interpolated_gnss_synchro); } @@ -538,7 +595,6 @@ int hybrid_observables_cc::general_work(int noutput_items __attribute__((unused) valid_channels[i] = false; } } - i++; } d_num_valid_channels = valid_channels.count(); if (d_num_valid_channels == 0) @@ -546,14 +602,14 @@ int hybrid_observables_cc::general_work(int noutput_items __attribute__((unused) return 0; } correct_TOW_and_compute_prange(epoch_data); - std::vector::iterator it2 = epoch_data.begin(); + std::vector::iterator it = epoch_data.begin(); for (i = 0; i < d_nchannels; i++) { if (valid_channels[i]) { - out[i][0] = (*it2); + out[i][0] = (*it); out[i][0].Flag_valid_pseudorange = true; - it2++; + it++; } else { diff --git a/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.h b/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.h index aedba43ab..298a9a0bb 100644 --- a/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.h +++ b/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.h @@ -35,12 +35,12 @@ #define GNSS_SDR_HYBRID_OBSERVABLES_CC_H #include "gnss_synchro.h" +#include "gnss_circular_deque.h" #include #include #include #include -#include -#include +#include class hybrid_observables_cc; @@ -65,14 +65,15 @@ private: friend hybrid_observables_cc_sptr hybrid_make_observables_cc(unsigned int nchannels_in, unsigned int nchannels_out, bool dump, std::string dump_filename); hybrid_observables_cc(unsigned int nchannels_in, unsigned int nchannels_out, bool dump, std::string dump_filename); - void clean_history(std::deque& data); + void clean_history(Gnss_circular_deque& data, unsigned int pos); double compute_T_rx_s(const Gnss_Synchro& a); - bool interpolate_data(Gnss_Synchro& out, std::deque& data, const double& ti); + bool interpolate_data(Gnss_Synchro& out, const unsigned int& ch, const double& ti); + std::pair find_interp_elements(const unsigned int& ch, const double& ti); void correct_TOW_and_compute_prange(std::vector& data); int save_matfile(); //Tracking observable history - std::vector> d_gnss_synchro_history; + Gnss_circular_deque d_gnss_synchro_history; boost::dynamic_bitset<> valid_channels; double T_rx_s; double T_rx_step_s;