[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 01/01: qtgui: fixed an issue with the numbe
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 01/01: qtgui: fixed an issue with the number sink mistreating non-float inputs. |
Date: |
Thu, 16 Oct 2014 16:55:06 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
trondeau pushed a commit to branch maint
in repository gnuradio.
commit ba0bb94b06d56083e51e237d5e2987140f3bf610
Author: Tom Rondeau <address@hidden>
Date: Thu Oct 16 12:53:19 2014 -0400
qtgui: fixed an issue with the number sink mistreating non-float inputs.
Dealing with ints will require an api change.
---
gr-qtgui/include/gnuradio/qtgui/number_sink.h | 20 +++++++++++++++-
gr-qtgui/lib/number_sink_impl.cc | 34 +++++++++++++++++++++++----
gr-qtgui/lib/number_sink_impl.h | 2 ++
3 files changed, 51 insertions(+), 5 deletions(-)
diff --git a/gr-qtgui/include/gnuradio/qtgui/number_sink.h
b/gr-qtgui/include/gnuradio/qtgui/number_sink.h
index c814100..3d6647c 100644
--- a/gr-qtgui/include/gnuradio/qtgui/number_sink.h
+++ b/gr-qtgui/include/gnuradio/qtgui/number_sink.h
@@ -42,7 +42,25 @@ namespace gr {
* \ingroup qtgui_blk
*
* \details
- * Number sink
+ *
+ * Displays the data stream in as a number in a simple text box
+ * GUI along with an optional bar graph. The bar graph can be set
+ * to horizontal (NUM_GRAPH_HORIZ), vertical (NUM_GRAPH_VERT), or
+ * no graph (NUM_GRAPH_NONE).
+ *
+ * The displayed value can be the average of the input stream, in
+ * which case all items received are averaged. If not averaging,
+ * the display simply samples a value in the data stream based on
+ * the update time of this block.
+ *
+ * Note that due to a flaw in the implementation, this block
+ * cannot receive integer value inputs. It will take chars,
+ * shorts, and floats and properly convert them by setting
+ * itemsize of the constructor to one of these three values
+ * (sizeof_char, sizeof_short, and sizeof_float, respectively). If
+ * using integers, the block treats these as floats. Instead, put
+ * the integer input stream through an gr::blocks::int_to_float
+ * converter block.
*/
class QTGUI_API number_sink : virtual public sync_block
{
diff --git a/gr-qtgui/lib/number_sink_impl.cc b/gr-qtgui/lib/number_sink_impl.cc
index 16e8d20..ea07c5d 100644
--- a/gr-qtgui/lib/number_sink_impl.cc
+++ b/gr-qtgui/lib/number_sink_impl.cc
@@ -328,6 +328,32 @@ namespace gr {
}
}
+ float
+ number_sink_impl::get_item(const void *input_items, int n)
+ {
+ char *inc;
+ short *ins;
+ float *inf;
+
+ switch(d_itemsize) {
+ case(1):
+ inc = (char*)input_items;
+ return static_cast<float>(inc[n]);
+ break;
+ case(2):
+ ins = (short*)input_items;
+ return static_cast<float>(ins[n]);
+ break;
+ case(4):
+ inf = (float*)input_items;
+ return static_cast<float>(inf[n]);
+ break;
+ default:
+ throw std::runtime_error("item size not supported");
+ }
+ return 0;
+ }
+
int
number_sink_impl::work(int noutput_items,
gr_vector_const_void_star &input_items,
@@ -339,10 +365,10 @@ namespace gr {
if(d_average > 0) {
for(int n = 0; n < d_nconnections; n++) {
- float *in = (float*)input_items[n];
for(int i = 0; i < noutput_items; i++) {
- if(std::isfinite(in[i]))
- d_avg_value[n] = d_iir[n].filter(in[i]);
+ float x = get_item(input_items[n], i);
+ if(std::isfinite(x))
+ d_avg_value[n] = d_iir[n].filter(x);
}
}
}
@@ -357,7 +383,7 @@ namespace gr {
}
else {
for(int n = 0; n < d_nconnections; n++) {
- float x = ((float*)input_items[n])[0];
+ float x = get_item(input_items[n], 0);
if(std::isfinite(x))
d[n] = x;
}
diff --git a/gr-qtgui/lib/number_sink_impl.h b/gr-qtgui/lib/number_sink_impl.h
index 0e357ef..a580935 100644
--- a/gr-qtgui/lib/number_sink_impl.h
+++ b/gr-qtgui/lib/number_sink_impl.h
@@ -60,6 +60,8 @@ namespace gr {
void _npoints_resize();
void _gui_update_trigger();
+ float get_item(const void *input_items, int n);
+
public:
number_sink_impl(size_t itemsize,
float average=0,