blob: fd7c585ca9418d46854b804ca1ccb79c792c3e51 [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
12class change_sign_of_dict_elements(gr.basic_block):
13 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))