Piotr Krysik | c362245 | 2017-12-01 12:02:55 +0100 | [diff] [blame] | 1 | """ |
| 2 | Embedded Python Blocks: |
| 3 | |
| 4 | Each this file is saved, GRC will instantiate the first class it finds to get |
| 5 | ports and parameters of your block. The arguments to __init__ will be the |
| 6 | parameters. All of them are required to have default values! |
| 7 | """ |
| 8 | |
| 9 | from gnuradio import gr |
| 10 | from pmt import * |
| 11 | |
Vadim Yanitskiy | ac3fe63 | 2018-12-21 06:27:29 +0700 | [diff] [blame^] | 12 | class dict_toggle_sign(gr.basic_block): |
Piotr Krysik | c362245 | 2017-12-01 12:02:55 +0100 | [diff] [blame] | 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)) |