def __init__(self, demodulator, access_code=None, callback=None, threshold=-1): """ Hierarchical block for demodulating and deframing packets. The input is the complex modulated signal at baseband. Demodulated packets are sent to the handler. Args: demodulator: instance of demodulator class (gr_block or hier_block2) (complex baseband in) access_code: AKA sync vector (string of 1's and 0's) callback: function of two args: ok, payload (ok: bool; payload: string) threshold: detect access_code with up to threshold bits wrong (-1 -> use default) (int) """ gr.hier_block2.__init__( self, "demod_pkts", gr.io_signature(1, 1, gr.sizeof_gr_complex), gr.io_signature(0, 0, 0) # Input signature ) # Output signature self._demodulator = demodulator if access_code is None: 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 if threshold == -1: threshold = 12 # FIXME raise exception self._rcvd_pktq = gr.msg_queue() # holds packets from the PHY self.correlator = digital.correlate_access_code_bb(access_code, threshold) self.framer_sink = digital.framer_sink_1(self._rcvd_pktq) self.connect(self, self._demodulator, self.correlator, self.framer_sink) self._watcher = _queue_watcher_thread(self._rcvd_pktq, callback)
def __init__(self, access_code=None, threshold=-1): """ Create a new packet deframer. @param access_code: AKA sync vector @type access_code: string of 1's and 0's @param threshold: detect access_code with up to threshold bits wrong (-1 -> use default) @type threshold: int """ gras.HierBlock.__init__(self, "PacketDeframer") try: import packet_utils except ImportError: from gnuradio.digital import packet_utils 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 try: import digital_swig as gr_digital except ImportError: import gnuradio.digital as gr_digital self.correlator = gr_digital.correlate_access_code_bb(access_code, threshold) self.framer_sink = gras.make('/grex/framer_sink_1') self._queue_to_datagram = _queue_to_datagram() self.connect(self, self.correlator, self.framer_sink, self._queue_to_datagram, self)
def __init__(self, access_code=None, threshold=-1): """ Create a new packet deframer. @param access_code: AKA sync vector @type access_code: string of 1's and 0's @param threshold: detect access_code with up to threshold bits wrong (-1 -> use default) @type threshold: int """ gras.HierBlock.__init__(self, "PacketDeframer") try: import packet_utils except ImportError: from gnuradio.digital import packet_utils 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 try: import digital_swig as gr_digital except ImportError: import gnuradio.digital as gr_digital self.correlator = gr_digital.correlate_access_code_bb( access_code, threshold) self.framer_sink = gras.make('/grex/framer_sink_1') self._queue_to_datagram = _queue_to_datagram() self.connect(self, self.correlator, self.framer_sink, self._queue_to_datagram, self)
def test_002(self): code = tuple(string_to_1_0_list(default_access_code)) access_code = to_1_0_string(code) header = tuple( 2 * [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]) # len=2 pad = (0, ) * 100 src_data = code + header + (0, 1, 0, 0, 1, 0, 0, 0) + (0, 1, 0, 0, 1, 0, 0, 1) + pad expected_data = 'HI' rcvd_pktq = gr.msg_queue() src = gr.vector_source_b(src_data) correlator = digital.correlate_access_code_bb(access_code, 0) framer_sink = digital.framer_sink_1(rcvd_pktq) vsnk = gr.vector_sink_b() self.tb.connect(src, correlator, framer_sink) self.tb.connect(correlator, vsnk) self.tb.run() result_data = rcvd_pktq.delete_head() result_data = result_data.to_string() self.assertEqual(expected_data, result_data)
def test_001(self): pad = (0,) * 64 # 0 0 0 1 0 0 0 1 src_data = (1, 0, 1, 1, 1, 1, 0, 1, 1) + pad + (0,) * 7 expected_result = pad + (1, 0, 1, 1, 3, 1, 0, 1, 1, 2) + (0,) * 6 src = blocks.vector_source_b(src_data) op = digital.correlate_access_code_bb("1011", 0) dst = blocks.vector_sink_b() self.tb.connect(src, op, dst) self.tb.run() result_data = dst.data() self.assertEqual(expected_result, result_data)
def test_001(self): pad = (0, ) * 64 # 0 0 0 1 0 0 0 1 src_data = (1, 0, 1, 1, 1, 1, 0, 1, 1) + pad + (0, ) * 7 expected_result = pad + (1, 0, 1, 1, 3, 1, 0, 1, 1, 2) + (0, ) * 6 src = gr.vector_source_b(src_data) op = digital.correlate_access_code_bb("1011", 0) dst = gr.vector_sink_b() self.tb.connect(src, op, dst) self.tb.run() result_data = dst.data() self.assertEqual(expected_result, result_data)
def test_002(self): code = tuple(string_to_1_0_list(default_access_code)) access_code = to_1_0_string(code) pad = (0,) * 64 #print code #print access_code src_data = code + (1, 0, 1, 1) + pad expected_result = pad + code + (3, 0, 1, 1) src = blocks.vector_source_b(src_data) op = digital.correlate_access_code_bb(access_code, 0) dst = blocks.vector_sink_b() self.tb.connect(src, op, dst) self.tb.run() result_data = dst.data() self.assertEqual(expected_result, result_data)
def test_002(self): code = tuple(string_to_1_0_list(default_access_code)) access_code = to_1_0_string(code) pad = (0, ) * 64 #print code #print access_code src_data = code + (1, 0, 1, 1) + pad expected_result = pad + code + (3, 0, 1, 1) src = gr.vector_source_b(src_data) op = digital.correlate_access_code_bb(access_code, 0) dst = gr.vector_sink_b() self.tb.connect(src, op, dst) self.tb.run() result_data = dst.data() self.assertEqual(expected_result, result_data)
def __init__(self, demodulator, access_code=None, callback=None, threshold=-1): """ Hierarchical block for demodulating and deframing packets. The input is the complex modulated signal at baseband. Demodulated packets are sent to the handler. @param demodulator: instance of demodulator class (gr_block or hier_block2) @type demodulator: complex baseband in @param access_code: AKA sync vector @type access_code: string of 1's and 0's @param callback: function of two args: ok, payload @type callback: ok: bool; payload: string @param threshold: detect access_code with up to threshold bits wrong (-1 -> use default) @type threshold: int """ gr.hier_block2.__init__( self, "demod_pkts", gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature gr.io_signature(0, 0, 0)) # Output signature self._demodulator = demodulator if access_code is None: 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 if threshold == -1: threshold = 12 # FIXME raise exception self._rcvd_pktq = gr.msg_queue() # holds packets from the PHY self.correlator = digital_swig.correlate_access_code_bb( access_code, threshold) self.framer_sink = gr.framer_sink_1(self._rcvd_pktq) self.connect(self, self._demodulator, self.correlator, self.framer_sink) self._watcher = _queue_watcher_thread(self._rcvd_pktq, callback)
def test_002(self): code = tuple(string_to_1_0_list(default_access_code)) access_code = to_1_0_string(code) header = tuple(2*[0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0]) # len=2 pad = (0,) * 100 src_data = code + header + (0,1,0,0,1,0,0,0) + (0,1,0,0,1,0,0,1) + pad expected_data = 'HI' rcvd_pktq = gr.msg_queue() src = blocks.vector_source_b(src_data) correlator = digital.correlate_access_code_bb(access_code, 0) framer_sink = digital.framer_sink_1(rcvd_pktq) vsnk = blocks.vector_sink_b() self.tb.connect(src, correlator, framer_sink) self.tb.connect(correlator, vsnk) self.tb.run() result_data = rcvd_pktq.delete_head() result_data = result_data.to_string() self.assertEqual(expected_data, result_data)