summaryrefslogtreecommitdiff
path: root/gr-qtgui/lib
diff options
context:
space:
mode:
authorTom Rondeau <tom@trondeau.com>2015-10-27 13:50:23 -0400
committerTom Rondeau <tom@trondeau.com>2015-10-29 16:21:03 -0400
commitbea941449edcb709f02f95c9f7cf1a47cd9d2ae8 (patch)
tree094bea3f3d53e9a35fb9619d52b727eb58c36436 /gr-qtgui/lib
parent253e6c3d8ab51eb8d660a0d8f881498c33b2bb1b (diff)
qtgui: time raster plotters support PDU message plotting.
Diffstat (limited to 'gr-qtgui/lib')
-rw-r--r--gr-qtgui/lib/TimeRasterDisplayPlot.cc4
-rw-r--r--gr-qtgui/lib/spectrumUpdateEvents.cc26
-rw-r--r--gr-qtgui/lib/time_raster_sink_b_impl.cc150
-rw-r--r--gr-qtgui/lib/time_raster_sink_b_impl.h7
-rw-r--r--gr-qtgui/lib/time_raster_sink_f_impl.cc135
-rw-r--r--gr-qtgui/lib/time_raster_sink_f_impl.h7
-rw-r--r--gr-qtgui/lib/timerasterdisplayform.cc7
7 files changed, 282 insertions, 54 deletions
diff --git a/gr-qtgui/lib/TimeRasterDisplayPlot.cc b/gr-qtgui/lib/TimeRasterDisplayPlot.cc
index e5e18b769f..201b470d21 100644
--- a/gr-qtgui/lib/TimeRasterDisplayPlot.cc
+++ b/gr-qtgui/lib/TimeRasterDisplayPlot.cc
@@ -457,7 +457,9 @@ TimeRasterDisplayPlot::replot()
((TimeRasterZoomer*)d_zoomer)->updateTrackerText();
}
- QwtPlot::replot();
+ if(!d_stop) {
+ QwtPlot::replot();
+ }
}
int
diff --git a/gr-qtgui/lib/spectrumUpdateEvents.cc b/gr-qtgui/lib/spectrumUpdateEvents.cc
index 1294587409..60e07fc644 100644
--- a/gr-qtgui/lib/spectrumUpdateEvents.cc
+++ b/gr-qtgui/lib/spectrumUpdateEvents.cc
@@ -473,6 +473,32 @@ TimeRasterUpdateEvent::getNumDataPoints() const
return _numDataPoints;
}
+
+
+
+TimeRasterSetSize::TimeRasterSetSize(const double nrows,
+ const double ncols)
+ : QEvent(QEvent::Type(SpectrumUpdateEventType+1)),
+ _nrows(nrows), _ncols(ncols)
+{
+}
+
+TimeRasterSetSize::~TimeRasterSetSize()
+{
+}
+
+double
+TimeRasterSetSize::nRows() const
+{
+ return _nrows;
+}
+
+double
+TimeRasterSetSize::nCols() const
+{
+ return _ncols;
+}
+
/***************************************************************************/
diff --git a/gr-qtgui/lib/time_raster_sink_b_impl.cc b/gr-qtgui/lib/time_raster_sink_b_impl.cc
index afc5e90e2d..cb35eb77ce 100644
--- a/gr-qtgui/lib/time_raster_sink_b_impl.cc
+++ b/gr-qtgui/lib/time_raster_sink_b_impl.cc
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2012,2013 Free Software Foundation, Inc.
+ * Copyright 2012,2013,2015 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -59,12 +59,12 @@ namespace gr {
int nconnections,
QWidget *parent)
: sync_block("time_raster_sink_b",
- io_signature::make(1, -1, sizeof(char)),
+ io_signature::make(0, nconnections, sizeof(char)),
io_signature::make(0, 0, 0)),
d_name(name), d_nconnections(nconnections), d_parent(parent),
d_rows(rows), d_cols(cols),
- d_mult(std::vector<float>(nconnections,1)),
- d_offset(std::vector<float>(nconnections,0)),
+ d_mult(std::vector<float>(nconnections+1,1)),
+ d_offset(std::vector<float>(nconnections+1,0)),
d_samp_rate(samp_rate)
{
// Required now for Qt; argc must be greater than 0 and argv
@@ -79,6 +79,11 @@ namespace gr {
d_index = 0;
+ // setup PDU handling input port
+ message_port_register_in(pmt::mp("pdus"));
+ set_msg_handler(pmt::mp("pdus"),
+ boost::bind(&time_raster_sink_b_impl::handle_pdus, this, _1));
+
d_scale = 1.0f;
d_icols = static_cast<int>(ceil(d_cols));
@@ -86,7 +91,8 @@ namespace gr {
volk_get_alignment());
memset(d_tmpflt, 0, d_icols*sizeof(float));
- for(int i = 0; i < d_nconnections; i++) {
+ // +1 for the PDU buffer
+ for(int i = 0; i < d_nconnections+1; i++) {
d_residbufs.push_back((double*)volk_malloc(d_icols*sizeof(double),
volk_get_alignment()));
memset(d_residbufs[i], 0, d_icols*sizeof(double));
@@ -104,7 +110,7 @@ namespace gr {
d_main_gui->close();
volk_free(d_tmpflt);
- for(int i = 0; i < d_nconnections; i++) {
+ for(int i = 0; i < d_nconnections+1; i++) {
volk_free(d_residbufs[i]);
}
@@ -142,7 +148,8 @@ namespace gr {
// and 0's from each stream, so we set the maximum intensity
// (zmax) to the number of connections so after adding the
// streams, the max will the the max of 1's from all streams.
- d_main_gui = new TimeRasterDisplayForm(d_nconnections,
+ int numplots = (d_nconnections > 0) ? d_nconnections : 1;
+ d_main_gui = new TimeRasterDisplayForm(numplots,
d_samp_rate,
d_rows, d_cols,
1, d_parent);
@@ -262,7 +269,28 @@ namespace gr {
void
time_raster_sink_b_impl::set_num_cols(double cols)
{
- d_main_gui->setNumCols(cols);
+ if(d_cols != cols) {
+ gr::thread::scoped_lock lock(d_setlock);
+
+ d_qApplication->postEvent(d_main_gui,
+ new TimeRasterSetSize(d_rows, cols));
+
+ d_cols = cols;
+ d_icols = static_cast<int>(ceil(d_cols));
+
+ volk_free(d_tmpflt);
+ d_tmpflt = (float*)volk_malloc(d_icols*sizeof(float),
+ volk_get_alignment());
+ memset(d_tmpflt, 0, d_icols*sizeof(float));
+
+ for(int i = 0; i < d_nconnections+1; i++) {
+ volk_free(d_residbufs[i]);
+ d_residbufs[i] = (double*)volk_malloc(d_icols*sizeof(double),
+ volk_get_alignment());
+ memset(d_residbufs[i], 0, d_icols*sizeof(double));
+ }
+ reset();
+ }
}
std::string
@@ -329,7 +357,7 @@ namespace gr {
time_raster_sink_b_impl::set_multiplier(const std::vector<float> &mult)
{
if(mult.size() == 0) {
- for(int i = 0; i < d_nconnections; i++) {
+ for(int i = 0; i < d_nconnections+1; i++) {
d_mult[i] = 1.0f;
}
}
@@ -338,6 +366,11 @@ namespace gr {
d_mult[i] = mult[i];
}
}
+ else if(mult.size() == (size_t)d_nconnections+1) {
+ for(int i = 0; i < d_nconnections+1; i++) {
+ d_mult[i] = mult[i];
+ }
+ }
else {
throw std::runtime_error("time_raster_sink_b_impl::set_multiplier incorrect dimensions.\n");
}
@@ -347,7 +380,7 @@ namespace gr {
time_raster_sink_b_impl::set_offset(const std::vector<float> &offset)
{
if(offset.size() == 0) {
- for(int i = 0; i < d_nconnections; i++) {
+ for(int i = 0; i < d_nconnections+1; i++) {
d_offset[i] = 0.0f;
}
}
@@ -356,6 +389,11 @@ namespace gr {
d_offset[i] = offset[i];
}
}
+ else if(offset.size() == (size_t)d_nconnections+1) {
+ for(int i = 0; i < d_nconnections+1; i++) {
+ d_offset[i] = offset[i];
+ }
+ }
else {
throw std::runtime_error("time_raster_sink_b_impl::set_offset incorrect dimensions.\n");
}
@@ -391,6 +429,13 @@ namespace gr {
d_index = 0;
}
+ void
+ time_raster_sink_b_impl::_ncols_resize()
+ {
+ double cols = d_main_gui->numCols();
+ set_num_cols(cols);
+ }
+
int
time_raster_sink_b_impl::work(int noutput_items,
gr_vector_const_void_star &input_items,
@@ -399,22 +444,7 @@ namespace gr {
int n=0, j=0, idx=0;
const int8_t *in = (const int8_t*)input_items[0];
- unsigned int cols = d_main_gui->numCols();
- if(d_cols != cols) {
- d_cols = cols;
- d_index = 0;
- d_icols = static_cast<int>(ceil(d_cols));
- volk_free(d_tmpflt);
- d_tmpflt = (float*)volk_malloc(d_icols*sizeof(float),
- volk_get_alignment());
- memset(d_tmpflt, 0, d_icols*sizeof(float));
- for(int i = 0; i < d_nconnections; i++) {
- volk_free(d_residbufs[i]);
- d_residbufs[i] = (double*)volk_malloc(d_icols*sizeof(double),
- volk_get_alignment());
- memset(d_residbufs[i], 0, d_icols*sizeof(double));
- }
- }
+ _ncols_resize();
for(int i = 0; i < noutput_items; i += d_icols) {
unsigned int datasize = noutput_items - i;
@@ -472,5 +502,73 @@ namespace gr {
return j;
}
+
+ void
+ time_raster_sink_b_impl::handle_pdus(pmt::pmt_t msg)
+ {
+ size_t len;
+ pmt::pmt_t dict, samples;
+
+ // Test to make sure this is either a PDU or a uniform vector of
+ // samples. Get the samples PMT and the dictionary if it's a PDU.
+ // If not, we throw an error and exit.
+ if(pmt::is_pair(msg)) {
+ dict = pmt::car(msg);
+ samples = pmt::cdr(msg);
+ }
+ else if(pmt::is_uniform_vector(msg)) {
+ samples = msg;
+ }
+ else {
+ throw std::runtime_error("time_sink_c: message must be either "
+ "a PDU or a uniform vector of samples.");
+ }
+
+ len = pmt::length(samples);
+
+ const int8_t *in;
+ if(pmt::is_s8vector(samples)) {
+ in = (const int8_t*)pmt::s8vector_elements(samples, len);
+ }
+ else if(pmt::is_u8vector(samples)) {
+ in = (const int8_t*)pmt::u8vector_elements(samples, len);
+ }
+ else {
+ throw std::runtime_error("time_raster_sink_b: unknown data type "
+ "of samples; must be char ({u}int8_t).");
+ }
+
+ // Plot if we're past the last update time
+ if(gr::high_res_timer_now() - d_last_time > d_update_time) {
+ d_last_time = gr::high_res_timer_now();
+
+ _ncols_resize();
+
+ d_rows = ceil(static_cast<double>(len) / static_cast<double>(d_cols));
+ int irows = static_cast<int>(d_rows);
+
+ d_qApplication->postEvent(d_main_gui,
+ new TimeRasterSetSize(d_rows, d_cols));
+
+ int idx = 0;
+ for(int r = 0; r < irows; r++) {
+ // Scale and add offset
+ int cpy_len = std::min(static_cast<size_t>(d_cols), len - idx);
+ memset(d_residbufs[d_nconnections], 0, d_cols*sizeof(double));
+ volk_8i_s32f_convert_32f(d_tmpflt, &in[idx], d_scale, cpy_len);
+ volk_32f_s32f_multiply_32f(d_tmpflt, d_tmpflt, d_mult[d_nconnections], cpy_len);
+ for(int c = 0; c < cpy_len; c++) {
+ d_tmpflt[c] = d_tmpflt[c] + d_offset[d_nconnections];
+ }
+
+ volk_32f_convert_64f_u(d_residbufs[d_nconnections], d_tmpflt, cpy_len);
+
+ d_qApplication->postEvent(d_main_gui,
+ new TimeRasterUpdateEvent(d_residbufs, d_cols));
+ idx += d_cols;
+ }
+ }
+ }
+
} /* namespace qtgui */
} /* namespace gr */
diff --git a/gr-qtgui/lib/time_raster_sink_b_impl.h b/gr-qtgui/lib/time_raster_sink_b_impl.h
index ba4b282194..4da6990a18 100644
--- a/gr-qtgui/lib/time_raster_sink_b_impl.h
+++ b/gr-qtgui/lib/time_raster_sink_b_impl.h
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2012,2013 Free Software Foundation, Inc.
+ * Copyright 2012,2013,2015 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -60,6 +60,11 @@ namespace gr {
gr::high_res_timer_type d_update_time;
gr::high_res_timer_type d_last_time;
+ void _ncols_resize();
+
+ // Handles message input port for displaying PDU samples.
+ void handle_pdus(pmt::pmt_t msg);
+
public:
time_raster_sink_b_impl(double samp_rate,
double rows, double cols,
diff --git a/gr-qtgui/lib/time_raster_sink_f_impl.cc b/gr-qtgui/lib/time_raster_sink_f_impl.cc
index 7d271abb20..df83bad006 100644
--- a/gr-qtgui/lib/time_raster_sink_f_impl.cc
+++ b/gr-qtgui/lib/time_raster_sink_f_impl.cc
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2012,2013 Free Software Foundation, Inc.
+ * Copyright 2012,2013,2015 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -59,12 +59,12 @@ namespace gr {
int nconnections,
QWidget *parent)
: sync_block("time_raster_sink_f",
- io_signature::make(1, -1, sizeof(float)),
- io_signature::make(0, 0, 0)),
+ io_signature::make(0, nconnections, sizeof(float)),
+ io_signature::make(0, 0, 0)),
d_name(name), d_nconnections(nconnections), d_parent(parent),
d_rows(rows), d_cols(cols),
- d_mult(std::vector<float>(nconnections,1)),
- d_offset(std::vector<float>(nconnections,0)),
+ d_mult(std::vector<float>(nconnections+1,1)),
+ d_offset(std::vector<float>(nconnections+1,0)),
d_samp_rate(samp_rate)
{
// Required now for Qt; argc must be greater than 0 and argv
@@ -79,12 +79,18 @@ namespace gr {
d_index = 0;
+ // setup PDU handling input port
+ message_port_register_in(pmt::mp("pdus"));
+ set_msg_handler(pmt::mp("pdus"),
+ boost::bind(&time_raster_sink_f_impl::handle_pdus, this, _1));
+
d_icols = static_cast<int>(ceil(d_cols));
d_tmpflt = (float*)volk_malloc(d_icols*sizeof(float),
volk_get_alignment());
memset(d_tmpflt, 0, d_icols*sizeof(float));
- for(int i = 0; i < d_nconnections; i++) {
+ // +1 for the PDU buffer
+ for(int i = 0; i < d_nconnections+1; i++) {
d_residbufs.push_back((double*)volk_malloc(d_icols*sizeof(double),
volk_get_alignment()));
memset(d_residbufs[i], 0, d_icols*sizeof(double));
@@ -102,7 +108,7 @@ namespace gr {
d_main_gui->close();
volk_free(d_tmpflt);
- for(int i = 0; i < d_nconnections; i++) {
+ for(int i = 0; i < d_nconnections+1; i++) {
volk_free(d_residbufs[i]);
}
@@ -140,7 +146,8 @@ namespace gr {
// and 0's from each stream, so we set the maximum intensity
// (zmax) to the number of connections so after adding the
// streams, the max will the the max of 1's from all streams.
- d_main_gui = new TimeRasterDisplayForm(d_nconnections,
+ int numplots = (d_nconnections > 0) ? d_nconnections : 1;
+ d_main_gui = new TimeRasterDisplayForm(numplots,
d_samp_rate,
d_rows, d_cols,
1, d_parent);
@@ -254,13 +261,36 @@ namespace gr {
void
time_raster_sink_f_impl::set_num_rows(double rows)
{
+ gr::thread::scoped_lock lock(d_setlock);
+ d_rows = rows;
d_main_gui->setNumRows(rows);
}
void
time_raster_sink_f_impl::set_num_cols(double cols)
{
- d_main_gui->setNumCols(cols);
+ if(d_cols != cols) {
+ gr::thread::scoped_lock lock(d_setlock);
+
+ d_qApplication->postEvent(d_main_gui,
+ new TimeRasterSetSize(d_rows, cols));
+
+ d_cols = cols;
+ d_icols = static_cast<int>(ceil(d_cols));
+
+ volk_free(d_tmpflt);
+ d_tmpflt = (float*)volk_malloc(d_icols*sizeof(float),
+ volk_get_alignment());
+ memset(d_tmpflt, 0, d_icols*sizeof(float));
+
+ for(int i = 0; i < d_nconnections+1; i++) {
+ volk_free(d_residbufs[i]);
+ d_residbufs[i] = (double*)volk_malloc(d_icols*sizeof(double),
+ volk_get_alignment());
+ memset(d_residbufs[i], 0, d_icols*sizeof(double));
+ }
+ reset();
+ }
}
std::string
@@ -389,6 +419,13 @@ namespace gr {
d_index = 0;
}
+ void
+ time_raster_sink_f_impl::_ncols_resize()
+ {
+ double cols = d_main_gui->numCols();
+ set_num_cols(cols);
+ }
+
int
time_raster_sink_f_impl::work(int noutput_items,
gr_vector_const_void_star &input_items,
@@ -397,22 +434,7 @@ namespace gr {
int n=0, j=0, idx=0;
const float *in = (const float*)input_items[0];
- double cols = d_main_gui->numCols();
- if(d_cols != cols) {
- d_cols = cols;
- d_index = 0;
- d_icols = static_cast<int>(ceil(d_cols));
- volk_free(d_tmpflt);
- d_tmpflt = (float*)volk_malloc(d_icols*sizeof(float),
- volk_get_alignment());
- memset(d_tmpflt, 0, d_icols*sizeof(float));
- for(int i = 0; i < d_nconnections; i++) {
- volk_free(d_residbufs[i]);
- d_residbufs[i] = (double*)volk_malloc(d_icols*sizeof(double),
- volk_get_alignment());
- memset(d_residbufs[i], 0, d_icols*sizeof(double));
- }
- }
+ _ncols_resize();
for(int i = 0; i < noutput_items; i += d_icols) {
unsigned int datasize = noutput_items - i;
@@ -467,5 +489,68 @@ namespace gr {
return j;
}
+ void
+ time_raster_sink_f_impl::handle_pdus(pmt::pmt_t msg)
+ {
+ size_t len;
+ pmt::pmt_t dict, samples;
+
+ // Test to make sure this is either a PDU or a uniform vector of
+ // samples. Get the samples PMT and the dictionary if it's a PDU.
+ // If not, we throw an error and exit.
+ if(pmt::is_pair(msg)) {
+ dict = pmt::car(msg);
+ samples = pmt::cdr(msg);
+ }
+ else if(pmt::is_uniform_vector(msg)) {
+ samples = msg;
+ }
+ else {
+ throw std::runtime_error("time_sink_c: message must be either "
+ "a PDU or a uniform vector of samples.");
+ }
+
+ len = pmt::length(samples);
+
+ const float *in;
+ if(pmt::is_f32vector(samples)) {
+ in = (const float*)pmt::f32vector_elements(samples, len);
+ }
+ else {
+ throw std::runtime_error("time_raster_sink_f: unknown data type "
+ "of samples; must be float.");
+ }
+
+ // Plot if we're past the last update time
+ if(gr::high_res_timer_now() - d_last_time > d_update_time) {
+ d_last_time = gr::high_res_timer_now();
+
+ _ncols_resize();
+
+ d_rows = ceil(static_cast<double>(len) / static_cast<double>(d_cols));
+ int irows = static_cast<int>(d_rows);
+
+ d_qApplication->postEvent(d_main_gui,
+ new TimeRasterSetSize(d_rows, d_cols));
+
+ int idx = 0;
+ for(int r = 0; r < irows; r++) {
+ // Scale and add offset
+ int cpy_len = std::min(static_cast<size_t>(d_cols), len - idx);
+ memset(d_residbufs[d_nconnections], 0, d_cols*sizeof(double));
+ volk_32f_s32f_multiply_32f(d_tmpflt, &in[idx], d_mult[d_nconnections], cpy_len);
+ for(int c = 0; c < cpy_len; c++) {
+ d_tmpflt[c] = d_tmpflt[c] + d_offset[d_nconnections];
+ }
+
+ volk_32f_convert_64f_u(d_residbufs[d_nconnections], d_tmpflt, cpy_len);
+
+ d_qApplication->postEvent(d_main_gui,
+ new TimeRasterUpdateEvent(d_residbufs, d_cols));
+ idx += d_cols;
+ }
+ }
+ }
+
} /* namespace qtgui */
} /* namespace gr */
diff --git a/gr-qtgui/lib/time_raster_sink_f_impl.h b/gr-qtgui/lib/time_raster_sink_f_impl.h
index 66f4465f0e..ad63e4d777 100644
--- a/gr-qtgui/lib/time_raster_sink_f_impl.h
+++ b/gr-qtgui/lib/time_raster_sink_f_impl.h
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2012,2013 Free Software Foundation, Inc.
+ * Copyright 2012,2013,2015 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -59,6 +59,11 @@ namespace gr {
gr::high_res_timer_type d_update_time;
gr::high_res_timer_type d_last_time;
+ void _ncols_resize();
+
+ // Handles message input port for displaying PDU samples.
+ void handle_pdus(pmt::pmt_t msg);
+
public:
time_raster_sink_f_impl(double samp_rate,
double rows, double cols,
diff --git a/gr-qtgui/lib/timerasterdisplayform.cc b/gr-qtgui/lib/timerasterdisplayform.cc
index eb5405d112..9582f02973 100644
--- a/gr-qtgui/lib/timerasterdisplayform.cc
+++ b/gr-qtgui/lib/timerasterdisplayform.cc
@@ -183,6 +183,13 @@ TimeRasterDisplayForm::customEvent( QEvent * e)
if(e->type() == TimeRasterUpdateEvent::Type()) {
newData(e);
}
+ else if(e->type() == TimeRasterSetSize::Type()) {
+ double r = ((TimeRasterSetSize*)e)->nRows();
+ double c = ((TimeRasterSetSize*)e)->nCols();
+ getPlot()->setNumRows(r);
+ getPlot()->setNumCols(c);
+ getPlot()->replot();
+ }
}
void