summaryrefslogtreecommitdiff
path: root/gr-fft
diff options
context:
space:
mode:
authorTim O'Shea <tim.oshea753@gmail.com>2013-05-30 08:02:59 -0400
committerTim O'Shea <tim.oshea753@gmail.com>2013-05-30 08:02:59 -0400
commit38f4e01af5936dfe36d633426a03cea6fcc1f50b (patch)
tree0c44d8c6122c13241551d741a8bc14221d0ed0af /gr-fft
parent923b8509d9ebcef79edf2137e10413c9f760091d (diff)
fft: adding ctrlport psd probe block
Diffstat (limited to 'gr-fft')
-rw-r--r--gr-fft/grc/CMakeLists.txt1
-rw-r--r--gr-fft/grc/fft_ctrlport_probe_psd.xml63
-rw-r--r--gr-fft/include/gnuradio/fft/CMakeLists.txt8
-rw-r--r--gr-fft/include/gnuradio/fft/ctrlport_probe_psd.h66
-rw-r--r--gr-fft/lib/CMakeLists.txt6
-rw-r--r--gr-fft/lib/ctrlport_probe_psd_impl.cc174
-rw-r--r--gr-fft/lib/ctrlport_probe_psd_impl.h69
-rw-r--r--gr-fft/swig/fft_swig.i13
8 files changed, 400 insertions, 0 deletions
diff --git a/gr-fft/grc/CMakeLists.txt b/gr-fft/grc/CMakeLists.txt
index 4c96d21738..cc972dfa7e 100644
--- a/gr-fft/grc/CMakeLists.txt
+++ b/gr-fft/grc/CMakeLists.txt
@@ -22,6 +22,7 @@ install(FILES
fft_fft_vxx.xml
fft_goertzel_fc.xml
fft_logpwrfft_x.xml
+ fft_ctrlport_probe_psd.xml
DESTINATION ${GRC_BLOCKS_DIR}
COMPONENT "fft_python"
)
diff --git a/gr-fft/grc/fft_ctrlport_probe_psd.xml b/gr-fft/grc/fft_ctrlport_probe_psd.xml
new file mode 100644
index 0000000000..14fd24a7d9
--- /dev/null
+++ b/gr-fft/grc/fft_ctrlport_probe_psd.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0"?>
+
+<!--
+ Copyright 2012 Free Software Foundation, Inc.
+
+ This file is part of GNU Radio
+
+ GNU Radio is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ GNU Radio is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNU Radio; see the file COPYING. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street,
+ Boston, MA 02110-1301, USA.
+-->
+
+<block>
+ <name>Ctrlport Probe PSD</name>
+ <key>fft_ctrlport_probe_psd</key>
+ <import>from gnuradio import fft</import>
+ <make>fft.ctrlport_probe_psd($name, $desc, $len)</make>
+ <callback>set_length($len)</callback>
+
+ <param>
+ <name>Name</name>
+ <key>name</key>
+ <value>psd</value>
+ <type>string</type>
+ </param>
+
+ <param>
+ <name>Description</name>
+ <key>desc</key>
+ <value>PSD Plot</value>
+ <type>string</type>
+ </param>
+
+ <param>
+ <name>Length</name>
+ <key>len</key>
+ <value>1024</value>
+ <type>int</type>
+ </param>
+
+
+ <sink>
+ <name>in</name>
+ <type>complex</type>
+ </sink>
+
+ <doc>
+ Place this in a graph to export PSD values to a GRCP port probe.
+ </doc>
+
+</block>
+
diff --git a/gr-fft/include/gnuradio/fft/CMakeLists.txt b/gr-fft/include/gnuradio/fft/CMakeLists.txt
index bce3da674d..1dfa220022 100644
--- a/gr-fft/include/gnuradio/fft/CMakeLists.txt
+++ b/gr-fft/include/gnuradio/fft/CMakeLists.txt
@@ -31,3 +31,11 @@ install(FILES
COMPONENT "fft_devel"
)
+if(ENABLE_GR_CTRLPORT)
+install(FILES
+ ctrlport_probe_psd.h
+ DESTINATION ${GR_INCLUDE_DIR}/gnuradio/fft
+ COMPONENT "fft_devel"
+)
+endif(ENABLE_GR_CTRLPORT)
+
diff --git a/gr-fft/include/gnuradio/fft/ctrlport_probe_psd.h b/gr-fft/include/gnuradio/fft/ctrlport_probe_psd.h
new file mode 100644
index 0000000000..5c872922c0
--- /dev/null
+++ b/gr-fft/include/gnuradio/fft/ctrlport_probe_psd.h
@@ -0,0 +1,66 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2012-2013 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_CTRLPORT_PROBE_PSD_H
+#define INCLUDED_CTRLPORT_PROBE_PSD_H
+
+#include <gnuradio/fft/api.h>
+#include <gnuradio/sync_block.h>
+
+namespace gr {
+ namespace fft {
+
+ /*!
+ * \brief A ControlPort probe to export vectors of signals.
+ * \ingroup measurement_tools_blk
+ * \ingroup controlport_blk
+ *
+ * \details
+ * This block acts as a sink in the flowgraph but also exports
+ * vectors of complex samples over ControlPort. This block holds
+ * the latest \p len number of complex samples so that every query
+ * by a ControlPort client will get the same length vector.
+ */
+ class FFT_API ctrlport_probe_psd : virtual public gr::sync_block
+ {
+ public:
+ typedef boost::shared_ptr<ctrlport_probe_psd> sptr;
+
+ /*!
+ * \brief Make a ControlPort probe block.
+ * \param id A string ID to name the probe over ControlPort.
+ * \param desc A string describing the probe.
+ * \param len Number of samples to transmit.
+ */
+ static sptr make(const std::string &id, const std::string &desc, int len);
+
+ virtual std::vector<gr_complex> get() = 0;
+
+ virtual void set_length(int len) = 0;
+ virtual int length() const = 0;
+ };
+
+ } /* namespace fft */
+} /* namespace gr */
+
+#endif /* INCLUDED_CTRLPORT_PROBE_PSD_H */
+
diff --git a/gr-fft/lib/CMakeLists.txt b/gr-fft/lib/CMakeLists.txt
index 20fb338465..c94d588f6a 100644
--- a/gr-fft/lib/CMakeLists.txt
+++ b/gr-fft/lib/CMakeLists.txt
@@ -48,6 +48,12 @@ list(APPEND fft_sources
goertzel.cc
)
+if(ENABLE_GR_CTRLPORT)
+list(APPEND fft_sources
+ ctrlport_probe_psd_impl.cc
+)
+endif(ENABLE_GR_CTRLPORT)
+
list(APPEND fft_libs
gnuradio-runtime
${Boost_LIBRARIES}
diff --git a/gr-fft/lib/ctrlport_probe_psd_impl.cc b/gr-fft/lib/ctrlport_probe_psd_impl.cc
new file mode 100644
index 0000000000..b517fa3ac4
--- /dev/null
+++ b/gr-fft/lib/ctrlport_probe_psd_impl.cc
@@ -0,0 +1,174 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2012-2013 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "ctrlport_probe_psd_impl.h"
+#include <gnuradio/io_signature.h>
+
+namespace gr {
+ namespace fft {
+
+ ctrlport_probe_psd::sptr
+ ctrlport_probe_psd::make(const std::string &id,
+ const std::string &desc, int len)
+ {
+ return gnuradio::get_initial_sptr
+ (new ctrlport_probe_psd_impl(id, desc, len));
+ }
+
+ ctrlport_probe_psd_impl::ctrlport_probe_psd_impl(const std::string &id,
+ const std::string &desc, int len)
+ : gr::sync_block("probe_psd",
+ gr::io_signature::make(1, 1, sizeof(gr_complex)),
+ gr::io_signature::make(0, 0, 0)),
+ d_id(id), d_desc(desc), d_len(len),
+ d_fft(len, true, 1)
+ {
+ set_length(len);
+ }
+
+ ctrlport_probe_psd_impl::~ctrlport_probe_psd_impl()
+ {
+ }
+
+ void
+ ctrlport_probe_psd_impl::forecast(int noutput_items,
+ gr_vector_int &ninput_items_required)
+ {
+ // make sure all inputs have noutput_items available
+ unsigned ninputs = ninput_items_required.size();
+ for(unsigned i = 0; i < ninputs; i++)
+ ninput_items_required[i] = d_len;
+ }
+
+ // boost::shared_mutex mutex_buffer;
+ // mutable boost::mutex mutex_notify;
+ // boost::condition_variable condition_buffer_ready;
+ std::vector<gr_complex>
+ ctrlport_probe_psd_impl::get()
+ {
+ mutex_buffer.lock();
+ d_buffer.clear();
+ mutex_buffer.unlock();
+
+ // wait for condition
+ boost::mutex::scoped_lock lock(mutex_notify);
+ condition_buffer_ready.wait(lock);
+
+ mutex_buffer.lock();
+
+ memcpy(d_fft.get_inbuf(), &d_buffer[0], d_len*sizeof(gr_complex));
+ d_fft.execute();
+ std::vector<gr_complex> buf_copy;
+
+ buf_copy.resize(d_len);
+
+ gr_complex* out = d_fft.get_outbuf();
+ for(size_t i=0; i<d_len; i++){
+ size_t idx = (i + d_len/2)%d_len;
+ float x = i/(d_len-1.0f)-0.5;
+ buf_copy[i] = gr_complex(x, 10*log10( (out[idx]*std::conj(out[idx])).real() ) );
+ }
+ mutex_buffer.unlock();
+ return buf_copy;
+ }
+
+ void
+ ctrlport_probe_psd_impl::set_length(int len)
+ {
+ if(len > 8191) {
+ std::cerr << "probe_psd: length " << len
+ << " exceeds maximum buffer size of 8191" << std::endl;
+ len = 8191;
+ }
+
+ d_len = len;
+ d_buffer.reserve(d_len);
+ }
+
+ int
+ ctrlport_probe_psd_impl::length() const
+ {
+ return (int)d_len;
+ }
+
+ int
+ ctrlport_probe_psd_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ const gr_complex *in = (const gr_complex*)input_items[0];
+
+ // copy samples to get buffer if we need samples
+ mutex_buffer.lock();
+ if(d_buffer.size() < d_len) {
+ // copy smaller of remaining buffer space and num inputs to work()
+ int num_copy = std::min( (int)(d_len - d_buffer.size()), noutput_items );
+
+ // TODO: convert this to a copy operator for speed...
+ for(int i = 0; i < num_copy; i++) {
+ d_buffer.push_back(in[i]);
+ }
+
+ // notify the waiting get() if we fill up the buffer
+ if(d_buffer.size() == d_len) {
+ condition_buffer_ready.notify_one();
+ }
+ }
+ mutex_buffer.unlock();
+
+ return noutput_items;
+ }
+
+ void
+ ctrlport_probe_psd_impl::setup_rpc()
+ {
+#ifdef GR_CTRLPORT
+ int len = static_cast<int>(d_len);
+ d_rpc_vars.push_back(
+ rpcbasic_sptr(new rpcbasic_register_get<ctrlport_probe_psd, std::vector<std::complex<float> > >(
+ alias(), d_id.c_str(), &ctrlport_probe_psd::get,
+ pmt::make_c32vector(0,-2),
+ pmt::make_c32vector(0,2),
+ pmt::make_c32vector(0,0),
+ "dB", d_desc.c_str(), RPC_PRIVLVL_MIN,
+ DISPXY | DISPOPTSCATTER)));
+
+ d_rpc_vars.push_back(
+ rpcbasic_sptr(new rpcbasic_register_get<ctrlport_probe_psd, int>(
+ alias(), "length", &ctrlport_probe_psd::length,
+ pmt::mp(1), pmt::mp(10*len), pmt::mp(len),
+ "samples", "get vector length", RPC_PRIVLVL_MIN, DISPNULL)));
+
+// d_rpc_vars.push_back(
+// rpcbasic_sptr(new rpcbasic_register_set<ctrlport_probe_psd, int>(
+// alias(), "length", &ctrlport_probe_psd::set_length,
+// pmt::mp(1), pmt::mp(10*len), pmt::mp(len),
+// "samples", "set vector length", RPC_PRIVLVL_MIN, DISPNULL)));
+#endif /* GR_CTRLPORT */
+ }
+
+ } /* namespace fft */
+} /* namespace gr */
diff --git a/gr-fft/lib/ctrlport_probe_psd_impl.h b/gr-fft/lib/ctrlport_probe_psd_impl.h
new file mode 100644
index 0000000000..c8277a4022
--- /dev/null
+++ b/gr-fft/lib/ctrlport_probe_psd_impl.h
@@ -0,0 +1,69 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2012-2013 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_CTRLPORT_PROBE_PSD_IMPL_H
+#define INCLUDED_CTRLPORT_PROBE_PSD_IMPL_H
+
+#include <gnuradio/fft/ctrlport_probe_psd.h>
+#include <gnuradio/rpcregisterhelpers.h>
+#include <boost/thread/shared_mutex.hpp>
+#include <gnuradio/fft/fft.h>
+
+namespace gr {
+ namespace fft {
+
+ class ctrlport_probe_psd_impl : public ctrlport_probe_psd
+ {
+ private:
+ std::string d_id;
+ std::string d_desc;
+ size_t d_len;
+ boost::shared_mutex mutex_buffer;
+ mutable boost::mutex mutex_notify;
+ boost::condition_variable condition_buffer_ready;
+
+ std::vector<gr_complex> d_buffer;
+ gr::fft::fft_complex d_fft;
+
+ public:
+ ctrlport_probe_psd_impl(const std::string &id, const std::string &desc, int len);
+ ~ctrlport_probe_psd_impl();
+
+ void setup_rpc();
+
+ void forecast(int noutput_items, gr_vector_int &ninput_items_required);
+
+ std::vector<gr_complex> get();
+
+ void set_length(int len);
+ int length() const;
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_CTRLPORT_PROBE_PSD_IMPL_H */
+
diff --git a/gr-fft/swig/fft_swig.i b/gr-fft/swig/fft_swig.i
index 860b400c28..edc3c594ac 100644
--- a/gr-fft/swig/fft_swig.i
+++ b/gr-fft/swig/fft_swig.i
@@ -40,3 +40,16 @@
GR_SWIG_BLOCK_MAGIC2(fft, fft_vcc);
GR_SWIG_BLOCK_MAGIC2(fft, fft_vfc);
GR_SWIG_BLOCK_MAGIC2(fft, goertzel_fc);
+
+#ifdef GR_CTRLPORT
+
+%{
+#include "gnuradio/fft/ctrlport_probe_psd.h"
+%}
+
+%include "gnuradio/fft/ctrlport_probe_psd.h"
+
+GR_SWIG_BLOCK_MAGIC2(fft, ctrlport_probe_psd);
+
+#endif /* GR_CTRLPORT */
+