mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2025-12-18 22:38:05 +00:00
refactor: moved sensor data source to algorithms/libs as well
This commit is contained in:
committed by
Carles Fernandez
parent
ae00dedfcb
commit
567426b415
@@ -211,7 +211,7 @@ void FileSourceBase::connect(gr::top_block_sptr top_block)
|
||||
if (sensor_data_source())
|
||||
{
|
||||
top_block->connect(std::move(output), 0, sensor_data_source(), 0);
|
||||
DLOG(INFO) << "connected output to extra data source, which now becomes the new output";
|
||||
DLOG(INFO) << "connected output to sensor data source, which now becomes the new output";
|
||||
output = sensor_data_source();
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
#ifndef GNSS_SDR_FILE_SOURCE_BASE_H
|
||||
#define GNSS_SDR_FILE_SOURCE_BASE_H
|
||||
|
||||
#include "../../libs/sensor_data/sensor_data_source.h"
|
||||
#include "concurrent_queue.h"
|
||||
#include "sensor_data_source.h"
|
||||
#include "signal_source_base.h"
|
||||
#include <gnuradio/blocks/file_sink.h> // for dump
|
||||
#include <gnuradio/blocks/file_source.h>
|
||||
|
||||
@@ -20,11 +20,6 @@ if(ENABLE_ION)
|
||||
set(OPT_DRIVER_HEADERS ${OPT_DRIVER_HEADERS} ion_gsms.h)
|
||||
endif()
|
||||
|
||||
if (ENABLE_SENSOR_DATA)
|
||||
set(OPT_DRIVER_SOURCES ${OPT_DRIVER_SOURCES} sensor_data_source.cc)
|
||||
set(OPT_DRIVER_HEADERS ${OPT_DRIVER_HEADERS} sensor_data_source.h)
|
||||
endif ()
|
||||
|
||||
set(SIGNAL_SOURCE_GR_BLOCKS_SOURCES
|
||||
fifo_reader.cc
|
||||
unpack_byte_2bit_samples.cc
|
||||
|
||||
@@ -1,114 +0,0 @@
|
||||
/*!
|
||||
* \file sensor_data_source.cc
|
||||
* \brief GNURadio block that adds extra data to the sample stream.
|
||||
* \author Victor Castillo, 2024. victorcastilloaguero(at).gmail.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: GPL-3.0-or-later
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "sensor_data_source.h"
|
||||
#include "sensor_data/sensor_data_file.h"
|
||||
#include <pmt/pmt.h>
|
||||
|
||||
#if USE_GLOG_AND_GFLAGS
|
||||
#include <glog/logging.h>
|
||||
#else
|
||||
#include <absl/log/log.h>
|
||||
#endif
|
||||
|
||||
using namespace std::string_literals;
|
||||
|
||||
SensorDataSource::SensorDataSource(
|
||||
const SensorDataSourceConfiguration& configuration,
|
||||
const gr::io_signature::sptr& io_signature)
|
||||
: gr::sync_block("Sensor Data Source",
|
||||
io_signature, io_signature),
|
||||
sensor_data_files_({}),
|
||||
item_size_(io_signature->sizeof_stream_item(0)),
|
||||
items_per_sample_(configuration.get_items_per_sample())
|
||||
{
|
||||
// Open needed data files
|
||||
for (const auto& file_pair : configuration.files())
|
||||
{
|
||||
const auto& id = file_pair.first;
|
||||
const auto& file = file_pair.second;
|
||||
|
||||
std::size_t s_offset = file.sample_offset;
|
||||
std::size_t s_period = file.sample_period;
|
||||
if (items_per_sample_ != 1)
|
||||
{
|
||||
s_offset *= items_per_sample_;
|
||||
s_period *= items_per_sample_;
|
||||
}
|
||||
|
||||
sensor_data_files_.emplace(id, std::make_shared<SensorDataFile>(file.filename, s_offset, s_period, file.file_offset, file.chunk_size, file.repeat));
|
||||
|
||||
if (not sensor_config_map_.contains(id))
|
||||
{
|
||||
sensor_config_map_[id] = {};
|
||||
}
|
||||
}
|
||||
|
||||
// Populate sensor map (groups sensors by file ID)
|
||||
for (const auto& sensor : configuration.sensors())
|
||||
{
|
||||
sensor_config_map_.at(sensor.file_id).emplace_back(sensor);
|
||||
}
|
||||
|
||||
// Sort lists in sensor map by byte offset within chunk
|
||||
for (auto& it : sensor_config_map_)
|
||||
{
|
||||
auto& sensors_in_file = it.second;
|
||||
std::sort(sensors_in_file.begin(), sensors_in_file.end(), [](const SensorDataConfiguration& lhs, const SensorDataConfiguration& rhs) -> bool {
|
||||
return lhs.offset < rhs.offset;
|
||||
});
|
||||
}
|
||||
|
||||
// Validate IO signature
|
||||
if (io_signature->min_streams() != 1 and io_signature->max_streams() != 1)
|
||||
{
|
||||
std::cout << "ERROR: This block only supports adding data to a single stream." << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
int SensorDataSource::work(int noutput_items,
|
||||
gr_vector_const_void_star& input_items,
|
||||
gr_vector_void_star& output_items)
|
||||
{
|
||||
static pmt::pmt_t TAG_KEY = pmt::mp("sensor_data");
|
||||
static pmt::pmt_t CHUNK_COUNT_KEY = pmt::mp("CHUNK_COUNT");
|
||||
static pmt::pmt_t SAMPLE_STAMP_KEY = pmt::mp("SAMPLE_STAMP");
|
||||
|
||||
std::memcpy(output_items[0], input_items[0], noutput_items * item_size_);
|
||||
|
||||
const uint64_t total_items_written = nitems_written(0) + noutput_items;
|
||||
|
||||
std::size_t sample_stamp;
|
||||
std::vector<uint8_t> chunk{};
|
||||
for (auto& file_pair : sensor_data_files_)
|
||||
{
|
||||
const auto& file_id = file_pair.first;
|
||||
auto& data_file = file_pair.second;
|
||||
while (data_file->read_until_sample(total_items_written, sample_stamp, chunk))
|
||||
{
|
||||
pmt::pmt_t data_tag = pmt::make_dict();
|
||||
data_tag = pmt::dict_add(data_tag, SAMPLE_STAMP_KEY, pmt::from_uint64(sample_stamp / items_per_sample_));
|
||||
data_tag = pmt::dict_add(data_tag, CHUNK_COUNT_KEY, pmt::from_long(data_file->get_chunks_read()));
|
||||
for (const auto& sensor : sensor_config_map_.at(file_id))
|
||||
{
|
||||
data_tag = pmt::dict_add(data_tag, sensor.tag_key, SensorDataType::make_value(sensor.type, &chunk[sensor.offset]));
|
||||
}
|
||||
add_item_tag(0, sample_stamp, TAG_KEY, data_tag);
|
||||
}
|
||||
}
|
||||
|
||||
return noutput_items;
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
/*!
|
||||
* \file sensor_data_source.h
|
||||
* \brief GNURadio block that adds extra data to the sample stream.
|
||||
* \author Victor Castillo, 2024. victorcastilloaguero(at).gmail.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: GPL-3.0-or-later
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#ifndef GNSS_SDR_SENSOR_DATA_SOURCE_H
|
||||
#define GNSS_SDR_SENSOR_DATA_SOURCE_H
|
||||
|
||||
#include "sensor_data/sensor_data_file.h"
|
||||
#include "sensor_data/sensor_data_source_configuration.h"
|
||||
#include "gnss_block_interface.h"
|
||||
#include <gnuradio/sync_block.h> // for sync_block
|
||||
#include <gnuradio/types.h> // for gr_vector_const_void_star
|
||||
#include <cstddef> // for size_t
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
/** \addtogroup Signal_Source
|
||||
* \{ */
|
||||
/** \addtogroup Signal_Source_gnuradio_blocks
|
||||
* \{ */
|
||||
|
||||
class SensorDataSource : public gr::sync_block
|
||||
{
|
||||
public:
|
||||
using sptr = gnss_shared_ptr<SensorDataSource>;
|
||||
|
||||
SensorDataSource(
|
||||
const SensorDataSourceConfiguration& configuration,
|
||||
const gr::io_signature::sptr& io_signature);
|
||||
|
||||
int work(int noutput_items,
|
||||
gr_vector_const_void_star& input_items,
|
||||
gr_vector_void_star& output_items) override;
|
||||
|
||||
private:
|
||||
std::unordered_map<SensorDataFile::id_type, SensorDataFile::sptr> sensor_data_files_;
|
||||
std::unordered_map<SensorDataFile::id_type, std::vector<SensorDataConfiguration>> sensor_config_map_;
|
||||
std::size_t item_size_;
|
||||
std::size_t items_per_sample_;
|
||||
};
|
||||
|
||||
/** \} */
|
||||
/** \} */
|
||||
#endif // GNSS_SDR_SENSOR_DATA_SOURCE_H
|
||||
Reference in New Issue
Block a user