def __init__(self, packet_sink=None): #initialize hier2 gr.hier_block2.__init__( self, "ofdm_mod", gr.io_signature( 1, 1, packet_sink._hb.input_signature().sizeof_stream_item( 0)), # Input signature gr.io_signature(1, 1, self._item_size_out) # Output signature ) #create blocks msg_source = gr.message_source(self._item_size_out, DEFAULT_MSGQ_LIMIT) self._msgq_out = msg_source.msgq() #connect self.connect(self, packet_sink) self.connect(msg_source, self) if packet_sink._hb.output_signature().sizeof_stream_item(0): self.connect( packet_sink, gr.null_sink( packet_sink._hb.output_signature().sizeof_stream_item(0))) self.lasttime = [] self.chars = []
def __init__(self, pad_for_usrp=True, *args, **kwargs): """ Hierarchical block for the 802_15_4 O-QPSK modulation. Packets to be sent are enqueued by calling send_pkt. The output is the complex modulated signal at baseband. @param msgq_limit: maximum number of messages in message queue @type msgq_limit: int @param pad_for_usrp: If true, packets are padded such that they end up a multiple of 128 samples See 802_15_4_mod for remaining parameters """ try: self.msgq_limit = kwargs.pop('msgq_limit') self.log = kwargs.get('log') except KeyError: pass gr.hier_block2.__init__( self, "ieee802_15_4_mod_pkts", gr.io_signature(0, 0, 0), # Input gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output self.pad_for_usrp = pad_for_usrp # accepts messages from the outside world self.pkt_input = gr.message_source(gr.sizeof_char, self.msgq_limit) self.ieee802_15_4_mod = ieee802_15_4.ieee802_15_4_mod( self, *args, **kwargs) self.connect(self.pkt_input, self.ieee802_15_4_mod, self) if self.log: self.connect(self.pkt_input, gr.file_sink(gr.sizeof_char, 'tx-input.dat'))
def __init__(self, fg, modulator, access_code=None, msgq_limit=2, pad_for_usrp=True, use_whitener_offset=False): """ Hierarchical block for sending packets Packets to be sent are enqueued by calling send_pkt. The output is the complex modulated signal at baseband. @param fg: flow graph @type fg: flow graph @param modulator: instance of modulator class (gr_block or hier_block) @type modulator: complex baseband out @param access_code: AKA sync vector @type access_code: string of 1's and 0's between 1 and 64 long @param msgq_limit: maximum number of messages in message queue @type msgq_limit: int @param pad_for_usrp: If true, packets are padded such that they end up a multiple of 128 samples @param use_whitener_offset: If true, start of whitener XOR string is incremented each packet See gmsk_mod for remaining parameters """ self._modulator = modulator self._pad_for_usrp = pad_for_usrp self._use_whitener_offset = use_whitener_offset self._whitener_offset = 0 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 # accepts messages from the outside world self._pkt_input = gr.message_source(gr.sizeof_char, msgq_limit) fg.connect(self._pkt_input, self._modulator) gr.hier_block.__init__(self, fg, None, self._modulator)
def __init__(self, samples_per_symbol, bits_per_symbol, access_code='', pad_for_usrp=True, kbid='', verbose=0): """ packet_mod constructor. @param samples_per_symbol number of samples per symbol @param bits_per_symbol number of bits per symbol @param access_code AKA sync vector @param pad_for_usrp If true, packets are padded such that they end up a multiple of 128 samples @param 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._kbid = kbid self._verbose = verbose 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 = gr.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, fg, access_code=None, msgq_limit=2, pad_for_usrp=True, *args, **kwargs): """ Hierarchical block for the CC1K fsk modulation. Packets to be sent are enqueued by calling send_pkt. The output is the complex modulated signal at baseband. @param fg: flow graph @type fg: flow graph @param access_code: 64-bit sync code @type access_code: string of length 8 @param msgq_limit: maximum number of messages in message queue @type msgq_limit: int @param pad_for_usrp: If true, packets are padded such that they end up a multiple of 128 samples See cc1k_mod for remaining parameters """ self.pad_for_usrp = pad_for_usrp if access_code is None: #this is 0x33CC access_code = struct.pack('BB', 0x33, 0xCC) #if not isinstance(access_code, str) or len(access_code) != 8: # raise ValueError, "Invalid access_code '%r'" % (access_code,) self._access_code = access_code # accepts messages from the outside world self.pkt_input = gr.message_source(gr.sizeof_char, msgq_limit) self.cc1k_mod = cc1k.cc1k_mod(fg, *args, **kwargs) fg.connect(self.pkt_input, self.cc1k_mod) gr.hier_block.__init__(self, fg, None, self.cc1k_mod)
def __init__(self, packet_sink=None): #we want outputs of different types # NOTE: The output signature depends on the number of the subcarriers signature_sizes = [self._item_size_out, gr.sizeof_gr_complex * packet_sink._occupied_tones] #initialize hier2 gr.hier_block2.__init__( self, "ofdm_demod", gr.io_signature(1, 1, packet_sink._hb.input_signature().sizeof_stream_item(0)), # Input signature gr.io_signaturev(2, 2, signature_sizes) # Output signature ) #create blocks msg_source = gr.message_source(self._item_size_out, DEFAULT_MSGQ_LIMIT) self._msgq_out = msg_source.msgq() #connect self.connect(self, packet_sink) self.connect(msg_source, self) # For the vector analyzer connection self.connect((packet_sink, 1), (self, 1)) if packet_sink._hb.output_signature().sizeof_stream_item(0): self.connect(packet_sink, gr.null_sink(packet_sink._hb.output_signature().sizeof_stream_item(0)))
def __init__(self, *args, **kwargs): """ Hierarchical block for the 802_15_4 O-QPSK modulation. Packets to be sent are enqueued by calling send_pkt. The output is the complex modulated signal at baseband. @param msgq_limit: maximum number of messages in message queue @type msgq_limit: int @param pad_for_usrp: If true, packets are padded such that they end up a multiple of 128 samples See 802_15_4_mod for remaining parameters """ try: self.pad_for_usrp = kwargs.pop('pad_for_usrp') self.msgq_limit = kwargs.pop('msgq_limit') except KeyError: pass gr.hier_block2.__init__(self, "ieee802_15_4_mod_pkts", gr.io_signature(0, 0, 0), # Input gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output #self.pad_for_usrp = pad_for_usrp # accepts messages from the outside world self.pkt_input = gr.message_source(gr.sizeof_char, self.msgq_limit) self.ieee802_15_4_mod = ieee802_15_4.ieee802_15_4_mod(*args, **kwargs) print "GR: ieee802_15_4_pkt: Connecting packet input and modulator." self.connect(self.pkt_input, self.ieee802_15_4_mod, self)
def __init__(self, audio_output_dev): gr.hier_block2.__init__(self, "audio_tx", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(0, 0, 0)) # Output signature self.packet_src = gr.message_source(33) voice_decoder = gsm_full_rate.decode_ps() s2f = gr.short_to_float () sink_scale = gr.multiply_const_ff(1.0/32767.) audio_sink = audio.sink(8000, audio_output_dev) self.connect(self.packet_src, voice_decoder, s2f, sink_scale, audio_sink)
def test_301(self): src = gr.message_source(gr.sizeof_char) dst = gr.vector_sink_b() self.fg.connect(src, dst) src.msgq().insert_tail(gr.message_from_string('01234')) src.msgq().insert_tail(gr.message_from_string('5')) src.msgq().insert_tail(gr.message_from_string('')) src.msgq().insert_tail(gr.message_from_string('6789')) src.msgq().insert_tail(gr.message(1)) # send EOF self.fg.run() self.assertEquals(tuple(map(ord, '0123456789')), dst.data())
def __init__(self): gr.top_block.__init__(self, 'Message Blocks Test') # initialize the queues self.sink_queue = gr.msg_queue() self.source_queue = gr.msg_queue() # initialize the blocks self.msg_source = gr.message_source(gr.sizeof_char, self.source_queue) self.msg_sink = gr.message_sink(gr.sizeof_char, self.sink_queue, False) self.connect((self.msg_source, 0), (self.msg_sink, 0))
def test_301(self): # Use itemsize, limit constructor src = gr.message_source(gr.sizeof_char) dst = gr.vector_sink_b() tb = gr.top_block() tb.connect(src, dst) src.msgq().insert_tail(gr.message_from_string('01234')) src.msgq().insert_tail(gr.message_from_string('5')) src.msgq().insert_tail(gr.message_from_string('')) src.msgq().insert_tail(gr.message_from_string('6789')) src.msgq().insert_tail(gr.message(1)) # send EOF tb.run() self.assertEquals(tuple(map(ord, '0123456789')), dst.data())
def __init__(self): gr.hier_block2.__init__(self, "transmit_path", gr.io_signature(0, 0, 0), gr.io_signature(1, 1, gr.sizeof_gr_complex)) self.msgq = msgq = gr.msg_queue() self.msg_src = gr.message_source(1, msgq) self.msk = digital.gmsk_mod(samples_per_symbol=2, bt=0.3) # Connections self.connect(self.msg_src, self.msk, self)
def __init__(self, audio_output_dev): gr.hier_block2.__init__( self, "audio_tx", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(0, 0, 0)) # Output signature self.packet_src = gr.message_source(33) voice_decoder = gsm_full_rate.decode_ps() s2f = gr.short_to_float() sink_scale = gr.multiply_const_ff(1.0 / 32767.) audio_sink = audio.sink(8000, audio_output_dev) self.connect(self.packet_src, voice_decoder, s2f, sink_scale, audio_sink)
def __init__(self): gr.top_block.__init__(self, "CC430 Transmitter") ################################ # TX Connections ################################ self.sent_pkts = 0 # 5555 5555 2c6e fd00 0071 da0b e2 self.test_packet = chr(0x55)*4 # preamble self.test_packet += chr(0x2c) + chr(0x6e) # sync self.test_packet += chr(0xfc) # length self.test_packet += chr(0x00) + chr(0x00) + chr(0x00) # payload self.test_packet += chr(0xc3) + chr(0xdb) # CRC16 (currently incorrect?) # Variables self.samp_rate = samp_rate = 125e3 self.f_center = f_center = 510e6 self.bandwidth = bandwidth = 125e3 self.gain = gain = 25 self.msgq = msgq = gr.msg_queue() # Blocks self.uhd_sink = uhd.usrp_sink( device_addr="serial=E4R11Y0B1", #panthro stream_args=uhd.stream_args( args="", cpu_format="fc32", channels=range(1), antenna="TX/RX" ), ) self.uhd_sink.set_samp_rate(samp_rate) self.uhd_sink.set_center_freq(f_center, 0) self.uhd_sink.set_gain(gain, 0) self.uhd_sink.set_bandwidth(bandwidth, 0) self.msg_src = gr.message_source(1, msgq) self.msk = level.msk_mod_bc( samples_per_symbol=2, bt=0.3, ti_adj=False ) self.connect(self.msg_src, self.msk, self.uhd_sink)
def __init__(self): gr.hier_block2.__init__(self, "transmit_path", gr.io_signature(0, 0, 0), gr.io_signature(1, 1, gr.sizeof_gr_complex)) self.msgq = msgq = gr.msg_queue() self.msg_src = gr.message_source(1, msgq) self.msk = digital.gmsk_mod( samples_per_symbol=2, bt=0.3 ) # Connections self.connect(self.msg_src, self.msk, self)
def __init__(self, options): self.tx = raw.ofdm_mod(options) self.params = self.tx.params symbol_size = self.params.data_tones * gr.sizeof_gr_complex gr.hier_block2.__init__(self, "TX", gr.io_signature(1,1, symbol_size), gr.io_signature(1,1, gr.sizeof_gr_complex)) self.msg = gr.message_source(gr.sizeof_char, 2) self.connect(self, (self.tx, 0), self) self.connect(self.msg, (self.tx, 1)) #self.connect(self.msg, gr.file_sink(gr.sizeof_char, 'tx-msg.datb')); self.size = options.size
def __init__(self, packet_sink=None): #initialize hier2 gr.hier_block2.__init__( self, "ofdm_mod", gr.io_signature(1, 1, packet_sink._hb.input_signature().sizeof_stream_item(0)), # Input signature gr.io_signature(1, 1, self._item_size_out) # Output signature ) #create blocks msg_source = gr.message_source(self._item_size_out, DEFAULT_MSGQ_LIMIT) self._msgq_out = msg_source.msgq() #connect self.connect(self, packet_sink) self.connect(msg_source, self) if packet_sink._hb.output_signature().sizeof_stream_item(0): self.connect(packet_sink, gr.null_sink(packet_sink._hb.output_signature().sizeof_stream_item(0)))
def __init__(self, samp_rate, fan_speed, heater_temp): gr.hier_block2.__init__(self, "sbhs_module", gr.io_signature(0, 0, 0), gr.io_signature(1, 1, gr.sizeof_float)) self.init_serial() self.set_samp_rate(samp_rate) self.set_fan_speed(fan_speed) self.set_heater_temp(heater_temp) message_source = gr.message_source(gr.sizeof_int, 1) self._msgq = message_source.msgq() self.connect(message_source, self) threading.Thread.__init__(self) self.setDaemon(True) self.start()
def __init__(self, gui, options): ''' See below for what options should hold ''' gr.hier_block2.__init__(self, "transmit_path", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(0, 0, 0)) # Output signature options = copy.copy(options) # make a copy so we can destructively modify self._verbose = options.verbose self._tx_amplitude = options.tx_amplitude # digital amplitude sent to USRP self._bitrate = options.rate # desired bit rate self._samples_per_symbol = options.sps # desired samples/baud #setup usrp self._setup_usrp_sink(options) #create a BPSK modulator self.modulator = bpsk_modulator(gui, options) # the modulator we are using #create packet input like in ieee 802.15.4 #the size of the queue is 2 messages #######################************* msgq_limit = 10 self.pkt_input = gr.message_source(gr.sizeof_char, msgq_limit) #self.vector_source = gr.vector_source_b([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,1,1,1,], True) #The same chain like in ieee transceiver #add gain like in ieee802.15.4 #######################################***************** #self.normal_gain = 8000 #self.gain = gr.multiply_const_cc (self.normal_gain) #self.amp = gr.multiply_const_cc(1) #self.set_tx_amplitude(self._tx_amplitude) # Display some information about the setup if self._verbose: self._print_verbage() # Connect components in the flowgraph #self.connect(self.packet_transmitter, self.amp, self) #self.connect(self.vector_source, self.modulator, self.u) self.connect(self.pkt_input, self.modulator, self.u)
def test_1 (self): data = ('hello', 'you', 'there') tx_msgq = gr.msg_queue () rx_msgq = gr.msg_queue () for d in data: tx_msgq.insert_tail(gr.message_from_string(d)) tb = gr.top_block() src = gr.message_source(gr.sizeof_char, tx_msgq, "packet_length") snk = gr.message_sink(gr.sizeof_char, rx_msgq, False, "packet_length") tb.connect(src, snk) tb.start() time.sleep(1) tb.stop() for d in data: msg = rx_msgq.delete_head() contents = msg.to_string() self.assertEqual(d, contents)
def test_1(self): data = ('hello', 'you', 'there') tx_msgq = gr.msg_queue() rx_msgq = gr.msg_queue() for d in data: tx_msgq.insert_tail(gr.message_from_string(d)) tb = gr.top_block() src = gr.message_source(gr.sizeof_char, tx_msgq, "packet_length") snk = gr.message_sink(gr.sizeof_char, rx_msgq, False, "packet_length") tb.connect(src, snk) tb.start() time.sleep(1) tb.stop() for d in data: msg = rx_msgq.delete_head() contents = msg.to_string() self.assertEqual(d, contents)
def __init__(self, modulator, options, access_code=None, msgq_limit=2, pad_for_usrp=True, use_whitener_offset=False, modulate=True, use_coding=0, logging=-1): """ Hierarchical block for sending packets Packets to be sent are enqueued by calling send_pkt. The output is the complex modulated signal at baseband. @param modulator: instance of modulator class (gr_block or hier_block2) @type modulator: complex baseband out @param access_code: AKA sync vector @type access_code: string of 1's and 0's between 1 and 64 long @param msgq_limit: maximum number of messages in message queue @type msgq_limit: int @param pad_for_usrp: If true, packets are padded such that they end up a multiple of 128 samples @param use_whitener_offset: If true, start of whitener XOR string is incremented each packet See gmsk_mod for remaining parameters """ gr.hier_block2.__init__(self, "mod_pkts", gr.io_signature(1, 1, gr.sizeof_char), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature self._modulator = modulator self._pad_for_usrp = pad_for_usrp self._use_whitener_offset = use_whitener_offset self._whitener_offset = 0 #just added to take coding from benchmark_tx self._use_coding = use_coding self._logging = logging self._options = options 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 # accepts messages from the outside world self._pkt_input = gr.message_source(gr.sizeof_char, msgq_limit) self.null_sink = gr.null_sink(gr.sizeof_char) self.connect(self._pkt_input, self._modulator, self) self.connect(self,self.null_sink)
def __init__(self, modulator, access_code=None, msgq_limit=2, pad_for_usrp=True, use_whitener_offset=False, modulate=True): """ Hierarchical block for sending packets Packets to be sent are enqueued by calling send_pkt. The output is the complex modulated signal at baseband. @param modulator: instance of modulator class (gr_block or hier_block2) @type modulator: complex baseband out @param access_code: AKA sync vector @type access_code: string of 1's and 0's between 1 and 64 long @param msgq_limit: maximum number of messages in message queue @type msgq_limit: int @param pad_for_usrp: If true, packets are padded such that they end up a multiple of 128 samples @param use_whitener_offset: If true, start of whitener XOR string is incremented each packet See gmsk_mod for remaining parameters """ gr.hier_block2.__init__( self, "mod_pkts", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature self._modulator = modulator self._pad_for_usrp = pad_for_usrp self._use_whitener_offset = use_whitener_offset self._whitener_offset = 0 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 # accepts messages from the outside world self._pkt_input = gr.message_source(gr.sizeof_char, msgq_limit) self.connect(self._pkt_input, self._modulator, self)
def __init__(self, sample_rate, fan_value, heater_value): gr.hier_block2.__init__(self, 'sbhs_source', gr.io_signature(0,0,0), gr.io_signature(1,1,gr.sizeof_float)) self.search_device() self.initialize_device() self.set_sample_rate(sample_rate) self.set_fan_speed(fan_value) self.set_heater_temperature(heater_value) message_source = gr.message_source(gr.sizeof_int,1) self._msgq = message_source.msgq() self.connect(message_source, self) threading.Thread.__init__(self) self.setDaemon(True) self.start()
def __init__(self, options): gr.top_block.__init__(self) if (options.tx_freq is not None): self.sink = uhd_transmitter(options.args, options.bandwidth, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose) elif (options.to_file is not None): self.sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file) else: self.sink = gr.null_sink(gr.sizeof_gr_complex) # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.txpath = gr.message_source(gr.sizeof_gr_complex, 3) self.amp = gr.multiply_const_cc(options.amp) self.connect(self.txpath, self.amp, self.sink)
def __init__(self, vlen=1): """! Queue source base contructor. @param vlen the vector length """ self._vlen = vlen #initialize hier2 gr.hier_block2.__init__( self, "queue_source", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(1, 1, self._item_size*self._vlen) # Output signature ) #create message sink message_source = gr.message_source(self._item_size*self._vlen, 1) self._msgq = message_source.msgq() #connect self.connect(message_source, self)
def add_source( self, signal = None ): try: if signal is None: src = gr.message_source( gr.sizeof_float, 1 ) # queue depth 1, MUST BE 1 self.sources.append( src ) self.lengths.append( 0 ) self.is_const.append( False ) else: src = gr.vector_source_f( list( signal ), True ) self.sources.append( src ) self.lengths.append( len( signal ) ) self.is_const.append( True ) id = len(self.sources)-1 self.tb.connect( src, ( self.mux, id ) ) except Exception,ex: print repr(ex) raise RuntimeError,"Could not connect new source to mux"
def __init__(self, probe_callback, probe_rate): #init hier block gr.hier_block2.__init__( self, 'probe_function', gr.io_signature(0, 0, 0), gr.io_signature(1, 1, gr.sizeof_float), ) self._probe_callback = probe_callback self.set_probe_rate(probe_rate) #create message source message_source = gr.message_source(gr.sizeof_float, 1) self._msgq = message_source.msgq() #connect self.connect(message_source, self) #setup thread threading.Thread.__init__(self) self.setDaemon(True) self.start()
def __init__(self, vlen=1): """! Queue source base contructor. @param vlen the vector length """ self._vlen = vlen # initialize hier2 gr.hier_block2.__init__( self, "queue_source", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(1, 1, self._item_size * self._vlen), # Output signature ) # create message sink message_source = gr.message_source(self._item_size * self._vlen, 1) self._msgq = message_source.msgq() # connect self.connect(message_source, self)
def add_source(self, signal=None): try: if signal is None: src = gr.message_source(gr.sizeof_float, 1) # queue depth 1, MUST BE 1 self.sources.append(src) self.lengths.append(0) self.is_const.append(False) else: src = gr.vector_source_f(list(signal), True) self.sources.append(src) self.lengths.append(len(signal)) self.is_const.append(True) id = len(self.sources) - 1 self.tb.connect(src, (self.mux, id)) except Exception, ex: print repr(ex) raise RuntimeError, "Could not connect new source to mux"
def __init__(self): gr.top_block.__init__(self) self.src = gr.message_source(gr.sizeof_char, msgq_limit) src = self.src b_to_syms = gr.bytes_to_syms() self.mult = gr.multiply_const_ff(MULTIPLIER) add = gr.add_const_ff(CENTER_FREQ) repeater = gr.repeat(gr.sizeof_float,REPEAT_TIME) fsk_f = gr.vco_f(AUDIO_RATE, 2*pi,0.5) speaker = audio.sink(AUDIO_RATE, "plughw:0,0"); self.connect(src,b_to_syms,self.mult,add,repeater,fsk_f,speaker)
def __init__(self, options): gr.top_block.__init__(self) if(options.tx_freq is not None): self.sink = uhd_transmitter(options.args, options.bandwidth, options.tx_freq, options.tx_gain, options.spec, options.antenna, options.verbose) elif(options.to_file is not None): self.sink = gr.file_sink(gr.sizeof_gr_complex, options.to_file) else: self.sink = gr.null_sink(gr.sizeof_gr_complex) # do this after for any adjustments to the options that may # occur in the sinks (specifically the UHD sink) self.txpath = gr.message_source(gr.sizeof_gr_complex, 3) self.amp = gr.multiply_const_cc(options.amp) self.connect(self.txpath, self.amp, self.sink)
def __init__(self): gr.top_block.__init__(self, "CC430 Transmitter") self.sent_pkts = 0 # 5555 5555 2c6e fd00 0071 da0b e2 self.packet = chr(0x55)*4 # preamble self.packet += chr(0x2c) + chr(0x6e) # sync self.packet += chr(0xfc) # length self.packet += chr(0x00) + chr(0x00) + chr(0x00) # payload self.packet += chr(0x71) + chr(0xda) + chr(0x0b) + chr(0xe2) # CRC (currently incorrect) # Variables self.samp_rate = samp_rate = 125e3 self.f_center = f_center = 868e6 self.bandwidth = bandwidth = 200e3 self.gain = gain = 5 self.msgq = msgq = gr.msg_queue() # Blocks self.uhd_sink = uhd.usrp_sink( device_addr="", stream_args=uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_sink.set_samp_rate(samp_rate) self.uhd_sink.set_center_freq(f_center, 0) self.uhd_sink.set_gain(gain, 0) self.uhd_sink.set_bandwidth(bandwidth, 0) self.msg_src = gr.message_source(1, msgq) self.msk = level.msk_mod_bc( samples_per_symbol=2, bt=0.3 ) # Connections self.connect(self.msg_src, self.msk, self.uhd_sink)
def __init__(self, options): gr.hier_block2.__init__(self, "ofdm_transmit_path", gr.io_signature(0, 0, 0), gr.io_signature(1, 1, gr.sizeof_gr_complex)) if options.data_file is not None: data = gr.message_source(gr.sizeof_gr_complex) ofdm = data framebytes = 0 else: ofdm = ofdm_rxtx.TX(options) qam = raw_qam.qam_tx(options.bitrate, ofdm.params.data_tones, ofdm.size, log=options.log) framebytes = qam.framebytes data = blocks.message_source(gr.sizeof_char * framebytes, 16) data = blocks.message_burst_source(gr.sizeof_char * framebytes, 16) self.connect( data, blocks.vector_to_stream(gr.sizeof_char, qam.framebytes), qam, blocks.stream_to_vector(gr.sizeof_gr_complex, ofdm.params.data_tones), ofdm) # precoding module nco_sensitivity = 2.0 / options.fft_length # correct for fine frequency nco = raw.pnc_frequency_modulator_fc(nco_sensitivity) print "===========>>>>>>>>>" print "precoding: ", options.precoding if options.precoding == "YES": self.connect(ofdm, nco, self) self.nco = nco else: self.connect(ofdm, self) self.nco = None self.data = data self.tx = ofdm self.framebytes = framebytes if options.log: self.connect(self.tx, blocks.file_sink(gr.sizeof_gr_complex, 'logs/tx.dat'))
def __init__(self, type='BER', win_size=default_win_size, bits_per_symbol=2): """ Error rate constructor. @param type a string 'BER' or 'SER' @param win_size the number of samples to calculate over @param bits_per_symbol the number of information bits per symbol (BER only) """ #init gr.hier_block2.__init__( self, 'error_rate', gr.io_signature(2, 2, gr.sizeof_char), gr.io_signature(1, 1, gr.sizeof_float), ) assert type in ('BER', 'SER') self._max_samples = win_size self._bits_per_symbol = bits_per_symbol #setup message queue msg_source = gr.message_source(gr.sizeof_float, 1) self._msgq_source = msg_source.msgq() msgq_sink = gr.msg_queue(2) msg_sink = gr.message_sink(gr.sizeof_char, msgq_sink, False) #False -> blocking inter = gr.interleave(gr.sizeof_char) #start thread self._num_errs = 0 self._err_index = 0 self._num_samps = 0 self._err_array = numpy.zeros(self._max_samples, numpy.int8) if type == 'BER': input_watcher(msgq_sink, self._handler_ber) elif type == 'SER': input_watcher(msgq_sink, self._handler_ser) #connect self.connect(msg_source, self) self.connect((self, 0), (inter, 0)) self.connect((self, 1), (inter, 1)) self.connect(inter, msg_sink)
def __init__(self): gr.top_block.__init__(self, "CC430 Transmitter") self.sent_pkts = 0 # 5555 5555 2c6e fd00 0071 da0b e2 self.packet = chr(0x55) * 4 # preamble self.packet += chr(0x2c) + chr(0x6e) # sync self.packet += chr(0xfc) # length self.packet += chr(0x00) + chr(0x00) + chr(0x00) # payload self.packet += chr(0x71) + chr(0xda) + chr(0x0b) + chr( 0xe2) # CRC (currently incorrect) # Variables self.samp_rate = samp_rate = 125e3 self.f_center = f_center = 868e6 self.bandwidth = bandwidth = 200e3 self.gain = gain = 5 self.msgq = msgq = gr.msg_queue() # Blocks self.uhd_sink = uhd.usrp_sink( device_addr="", stream_args=uhd.stream_args( cpu_format="fc32", channels=range(1), ), ) self.uhd_sink.set_samp_rate(samp_rate) self.uhd_sink.set_center_freq(f_center, 0) self.uhd_sink.set_gain(gain, 0) self.uhd_sink.set_bandwidth(bandwidth, 0) self.msg_src = gr.message_source(1, msgq) self.msk = level.msk_mod_bc(samples_per_symbol=2, bt=0.3) # Connections self.connect(self.msg_src, self.msk, self.uhd_sink)
def __init__(self, samples_per_symbol, bits_per_symbol, access_code='', pad_for_usrp=True, kbid='', verbose=0): """ packet_mod constructor. @param samples_per_symbol number of samples per symbol @param bits_per_symbol number of bits per symbol @param access_code AKA sync vector @param pad_for_usrp If true, packets are padded such that they end up a multiple of 128 samples @param 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._kbid = kbid self._verbose = verbose 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 = gr.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, fg, msgq_limit=2, pad_for_usrp=True, *args, **kwargs): """ Hierarchical block for the 802_15_4 O-QPSK modulation. Packets to be sent are enqueued by calling send_pkt. The output is the complex modulated signal at baseband. @param fg: flow graph @type fg: flow graph @param msgq_limit: maximum number of messages in message queue @type msgq_limit: int @param pad_for_usrp: If true, packets are padded such that they end up a multiple of 128 samples See 802_15_4_mod for remaining parameters """ self.pad_for_usrp = pad_for_usrp # accepts messages from the outside world self.pkt_input = gr.message_source(gr.sizeof_char, msgq_limit) self.ieee802_15_4_mod = ieee802_15_4.ieee802_15_4_mod(fg, *args, **kwargs) fg.connect(self.pkt_input, self.ieee802_15_4_mod) gr.hier_block.__init__(self, fg, None, self.ieee802_15_4_mod)
def __init__(self, type="BER", win_size=default_win_size, bits_per_symbol=2): """ Error rate constructor. @param type a string 'BER' or 'SER' @param win_size the number of samples to calculate over @param bits_per_symbol the number of information bits per symbol (BER only) """ # init gr.hier_block2.__init__( self, "error_rate", gr.io_signature(2, 2, gr.sizeof_char), gr.io_signature(1, 1, gr.sizeof_float) ) # initialize ber and ser self.ber_ = 0 self.ser_ = 0 assert type in ("BER", "SER") self._max_samples = win_size self._bits_per_symbol = bits_per_symbol # setup message queue msg_source = gr.message_source(gr.sizeof_float, 1) self._msgq_source = msg_source.msgq() msgq_sink = gr.msg_queue(2) msg_sink = gr.message_sink(gr.sizeof_char, msgq_sink, False) # False -> blocking inter = gr.interleave(gr.sizeof_char) # start thread self._num_errs = 0 self._err_index = 0 self._num_samps = 0 self._err_array = numpy.zeros(self._max_samples, numpy.int8) if type == "BER": input_watcher(msgq_sink, self._handler_ber) elif type == "SER": input_watcher(msgq_sink, self._handler_ser) # connect self.connect(msg_source, self) self.connect((self, 0), (inter, 0)) self.connect((self, 1), (inter, 1)) self.connect(inter, msg_sink)
def __init__( self, modulator, access_code=None, msgq_limit=2, pad_for_usrp=True, use_whitener_offset=False, modulate=True ): """ Hierarchical block for sending packets Packets to be sent are enqueued by calling send_pkt. The output is the complex modulated signal at baseband. Args: modulator: instance of modulator class (gr_block or hier_block2) (complex baseband out) access_code: AKA sync vector (string of 1's and 0's between 1 and 64 long) msgq_limit: maximum number of messages in message queue (int) pad_for_usrp: If true, packets are padded such that they end up a multiple of 128 samples use_whitener_offset: If true, start of whitener XOR string is incremented each packet See gmsk_mod for remaining parameters """ gr.hier_block2.__init__( self, "mod_pkts", gr.io_signature(0, 0, 0), gr.io_signature(1, 1, gr.sizeof_gr_complex) # Input signature ) # Output signature self._modulator = modulator self._pad_for_usrp = pad_for_usrp self._use_whitener_offset = use_whitener_offset self._whitener_offset = 0 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 # accepts messages from the outside world self._pkt_input = gr.message_source(gr.sizeof_char, msgq_limit) self.connect(self._pkt_input, self._modulator, self)
def __init__(self): gr.top_block.__init__(self) audio_rate =48000 # audio rate changed self.src = gr.message_source(gr.sizeof_char, msgq_limit) src = self.src b_to_syms = gr.bytes_to_syms() mult = gr.multiply_const_ff(1000) add = gr.add_const_ff(CentreFreq) repeater = gr.repeat(gr.sizeof_float,RepeatTime) fsk_f = gr.vco_f(audio_rate, 2*pi,0.5) # Sensitivity is rad/sec/volt ( e.g 2*pi*f/sec = 1Khz) and here f = volts (input amplitude of VCO) attenuator = gr.multiply_const_ff(0.05) # multiply speaker = audio.sink(audio_rate, "plughw:0,0"); dst = gr.wavfile_sink("tx-signal.wav",1, audio_rate, 16) self.connect(src,b_to_syms,mult,add,repeater,fsk_f,attenuator,speaker) self.connect(fsk_f,dst)
def __init__(self, principal_gui, options): ''' See below for what options should hold ''' gr.hier_block2.__init__(self, "transmit_path", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(0, 0, 0)) # Output signature options = copy.copy(options) # make a copy so we can destructively modify self._verbose = options.verbose self._tx_amplitude = options.tx_amplitude # digital amplitude sent to USRP self._bitrate = options.rate # desired bit rate self._samples_per_symbol = options.sps # desired samples/baud #setup usrp self._setup_usrp_sink(options) #create a BPSK modulator self.modulator = bpsk_modulator(principal_gui, options) # the modulator we are using #create packet input like in ieee 802.15.4 #the size of the queue is 2 messages #######################************* msgq_limit = 10 self.pkt_input = gr.message_source(gr.sizeof_char, msgq_limit) #The same chain like in ieee transceiver #add gain like in ieee802.15.4 #######################################***************** #self.normal_gain = 8000 #self.gain = gr.multiply_const_cc (self.normal_gain) self.amp = gr.multiply_const_cc(options.amplitude) #self.set_tx_amplitude(self._tx_amplitude) # Display some information about the setup if self._verbose: self._print_verbage() # Connect components in the flowgraph #self.connect(self.packet_transmitter, self.amp, self) # self.wxgui_constellationsink2_0 = constsink_gl.const_sink_c( # principal_gui.GetWin(), # title="Constellation Plot", # sample_rate=options.samp_rate, # frame_rate=5, # const_size=2048, # M=2, # theta=0, # fmax=0.06, # mu=0.5, # gain_mu=0.005, # symbol_rate=options.samp_rate/self._samples_per_symbol, # omega_limit=0.005, # ) # principal_gui.Add(self.wxgui_constellationsink2_0.win) '''For Stream of bits ''' self.vector_source = gr.vector_source_b([1,], True) self.scrambler = gr.scrambler_bb(0x10,0x7F,7) #self.connect(self.vector_source,self.scrambler, self.modulator, self.amp, self.u) #self.connect(self.modulator,self.wxgui_constellationsink2_0) '''End For Stream of bits ''' self.connect(self.pkt_input, self.modulator, self.amp, self.u)
def __init__(self, options, parent): ''' See below for what options should hold ''' gr.hier_block2.__init__(self, "transmit_path", gr.io_signature(0, 0, 0), # Input signature gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature options = copy.copy(options) # make a copy so we can destructively modify self._bitrate = options.bitrate # desired bit rate #self._inter = options.inter # Decimating rate for the USRP (prelim) self._samples_per_symbol = options.samples_per_symbol # desired samples/symbol self._down_sample_rate = options.down_sample_rate self._verbose = options.verbose self._tx_amplitude = options.tx_amplitude # digital amplitude sent to USRP self._use_whitener_offset = options.use_whitener_offset # increment start of whitener XOR data self._access_code = packet_utils.conv_packed_binary_string_to_1_0_string(default_ola_spade_code) self._subchannel = options.subchannel self._msgq_limit = 4 self.parent = parent # Turn it into NRZ data. self.nrz = gr.bytes_to_syms() self.sqwave = (1,) * self._samples_per_symbol # rectangular window self.gaussian_filter = gr.interp_fir_filter_fff(self._samples_per_symbol, self.sqwave) #Sensitivity will be seletected by set_sensitivity function in main loop self.sensitivity_a = (2 *pi * self._subchannel) / self._samples_per_symbol # phase change per bit = pi / 2 (for BFSK) self.sensitivity_b = (2 *pi * (self._subchannel)) / self._samples_per_symbol # phase change per bit = pi / 2 (for BFSK) self._pad_for_usrp = True self._use_whitener_offset = False self._whitener_offset = 0 # TODO # BUG : Improve or Implement Stream Selector!!!! (Check the new GNU Radio blocks!!!) # ============================================================================= # The first flowgraph for Digital Only Modulation # ============================================================================= self._pkt_input = gr.message_source(gr.sizeof_char, self._msgq_limit) # accepts messages from the outside world self.fmmod = gtlib.bfsk_modulator_fc(self.sensitivity_a,self.sensitivity_b) # BFSK modulation self.amp = gr.multiply_const_cc(1) # (Note that on the RFX cards this is a nop.) self.amp_2 = gr.multiply_const_cc(1) # (Sub channel correction) if self._subchannel >= 1 and self._subchannel <= 4: self.amp_2.set_k(pow(1.2,(float(self._subchannel)-1))) #self.timetag_inserter = gtlib.usrp_timetag_insert() if self._verbose: self._print_verbage() # Display some information about the setup # ============================================================================= # Flowgraph connection # ============================================================================= self.connect(self._pkt_input, self.nrz, self.gaussian_filter,self.fmmod,self.amp, self.amp_2, self) self.set_tx_amplitude(self._tx_amplitude)