1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2026-04-30 10:41:25 +00:00

Fix for old environments

Fix usage of pmt library in GNU Radio > 3.8
Fix usage of string_literals in C++11
Reordering of structs and private members for padding reduction
Fix email address in headers
Fix copyright years in headers
Improve consistency of blank lines usage
This commit is contained in:
Carles Fernandez
2025-07-10 09:44:00 +02:00
parent b34540ffb9
commit 3c77662723
13 changed files with 90 additions and 48 deletions

View File

@@ -122,6 +122,7 @@ target_link_libraries(algorithms_libs
Gnuradio::runtime
Gnuradio::blocks
Gnuradio::fft
Gnuradio::pmt
PRIVATE
core_system_parameters
Volk::volk

View File

@@ -1,14 +1,14 @@
/*!
* \file sensor_data_aggregator.cc
* \brief Aggregates sensor samples from gnu radio stream tags into typed lists for easy access
* \author Victor Castillo, 2024. victorcastilloaguero(at).gmail.es
* \author Victor Castillo, 2024. victorcastilloaguero(at)gmail.com
*
* -----------------------------------------------------------------------------
*
* 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)
* Copyright (C) 2024-2025 (see AUTHORS file for a list of contributors)
* SPDX-License-Identifier: GPL-3.0-or-later
*
* -----------------------------------------------------------------------------
@@ -62,6 +62,7 @@ SensorDataAggregator::SensorDataAggregator(const SensorDataSourceConfiguration&
}
}
void SensorDataAggregator::update(const std::vector<gr::tag_t>& tags)
{
// Delete all data except last sample for each sensor
@@ -81,13 +82,14 @@ void SensorDataAggregator::update(const std::vector<gr::tag_t>& tags)
// Append new data
for (const auto& sensor_tag : tags)
{
if (sensor_tag.value->is_dict())
if (pmt::is_dict(sensor_tag.value))
{
append_data(sensor_tag.value);
}
}
}
const std::vector<SensorDataSample<float>>& SensorDataAggregator::get_f32(SensorIdentifier::value_type sensor_id) const
{
// The map is populated on construction with empty vectors for each provided sensor.
@@ -95,6 +97,7 @@ const std::vector<SensorDataSample<float>>& SensorDataAggregator::get_f32(Sensor
return f32_data_.at(sensor_id);
}
SensorDataSample<float> SensorDataAggregator::get_last_f32(SensorIdentifier::value_type sensor_id) const
{
// The map is populated on construction with empty vectors for each provided sensor.
@@ -130,9 +133,7 @@ void SensorDataAggregator::append_data(const pmt::pmt_t& data_dict)
case SensorDataType::F32:
if (f32_data_.find(sensor_id) != f32_data_.end())
{
f32_data_.at(sensor_id).push_back(SensorDataSample<float>{
.rf_sample_stamp = sample_stamp,
.value = pmt::to_float(val)});
f32_data_.at(sensor_id).emplace_back(sample_stamp, pmt::to_float(val));
}
break;

View File

@@ -1,14 +1,14 @@
/*!
* \file sensor_data_aggregator.h
* \brief Aggregates sensor samples from gnu radio stream tags into typed lists for easy access
* \author Victor Castillo, 2024. victorcastilloaguero(at).gmail.es
* \author Victor Castillo, 2024. victorcastilloaguero(at)gmail.com
*
* -----------------------------------------------------------------------------
*
* 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)
* Copyright (C) 2024-2025 (see AUTHORS file for a list of contributors)
* SPDX-License-Identifier: GPL-3.0-or-later
*
* -----------------------------------------------------------------------------
@@ -21,6 +21,7 @@
#include "sensor_data_source_configuration.h"
#include "sensor_identifier.h"
#include <gnuradio/tags.h>
#include <cstdint>
#include <gnss_block_interface.h>
#include <vector>
@@ -29,13 +30,18 @@
/** \addtogroup Algorithm_libs algorithms_libs
* \{ */
template <typename DataType>
struct SensorDataSample
{
uint64_t rf_sample_stamp{};
DataType value{};
uint64_t timestamp;
DataType value;
constexpr SensorDataSample() = default;
constexpr SensorDataSample(uint64_t t, DataType v)
: timestamp(t), value(v) {}
};
class SensorDataAggregator
{
public:

View File

@@ -1,14 +1,14 @@
/*!
* \file sensor_data_file.cc
* \brief Provides a simple abstraction for reading contiguous binary data from a file
* \author Victor Castillo, 2024. victorcastilloaguero(at).gmail.es
* \author Victor Castillo, 2024. victorcastilloaguero(at)gmail.com
*
* -----------------------------------------------------------------------------
*
* 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)
* Copyright (C) 2024-2025 (see AUTHORS file for a list of contributors)
* SPDX-License-Identifier: GPL-3.0-or-later
*
* -----------------------------------------------------------------------------
@@ -32,18 +32,19 @@ SensorDataFile::SensorDataFile(
sample_period_(sample_period),
offset_in_file_(offset_in_file),
item_size_(item_size),
repeat_(repeat),
done_(false),
chunks_read_(0),
last_sample_stamp_(sample_delay),
io_buffer_size_(item_size * IO_BUFFER_MAX_SIZE),
offset_in_io_buffer_(io_buffer_size_) // Set to end of buffer so that first look up will trigger a read.
offset_in_io_buffer_(io_buffer_size_), // Set to end of buffer so that first look up will trigger a read.
repeat_(repeat),
done_(false)
{
file_.seekg(offset_in_file_, std::ios_base::beg);
io_buffer_.resize(io_buffer_size_);
}
void SensorDataFile::reset()
{
file_.clear();
@@ -52,6 +53,7 @@ void SensorDataFile::reset()
done_ = false;
}
bool SensorDataFile::read_item(std::vector<uint8_t>& buffer)
{
if (offset_in_io_buffer_ >= io_buffer_size_)
@@ -71,6 +73,7 @@ bool SensorDataFile::read_item(std::vector<uint8_t>& buffer)
return true;
}
bool SensorDataFile::read_until_sample(std::size_t end_sample, std::size_t& sample_stamp, std::vector<uint8_t>& buffer)
{
if (last_sample_stamp_ + sample_period_ < end_sample)
@@ -84,11 +87,13 @@ bool SensorDataFile::read_until_sample(std::size_t end_sample, std::size_t& samp
return false;
}
std::size_t SensorDataFile::get_chunks_read() const
{
return chunks_read_;
}
void SensorDataFile::read_into_io_buffer()
{
file_.read(reinterpret_cast<char*>(&io_buffer_[0]), io_buffer_size_);
@@ -117,6 +122,7 @@ void SensorDataFile::read_into_io_buffer()
offset_in_io_buffer_ = 0;
}
void SensorDataFile::read_into_item_buffer(std::vector<uint8_t>& item_buf)
{
item_buf.resize(item_size_);

View File

@@ -1,14 +1,14 @@
/*!
* \file sensor_data_file.h
* \brief Provides a simple abstraction for reading contiguous binary data from a file
* \author Victor Castillo, 2024. victorcastilloaguero(at).gmail.es
* \author Victor Castillo, 2024. victorcastilloaguero(at)gmail.com
*
* -----------------------------------------------------------------------------
*
* 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)
* Copyright (C) 2024-2025 (see AUTHORS file for a list of contributors)
* SPDX-License-Identifier: GPL-3.0-or-later
*
* -----------------------------------------------------------------------------
@@ -46,7 +46,6 @@ public:
const std::size_t& item_size,
const bool& repeat);
void reset();
bool read_until_sample(std::size_t end_sample, std::size_t& sample_stamp, std::vector<uint8_t>& buffer);
@@ -65,14 +64,14 @@ private:
std::size_t sample_period_;
std::size_t offset_in_file_;
std::size_t item_size_;
bool repeat_;
bool done_;
std::size_t chunks_read_;
std::size_t last_sample_stamp_;
std::vector<uint8_t> io_buffer_;
std::size_t io_buffer_size_;
std::size_t offset_in_io_buffer_;
bool repeat_;
bool done_;
};
/** \} */

View File

@@ -1,14 +1,14 @@
/*!
* \file sensor_data_source.cc
* \brief GNURadio block that adds extra data to the sample stream.
* \author Victor Castillo, 2024. victorcastilloaguero(at).gmail.es
* \author Victor Castillo, 2024. victorcastilloaguero(at)gmail.com
*
* -----------------------------------------------------------------------------
*
* 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)
* Copyright (C) 2024-2025 (see AUTHORS file for a list of contributors)
* SPDX-License-Identifier: GPL-3.0-or-later
*
* -----------------------------------------------------------------------------
@@ -85,6 +85,7 @@ SensorDataSource::SensorDataSource(
}
}
int SensorDataSource::work(int noutput_items,
gr_vector_const_void_star& input_items,
gr_vector_void_star& output_items)

View File

@@ -1,14 +1,14 @@
/*!
* \file sensor_data_source.h
* \brief GNURadio block that adds extra data to the sample stream.
* \author Victor Castillo, 2024. victorcastilloaguero(at).gmail.es
* \author Victor Castillo, 2024. victorcastilloaguero(at)gmail.com
*
* -----------------------------------------------------------------------------
*
* 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)
* Copyright (C) 2024-2025 (see AUTHORS file for a list of contributors)
* SPDX-License-Identifier: GPL-3.0-or-later
*
* -----------------------------------------------------------------------------

View File

@@ -1,14 +1,14 @@
/*!
* \file sensor_data_source_configuration.cc
* \brief
* \author Victor Castillo, 2025. victorcastilloaguero(at).gmail.es
* \author Victor Castillo, 2025. victorcastilloaguero(at)gmail.com
*
* -----------------------------------------------------------------------------
*
* 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)
* Copyright (C) 2024-2025 (see AUTHORS file for a list of contributors)
* SPDX-License-Identifier: GPL-3.0-or-later
*
* -----------------------------------------------------------------------------
@@ -33,16 +33,19 @@ SensorDataSourceConfiguration::SensorDataSourceConfiguration(const Configuration
}
}
bool SensorDataSourceConfiguration::validate() const
{
return validate_files() and validate_sensors();
}
bool SensorDataSourceConfiguration::is_enabled() const
{
return enabled_;
}
bool SensorDataSourceConfiguration::is_sensor_provided(SensorIdentifier::value_type sensor_id) const
{
if (not enabled_)
@@ -67,6 +70,7 @@ void SensorDataSourceConfiguration::set_items_per_sample(uint64_t items_per_samp
items_per_sample_ = items_per_sample;
}
uint64_t SensorDataSourceConfiguration::get_items_per_sample() const
{
return items_per_sample_;
@@ -78,11 +82,13 @@ const std::unordered_map<uint64_t, SensorDataFileConfiguration>& SensorDataSourc
return files_;
}
const std::vector<SensorDataConfiguration>& SensorDataSourceConfiguration::sensors() const
{
return sensors_;
}
void SensorDataSourceConfiguration::configure_files(const ConfigurationInterface* configuration)
{
for (uint64_t id = 0;; ++id)
@@ -102,15 +108,16 @@ void SensorDataSourceConfiguration::configure_files(const ConfigurationInterface
id,
SensorDataFileConfiguration{
.id = id,
.filename = filename,
.repeat = configuration->property(role + ".repeat"s, false),
.chunk_size = configuration->property(role + ".chunk_size"s, uint64_t{0UL}),
.file_offset = configuration->property(role + ".file_offset"s, uint64_t{0UL}),
.sample_offset = configuration->property(role + ".sample_offset"s, uint64_t{0UL}),
.sample_period = configuration->property(role + ".sample_period"s, uint64_t{0UL})});
.sample_period = configuration->property(role + ".sample_period"s, uint64_t{0UL}),
.filename = filename,
.repeat = configuration->property(role + ".repeat"s, false)});
}
}
void SensorDataSourceConfiguration::configure_sensors(const ConfigurationInterface* configuration)
{
for (uint64_t id = 0;; ++id)
@@ -164,9 +171,9 @@ void SensorDataSourceConfiguration::configure_sensors(const ConfigurationInterfa
sensors_.emplace_back(SensorDataConfiguration{
.id = id,
.file_id = file_id,
.offset = offset,
.identifier = SensorIdentifier::from_string(sensor_identifier),
.type = data_type,
.offset = offset,
.tag_key = pmt::mp(sensor_identifier)});
}
}
@@ -190,6 +197,7 @@ bool SensorDataSourceConfiguration::validate_files() const
return ok;
}
bool SensorDataSourceConfiguration::validate_sensors() const
{
bool ok = true;

View File

@@ -1,14 +1,14 @@
/*!
* \file sensor_data_source_configuration.h
* \brief
* \author Victor Castillo, 2024. victorcastilloaguero(at).gmail.es
* \author Victor Castillo, 2024. victorcastilloaguero(at)gmail.com
*
* -----------------------------------------------------------------------------
*
* 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)
* Copyright (C) 2024-2025 (see AUTHORS file for a list of contributors)
* SPDX-License-Identifier: GPL-3.0-or-later
*
* -----------------------------------------------------------------------------
@@ -19,6 +19,7 @@
#define GNSS_SDR_SENSOR_DATA_SOURCE_CONFIGURATION_H
#include "configuration_interface.h"
#include "gnss_sdr_string_literals.h"
#include "sensor_data_type.h"
#include "sensor_identifier.h"
#include <string>
@@ -38,25 +39,26 @@ class ConfigurationInterface;
struct SensorDataFileConfiguration
{
uint64_t id;
std::string filename;
bool repeat;
uint64_t chunk_size;
uint64_t file_offset;
uint64_t sample_offset;
uint64_t sample_period;
std::string filename;
bool repeat;
};
struct SensorDataConfiguration
{
uint64_t id;
uint64_t file_id;
uint64_t offset;
SensorIdentifier::value_type identifier;
SensorDataType::value_type type;
uint64_t offset;
pmt::pmt_t tag_key;
};
class SensorDataSourceConfiguration
{
public:
@@ -81,12 +83,10 @@ private:
void configure_sensors(const ConfigurationInterface* configuration);
bool validate_files() const;
bool validate_sensors() const;
private:
bool enabled_;
std::unordered_map<uint64_t, SensorDataFileConfiguration> files_;
std::vector<SensorDataConfiguration> sensors_;

View File

@@ -1,23 +1,21 @@
/*!
* \file sensor_data_type.cc
* \brief
* \author Victor Castillo, 2025. victorcastilloaguero(at).gmail.es
* \author Victor Castillo, 2025. victorcastilloaguero(at)gmail.com
*
* -----------------------------------------------------------------------------
*
* 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)
* Copyright (C) 2024-2025 (see AUTHORS file for a list of contributors)
* SPDX-License-Identifier: GPL-3.0-or-later
*
* -----------------------------------------------------------------------------
*/
#include "sensor_data_type.h"
#include <pmt/pmt.h>
#include <stdexcept>
#include <string>
SensorDataType::value_type SensorDataType::from_string(const std::string& s)
{
@@ -50,6 +48,7 @@ SensorDataType::value_type SensorDataType::from_string(const std::string& s)
throw std::runtime_error{"Unknown sensor data type: " + s};
}
std::string SensorDataType::to_string(const SensorDataType::value_type& v)
{
switch (v)
@@ -69,6 +68,7 @@ std::string SensorDataType::to_string(const SensorDataType::value_type& v)
}
}
uint64_t SensorDataType::get_size(const SensorDataType::value_type& v)
{
switch (v)
@@ -88,6 +88,7 @@ uint64_t SensorDataType::get_size(const SensorDataType::value_type& v)
}
}
pmt::pmt_t SensorDataType::make_value(const SensorDataType::value_type& v, void* value)
{
switch (v)

View File

@@ -1,14 +1,14 @@
/*!
* \file sensor_data_type.h
* \brief
* \author Victor Castillo, 2025. victorcastilloaguero(at).gmail.es
* \author Victor Castillo, 2025. victorcastilloaguero(at)gmail.com
*
* -----------------------------------------------------------------------------
*
* 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)
* Copyright (C) 2024-2025 (see AUTHORS file for a list of contributors)
* SPDX-License-Identifier: GPL-3.0-or-later
*
* -----------------------------------------------------------------------------

View File

@@ -1,14 +1,14 @@
/*!
* \file sensor_identifier.cc
* \brief
* \author Victor Castillo, 2025. victorcastilloaguero(at).gmail.es
* \author Victor Castillo, 2025. victorcastilloaguero(at)gmail.com
*
* -----------------------------------------------------------------------------
*
* 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)
* Copyright (C) 2024-2025 (see AUTHORS file for a list of contributors)
* SPDX-License-Identifier: GPL-3.0-or-later
*
* -----------------------------------------------------------------------------
@@ -27,6 +27,7 @@ struct ConversionEntry
pmt::pmt_t (*conversion_fun)(const pmt::pmt_t&);
};
static const ConversionEntry conversion_table[] = {
{SensorDataType::F32, SensorDataType::F32, [](const pmt::pmt_t& val) { return val; }},
{SensorDataType::F64, SensorDataType::F32, [](const pmt::pmt_t& val) { return pmt::from_float(pmt::to_double(val)); }},
@@ -34,6 +35,7 @@ static const ConversionEntry conversion_table[] = {
{SensorDataType::I64, SensorDataType::F32, [](const pmt::pmt_t& val) { return pmt::from_float(pmt::to_long(val)); }},
};
const ConversionEntry* lookup_conversion(SensorDataType::value_type from_type, SensorDataType::value_type to_type)
{
for (const auto& conversion_entry : conversion_table)
@@ -108,6 +110,7 @@ SensorIdentifier::value_type SensorIdentifier::from_string(const std::string& s)
throw std::runtime_error{"Unknown sensor identifier: " + s};
}
std::string SensorIdentifier::to_string(SensorIdentifier::value_type v)
{
switch (v)

View File

@@ -1,14 +1,14 @@
/*!
* \file sensor_identifier.h
* \brief
* \author Victor Castillo, 2025. victorcastilloaguero(at).gmail.es
* \author Victor Castillo, 2025. victorcastilloaguero(at)gmail.com
*
* -----------------------------------------------------------------------------
*
* 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)
* Copyright (C) 2024-2025 (see AUTHORS file for a list of contributors)
* SPDX-License-Identifier: GPL-3.0-or-later
*
* -----------------------------------------------------------------------------
@@ -19,6 +19,7 @@
#define GNSS_SDR_SENSOR_IDENTIFIER_H
#include "sensor_data_type.h"
#include <functional>
#include <string>
/** \addtogroup Algorithms_Library
@@ -58,6 +59,21 @@ struct SensorIdentifier
static pmt::pmt_t convert_to_internal_type(value_type sensor_id, SensorDataType::value_type original_type, const pmt::pmt_t& value);
};
// Fix for C++11
namespace std
{
template <>
struct hash<SensorIdentifier::value_type>
{
std::size_t operator()(const SensorIdentifier::value_type& key) const noexcept
{
return std::hash<unsigned short>()(static_cast<unsigned short>(key));
}
};
} // namespace std
/** \} */
/** \} */
#endif // GNSS_SDR_SENSOR_IDENTIFIER_H