Files
GnuRadio/gr-jay/python/peak_manager.py
T
2019-05-28 17:19:19 +00:00

96 lines
2.6 KiB
Python

#!/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 peak_manager(gr.basic_block):
"""
docstring for block peak_manager
"""
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"))
# Register in message handler
self.set_msg_handler(pmt.intern("control"), self.msg_handler)
#self.message_port_pub(pmt.intern("port name"), < pmt message >)
def msg_handler(self, msg):
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):
value = pmt.to_long(val)
peak[key_str] = value
# print("{}={}".format(key_str, value))
elif pmt.is_real(val):
value = pmt.to_float(val)
peak[key_str] = value
# print("{}={}".format(key_str, value))
elif pmt.is_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))
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])