OK, I'll try to explain everything. I want to design block responsible for decoding messages, calculating crc, etc ... In order to do that I investigated packet_demod_base block from main gnuradio branch, and also packet_deframer from gr_extras group of blocks. I realized that such kind of blocks consists of correlator, framer sink which acts like message sink, and finally of some kind of message source. Framer sink sends messages to message source and message source then does packet checking and everything.
I also wanted to design my block in that fashion, so I used correlator and framer sink and I wanted to design my own block which is able to receive messages from packet framer and to check it. The code I provided in the last post is my own, and not the part of gnuradio. Here is complete source file of my block: import numpy from math import pi from gnuradio import gr from gruel import pmt from gnuradio.digital import packet_utils import gnuradio.digital as gr_digital class packet_tst(gr.hier_block2): def __init__(self, access_code=None, threshold=-1): gr.hier_block2.__init__( self, "packet_tst", gr.io_signature(1, 1, 1), # Input signature gr.io_signature(0, 0, 0) # Output signature ) if not access_code: access_code = packet_utils.default_access_code if not packet_utils.is_1_0_string(access_code): raise ValueError, "Invalid access_code %r. Must be string of 1's and 0's" % (access_code,) if threshold == -1: threshold = 12 # FIXME raise exception msgq = gr.msg_queue(4) # holds packets from the PHY self.correlator = gr_digital.correlate_access_code_bb(access_code, threshold) self.framer_sink = gr.framer_sink_1(msgq) self.connect(self, self.correlator, self.framer_sink) self.hlp_blk = helper_block(msgq) class helper_block(gr.basic_block): def __init__(self, msgq): gr.basic_block.__init__( self, name = "helper_block", in_sig = None, out_sig = None # num_msg_outputs = 1 ) self._msgq = msgq def work(self, input_items, output_items): while True: try: msg = self._msgq.delete_head() except: return -1 print "Message received" At the moment the block is designed only to write something to standard output if it receives a message. The problem is gr.basic_block as I described in previous post. Python interpreter doesn't complain about gr.hier_block2, but only about gr.basic_block. The tutorial for writing blocks in python is from gnuradio.org: http://gnuradio.org/redmine/projects/gnuradio/wiki/OutOfTreeModules#Tutorial-3-Writing-a-signal-processing-block-in-Python Hope this helps. Thanks On Tue, Jan 29, 2013 at 2:16 PM, Tom Rondeau <t...@trondeau.com> wrote: > On Tue, Jan 29, 2013 at 7:40 AM, Nemanja Savic <vlasi...@gmail.com> wrote: > >> I'm not sure what you mean by "load gr.basic_block." Do you mean inherit >>> from? >> >> >> I want to make my block which very similar to packet deframer. Here is th >> code: >> >> class packet_tst(gr.hier_block2): >>> def __init__(self, access_code=None, threshold=-1): >>> >>> gr.hier_block2.__init__( >>> self, >>> "packet_tst", >>> gr.io_signature(1, 1, 1), # Input signature >>> gr.io_signature(0, 0, 0) # Output signature >>> ) >>> >>> if not access_code: >>> access_code = packet_utils.default_access_code >>> if not packet_utils.is_1_0_string(access_code): >>> raise ValueError, "Invalid access_code %r. Must be string of >>> 1's and 0's" % (access_code,) >>> >>> if threshold == -1: >>> threshold = 12 # FIXME raise exception >>> >>> msgq = gr.msg_queue(4) # holds packets from the PHY >>> self.correlator = >>> gr_digital.correlate_access_code_bb(access_code, threshold) >>> >>> self.framer_sink = gr.framer_sink_1(msgq) >>> self.connect(self, self.correlator, self.framer_sink) >>> >>> self.hlp_blk = helper_block(msgq) >>> >> >> in the same file is also defined class helper_block in this way: >> >> class helper_block(gr.basic_block): >>> def __init__(self, msgq): >>> gr.basic_block.__init__( >>> self, name = "helper_block", >>> in_sig = None, out_sig = None >>> # num_msg_outputs = 1 >>> ) >>> >>> self._msgq = msgq >>> >>> def work(self, input_items, output_items): >>> while True: >>> try: msg = self._msgq.delete_head() >>> except: return -1 >>> print "Message received" >> >> > I have no idea what files these are from. Are they part of the GNU Radio > source code? I can't find references to them. > > > >> when I try to run test or flowgraph, I get this error: >> >> in <module> >>> class helper_block(gr.basic_block): >>> >>> AttributeError: 'module' object has no attribute 'basic_block' >>> -- Process completed >>> ***Failed >>> >>> 0% tests passed, 1 tests failed out of 1 >> >> > Sounds like you don't have something installed correctly. You wouldn't > normally be inheriting straight from gr_basic_block, but you should be able > to. > > >> And in tutorial on how to write signal processing block, it is stated to >> use gr.basic_block. >> > > Which tutorial? Again, I don't think this is in the main GNU Radio source, > so please point out where you are getting this from. > > Tom > > -- Nemanja Savić
_______________________________________________ Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org https://lists.gnu.org/mailman/listinfo/discuss-gnuradio