- added and modified
git-svn-id: http://moon:8086/svn/software/trunk/projects/GnuRadio@505 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
@@ -27,5 +27,6 @@ install(FILES
|
|||||||
jay_peak_detect.xml
|
jay_peak_detect.xml
|
||||||
jay_message_debug.xml
|
jay_message_debug.xml
|
||||||
jay_peak_manager.xml
|
jay_peak_manager.xml
|
||||||
jay_squelch.xml DESTINATION share/gnuradio/grc/blocks
|
jay_squelch.xml
|
||||||
|
jay_message_filter.xml DESTINATION share/gnuradio/grc/blocks
|
||||||
)
|
)
|
||||||
|
|||||||
+26
-19
@@ -64,12 +64,6 @@ namespace gr {
|
|||||||
pmt::pmt_t key = pmt::car(pair);
|
pmt::pmt_t key = pmt::car(pair);
|
||||||
pmt::pmt_t val = pmt::cdr(pair);
|
pmt::pmt_t val = pmt::cdr(pair);
|
||||||
|
|
||||||
if (pmt::symbol_to_string(key) == std::string("gain"))
|
|
||||||
{
|
|
||||||
float gain_dB = pmt::to_float(val) - 50.f;
|
|
||||||
m_gain_target = std::pow(10.f, gain_dB/10);
|
|
||||||
fprintf(stderr, "Set gain to %0.2f\n", m_gain_target);
|
|
||||||
}
|
|
||||||
if (pmt::is_integer(val))
|
if (pmt::is_integer(val))
|
||||||
{
|
{
|
||||||
fprintf(stderr, "[%s=%d]", pmt::symbol_to_string(key).c_str(), (int)pmt::to_long(val));
|
fprintf(stderr, "[%s=%d]", pmt::symbol_to_string(key).c_str(), (int)pmt::to_long(val));
|
||||||
@@ -84,25 +78,38 @@ namespace gr {
|
|||||||
}
|
}
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void squelch_impl::check_pair(pmt::pmt_t pair)
|
||||||
|
{
|
||||||
|
pmt::pmt_t key = pmt::car(pair);
|
||||||
|
pmt::pmt_t val = pmt::cdr(pair);
|
||||||
|
|
||||||
|
// Check pair for data
|
||||||
|
if (pmt::symbol_to_string(key) == std::string("gain"))
|
||||||
|
{
|
||||||
|
float gain_dB = pmt::to_float(val) - 40.f;
|
||||||
|
m_gain_target = std::pow(10.f, gain_dB/10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void squelch_impl::on_message(pmt::pmt_t msg)
|
void squelch_impl::on_message(pmt::pmt_t msg)
|
||||||
{
|
{
|
||||||
if (pmt::is_pair(msg))
|
if (pmt::is_dict(msg))
|
||||||
{
|
|
||||||
print_pair(msg);
|
|
||||||
}
|
|
||||||
else if (pmt::is_dict(msg))
|
|
||||||
{
|
{
|
||||||
pmt::pmt_t items = pmt::dict_items(msg);
|
pmt::pmt_t items = pmt::dict_items(msg);
|
||||||
for (int i=0; i < pmt::length(items); i++)
|
try
|
||||||
{
|
{
|
||||||
pmt::pmt_t pair = pmt::nth(i, items);
|
size_t len_items = pmt::length(items);
|
||||||
print_pair(pair);
|
for (int i=0; i < len_items; i++)
|
||||||
|
{
|
||||||
|
pmt::pmt_t pair = pmt::nth(i, items);
|
||||||
|
check_pair(pair);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const std::exception& e)
|
||||||
|
{
|
||||||
|
check_pair(msg);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fprintf(stderr, "%s\n", pmt::symbol_to_string(msg).c_str());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ namespace gr {
|
|||||||
~squelch_impl();
|
~squelch_impl();
|
||||||
void print_pair(pmt::pmt_t pair);
|
void print_pair(pmt::pmt_t pair);
|
||||||
void on_message(pmt::pmt_t msg);
|
void on_message(pmt::pmt_t msg);
|
||||||
|
void check_pair(pmt::pmt_t pair);
|
||||||
|
|
||||||
// Where all the action really happens
|
// Where all the action really happens
|
||||||
int work(int noutput_items,
|
int work(int noutput_items,
|
||||||
|
|||||||
@@ -32,7 +32,8 @@ endif()
|
|||||||
GR_PYTHON_INSTALL(
|
GR_PYTHON_INSTALL(
|
||||||
FILES
|
FILES
|
||||||
__init__.py
|
__init__.py
|
||||||
peak_manager.py DESTINATION ${GR_PYTHON_DIR}/jay
|
peak_manager.py
|
||||||
|
message_filter.py DESTINATION ${GR_PYTHON_DIR}/jay
|
||||||
)
|
)
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
@@ -52,3 +53,4 @@ GR_ADD_TEST(qa_peak_detect ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_p
|
|||||||
GR_ADD_TEST(qa_message_debug ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_message_debug.py)
|
GR_ADD_TEST(qa_message_debug ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_message_debug.py)
|
||||||
GR_ADD_TEST(qa_peak_manager ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_peak_manager.py)
|
GR_ADD_TEST(qa_peak_manager ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_peak_manager.py)
|
||||||
GR_ADD_TEST(qa_squelch ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_squelch.py)
|
GR_ADD_TEST(qa_squelch ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_squelch.py)
|
||||||
|
GR_ADD_TEST(qa_message_filter ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_message_filter.py)
|
||||||
|
|||||||
@@ -32,4 +32,5 @@ except ImportError:
|
|||||||
|
|
||||||
# import any pure python here
|
# import any pure python here
|
||||||
from peak_manager import peak_manager
|
from peak_manager import peak_manager
|
||||||
|
from message_filter import message_filter
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright 2019 Jay Arrowfield.
|
||||||
|
#
|
||||||
|
# This 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.
|
||||||
|
#
|
||||||
|
# This software 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 this software; see the file COPYING. If not, write to
|
||||||
|
# the Free Software Foundation, Inc., 51 Franklin Street,
|
||||||
|
# Boston, MA 02110-1301, USA.
|
||||||
|
#
|
||||||
|
|
||||||
|
import numpy
|
||||||
|
import pmt
|
||||||
|
from gnuradio import gr
|
||||||
|
|
||||||
|
class message_filter(gr.basic_block):
|
||||||
|
"""
|
||||||
|
docstring for block message_filter
|
||||||
|
"""
|
||||||
|
def __init__(self, filter='freq'):
|
||||||
|
gr.basic_block.__init__(self,
|
||||||
|
name="message_filter",
|
||||||
|
in_sig=None,
|
||||||
|
out_sig=None)
|
||||||
|
|
||||||
|
self.filter = filter
|
||||||
|
|
||||||
|
# Register in / out message ports
|
||||||
|
self.port_in = pmt.intern("in")
|
||||||
|
self.port_out = pmt.intern("out")
|
||||||
|
|
||||||
|
self.message_port_register_in(self.port_in)
|
||||||
|
self.message_port_register_out(self.port_out)
|
||||||
|
|
||||||
|
# Register in message handler
|
||||||
|
self.set_msg_handler(self.port_in, self.msg_handler)
|
||||||
|
|
||||||
|
def delegate_pair(self, pair):
|
||||||
|
key = pmt.car(pair)
|
||||||
|
key_str = pmt.symbol_to_string(key)
|
||||||
|
|
||||||
|
if self.filter in key_str:
|
||||||
|
self.message_port_pub(self.port_out, pair)
|
||||||
|
|
||||||
|
def msg_handler(self, msg):
|
||||||
|
# Üble Verrenkungen, um fest zu stellen of dict oder pair
|
||||||
|
if pmt.is_dict(msg):
|
||||||
|
items = pmt.dict_items(msg)
|
||||||
|
try:
|
||||||
|
# Dict, wenn len_items > 1
|
||||||
|
len_items = pmt.length(items)
|
||||||
|
|
||||||
|
# Iterate through dict to get single pairs
|
||||||
|
for n in range(0, len_items):
|
||||||
|
pair = pmt.nth(n, items)
|
||||||
|
self.delegate_pair(pair)
|
||||||
|
except:
|
||||||
|
# Wrong Type exception -> pair
|
||||||
|
self.delegate_pair(msg)
|
||||||
|
|
||||||
|
|
||||||
|
def forecast(self, noutput_items, ninput_items_required):
|
||||||
|
#setup size of input_items[i] for work call
|
||||||
|
for i in range(len(ninput_items_required)):
|
||||||
|
ninput_items_required[i] = noutput_items
|
||||||
|
|
||||||
|
def general_work(self, input_items, output_items):
|
||||||
|
output_items[0][:] = input_items[0]
|
||||||
|
consume(0, len(input_items[0]))
|
||||||
|
#self.consume_each(len(input_items[0]))
|
||||||
|
return len(output_items[0])
|
||||||
@@ -94,15 +94,12 @@ class peak_manager(gr.basic_block):
|
|||||||
if pmt.is_integer(val):
|
if pmt.is_integer(val):
|
||||||
value = pmt.to_long(val)
|
value = pmt.to_long(val)
|
||||||
peakMsg[key_str] = value
|
peakMsg[key_str] = value
|
||||||
# print("{}={}".format(key_str, value))
|
|
||||||
elif pmt.is_real(val):
|
elif pmt.is_real(val):
|
||||||
value = pmt.to_float(val)
|
value = pmt.to_float(val)
|
||||||
peakMsg[key_str] = value
|
peakMsg[key_str] = value
|
||||||
# print("{}={}".format(key_str, value))
|
|
||||||
elif pmt.is_bool(val):
|
elif pmt.is_bool(val):
|
||||||
value = pmt.to_bool(val)
|
value = pmt.to_bool(val)
|
||||||
peakMsg[key_str] = value
|
peakMsg[key_str] = value
|
||||||
# print("{}={}".format(key_str, value))
|
|
||||||
|
|
||||||
id = peakMsg['id']
|
id = peakMsg['id']
|
||||||
freq_MHz = peakMsg['freq_Hz']*1e-6
|
freq_MHz = peakMsg['freq_Hz']*1e-6
|
||||||
@@ -114,20 +111,20 @@ class peak_manager(gr.basic_block):
|
|||||||
if peakEntry is not None:
|
if peakEntry is not None:
|
||||||
portname = peakEntry['port_name']
|
portname = peakEntry['port_name']
|
||||||
print("Update " + peak_key + "(" + portname + ")")
|
print("Update " + peak_key + "(" + portname + ")")
|
||||||
pair = pmt.cons(pmt.intern("freq"), pmt.from_float(peakMsg['freq_Hz']))
|
msg_dict = pmt.make_dict()
|
||||||
self.message_port_pub(pmt.intern(portname), pair)
|
msg_dict = pmt.dict_add(msg_dict, pmt.intern("freq"), pmt.from_double(peakMsg['freq_Hz']))
|
||||||
pair = pmt.cons(pmt.intern("gain"), pmt.from_float(-peakMsg['height']))
|
msg_dict = pmt.dict_add(msg_dict, pmt.intern("gain"), pmt.from_double(-peakMsg['height']))
|
||||||
self.message_port_pub(pmt.intern(portname), pair)
|
self.message_port_pub(pmt.intern(portname), msg_dict)
|
||||||
else:
|
else:
|
||||||
print ("New peak #{} at {:0.2f} MHz".format(id, freq_MHz))
|
print ("New peak #{} at {:0.2f} MHz".format(id, freq_MHz))
|
||||||
peakEntry = self.peak_add(peak_key, peakMsg)
|
peakEntry = self.peak_add(peak_key, peakMsg)
|
||||||
if peakEntry is not None:
|
if peakEntry is not None:
|
||||||
portname = peakEntry['port_name']
|
portname = peakEntry['port_name']
|
||||||
print("Added " + peak_key + "(" + portname + ")")
|
print("Added " + peak_key + "(" + portname + ")")
|
||||||
pair = pmt.cons(pmt.intern("freq"), pmt.from_float(peakMsg['freq_Hz']))
|
msg_dict = pmt.make_dict()
|
||||||
self.message_port_pub(pmt.intern(portname), pair)
|
msg_dict = pmt.dict_add(msg_dict, pmt.intern("freq"), pmt.from_double(peakMsg['freq_Hz']))
|
||||||
pair = pmt.cons(pmt.intern("gain"), pmt.from_float(-peakMsg['height']))
|
msg_dict = pmt.dict_add(msg_dict, pmt.intern("gain"), pmt.from_double(-peakMsg['height']))
|
||||||
self.message_port_pub(pmt.intern(portname), pair)
|
self.message_port_pub(pmt.intern(portname), msg_dict)
|
||||||
else:
|
else:
|
||||||
if peakEntry is not None:
|
if peakEntry is not None:
|
||||||
print ("Lost peak #{} at {:0.2f} MHz".format(id, freq_MHz))
|
print ("Lost peak #{} at {:0.2f} MHz".format(id, freq_MHz))
|
||||||
|
|||||||
Executable
+41
@@ -0,0 +1,41 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright 2019 Jay Arrowfield.
|
||||||
|
#
|
||||||
|
# This 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.
|
||||||
|
#
|
||||||
|
# This software 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 this software; see the file COPYING. If not, write to
|
||||||
|
# the Free Software Foundation, Inc., 51 Franklin Street,
|
||||||
|
# Boston, MA 02110-1301, USA.
|
||||||
|
#
|
||||||
|
|
||||||
|
from gnuradio import gr, gr_unittest
|
||||||
|
from gnuradio import blocks
|
||||||
|
from message_filter import message_filter
|
||||||
|
|
||||||
|
class qa_message_filter (gr_unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp (self):
|
||||||
|
self.tb = gr.top_block ()
|
||||||
|
|
||||||
|
def tearDown (self):
|
||||||
|
self.tb = None
|
||||||
|
|
||||||
|
def test_001_t (self):
|
||||||
|
# set up fg
|
||||||
|
self.tb.run ()
|
||||||
|
# check data
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
gr_unittest.run(qa_message_filter, "qa_message_filter.xml")
|
||||||
Reference in New Issue
Block a user