1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-11-05 01:26:24 +00:00

Added cfloat type, data is assumed to be little endian

The sample_type property of gr_complex_ip_packet_source was augmented
to support the "cfloat" enumeration. It packs 8 bytes of data from
the UDP payload into a single complex float sample. The float data
in the UDP payload is assumed to be little endian.
This commit is contained in:
Josh Schindehette 2020-09-30 14:00:35 -04:00
parent 1ce0b893e1
commit 202f032e88

View File

@ -118,6 +118,11 @@ Gr_Complex_Ip_Packet_Source::Gr_Complex_Ip_Packet_Source(std::string src_device,
d_wire_sample_type = 2; d_wire_sample_type = 2;
d_bytes_per_sample = d_n_baseband_channels; d_bytes_per_sample = d_n_baseband_channels;
} }
else if (wire_sample_type == "cfloat")
{
d_wire_sample_type = 3;
d_bytes_per_sample = d_n_baseband_channels * 8;
}
else else
{ {
std::cout << "Unknown wire sample type\n"; std::cout << "Unknown wire sample type\n";
@ -319,9 +324,6 @@ void Gr_Complex_Ip_Packet_Source::my_pcap_loop_thread(pcap_t *pcap_handle)
void Gr_Complex_Ip_Packet_Source::demux_samples(const gr_vector_void_star &output_items, int num_samples_readed) void Gr_Complex_Ip_Packet_Source::demux_samples(const gr_vector_void_star &output_items, int num_samples_readed)
{ {
int8_t real;
int8_t imag;
uint8_t tmp_char2;
for (int n = 0; n < num_samples_readed; n++) for (int n = 0; n < num_samples_readed; n++)
{ {
switch (d_wire_sample_type) switch (d_wire_sample_type)
@ -329,6 +331,7 @@ void Gr_Complex_Ip_Packet_Source::demux_samples(const gr_vector_void_star &outpu
case 1: // interleaved byte samples case 1: // interleaved byte samples
for (auto &output_item : output_items) for (auto &output_item : output_items)
{ {
int8_t real, imag;
real = fifo_buff[fifo_read_ptr++]; real = fifo_buff[fifo_read_ptr++];
imag = fifo_buff[fifo_read_ptr++]; imag = fifo_buff[fifo_read_ptr++];
if (d_IQ_swap) if (d_IQ_swap)
@ -344,6 +347,8 @@ void Gr_Complex_Ip_Packet_Source::demux_samples(const gr_vector_void_star &outpu
case 2: // 4-bit samples case 2: // 4-bit samples
for (auto &output_item : output_items) for (auto &output_item : output_items)
{ {
int8_t real, imag;
uint8_t tmp_char2;
tmp_char2 = fifo_buff[fifo_read_ptr] & 0x0F; tmp_char2 = fifo_buff[fifo_read_ptr] & 0x0F;
if (tmp_char2 >= 8) if (tmp_char2 >= 8)
{ {
@ -373,6 +378,24 @@ void Gr_Complex_Ip_Packet_Source::demux_samples(const gr_vector_void_star &outpu
} }
} }
break; break;
case 3: // interleaved float samples
for (auto &output_item : output_items)
{
float real, imag;
memcpy(&real, &fifo_buff[fifo_read_ptr], sizeof(real));
fifo_read_ptr += 4; // Four bytes in float
memcpy(&imag, &fifo_buff[fifo_read_ptr], sizeof(imag));
fifo_read_ptr += 4; // Four bytes in float
if (d_IQ_swap)
{
static_cast<gr_complex *>(output_item)[n] = gr_complex(real, imag);
}
else
{
static_cast<gr_complex *>(output_item)[n] = gr_complex(imag, real);
}
}
break;
default: default:
std::cout << "Unknown wire sample type\n"; std::cout << "Unknown wire sample type\n";
exit(0); exit(0);
@ -407,6 +430,7 @@ int Gr_Complex_Ip_Packet_Source::work(int noutput_items,
{ {
case 1: // complex byte samples case 1: // complex byte samples
case 2: // complex 4 bits samples case 2: // complex 4 bits samples
case 3: // complex float samples
bytes_requested = noutput_items * d_bytes_per_sample; bytes_requested = noutput_items * d_bytes_per_sample;
if (bytes_requested < fifo_items) if (bytes_requested < fifo_items)
{ {