diff options
Diffstat (limited to 'gr-qtgui/lib/time_raster_sink_f_impl.cc')
-rw-r--r-- | gr-qtgui/lib/time_raster_sink_f_impl.cc | 135 |
1 files changed, 110 insertions, 25 deletions
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 */ |