mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2024-11-17 23:34:56 +00:00
Merge branch 'next' of https://github.com/stefanlinden/gnss-sdr into stefanlinden-next
This commit is contained in:
commit
e0fb76e44a
@ -64,9 +64,14 @@ int FifoReader::work(int noutput_items,
|
||||
// ishort == int16_t
|
||||
items_retrieved = read_interleaved<int16_t>(noutput_items, output_items);
|
||||
}
|
||||
else if (sample_type_ == "ibyte") // Does this also work with cbyte?
|
||||
{
|
||||
// ibyte == int8_t
|
||||
items_retrieved = read_interleaved<int8_t>(noutput_items, output_items);
|
||||
}
|
||||
else if (sample_type_ == "gr_complex")
|
||||
{
|
||||
LOG(WARNING) << sample_type_ << " is not yet tested. Please consider removing this warning if tested successfully";
|
||||
// gr_complex == complex<float>
|
||||
items_retrieved = read_gr_complex(noutput_items, output_items);
|
||||
}
|
||||
else
|
||||
@ -80,6 +85,7 @@ int FifoReader::work(int noutput_items,
|
||||
return this->WORK_CALLED_PRODUCE;
|
||||
}
|
||||
|
||||
|
||||
// read gr_complex items from fifo
|
||||
// this fct has duplicate code with the templated read_interleaved fct in header
|
||||
size_t FifoReader::read_gr_complex(int noutput_items, gr_vector_void_star &output_items)
|
||||
|
@ -51,8 +51,11 @@ private:
|
||||
FifoReader(const std::string &file_name, const std::string &sample_type);
|
||||
|
||||
size_t read_gr_complex(int noutput_items, gr_vector_void_star &output_items);
|
||||
|
||||
//! function to read data out of FIFO which is stored as interleaved I/Q stream.
|
||||
//! template argument determines sample_type
|
||||
// Note: template definition necessary in header file
|
||||
// See also: https://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file
|
||||
template <typename Type>
|
||||
size_t read_interleaved(int noutput_items, gr_vector_void_star &output_items)
|
||||
{
|
||||
@ -61,15 +64,13 @@ private:
|
||||
{
|
||||
// TODO: try if performance increases if we copy larger chunks to vector.
|
||||
// how to read from stream: https://en.cppreference.com/w/cpp/io/basic_ifstream
|
||||
std::array<char, 4> buffer; // gr_complex is 32bit = 4*char
|
||||
fifo_.read(reinterpret_cast<char *>(&buffer[0]), buffer.size());
|
||||
std::array<char, 2 * sizeof(Type)> buffer;
|
||||
fifo_.read(reinterpret_cast<char *>(buffer.data()), buffer.size());
|
||||
if (fifo_.good())
|
||||
{
|
||||
Type real;
|
||||
Type imag;
|
||||
memcpy(&real, &buffer[0], sizeof(real));
|
||||
memcpy(&imag, &buffer[2], sizeof(imag));
|
||||
static_cast<gr_complex *>(output_items.at(0))[n] = gr_complex(real, imag);
|
||||
auto real = reinterpret_cast<Type const *>(&buffer[0]);
|
||||
auto imag = reinterpret_cast<Type const *>(&buffer[sizeof(Type)]);
|
||||
static_cast<gr_complex *>(output_items[0])[n] = gr_complex(*real, *imag);
|
||||
items_retrieved++;
|
||||
}
|
||||
else if (fifo_.eof())
|
||||
|
Loading…
Reference in New Issue
Block a user