From 202f032e889745f98104a28eae5dabaabe8fec40 Mon Sep 17 00:00:00 2001 From: Josh Schindehette Date: Wed, 30 Sep 2020 14:00:35 -0400 Subject: [PATCH 1/5] 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. --- .../gr_complex_ip_packet_source.cc | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/algorithms/signal_source/gnuradio_blocks/gr_complex_ip_packet_source.cc b/src/algorithms/signal_source/gnuradio_blocks/gr_complex_ip_packet_source.cc index f3018b359..b2db888c5 100644 --- a/src/algorithms/signal_source/gnuradio_blocks/gr_complex_ip_packet_source.cc +++ b/src/algorithms/signal_source/gnuradio_blocks/gr_complex_ip_packet_source.cc @@ -118,6 +118,11 @@ Gr_Complex_Ip_Packet_Source::Gr_Complex_Ip_Packet_Source(std::string src_device, d_wire_sample_type = 2; 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 { 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) { - int8_t real; - int8_t imag; - uint8_t tmp_char2; for (int n = 0; n < num_samples_readed; n++) { 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 for (auto &output_item : output_items) { + int8_t real, imag; real = fifo_buff[fifo_read_ptr++]; imag = fifo_buff[fifo_read_ptr++]; 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 for (auto &output_item : output_items) { + int8_t real, imag; + uint8_t tmp_char2; tmp_char2 = fifo_buff[fifo_read_ptr] & 0x0F; if (tmp_char2 >= 8) { @@ -373,6 +378,24 @@ void Gr_Complex_Ip_Packet_Source::demux_samples(const gr_vector_void_star &outpu } } 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(output_item)[n] = gr_complex(real, imag); + } + else + { + static_cast(output_item)[n] = gr_complex(imag, real); + } + } + break; default: std::cout << "Unknown wire sample type\n"; exit(0); @@ -407,6 +430,7 @@ int Gr_Complex_Ip_Packet_Source::work(int noutput_items, { case 1: // complex byte samples case 2: // complex 4 bits samples + case 3: // complex float samples bytes_requested = noutput_items * d_bytes_per_sample; if (bytes_requested < fifo_items) { From 8189b37ebadda10ed2b39575b50fdc45327123bb Mon Sep 17 00:00:00 2001 From: Josh Schindehette Date: Wed, 30 Sep 2020 14:15:12 -0400 Subject: [PATCH 2/5] Fixed code/comment spacing issue for cpplint --- .../gnuradio_blocks/gr_complex_ip_packet_source.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/algorithms/signal_source/gnuradio_blocks/gr_complex_ip_packet_source.cc b/src/algorithms/signal_source/gnuradio_blocks/gr_complex_ip_packet_source.cc index b2db888c5..c151c915b 100644 --- a/src/algorithms/signal_source/gnuradio_blocks/gr_complex_ip_packet_source.cc +++ b/src/algorithms/signal_source/gnuradio_blocks/gr_complex_ip_packet_source.cc @@ -383,9 +383,9 @@ void Gr_Complex_Ip_Packet_Source::demux_samples(const gr_vector_void_star &outpu { float real, imag; memcpy(&real, &fifo_buff[fifo_read_ptr], sizeof(real)); - fifo_read_ptr += 4; // Four bytes in float + 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 + fifo_read_ptr += 4; // Four bytes in float if (d_IQ_swap) { static_cast(output_item)[n] = gr_complex(real, imag); From 5648579a267972b958530570a0e0436caa2be776 Mon Sep 17 00:00:00 2001 From: Josh Schindehette Date: Wed, 30 Sep 2020 15:24:07 -0400 Subject: [PATCH 3/5] Fixed variable declaration syntax for clang-tidy --- .../gnuradio_blocks/gr_complex_ip_packet_source.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/algorithms/signal_source/gnuradio_blocks/gr_complex_ip_packet_source.cc b/src/algorithms/signal_source/gnuradio_blocks/gr_complex_ip_packet_source.cc index c151c915b..a72ee564e 100644 --- a/src/algorithms/signal_source/gnuradio_blocks/gr_complex_ip_packet_source.cc +++ b/src/algorithms/signal_source/gnuradio_blocks/gr_complex_ip_packet_source.cc @@ -331,7 +331,8 @@ void Gr_Complex_Ip_Packet_Source::demux_samples(const gr_vector_void_star &outpu case 1: // interleaved byte samples for (auto &output_item : output_items) { - int8_t real, imag; + int8_t real; + int8_t imag; real = fifo_buff[fifo_read_ptr++]; imag = fifo_buff[fifo_read_ptr++]; if (d_IQ_swap) @@ -347,7 +348,8 @@ void Gr_Complex_Ip_Packet_Source::demux_samples(const gr_vector_void_star &outpu case 2: // 4-bit samples for (auto &output_item : output_items) { - int8_t real, imag; + int8_t real; + int8_t imag; uint8_t tmp_char2; tmp_char2 = fifo_buff[fifo_read_ptr] & 0x0F; if (tmp_char2 >= 8) @@ -381,7 +383,8 @@ void Gr_Complex_Ip_Packet_Source::demux_samples(const gr_vector_void_star &outpu case 3: // interleaved float samples for (auto &output_item : output_items) { - float real, imag; + float real; + float 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)); From d8cc2efeee7cb7de557dadfe3e5c3ee4cd5b5f94 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Thu, 1 Oct 2020 10:45:59 +0200 Subject: [PATCH 4/5] Update changelog --- docs/changelog.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/changelog.md b/docs/changelog.md index 5a962c839..bcd5dfb30 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -48,6 +48,9 @@ SPDX-FileCopyrightText: 2011-2020 Carles Fernandez-Prades Date: Thu, 1 Oct 2020 10:47:38 +0200 Subject: [PATCH 5/5] Fix typo --- docs/changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/changelog.md b/docs/changelog.md index bcd5dfb30..9094120ed 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -49,7 +49,7 @@ SPDX-FileCopyrightText: 2011-2020 Carles Fernandez-Prades