def device_definition(options): """ Definition of the devices used in the program. @param options """ tb = OpERAFlow(name='US') the_source = blocks.file_source(gr.sizeof_gr_complex, "./%d_%d_%d_%d_noise.bin" % (options.fft_length, options.cp_length, options.ebn0, options.it), False) radio = RadioDevice(name="radio") det = Correlator() middle = gr.hier_block2( name='hier', input_signature = gr.io_signature(1, 1, gr.sizeof_gr_complex), output_signature = gr.io_signature(1, 1, gr.sizeof_float * 1024), ) middle.connect(middle, blocks.stream_to_vector(gr.sizeof_gr_complex, 1024), blocks.complex_to_mag(1024), middle) ed = EnergySSArch(1024, 1, EnergyDecision(th = options.threshold)) radio.add_arch(source = the_source, arch = middle, sink =(det,0), uhd_device=the_source, name='estimator') radio.add_arch(source = the_source, arch = ed, sink =(det,1), uhd_device=the_source, name = "ed") tb.add_radio(radio, "radio") return tb, radio, det
def main(options): """ Main function. @param options """ options.my_ip = all_radios_ip[options.my_id] radio = build_radio(options) radio.id = options.my_id radio.set_gain(radios_gain[radio.id]) tb = OpERAFlow('OperaFlow') tb.add_radio(radio, 'radio') tb.start() channel_list = [Channel(ch=0, freq=1.11e9, bw=200e3), Channel(ch=1, freq=1.51e9, bw=400e3), Channel(ch=2, freq=1.7e9, bw=500e3), Channel(ch=3, freq=1.9e9, bw=400e3), ] cognitive_radio_loop(options, radio, channel_list) tb.stop() tb.wait()
def device_definition(options): """ Definition of the devices used in the program. @param options """ tb = OpERAFlow(name="US") bits_per_symbol = 2 modulator = grc_blks2.packet_mod_b( digital.ofdm_mod( options=grc_blks2.options( modulation="bpsk", fft_length=512, occupied_tones=200, cp_length=128, pad_for_usrp=True, log=None, verbose=None, ) ), payload_length=0, ) uhd_source = UHDSourceDummy(modulator=modulator, f=change_status_fun) uhd_source.pre_connect(tb) # Gambi the_source = AWGNChannel(bits_per_symbol=bits_per_symbol, component=uhd_source) algorithm = None if options.sensing == "ed": sensing = EnergySSArch(fft_size=1024, mavg_size=1) algorithm = EnergyDecision(options.th) sink = EnergyDetector(1024, algorithm) elif options.sensing == "wfd": sensing = WaveformSSArch(fft_size=1024) algorithm = WaveformDecision(options.th) sink = WaveformDetector(1024, algorithm) elif options.sensing == "cfd": sensing = CycloSSArch(64, 16, 4) from sensing import CycloDecision algorithm = CycloDecision(64, 16, 4, options.th) sink = CycloDetector(64, 16, 4, algorithm) else: raise AttributeError radio = RadioDevice(name="radio") radio.add_arch(source=the_source, arch=sensing, sink=sink, uhd_device=uhd_source, name="sensing") tb.add_radio(radio, "radio") return tb, radio, algorithm
def build_us_block(options): """ Builds the US top block. The RX path performs the ED sensing The TX path transmits a BER @param options """ # TOP BLOCK tb = OpERAFlow(name='US') # RX PATH if not options.tx_only: uhd_source = UHDSource(device_addr=options.args) uhd_source.samp_rate = 195512 the_source = uhd_source the_sink = blocks.probe_signal_f() rx_path = EnergySSArch(fft_size=512, mavg_size=5, algorithm=EnergyDecision(th=0.000005) ) device_source = RadioDevice() device_source.add_arch(source=the_source, arch=rx_path, sink=the_sink, uhd_device=None, name="source") ###tb.add_arch( abstract_arch = rx_path, radio_device = device_source, name_of_arch = 'rx') tb.ad_radio(device_source, 'rx') # TX PATH tx_path = PacketGMSKTx(name='a') Logger.add_to_print_list("a_bit_rate", 'bps') uhd_sink = UHDSink(device_addr = options.args) uhd_sink.samp_rate = options.samp_rate the_source = None the_sink = uhd_sink uhd_device = uhd_sink radio_sink = RadioDevice() #::TODO:: conferir se arch é mesmo tx_path, e fazer essa verificacao do tx_path e rx_path para todos os outros arquivos radio_sink.add_arch(source=the_source, arch=tx_path, sink=the_sink, uhd_device=uhd_device, name="sink") ###tb.add_arch( tx_path, radio_sink, 'tx', connection_type = OpERAFlow.CONN_SINK) tb.add_radio(radio_sink, 'tx') return tb
def device_definition(options): """ Definition of the devices used in the program. @param options """ tb = OpERAFlow(name='US') bits_per_symbol = 2 modulator = grc_blks2.packet_mod_b(digital.ofdm_mod( options=grc_blks2.options( modulation="bpsk", fft_length=512, occupied_tones=200, cp_length=128, pad_for_usrp=True, log=None, verbose=None, ), ), payload_length=0, ) uhd_source = UHDSourceDummy(modulator=modulator) uhd_source.pre_connect(tb) # Gambi the_source = AWGNChannel(component=uhd_source, bits_per_symbol = bits_per_symbol) arch1 = EnergySSArch(fft_size=1024, mavg_size=1) algo1 = EnergyDecision(options.th['ed']) if options.sensing == "wfd": arch2 = WaveformSSArch(fft_size=1024) algo2 = WaveformDecision(options.th['wfd']) elif options.sensing == 'cfd': arch2 = CycloSSArch(64, 16, 4) from sensing import CycloDecision algo2 = CycloDecision(64, 16, 4, options.th['cfd']) else: raise AttributeError hier = HierarchicalSSArch(1024, algo1=algo1, algo2=algo2) radio = RadioDevice(name="radio") radio.add_arch(source=the_source, arch=arch1, sink=(hier, 0), uhd_device=uhd_source, name='ed') radio.add_arch(source=the_source, arch=arch2, sink=(hier, 1), uhd_device=uhd_source, name='sensing') tb.add_radio(radio, "radio") return tb, radio, algo1, algo1
def build_us_block(options): """ Builds the US top block. The RX path performs the ED sensing. The TX path transmits a BER. @param options """ # TOP BLOCK tb = OpERAFlow(name='US') # RX PATH uhd_source = UHDSource(device_addr=options.args) uhd_source.samp_rate = 195512 #::TODO:: nova versao do radiodevice --> atualizar the_source = uhd_source the_sink = blocks.probe_signal_f() ###device_source = RadioDevice(the_source = uhd_source, the_sink = blocks.probe_signal_f() ) device_source = RadioDevice() device_source.add_arch(source=the_source, arch=None, sink=the_sink, uhd_device=None, name="source") # ::TODO:: energyssarch NAO tem o parametro device!!! rx_path = EnergySSArch(device=device_source, fft_size=512, mavg_size=5, algorithm=None) #algorithm = EnergyDecision( th = 0.00000001 )) ## tb.add_arch( abstract_arch = rx_path, radio_device = device_source, name_of_arch = 'rx') tb.add_radio(device_source, "rx") # TX PATH tx_path = PacketGMSKTx() uhd_sink = UHDSink(device_addr=options.args) uhd_sink.samp_rate = options.samp_rate the_source = None the_sink = uhd_sink uhd_device = uhd_sink radio_sink = RadioDevice() radio_sink.add_arch(source=the_source, arch=None, sink=the_sink, uhd_device=uhd_device, name="sink") ####tb.add_arch( tx_path, radio_sink, 'tx', connection_type = OpERAFlow.CONN_SINK) tb.add_radio(radio_sink, "sink") return tb
def device_definition(): """ Definition of the devices used in the program. """ tb = OpERAFlow(name='US') uhd_source = UHDSource() uhd_source.samp_rate = 195512 energy = EnergySSArch(fft_size=512, mavg_size=5, algorithm=EnergyDecision(th=0)) radio = RadioDevice(name="radio") radio.add_arch(source=uhd_source, arch=energy, sink=blocks.probe_signal_f(), uhd_device=uhd_source, name='ss') tb.add_radio(radio, "radio") return tb, radio
def main(options): """ Main function @param options """ options.my_ip = all_radios_ip[options.my_id] radio = build_radio(options) radio.id = options.my_id tb = OpERAFlow('OperaFlow') tb.add_radio(radio, 'radio') tb.start() channel_list = [Channel(ch=0, freq=2.2e9, bw=200e3), ] cognitive_radio_loop(options, radio, channel_list) tb.stop() tb.wait()
def build_up_block(options, channel_list): """ Builds the UP top block. The RX path performs the ED sensing AND BER reception @param options @param channel_list """ # TOP BLOCK tb = OpERAFlow(name='UP') def rx_callback(ok, payload): """ @param ok @param payload """ global t_rcv, t_cor t_rcv += 1 t_cor += 1 if ok else 0 def dist_callback(channel, status): """ @param channel @param status """ return random.expovariate(1/10.0) # RX PATH uhd_source = UHDSource(device_addr=options.args) uhd_source.samp_rate = options.samp_rate the_source = uhd_source the_sink = None rx_path = PacketGMSKRx(rx_callback) # ::TODO:: os packet podem entrar no parametro 'arch'? conferir isso!! radio_source = RadioDevice() radio_source.add_arch(source=the_source, arch=rx_path, sink=the_sink, uhd_device=uhd_source, name="source") ## tb.add_arch(rx_path, radio_source, 'rx') tb.add_radio(radio_source, 'rx') # TX PATH if not options.tx_only: uhd_sink = UHDSink(device_addr = options.args) uhd_sink.samp_rate = 195512 the_source = blocks.vector_source_f(map(int, np.random.randint(0, 100, 1000)), True) the_sink = uhd_sink, uhd_device = uhd_sink radio_sink = RadioDevice() #::TODO:: checar como faz aqui, que tem um radio_proxy e tb um tx_path. algum deles eh o uhd? e o arch? radio_proxy = ChannelModeler(device=radio_sink, channel_list=channel_list, dist_callback=dist_callback) tx_path = SimpleTx() radio_sink.add_arch(source=the_source, arch=tx_path, sink=the_sink, uhd_device=uhd_sink, name="sink") # ?????? ##tb.add_arch(tx_path, radio_proxy, 'tx') tb.add_radio(radio_sink, 'tx') return tb
def setUp(self): """ Set globals for all tests. Called before a test is started. """ self.tb = OpERAFlow(name='top')
class QaEnergyDetector(gr_unittest.TestCase): """ QA related to EnergyDetector class. """ def setUp(self): """ Set globals for all tests. Called before a test is started. """ self.tb = OpERAFlow(name='top') def tear_down(self): """ Destroy globals for all tests. Called right after a test if finished. """ self.tb = None def test_001(self): """ Test the energy of a simple sequence (1, 2, -1, -2). """ # input and expected results src_data = (1, 1, 1, 1) expected_result = 1 # blocks fft_size = len(src_data) mavg_size = 1 src = blocks.vector_source_c(data=src_data) dst = blocks.probe_signal_f() ed = EnergySSArch(fft_size, mavg_size, EnergyDecision(1)) #radio_device = RadioDevice(the_source = src, the_sink = dst) radio_device = RadioDevice() radio_device.add_arch(source=src, arch=ed, sink=dst, uhd_device=None, name='ed') ################ FIM NOVO RADIO DEVICE ## flowgraph ##self.tb.add_arch(ed, radio_device, 'ed') self.tb.add_radio(radio_device) self.tb.run() result_data = dst.level() self.assertEqual(expected_result, result_data) def test_002(self): """ Test a sequence with float number (0.1, 0.1, 0.1, 0.1). """ # input and expected results src_data = (0.1, 0.1, 0.1, 0.1) expected_result = 0 # blocks fft_size = len(src_data) mavg_size = 1 src = blocks.vector_source_c(data=src_data) ed = EnergyDetectorC(fft_size, mavg_size, EnergyDecision(1)) dst = blocks.probe_signal_f() # flowgraph self.tb.connect(src, ed, dst) self.tb.run() result_data = dst.level() self.assertEqual(expected_result, result_data) def test_003(self): """ Test EDTopBlock with the input (1, 1, 1, 1, 1, 1, 1, 1). """ arr = (1, 1, 1, 1, 1, 1, 1, 1) expected_out = 8 ed = EnergySSArch(fft_size=len(arr), mavg_size=8, algorithm=EnergyDecision(expected_out - 1) ) src = blocks.vector_source_c(data=arr, vlen=1) sink = blocks.probe_signal_f() device = RadioDevice() device.add_arch(source=src, arch=ed, sink=sink, uhd_device=None, name='ed') self.tb.add_radio(device, 'ed') self.tb.run() ##self.assertEqual(1 , device.sink.level()) # didn't work self.assertEqual(1, device.output()[0]) def test_004(self): """ Test EDTopBlock with a simple input (1, 2, 3, 4). """ arr = (1.0, 2.0, 3.0, 4.0) expected_result = 30 # before expected result was 2536 ed = EnergySSArch(fft_size=len(arr), mavg_size=1, algorithm=EnergyDecision(expected_result + 1) # (expected_out + 1) ) src = blocks.vector_source_c(data=arr, vlen=1) sink = blocks.probe_signal_f() device = RadioDevice() device.add_arch(source=src, arch=ed, sink=sink, uhd_device=None, name='ed') self.tb.add_radio(device, 'ed') self.tb.start() self.tb.wait() ###self.assertEqual(expected_result , device.sink.output()[1]) self.assertEqual(expected_result, device.ed.output()[1]) # uses 'name' parameter of the add_arch method
def setUp(self): """ Set globals for all tests. Called before a test is started. """ self.tb = OpERAFlow('QaFeedback')
class QaFeedback(gr_unittest.TestCase): """ QA tests related to feeback. """ def setUp(self): """ Set globals for all tests. Called before a test is started. """ self.tb = OpERAFlow('QaFeedback') def tear_down(self): """ Destroy globals for all tests. Called right after a test if finished. """ self.tb = None def test_001(self): """ Test Feedback Algorithm architecture. This test validates the feedback architecture when the 'manager' says the channel is idle and the 'learner' says is occupied. """ return """ ::TODO:: Update this test. """ print 't1' data_l = [1] data_m = [0] # Bayes learning parameters in_th = 10 min_th = 0.001 max_th = 20 delta_th = 0.001 k = 1 # Feeback architecture bl_algo = BayesLearningThreshold(in_th=in_th, min_th=min_th, max_th=max_th, delta_th=delta_th, k=k) fb_algo = FeedbackAlgorithm(bl_algo, AlwaysTimeFeedback()) fb = FeedbackF(fb_algo) # Data blocks src_l = blocks.vector_source_f(data_l) src_m = blocks.vector_source_f(data_m) # Flow graph tb = gr.top_block() tb.connect(src_l, (fb, 0)) tb.connect(src_m, (fb, 1)) tb.run() # bayes feedback has to be 0 self.assertEqual(bl_algo.feedback, 0) def test_002(self): """ Test Feedback Algorithm architecture This test validates the feedback architecture when the 'manager' says the channel is occupied and the 'learner' says is idle. """ return """ ::TODO:: Update this test. """ data_l = [0] data_m = [1] # Bayes learning parameters in_th = 10 min_th = 0.001 max_th = 20 delta_th = 0.001 k = 1 # Feeback architecture bl_algo = BayesLearningThreshold(in_th=in_th, min_th=min_th, max_th=max_th, delta_th=delta_th, k=k) fb_algo = FeedbackSSArch2(bl_algo, AlwaysTimeFeedback()) ### learner, manager, a_feedback_strategy fb = FeedbackF(fb_algo) # Data blocks src_l = blocks.vector_source_f(data_l) src_m = blocks.vector_source_f(data_m) # Flow graph tb = gr.top_block() tb.connect(src_l, (fb, 0)) tb.connect(src_m, (fb, 1)) tb.run() # bayes feedback has to be 0 self.assertEqual(bl_algo.feedback, 1) def test_003(self): """ Test a more elaborate scenario with feedback. In this test the FeedbackTopBlock is utilized with n waveform algorithm as manager, an energy and a feedback algorithm. """ return """ ::TODO:: Update this test. """ # Random 'signal' utilized in the test arr = [random.random() for i in xrange(1024)] fft_size = 1024 # Bayes learning parameters in_th = 1 min_th = 0.001 max_th = 20 delta_th = 0.001 k = 1 # Feeback architecture bl_algo = BayesLearningThreshold(in_th=in_th, min_th=min_th, max_th=max_th, delta_th=delta_th, k=k) # detectors utilized bl = EnergyDetectorC(fft_size, 1, bl_algo) ev = WaveformSSArch(fft_size, WaveformDecision(0.7)) # top block t = FeedbackSSArch(block_manager=ev, block_learner=bl, feedback_algorithm=FeedbackAlgorithm(bl_algo, AlwaysTimeFeedback()) ### learner, manager, a_feedback_strategy ) source = blocks.vector_source_c(data=arr, vlen=1) sink = blocks.probe_signal_f() device = RadioDevice() device.add_arch(source=source, arch=t, sink=sink, uhd_device=None, name='ss_arch') self.tb.add_path(t, device, 'ss') self.tb.run() # As the waveform will (probably) not detected the channel as occupied, the feedback system should decrease the threshold by 1 self.assertEqual(0, bl_algo.feedback)
def build_up_block(options, channel_list): """ Builds the UP top block. The RX path performs the ED sensing AND BER reception @param options @param channel_list """ # TOP BLOCK tb = OpERAFlow(name='UP') def rx_callback(ok, payload): """ @param ok @param payload """ global t_rcv, t_cor global g_namespace t_rcv += 1 t_cor += 1 if ok else 0 g_namespace.pkt_r += 1 #print 'r: ', g_namespace.pkt_r def dist_callback(channel, status): """ @param channel @param status """ if status: return 1.0 else: return channel.channel*0.25 # RX PATH uhd_source = UHDSource(device_addr=options.args) uhd_source.samp_rate = options.samp_rate #::TODO:: atualizar para novo radiodevice the_source = uhd_source the_sink = None radio_source = RadioDevice() radio_source.add_arch(source=the_source, arch=None, sink=the_sink, uhd_device=None, name="source") rx_path = PacketGMSKRx(rx_callback) ##tb.add_arch( rx_path, radio_source, 'rx' ) tb.add_radio(radio_source, 'rx') # TX PATH uhd_sink = UHDSink(device_addr=options.args) uhd_sink.samp_rate = 195512 uhd_sink.gain = 28 the_source = blocks.vector_source_f(map(int, np.random.randint(0, 100, 1000)), True) the_sink = uhd_sink uhd_device = uhd_sink radio_sink = RadioDevice() radio_sink.add_arch(source=the_source, arch=None, sink=the_sink, uhd_device=uhd_device, name="source") radio_proxy = ChannelModeler(device=radio_sink, channel_list=channel_list, dist_callback=dist_callback) tx_path = SimpleTx() ###tb.add_arch( tx_path, radio_proxy, 'tx') tb.add_radio(radio_proxy, 'tx') return tb