From 1435ef5e0b8912088bcf62e27c59bbbc27718d26 Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Mon, 27 May 2019 18:41:15 +0000 Subject: [PATCH] - added messsage port - emit peak messages git-svn-id: http://moon:8086/svn/software/trunk/projects/GnuRadio@481 b431acfa-c32f-4a4a-93f1-934dc6c82436 --- gr-jay/grc/jay_peak_detect.xml | 5 ++ gr-jay/lib/peak_detect_impl.cc | 23 ++++++-- gr-jay/lib/peak_detect_impl.h | 8 ++- peak_det_eval.grc | 100 ++++++++++++++++++++++++++++++--- 4 files changed, 121 insertions(+), 15 deletions(-) diff --git a/gr-jay/grc/jay_peak_detect.xml b/gr-jay/grc/jay_peak_detect.xml index dc1e58b..857d652 100644 --- a/gr-jay/grc/jay_peak_detect.xml +++ b/gr-jay/grc/jay_peak_detect.xml @@ -79,4 +79,9 @@ float $vlen + + status + message + 1 + diff --git a/gr-jay/lib/peak_detect_impl.cc b/gr-jay/lib/peak_detect_impl.cc index 1a004b3..f85632e 100644 --- a/gr-jay/lib/peak_detect_impl.cc +++ b/gr-jay/lib/peak_detect_impl.cc @@ -72,7 +72,12 @@ namespace gr { std::stringstream str; str << name() << unique_id(); m_tag_id = pmt::string_to_symbol(str.str()); - + + m_msg_port_in = pmt::mp("msgIn"); + m_msg_port_out = pmt::mp("status"); + message_port_register_in(m_msg_port_in); + message_port_register_out(m_msg_port_out); + set_msg_handler(m_msg_port_in, boost::bind(&peak_detect_impl::set_msg, this, _1)); } /* @@ -284,17 +289,18 @@ namespace gr { Peak &peak = m_peakHistory[j]; peak.heightUpdate_rel(m_pXds, nitems_per_block); - if (peak.height_rel >= (m_peak_height_min-6.f)) + if (peak.height_rel >= (m_peak_height_min-10.f)) { temp.push_back(peak); } else { // Output OFF-tags + std::string msgStr(std::string("id=") + std::to_string(peak.id) + std::string(":pos=") + std::to_string(peak.pos) + std::string(":state=") + std::string("OFF")); pmt::pmt_t tag_key = pmt::string_to_symbol(std::string("peak")); - pmt::pmt_t tag_value = pmt::string_to_symbol(std::string("id=") + std::to_string(peak.id) + std::string(":pos=") + std::to_string(peak.pos) + std::string(":state=") + std::string("OFF")); + pmt::pmt_t tag_value = pmt::string_to_symbol(msgStr); add_item_tag(DATA, nitems_written(DATA) + k, tag_key, tag_value, m_tag_id); - fprintf(stderr, "Lost Peak #%u at %d\n", (int)peak.id, (int)peak.pos); + message_port_pub(m_msg_port_out, pmt::string_to_symbol(msgStr)); } } @@ -318,10 +324,15 @@ namespace gr { temp.push_back(peak); // Output ON-tags + std::string msgStr(std::string("id=") + std::to_string(peak.id) + std::string(":pos=") + std::to_string(peak.pos) + std::string(":state=") + std::string("ON")); pmt::pmt_t tag_key = pmt::string_to_symbol(std::string("peak")); - pmt::pmt_t tag_value = pmt::string_to_symbol(std::string("id=") + std::to_string(peak.id) + std::string(":pos=") + std::to_string(peak.pos) + std::string(":state=") + std::string("ON")); + pmt::pmt_t tag_value = pmt::string_to_symbol(msgStr); add_item_tag(DATA, nitems_written(DATA) + k, tag_key, tag_value, m_tag_id); - fprintf(stderr, "New Peak #%u at %d\n", (int)peak.id, (int)peak.pos); + +// pmt::pmt_t dict = pmt::make_dict(); +// pmt::dict_add(dict, pmt::string_to_symbol(std::string("id=")), pmt::from_long(peak.id)); +// message_port_pub(m_msg_port_out, dict); + message_port_pub(m_msg_port_out, pmt::string_to_symbol(msgStr)); } } diff --git a/gr-jay/lib/peak_detect_impl.h b/gr-jay/lib/peak_detect_impl.h index 28821f0..ca2bb71 100644 --- a/gr-jay/lib/peak_detect_impl.h +++ b/gr-jay/lib/peak_detect_impl.h @@ -172,7 +172,11 @@ namespace jay { }; private: - + void set_msg(pmt::pmt_t msg) + { + + } + Peak peakCheck(float const *pData, Peak const &peak, float thresh) { Peak result; @@ -219,6 +223,8 @@ namespace jay { std::vector m_peakHistory; std::vector temp; uint64_t m_peak_id; + pmt::pmt_t m_msg_port_in; + pmt::pmt_t m_msg_port_out; public: peak_detect_impl(int vlen, float framerate, float peak_height_min, int peak_width_min, int peak_width_max, float alpha_s, float alpha_m); diff --git a/peak_det_eval.grc b/peak_det_eval.grc index c1faf62..b64519a 100644 --- a/peak_det_eval.grc +++ b/peak_det_eval.grc @@ -323,6 +323,53 @@ counter_slider + + variable_qtgui_check_box + + comment + + + + value + 0 + + + _enabled + True + + + false + 0 + + + _coordinate + (656, 540) + + + gui_hint + + + + _rotation + 0 + + + id + variable_test_tone_scale + + + label + Test tones + + + true + 1 + + + type + int + + analog_noise_source_x @@ -398,7 +445,7 @@ _enabled - 1 + 0 _coordinate @@ -437,7 +484,7 @@ analog_sig_source_x amp - 0.1 + 0.1*variable_test_tone_scale alias @@ -500,7 +547,7 @@ analog_sig_source_x amp - variable_amp_2 + variable_amp_2*variable_test_tone_scale alias @@ -563,7 +610,7 @@ analog_sig_source_x amp - 0.5 + 0.5*variable_test_tone_scale alias @@ -716,6 +763,37 @@ N_FFT + + blocks_message_debug + + alias + + + + comment + + + + affinity + + + + _enabled + True + + + _coordinate + (856, 920) + + + _rotation + 0 + + + id + blocks_message_debug_0 + + blocks_multiply_const_vxx @@ -889,7 +967,7 @@ display - True + False _enabled @@ -897,7 +975,7 @@ _coordinate - (888, 708) + (888, 716) _rotation @@ -1200,7 +1278,7 @@ peak_height_min - 18 + 15 peak_width_max @@ -3284,7 +3362,7 @@ _enabled - 0 + 1 _coordinate @@ -3557,6 +3635,12 @@ 1 0 + + jay_peak_detect_1 + blocks_message_debug_0 + status + print + uhd_usrp_source_1 blocks_add_xx_0