blob: d6cd8bddcc50b4e363afda3b6ebc9b2cbdc45632 [file] [log] [blame]
Piotr Krysikc3622452017-12-01 12:02:55 +01001"""
2Embedded Python Blocks:
3
4Each this file is saved, GRC will instantiate the first class it finds to get
5ports and parameters of your block. The arguments to __init__ will be the
6parameters. All of them are required to have default values!
7"""
8
9from gnuradio import gr
10from pmt import *
11
Vadim Yanitskiya1a871e2018-12-21 06:27:29 +070012class dict_toggle_sign(gr.basic_block):
Piotr Krysikc3622452017-12-01 12:02:55 +010013 def __init__(self): # only default arguments here
14 gr.basic_block.__init__(
15 self,
16 name='Change sign of elts in dict',
17 in_sig=[],
18 out_sig=[]
19 )
20 self.message_port_register_in(intern("dict_in"))
21 self.message_port_register_out(intern("dict_out"))
22 self.set_msg_handler(intern("dict_in"), self.change_sign)
23
24 def change_sign(self, msg):
25 if is_dict(msg):
26 d = to_python(msg)
27 #print d
28 for key, value in d.items():
29 d[key] *= -1
30 self.message_port_pub(intern("dict_out"), to_pmt(d))