def __init__(self, samples_per_symbol, bits_per_symbol, access_code='', pad_for_usrp=True): """ packet_mod constructor. Args: samples_per_symbol: number of samples per symbol bits_per_symbol: number of bits per symbol access_code: AKA sync vector pad_for_usrp: If true, packets are padded such that they end up a multiple of 128 samples payload_length: number of bytes in a data-stream slice """ #setup parameters self._samples_per_symbol = samples_per_symbol self._bits_per_symbol = bits_per_symbol self._pad_for_usrp = pad_for_usrp if not access_code: #get 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,) self._access_code = access_code self._pad_for_usrp = pad_for_usrp #create blocks msg_source = blocks.message_source(gr.sizeof_char, DEFAULT_MSGQ_LIMIT) self._msgq_out = msg_source.msgq() #initialize hier2 gr.hier_block2.__init__( self, "packet_encoder", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(1, 1, gr.sizeof_char) # Output signature ) #connect self.connect(msg_source, self)
def __init__(self, access_code='', threshold=-1, callback=None): """ packet_demod constructor. Args: access_code: AKA sync vector threshold: detect access_code with up to threshold bits wrong (0 -> use default) callback: a function of args: ok, payload """ #access code if not access_code: #get 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,) self._access_code = access_code #threshold if threshold < 0: threshold = DEFAULT_THRESHOLD self._threshold = threshold #blocks msgq = gr.msg_queue(DEFAULT_MSGQ_LIMIT) #holds packets from the PHY correlator = digital.correlate_access_code_bb(self._access_code, self._threshold) framer_sink = digital.framer_sink_1(msgq) #initialize hier2 gr.hier_block2.__init__( self, "packet_decoder", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(0, 0, 0) # Output signature ) #connect self.connect(self, correlator, framer_sink) #start thread _packet_decoder_thread(msgq, callback)