- Peak detector delivers frequency instead of bin

git-svn-id: http://moon:8086/svn/software/trunk/projects/GnuRadio@492 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
2019-05-28 17:19:19 +00:00
parent 315932ea4e
commit dc6485e73f
6 changed files with 73 additions and 18 deletions
+26 -6
View File
@@ -27,12 +27,16 @@ class peak_manager(gr.basic_block):
"""
docstring for block peak_manager
"""
def __init__(self):
def __init__(self, test):
gr.basic_block.__init__(self,
name="peak_manager",
in_sig=None,
out_sig=None)
self.test = test
print ("test : ", test)
# Register in / out message ports
self.message_port_register_in(pmt.intern("control"))
self.message_port_register_out(pmt.intern("status"))
@@ -43,22 +47,38 @@ class peak_manager(gr.basic_block):
#self.message_port_pub(pmt.intern("port name"), < pmt message >)
def msg_handler(self, msg):
print ("Message received:")
if pmt.is_dict(msg):
items = pmt.dict_items(msg)
peak = {}
for n in range(0, pmt.length(items)):
pair = pmt.nth(n, items)
key = pmt.car(pair)
val = pmt.cdr(pair)
key_str = pmt.symbol_to_string(key)
if pmt.is_integer(val):
print("{}={}".format(pmt.symbol_to_string(key), pmt.to_long(val)))
value = pmt.to_long(val)
peak[key_str] = value
# print("{}={}".format(key_str, value))
elif pmt.is_real(val):
print("{}={}".format(pmt.symbol_to_string(key), pmt.to_float(val)))
value = pmt.to_float(val)
peak[key_str] = value
# print("{}={}".format(key_str, value))
elif pmt.is_bool(val):
print("{}={}".format(pmt.symbol_to_string(key), pmt.to_bool(val)))
value = pmt.to_bool(val)
peak[key_str] = value
# print("{}={}".format(key_str, value))
id = peak['id']
freq_MHz = peak['freq_Hz']*1e-6
if peak['state'] == 1:
print ("New peak #{} at {:0.2f} MHz".format(id, freq_MHz))
else:
print ("Lost peak #{} at {:0.2f} MHz".format(id, freq_MHz))
else:
print(pmt.symbol_to_string(msg))