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 = cat_packet_utils.default_access_code if not cat_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.framer_sink.setlen(1670) # Xu: set d_packetlen self.connect(self, self._demodulator, self.correlator, self.framer_sink) self._watcher = _queue_watcher_thread(self._rcvd_pktq, callback)
def __init__(self,q_rx,q_tx,noise_voltage=0.01,frequency_offset=0.01,epsilon=1.001,taps=(1+0.5j, ),): '''Constructor. @param q_rx: ''' samp_per_sym =5 gr.top_block.__init__(self) self.sink_queue = gr.msg_queue() #self.Add(self.wxgui_scopesink2_0_0.win) self.hier_rx_0 = hier_rx.hier_rx( bw_clock_sync=2*math.pi/5, bw_fll=math.pi/400, bits_per_sym=2, bw_costas=2*math.pi/100, n_filts=32, len_sym_srrc=7, constellation=digital.constellation_calcdist([-1-1j, 1-1j, 1+1j, -1+1j], [], 4, 1).base(), samp_per_sym=samp_per_sym, alfa=0.35, ) self.hier_tx_0 = hier_tx.hier_tx( alfa=0.35, samp_per_sym=samp_per_sym, bits_per_sym=2, constellation=[-1-1j,1-1j, 1+1j, -1+1j], len_sym_srrc=7, out_const_mul=0.4, ) #self.hier_rx_0 = hier_rx() self.channels_channel_model_0 = channels.channel_model( noise_voltage, frequency_offset, epsilon, taps, noise_seed=0, block_tags=False ) threshold = 12 # FIXME raise exception access_code = packet_utils.default_access_code self.blocks_message_source_0 = blocks.message_source(gr.sizeof_char*1, 4) self._rcvd_pktq = gr.msg_queue() # holds packets from the PHY self.correlator = digital.correlate_access_code_bb( access_code, threshold) #"Arreglar access_code en la llamada a correlate"""""" self.framer_sink = digital.framer_sink_1(self._rcvd_pktq) self.vsnk_src = blocks.vector_sink_b() self.m_sink = blocks.message_sink(gr.sizeof_char*1, self.sink_queue,True) ################################################## # Connections ################################################## #self.connect((self.hier_tx_pencoder_0, 0), (self.wxgui_scopesink2_0_0, 0)) self.connect(( self.blocks_message_source_0, 0),(self.hier_tx_0, 0) ) self.connect((self.hier_tx_0, 0), (self.channels_channel_model_0, 0)) self.connect((self.channels_channel_model_0, 0), (self.hier_rx_0, 0)) self.connect((self.hier_rx_0, 0), self.correlator, self.framer_sink) self._watcher = _queue_watcher_thread(self._rcvd_pktq,q_rx) queue = self.blocks_message_source_0.msgq() self.snd = SendData(q_tx,queue,samp_per_sym)
def __init__(self, access_code=None, callback=None, threshold=-1): # """ # Hierarchical block for frame syncing. # @param access_code: Attached Sync Marker # @type access_code: hex string # @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, "bpsk_frame_sync", gr.io_signature(2, 2, gr.sizeof_char), # Input signature gr.io_signature(0, 0, 0)) # Output signature if access_code is None: access_code = '1ACFFC1D' # if not digital.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 = hexstr2binstr(access_code) self._inv_access_code = self._access_code.translate( maketrans("10", "01")) # Convolutional encoded ASM k = 7 code_length = (len(access_code) * 4) seed_length = k - 1 length2encode = code_length - seed_length self.encoder = ccsds.ccsds_conv_encode( hexstr2int(access_code) >> length2encode, k) #, 2, asarray([79, 91])) enc_access_code = self.encoder.encode(hexstr2int(access_code), length2encode, 79, 109) self._enc_access_code = int2binstr(enc_access_code, length2encode * 2) self._enc_inv_access_code = self._enc_access_code.translate( maketrans("10", "01")) print "encoded ASM: %s" % str(hex(enc_access_code)) # print "encoded ASM: %s" % str(self._enc_access_code) self._access_code = self._enc_access_code self._inv_access_code = self._enc_inv_access_code if threshold == -1: threshold = 12 # FIXME raise exception self.output_msgq = gr.msg_queue() # holds packets from the PHY # correlator looking for the non-inverted ASM self.correlator = digital_swig.correlate_access_code_bb( self._access_code, threshold) # correlator looking for the inverted ASM self.inv_correlator = digital_swig.correlate_access_code_bb( self._inv_access_code, threshold) # new framer that accepts parallel inputs from two correlators self.framer_sink = ccsds_swig.framer_sink_dual(self.output_msgq, 2550, 8) #2550, 8 1275, 4 # connect the block input to the correlators # and the correlators to their respective port on the framer self.connect((self, 0), self.correlator, (self.framer_sink, 0)) self.connect((self, 1), self.inv_correlator, (self.framer_sink, 1))
def __init__(self,q_rx,q_tx,samp_per_sym=3, antenna='TX/RX', \ rx_freq=850000000.0, rx_gain=15.0, spec='A:0', tx_gain=15.0, \ args='serial=E0R11Y0B1', bit_rate=100000.0, \ tx_freq=851000000.0, tx_amplitude=0.25,): '''Constructor. TODO: I AM NOT SETTING the Tx_AMPLITUDE @param q_rx: ''' gr.top_block.__init__(self) self.sink_queue = gr.msg_queue() bits_per_sym = 2 # only for QPSK! #samp_per_sym=3 sym_rate = bit_rate/bits_per_sym self.uhd_usrp_source_0 = uhd.usrp_source( device_addr=args, stream_args=uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_source_0.set_subdev_spec(spec, 0) self.uhd_usrp_source_0.set_center_freq(rx_freq, 0) self.uhd_usrp_source_0.set_gain(rx_gain, 0) self.uhd_usrp_source_0.set_antenna(antenna, 0) self.set_sample_rate(self.uhd_usrp_source_0,sym_rate, samp_per_sym) self.uhd_usrp_sink_0 = uhd.usrp_sink( device_addr=args, stream_args=uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_usrp_sink_0.set_subdev_spec(spec, 0) self.uhd_usrp_sink_0.set_center_freq(tx_freq, 0) self.uhd_usrp_sink_0.set_gain(tx_gain, 0) self.uhd_usrp_sink_0.set_antenna(antenna, 0) self.set_sample_rate(self.uhd_usrp_sink_0,sym_rate, samp_per_sym) #self.Add(self.wxgui_scopesink2_0_0.win) self.hier_rx_0 = hier_rx.hier_rx( bw_clock_sync=2*math.pi/100, bw_fll=2*math.pi/100, bits_per_sym=bits_per_sym, bw_costas=2*math.pi/100, n_filts=32, len_sym_srrc=11, constellation=digital.constellation_calcdist([-1-1j, 1-1j, 1+1j, -1+1j], [], 4, 1).base(), samp_per_sym=samp_per_sym, alfa=0.45, ) self.hier_tx_0 = hier_tx.hier_tx( alfa=0.45, samp_per_sym=samp_per_sym, constellation=[-1-1j,1-1j, 1+1j, -1+1j], len_sym_srrc=11, out_const_mul=0.4, bits_per_sym=bits_per_sym, ) threshold = 12 # FIXME raise exception access_code = packet_utils.default_access_code self.blocks_message_source_0 = blocks.message_source(gr.sizeof_char*1, 4) self._rcvd_pktq = gr.msg_queue() # holds packets from the PHY self.correlator = digital.correlate_access_code_bb( access_code, threshold) #"Arreglar access_code en la llamada a correlate"""""" self.framer_sink = digital.framer_sink_1(self._rcvd_pktq) self.vsnk_src = blocks.vector_sink_b() self.m_sink = blocks.message_sink(gr.sizeof_char*1, self.sink_queue,True) ################################################## # Connections ################################################## #self.connect((self.hier_tx_pencoder_0, 0), (self.wxgui_scopesink2_0_0, 0)) self.connect(( self.blocks_message_source_0, 0),(self.hier_tx_0, 0) ) self.connect((self.hier_tx_0, 0), (self.uhd_usrp_sink_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.hier_rx_0, 0)) self.connect((self.hier_rx_0, 0), self.correlator, self.framer_sink) self._watcher = _queue_watcher_thread(self._rcvd_pktq,q_rx) queue = self.blocks_message_source_0.msgq() self.snd = SendData(q_tx,queue,samp_per_sym)