#!/usr/bin/env python from gnuradio import gr, gru, blks2 from gnuradio import usrp2 from gnuradio import eng_notation from gnuradio.eng_option import eng_option import gnuradio.gr.gr_threading as _threading from optparse import OptionParser import os, struct, sys, time, math, random, threading def get_fir_filter(): taps = [0.50, 0.25, 0.125, 0.0645] return gr.fir_filter_ccf(1, taps) class USRP2source: __instance = None def __init__(self, interface, mac_addr): if USRP2source.__instance: raise USRP2source.__instance USRP2source.__instance = self self.shared_usrp2_source32fc = usrp2.source_32fc(interface, mac_addr) def get_usrp2_sorce32fc(interface, mac_addr): try: instance = USRP2source(interface, mac_addr) except USRP2source, e: instance = e return instance.shared_usrp2_source32fc class test1(gr.top_block): def __init__(self): gr.top_block.__init__(self) #self.u = get_usrp2_sorce32fc("eth0", "") self.u = usrp2.source_32fc("eth0", "") self.fir = get_fir_filter() self.sink = gr.file_sink(gr.sizeof_gr_complex, "test1.dat") tr = self.u.set_center_freq(2.462e9) if tr == None: sys.stderr.write('Failed to set center frequency\n') raise SystemExit, 1 self.u.set_decim(16) self.connect(self.u, self.fir, self.sink) class test2(gr.top_block): def __init__(self): gr.top_block.__init__(self) #self.u = get_usrp2_sorce32fc("eth0", "") self.u = usrp2.source_32fc("eth0", "") self.fir = get_fir_filter() self.sink = gr.file_sink(gr.sizeof_gr_complex, "test2.dat") tr = self.u.set_center_freq(2.412e9) if tr == None: sys.stderr.write('Failed to set center frequency\n') raise SystemExit, 1 self.u.set_decim(14) self.connect(self.u, self.fir, self.sink) def main (): print "Running test 1" t1 = test1() t1.start() time.sleep(5) print "Stopping test1" t1.stop() t1.wait() print "Running test2" t2 = test2() t2.start() time.sleep(5) print "Stopping test2" t2.stop() if __name__ == '__main__': try: main() except KeyboardInterrupt: raise SystemExit