Beispiel #1
0
def draw_menu(stdscr):
    global src
    global decoder
    global dab_ofdm_demod_0
    global c2f
    global f2c
    global audio_sink_0
    global xrun_monitor
    global fg
    global use_zeromq
    global rpc_mgr_server
    global dab_ofdm_demod_0
    global ppm_shared

    k = 0
    cursor_x = 0
    cursor_y = 0


    # Clear and refresh the screen for a blank canvas
    stdscr.clear()
    stdscr.refresh()
    curses.curs_set(0)

    kThread = KeyDetecThread(stdscr)

    # Start colors in curses
    curses.start_color()
    curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK)
    curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK)
    curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE)

    selected = 0
    active = 0
    scroll = 0
    nelem = len(channel_list)
    # Loop where k is the last character pressed
    while (k != ord('q')):

        # Initialization
        stdscr.clear()
        height, width = stdscr.getmaxyx()
        center_x = int((width // 2) - 2)
        center_y = int((height // 2) - 2)

        if k == curses.KEY_DOWN:
            cursor_y = cursor_y + 1
        elif k == curses.KEY_UP:
            cursor_y = cursor_y - 1
        elif k == curses.KEY_RIGHT:
            cursor_x = cursor_x + 1
        elif k == curses.KEY_LEFT:
            cursor_x = cursor_x - 1

        previous_active = active

        if k == 259: # key up
            if selected > 0:
                selected -= 1
            if selected <= scroll:
                if scroll > 1:
                    scroll -= 1
                else:
                    scroll = 0
        elif k == 258: # key down
            if selected < (nelem-1):
                selected += 1
            if selected == height - 1 + scroll:
                scroll += 1
        elif k == 339: # page up
            if selected >= 15:
                selected -= 15
            else:
                selected = 0
            if selected <= height - 1 + scroll:
                if scroll >= 15:
                    scroll -= 15
                else:
                    scroll = 0
        elif k == 338: # page down
            if selected < (nelem-15):
                selected += 15
            else:
                selected = nelem-1
            if selected >= height - 1 + scroll:
                scroll += 15
        elif k == 360: # end
            selected = nelem-1
            if selected >= height - 1 + scroll:
                scroll = nelem - height + 1
        elif k == 262: # home
            selected = 0
            scroll = 0
        elif k == 10: # enter
            active = selected

        if k == 10:
            stdscr.move(center_y, center_x)
            ch = channel_list[active]
            freq = float(ch['frequency'])*1e6
            if use_zeromq:
                rpc_mgr_server.request("set_frequency",[freq])
            else:
                src.set_center_freq(freq, 0)

            if 'classic' in ch and ch['classic'] == True:
                dabplus = False
            else:
                dabplus = True

            if dabplus:
                new = grdab.dabplus_audio_decoder_ff(grdab.parameters.dab_parameters(mode=1, sample_rate=samp_rate, verbose=False), ch['bit_rate'], ch['address'], ch['subch_size'], ch['protect_level'], True)
            else:
                new = grdab.dab_audio_decoder_ff(grdab.parameters.dab_parameters(mode=1, sample_rate=samp_rate, verbose=False), ch['bit_rate'], ch['address'], ch['subch_size'], ch['protect_level'], True)

            newaudio = audio.sink(48000, '', True)
            fg.stop()
            fg.wait()
            xrun_monitor.stop_until_tag()
            fg.disconnect(src, dab_ofdm_demod_0, decoder)
            fg.disconnect((decoder, 0), (f2c, 0))
            fg.disconnect((decoder, 1), (f2c, 1))
            fg.disconnect((c2f, 0), (audio_sink_0, 0))
            fg.disconnect((c2f, 1), (audio_sink_0, 1))
            del decoder
            del audio_sink_0
            decoder = new
            audio_sink_0 = newaudio
            fg.connect(src, dab_ofdm_demod_0, decoder)
            fg.connect((decoder, 0), (f2c, 0))
            fg.connect((decoder, 1), (f2c, 1))
            fg.connect((c2f, 0), (audio_sink_0, 0))
            fg.connect((c2f, 1), (audio_sink_0, 1))
            time.sleep(1)
            fg.start()
            stdscr.move(cursor_y, cursor_x)

        cursor_x = max(0, cursor_x)
        cursor_x = min(width-1, cursor_x)

        cursor_y = max(0, cursor_y)
        cursor_y = min(height-1, cursor_y)

        statusbarstr = "Press 'q' to exit. Select channel and push Enter to change | Selected: {}. Listening to: {}".format(cursor_y, active)

        start_y = int((height // 2) - 2)

        # Rendering some text
        whstr = "Width: {}, Height: {}".format(width, height)
        ntorender = len(channel_list)-scroll
        if ntorender >= height - 1:
            ntorender = height - 1;
        for i in range(scroll, ntorender+scroll):
            channel_name = channel_list[i]['name'].encode('utf-8')
            if i == selected:
                stdscr.addstr(i-scroll, 0, channel_name, curses.color_pair(3))
            elif i == active:
                stdscr.addstr(i-scroll, 0, channel_name, curses.color_pair(2))
            else:
                stdscr.addstr(i-scroll, 0, channel_name, curses.color_pair(1))

        # Render status bar
        stdscr.attron(curses.color_pair(3))
        stdscr.addstr(height-1, 0, statusbarstr)
        stdscr.addstr(height-1, len(statusbarstr), " " * (width - len(statusbarstr) - 1))
        stdscr.attroff(curses.color_pair(3))

        # Turning on attributes for title
        stdscr.attron(curses.color_pair(2))
        stdscr.attron(curses.A_BOLD)

        # Rendering title
        #stdscr.addstr(start_y, start_x_title, title)

        # Turning off attributes for title
        stdscr.attroff(curses.color_pair(2))
        stdscr.attroff(curses.A_BOLD)

        stdscr.move(cursor_y, cursor_x)

        # Refresh the screen
        stdscr.refresh()


        stdscr.timeout(0)
        kn = stdscr.getch()
        k = kn
        stdscr.timeout(-1)
        # Wait for next input
        #queue.
        if k == -1:
            stdscr.move(center_y, center_x)
            time.sleep(0.1)
            stdscr.move(cursor_y, cursor_x)
Beispiel #2
0
def receive_dabplus(frequency=220.352e6,
                    rf_gain=25,
                    if_gain=0,
                    bb_gain=0,
                    ppm=80,
                    audio_sample_rate=48000,
                    dab_bit_rate=64,
                    dab_address=304,
                    dab_subch_size=64,
                    dab_protect_level=1,
                    use_zeromq=False,
                    dabplus=True,
                    server="tcp://127.0.0.1:10444",
                    server_control="tcp://127.0.0.1:10445",
                    from_file=None,
                    from_file_repeat=False,
                    skip_xrun_monitor=False):
    from gnuradio import gr, blocks, audio
    if use_zeromq:
        from gnuradio import zeromq

    import time
    import osmosdr
    import grdab

    samp_rate = samp_rate = 2048000

    print("Setting frequency: %0.3f MHz" % (frequency / 1e6))
    print("Setting RF gain to: %d" % rf_gain)
    print("Setting Frequency error (ppm) to: %d" % ppm)

    fg = gr.top_block()

    if from_file != None:
        file_input = blocks.file_source(gr.sizeof_gr_complex, from_file,
                                        from_file_repeat)
        if skip_xrun_monitor:
            src = file_input
        else:
            fthrottle = blocks.throttle(gr.sizeof_gr_complex, samp_rate)
            fg.connect(file_input, fthrottle)
            src = fthrottle
        print("Run from file %s" % from_file)
    elif not use_zeromq:
        osmosdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " + '')
        osmosdr_source_0.set_sample_rate(samp_rate)
        osmosdr_source_0.set_center_freq(frequency, 0)
        osmosdr_source_0.set_freq_corr(0, 0)
        osmosdr_source_0.set_dc_offset_mode(0, 0)
        osmosdr_source_0.set_iq_balance_mode(0, 0)
        osmosdr_source_0.set_gain_mode(False, 0)
        osmosdr_source_0.set_gain(rf_gain, 0)
        osmosdr_source_0.set_if_gain(if_gain, 0)
        osmosdr_source_0.set_bb_gain(bb_gain, 0)
        osmosdr_source_0.set_antenna('RX2', 0)
        osmosdr_source_0.set_bandwidth(2000000, 0)
        src = osmosdr_source_0
    else:
        zeromq_source = zeromq.sub_source(gr.sizeof_gr_complex, 1, server, 100,
                                          False, -1)
        rpc_mgr_server = zeromq.rpc_manager()
        rpc_mgr_server.set_request_socket(server_control)
        rpc_mgr_server.request("set_sample_rate", [samp_rate])
        rpc_mgr_server.request("set_rf_gain", [rf_gain])
        rpc_mgr_server.request("set_if_gain", [if_gain])
        rpc_mgr_server.request("set_bb_gain", [bb_gain])
        rpc_mgr_server.request(
            "set_ppm", [0]
        )  # Not using hardware correction since it behaves differently on different hardware
        rpc_mgr_server.request("set_frequency", [frequency])
        time.sleep(0.7)
        src = zeromq_source

    sample_rate_correction_factor = 1 + float(ppm) * 1e-6
    dab_ofdm_demod_0 = grdab.ofdm_demod(
        grdab.parameters.dab_parameters(mode=1,
                                        sample_rate=samp_rate,
                                        verbose=False),
        grdab.parameters.receiver_parameters(
            mode=1,
            softbits=True,
            input_fft_filter=True,
            autocorrect_sample_rate=False,
            sample_rate_correction_factor=sample_rate_correction_factor,
            always_include_resample=True,
            verbose=False,
            correct_ffe=True,
            equalize_magnitude=True))

    if dabplus:
        decoder = grdab.dabplus_audio_decoder_ff(
            grdab.parameters.dab_parameters(mode=1,
                                            sample_rate=samp_rate,
                                            verbose=False), dab_bit_rate,
            dab_address, dab_subch_size, dab_protect_level, True)
    else:
        decoder = grdab.dab_audio_decoder_ff(
            grdab.parameters.dab_parameters(mode=1,
                                            sample_rate=samp_rate,
                                            verbose=False), dab_bit_rate,
            dab_address, dab_subch_size, dab_protect_level, True)

    xrun_monitor = grdab.xrun_monitor_cc(100000)
    f2c = blocks.float_to_complex()
    c2f = blocks.complex_to_float()

    audio_sink_0 = audio.sink(audio_sample_rate, '', True)

    fg.connect(src, dab_ofdm_demod_0, decoder)
    fg.connect((decoder, 0), (f2c, 0))
    fg.connect((decoder, 1), (f2c, 1))
    if skip_xrun_monitor:
        fg.connect(f2c, c2f)
    else:
        fg.connect(f2c, xrun_monitor)
        fg.connect(xrun_monitor, c2f)
    fg.connect((c2f, 0), (audio_sink_0, 0))
    fg.connect((c2f, 1), (audio_sink_0, 1))

    if from_file != None and from_file_repeat == False and skip_xrun_monitor:
        fg.run()
    else:
        fg.start()
        input("Running..")
        fg.stop()
Beispiel #3
0
def main(rf_gain, if_gain, bb_gain, ppm, use_zeromq_in=False, server="tcp://127.0.0.1:10444", server_control="tcp://127.0.0.1:10445"):
    global src
    global decoder
    global dab_ofdm_demod_0
    global c2f
    global f2c
    global audio_sink_0
    global fg
    global xrun_monitor
    global use_zeromq
    global rpc_mgr_server
    global dab_ofdm_demod_0
    global ppm_shared
    frequency=220.352e6
    audio_sample_rate=48000
    ppm_shared = ppm
    dab_bit_rate=64
    dab_address=304
    dab_subch_size=64
    dab_protect_level=1
    use_zeromq=use_zeromq_in
    if use_zeromq:
        from gnuradio import zeromq
    else:
        import osmosdr
    import time

    if len(channel_list) > 0:
        ch = channel_list[0]
        frequency = float(ch['frequency'])*1e6
    else:
        ch = {"bit_rate" : 64, "address" : 304, "subch_size" : 64, "protect_level" : 1}

    print("Setting frequency: %0.3f MHz" % (frequency/1e6))

    if not use_zeromq:
        osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + '' )
        osmosdr_source_0.set_sample_rate(samp_rate)
        osmosdr_source_0.set_center_freq(frequency, 0)
        osmosdr_source_0.set_freq_corr(0, 0)
        osmosdr_source_0.set_dc_offset_mode(0, 0)
        osmosdr_source_0.set_iq_balance_mode(0, 0)
        osmosdr_source_0.set_gain_mode(False, 0)
        osmosdr_source_0.set_gain(rf_gain, 0)
        osmosdr_source_0.set_if_gain(if_gain, 0)
        osmosdr_source_0.set_bb_gain(bb_gain, 0)
        osmosdr_source_0.set_antenna('RX2', 0)
        osmosdr_source_0.set_bandwidth(2000000, 0)
    else:
        zeromq_source = zeromq.sub_source(gr.sizeof_gr_complex, 1, server, 100, False, -1)
        rpc_mgr_server = zeromq.rpc_manager()
        rpc_mgr_server.set_request_socket(server_control)
        rpc_mgr_server.request("set_sample_rate",[samp_rate])
        rpc_mgr_server.request("set_rf_gain",[rf_gain])
        rpc_mgr_server.request("set_if_gain",[if_gain])
        rpc_mgr_server.request("set_bb_gain",[bb_gain])
        rpc_mgr_server.request("set_ppm",[0]) # Not using hardware correction since it behaves differently on different hardware
        rpc_mgr_server.request("set_frequency",[frequency])
        time.sleep(0.7)

    sample_rate_correction_factor = 1 + float(ppm_shared)*1e-6
    dab_ofdm_demod_0 = grdab.ofdm_demod(
              grdab.parameters.dab_parameters(
                mode=1,
                sample_rate=samp_rate,
                verbose=False
              ),
              grdab.parameters.receiver_parameters(
                mode=1,
                softbits=True,
                input_fft_filter=True,
                autocorrect_sample_rate=False,
                sample_rate_correction_factor=sample_rate_correction_factor,
                always_include_resample=True,
                verbose=False,
                correct_ffe=True,
                equalize_magnitude=True
              )
            )

    if 'classic' in ch and ch['classic'] == True:
        dabplus = False
    else:
        dabplus = True

    if dabplus:
        decoder = grdab.dabplus_audio_decoder_ff(grdab.parameters.dab_parameters(mode=1, sample_rate=samp_rate, verbose=False), ch['bit_rate'], ch['address'], ch['subch_size'], ch['protect_level'], True)
    else:
        decoder = grdab.dab_audio_decoder_ff(grdab.parameters.dab_parameters(mode=1, sample_rate=samp_rate, verbose=False), ch['bit_rate'], ch['address'], ch['subch_size'], ch['protect_level'], True)

    xrun_monitor = grdab.xrun_monitor_cc(100000)
    xrun_monitor.set_report_fill(False)
    f2c = blocks.float_to_complex()
    c2f = blocks.complex_to_float()

    audio_sink_0 = audio.sink(audio_sample_rate, '', True)


    fg = gr.top_block()

    if not use_zeromq:
        src = osmosdr_source_0
    else:
        src = zeromq_source

    fg.connect(src, dab_ofdm_demod_0, decoder)
    fg.connect((decoder, 0), (f2c, 0))
    fg.connect((decoder, 1), (f2c, 1))
    fg.connect(f2c, xrun_monitor)
    fg.connect(xrun_monitor, c2f)
    fg.connect((c2f, 0), (audio_sink_0, 0))
    fg.connect((c2f, 1), (audio_sink_0, 1))




    fg.start()
    curses.wrapper(draw_menu)
Beispiel #4
0
    def __init__(self):
        gr.top_block.__init__(self)

        parser = OptionParser(option_class=eng_option,
                              usage="%prog: [options] output-filename")
        parser.add_option("-m",
                          "--dab-mode",
                          type="int",
                          default=1,
                          help="DAB mode [default=%default]")
        parser.add_option("-F",
                          "--filter-input",
                          action="store_true",
                          default=False,
                          help="Enable FFT filter at input")
        parser.add_option('-c',
                          '--correct-ffe',
                          action="store_true",
                          default=False,
                          help="do fine frequency correction")
        parser.add_option(
            '-u',
            '--correct-ffe-usrp',
            action="store_true",
            default=False,
            help=
            "do fine frequency correction by retuning the USRP instead of in software"
        )
        parser.add_option('-e',
                          '--equalize-magnitude',
                          action="store_true",
                          default=False,
                          help="do magnitude equalization")
        parser.add_option(
            "-s",
            "--resample-fixed",
            type="eng_float",
            default=1,
            help="resample by a fixed factor (fractional interpolation)")
        parser.add_option(
            "-S",
            "--autocorrect-sample-rate",
            action="store_true",
            default=False,
            help=
            "Estimate sample rate offset and resample (dynamic fractional interpolation)"
        )
        parser.add_option("-R",
                          "--rx-subdev-spec",
                          type="subdev",
                          default=(0, 0),
                          help="select USRP Rx side A or B [default=A]")
        parser.add_option("-f",
                          "--freq",
                          type="eng_float",
                          default=227.36e6,
                          help="set frequency to FREQ [default=%default]")
        parser.add_option(
            "-d",
            "--decim",
            type="intx",
            default=32,
            help="set decimation rate to DECIM [default=%default]")
        parser.add_option("-g",
                          "--rx-gain",
                          type="eng_float",
                          default=None,
                          help="set receive gain in dB (default is midpoint)")
        parser.add_option('-v',
                          '--verbose',
                          action="store_true",
                          default=False,
                          help="verbose output")
        parser.add_option('-a',
                          '--antenna',
                          type="string",
                          default="TX/RX",
                          help="select antenna")
        (options, args) = parser.parse_args()

        # if len(args)!=1:
        # parser.print_help()
        # sys.exit(1)
        # else:
        # self.filename = args[0]

        # if gr.enable_realtime_scheduling() != gr.RT_OK:
        #       print "-> failed to enable realtime scheduling"

        self.verbose = options.verbose

        self.src = uhd.usrp_source("", uhd.io_type.COMPLEX_FLOAT32, 1)
        #self.src.set_mux(usrp.determine_rx_mux_value(self.src, options.rx_subdev_spec))
        #self.subdev = uhd.selected_subdev(self.src, options.rx_subdev_spec)
        #print "--> using RX dboard " + self.subdev.side_and_name()

        self.sample_rate = 2e6  #self.src.adc_rate()/options.decim
        self.src.set_samp_rate(self.sample_rate)
        self.src.set_antenna(options.antenna)
        self.dab_params = grdab.parameters.dab_parameters(
            mode=options.dab_mode,
            sample_rate=self.sample_rate,
            verbose=options.verbose)
        self.rx_params = grdab.parameters.receiver_parameters(
            mode=options.dab_mode,
            softbits=True,
            input_fft_filter=options.filter_input,
            autocorrect_sample_rate=options.autocorrect_sample_rate,
            sample_rate_correction_factor=options.resample_fixed,
            verbose=options.verbose,
            correct_ffe=options.correct_ffe,
            equalize_magnitude=options.equalize_magnitude)

        self.demod = grdab.ofdm_demod(self.dab_params,
                                      self.rx_params,
                                      verbose=options.verbose)

        # self.sink = gr.file_sink(gr.sizeof_char*384, self.filename)
        # self.trigsink = gr.null_sink(gr.sizeof_char)
        # self.connect(self.src, self.demod, self.sink)
        # self.connect((self.demod,1), self.trigsink)

        self.fic_dec = grdab.fic_decode(self.dab_params)
        self.connect(self.src, self.demod, self.fic_dec)

        # add MSC chain
        self.dabplus = grdab.dabplus_audio_decoder_ff(self.dab_params, 112, 54,
                                                      84, 2, True)
        self.audio = audio.sink_make(32000)
        self.connect(self.demod, self.dabplus)
        # left stereo channel
        self.connect((self.dabplus, 0), (self.audio, 0))
        # right stereo channel
        self.connect((self.dabplus, 1), (self.audio, 1))

        # tune frequency
        self.frequency = options.freq
        self.set_freq(options.freq)

        # set gain
        if options.rx_gain is None:
            # if no gain was specified, use the mid-point in dB
            g = self.src.get_gain_range()
            options.rx_gain = float(g.start() + g.stop()) / 2
        self.src.set_gain(options.rx_gain)
        #self.subdev.set_gain(options.rx_gain)

        self.update_ui = options.verbose
        if self.update_ui:
            self.run_ui_update_thread = True
            self.ui_updater = threading.Timer(0.1, self.update_ui_function)
            self.ui_updater.setDaemon(True)
            self.ui_updater.start()

        self.correct_ffe_usrp = options.correct_ffe_usrp
        if self.correct_ffe_usrp:
            print "--> correcting FFE on USRP"
            self.run_correct_ffe_thread = True
            self.ffe_updater = threading.Timer(0.1, self.correct_ffe)
            self.ffe_updater.setDaemon(True)
            self.ffe_updater.start()
Beispiel #5
0
    def __init__(self):
        gr.top_block.__init__(self, "Top Block")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Top Block")
        qtgui.util.check_set_qss()
        try:
            self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        except:
            pass
        self.top_scroll_layout = Qt.QVBoxLayout()
        self.setLayout(self.top_scroll_layout)
        self.top_scroll = Qt.QScrollArea()
        self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
        self.top_scroll_layout.addWidget(self.top_scroll)
        self.top_scroll.setWidgetResizable(True)
        self.top_widget = Qt.QWidget()
        self.top_scroll.setWidget(self.top_widget)
        self.top_layout = Qt.QVBoxLayout(self.top_widget)
        self.top_grid_layout = Qt.QGridLayout()
        self.top_layout.addLayout(self.top_grid_layout)

        self.settings = Qt.QSettings("GNU Radio", "top_block")

        try:
            if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"):
                self.restoreGeometry(
                    self.settings.value("geometry").toByteArray())
            else:
                self.restoreGeometry(self.settings.value("geometry"))
        except:
            pass

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 2000000
        self.gain_slider = gain_slider = 50

        ##################################################
        # Blocks
        ##################################################
        self.rtlsdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " +
                                              "")
        self.rtlsdr_source_0.set_time_unknown_pps(osmosdr.time_spec_t())
        self.rtlsdr_source_0.set_sample_rate(samp_rate)
        self.rtlsdr_source_0.set_center_freq(201072000, 0)
        self.rtlsdr_source_0.set_freq_corr(0, 0)
        self.rtlsdr_source_0.set_dc_offset_mode(0, 0)
        self.rtlsdr_source_0.set_iq_balance_mode(0, 0)
        self.rtlsdr_source_0.set_gain_mode(False, 0)
        self.rtlsdr_source_0.set_gain(10, 0)
        self.rtlsdr_source_0.set_if_gain(20, 0)
        self.rtlsdr_source_0.set_bb_gain(20, 0)
        self.rtlsdr_source_0.set_antenna('', 0)
        self.rtlsdr_source_0.set_bandwidth(0, 0)
        self._gain_slider_range = Range(0, 100, 1, 50, 200)
        self._gain_slider_win = RangeWidget(self._gain_slider_range,
                                            self.set_gain_slider, 'Gain',
                                            "counter_slider", float)
        self.top_grid_layout.addWidget(self._gain_slider_win)
        self.dab_ofdm_demod_0 = grdab.ofdm_demod(
            grdab.parameters.dab_parameters(mode=1,
                                            sample_rate=samp_rate,
                                            verbose=False),
            grdab.parameters.receiver_parameters(
                mode=1,
                softbits=True,
                input_fft_filter=True,
                autocorrect_sample_rate=True,
                sample_rate_correction_factor=1 + float(0) * 1e-6,
                always_include_resample=True,
                verbose=False,
                correct_ffe=True,
                equalize_magnitude=True))

        self.dab_dabplus_audio_decoder_ff_0 = grdab.dabplus_audio_decoder_ff(
            grdab.parameters.dab_parameters(mode=1,
                                            sample_rate=samp_rate,
                                            verbose=False), 112, 234, 84, 2,
            True)
        self.audio_sink_0 = audio.sink(48000, '', True)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.dab_dabplus_audio_decoder_ff_0, 1),
                     (self.audio_sink_0, 1))
        self.connect((self.dab_dabplus_audio_decoder_ff_0, 0),
                     (self.audio_sink_0, 0))
        self.connect((self.dab_ofdm_demod_0, 0),
                     (self.dab_dabplus_audio_decoder_ff_0, 0))
        self.connect((self.rtlsdr_source_0, 0), (self.dab_ofdm_demod_0, 0))
Beispiel #6
0
def receive_dabplus(frequency=220.352e6, rf_gain=25, if_gain=0, bb_gain=0, ppm=80, audio_sample_rate=48000, dab_bit_rate=64, dab_address=304, dab_subch_size=64, dab_protect_level=1, use_zeromq=False, dabplus=True, server="tcp://127.0.0.1:10444", server_control="tcp://127.0.0.1:10445"):
    from gnuradio import gr, blocks, audio
    if use_zeromq:
        from gnuradio import zeromq

    import time
    import osmosdr
    import grdab

    samp_rate = samp_rate = 2000000

    print("Setting frequency: %0.3f MHz" % (frequency/1e6))
    print("Setting RF gain to: %d" % rf_gain)
    print("Setting Frequency error (ppm) to: %d" % ppm)

    if not use_zeromq:
        osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + '' )
        osmosdr_source_0.set_sample_rate(samp_rate)
        osmosdr_source_0.set_center_freq(frequency, 0)
        osmosdr_source_0.set_freq_corr(0, 0)
        osmosdr_source_0.set_dc_offset_mode(0, 0)
        osmosdr_source_0.set_iq_balance_mode(0, 0)
        osmosdr_source_0.set_gain_mode(False, 0)
        osmosdr_source_0.set_gain(rf_gain, 0)
        osmosdr_source_0.set_if_gain(if_gain, 0)
        osmosdr_source_0.set_bb_gain(bb_gain, 0)
        osmosdr_source_0.set_antenna('RX2', 0)
        osmosdr_source_0.set_bandwidth(2000000, 0)
    else:
        zeromq_source = zeromq.sub_source(gr.sizeof_gr_complex, 1, server, 100, False, -1)
        rpc_mgr_server = zeromq.rpc_manager()
        rpc_mgr_server.set_request_socket(server_control)
        rpc_mgr_server.request("set_sample_rate",[samp_rate])
        rpc_mgr_server.request("set_rf_gain",[rf_gain])
        rpc_mgr_server.request("set_if_gain",[if_gain])
        rpc_mgr_server.request("set_bb_gain",[bb_gain])
        rpc_mgr_server.request("set_ppm",[0]) # Not using hardware correction since it behaves differently on different hardware
        rpc_mgr_server.request("set_frequency",[frequency])
        time.sleep(0.7)

    sample_rate_correction_factor = 1 + float(ppm)*1e-6
    dab_ofdm_demod_0 = grdab.ofdm_demod(
              grdab.parameters.dab_parameters(
                mode=1,
                sample_rate=samp_rate,
                verbose=False
              ),
              grdab.parameters.receiver_parameters(
                mode=1,
                softbits=True,
                input_fft_filter=True,
                autocorrect_sample_rate=False,
                sample_rate_correction_factor=sample_rate_correction_factor,
                always_include_resample=True,
                verbose=False,
                correct_ffe=True,
                equalize_magnitude=True
              )
            )

    if dabplus:
        decoder = grdab.dabplus_audio_decoder_ff(grdab.parameters.dab_parameters(mode=1, sample_rate=samp_rate, verbose=False), dab_bit_rate, dab_address, dab_subch_size, dab_protect_level, True)
    else:
        decoder = grdab.dab_audio_decoder_ff(grdab.parameters.dab_parameters(mode=1, sample_rate=samp_rate, verbose=False), dab_bit_rate, dab_address, dab_subch_size, dab_protect_level, True)

    xrun_monitor = grdab.xrun_monitor_cc(100000)
    f2c = blocks.float_to_complex()
    c2f = blocks.complex_to_float()

    audio_sink_0 = audio.sink(audio_sample_rate, '', True)

    fg = gr.top_block()

    if not use_zeromq:
        src = osmosdr_source_0
    else:
        src = zeromq_source

    fg.connect(src, dab_ofdm_demod_0, decoder)
    fg.connect((decoder, 0), (f2c, 0))
    fg.connect((decoder, 1), (f2c, 1))
    fg.connect(f2c, xrun_monitor)
    fg.connect(xrun_monitor, c2f)
    fg.connect((c2f, 0), (audio_sink_0, 0))
    fg.connect((c2f, 1), (audio_sink_0, 1))



    fg.start()
    raw_input("Running..")
    #new = grdab.dabplus_audio_decoder_ff(grdab.parameters.dab_parameters(mode=1, sample_rate=samp_rate, verbose=False), 64, 304, 64, 1, True)
    #newaudio = audio.sink(44100, '', True)
    fg.stop()
Beispiel #7
0
	def __init__(self):
		gr.top_block.__init__(self)
        
		
		parser = OptionParser(option_class=eng_option, usage="%prog: [options] output-filename")
  		parser.add_option("-m", "--dab-mode", type="int", default=1,
        	     	help="DAB mode [default=%default]")
		parser.add_option("-F", "--filter-input", action="store_true", default=False,
                          help="Enable FFT filter at input")
		parser.add_option('-c', '--correct-ffe', action="store_true", default=False,
		     help="do fine frequency correction")
		parser.add_option('-u', '--correct-ffe-usrp', action="store_true", default=False,
		     help="do fine frequency correction by retuning the USRP instead of in software")
		parser.add_option('-e', '--equalize-magnitude', action="store_true", default=False,
		     help="do magnitude equalization")
  		parser.add_option("-s", "--resample-fixed", type="eng_float", default=1,
			help="resample by a fixed factor (fractional interpolation)")
		parser.add_option("-S", "--autocorrect-sample-rate", action="store_true", default=False,
                          help="Estimate sample rate offset and resample (dynamic fractional interpolation)")
		parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=(0, 0),
		     help="select USRP Rx side A or B [default=A]")
		parser.add_option("-f", "--freq", type="eng_float", default=227.36e6,
		     help="set frequency to FREQ [default=%default]")
		parser.add_option("-d", "--decim", type="intx", default=32,
		     help="set decimation rate to DECIM [default=%default]")
		parser.add_option("-g", "--rx-gain", type="eng_float", default=None,
		     help="set receive gain in dB (default is midpoint)")
		parser.add_option('-v', '--verbose', action="store_true", default=False,
		     help="verbose output")
		parser.add_option('-a', '--antenna', type="string", default="TX/RX",
		     help="select antenna")
        	(options, args) = parser.parse_args ()

		# if len(args)!=1:
			# parser.print_help()
			# sys.exit(1)
		# else:
			# self.filename = args[0]

		# if gr.enable_realtime_scheduling() != gr.RT_OK:
		#       print "-> failed to enable realtime scheduling"

		self.verbose = options.verbose

		self.src = uhd.usrp_source("",uhd.io_type.COMPLEX_FLOAT32,1)
        	#self.src.set_mux(usrp.determine_rx_mux_value(self.src, options.rx_subdev_spec))
        	#self.subdev = uhd.selected_subdev(self.src, options.rx_subdev_spec)
        	#print "--> using RX dboard " + self.subdev.side_and_name()
		
		self.sample_rate = 2e6#self.src.adc_rate()/options.decim
		self.src.set_samp_rate(self.sample_rate)
		self.src.set_antenna(options.antenna)
		self.dab_params = grdab.parameters.dab_parameters(mode=options.dab_mode, sample_rate=self.sample_rate, verbose=options.verbose)
		self.rx_params = grdab.parameters.receiver_parameters(mode=options.dab_mode, softbits=True, input_fft_filter=options.filter_input, autocorrect_sample_rate=options.autocorrect_sample_rate, sample_rate_correction_factor=options.resample_fixed, verbose=options.verbose, correct_ffe=options.correct_ffe, equalize_magnitude=options.equalize_magnitude)

		self.demod = grdab.ofdm_demod(self.dab_params, self.rx_params, verbose=options.verbose) 

		# self.sink = gr.file_sink(gr.sizeof_char*384, self.filename)
		# self.trigsink = gr.null_sink(gr.sizeof_char)
		# self.connect(self.src, self.demod, self.sink)
		# self.connect((self.demod,1), self.trigsink)
		
		self.fic_dec = grdab.fic_decode(self.dab_params)
		self.connect(self.src, self.demod, self.fic_dec)

		# add MSC chain
		self.dabplus = grdab.dabplus_audio_decoder_ff(self.dab_params, 112, 54, 84, 2, True)
		self.audio = audio.sink_make(32000)
		self.connect(self.demod, self.dabplus)
		# left stereo channel
		self.connect((self.dabplus, 0), (self.audio, 0))
		# right stereo channel
		self.connect((self.dabplus, 1), (self.audio, 1))		


		# tune frequency
		self.frequency = options.freq
		self.set_freq(options.freq)

		# set gain      
		if options.rx_gain is None:
			# if no gain was specified, use the mid-point in dB
			g = self.src.get_gain_range()
			options.rx_gain = float(g.start()+g.stop())/2
		self.src.set_gain(options.rx_gain)
		#self.subdev.set_gain(options.rx_gain)

		self.update_ui = options.verbose
		if self.update_ui:
			self.run_ui_update_thread = True
			self.ui_updater = threading.Timer(0.1,self.update_ui_function)
			self.ui_updater.setDaemon(True)
			self.ui_updater.start()

		self.correct_ffe_usrp = options.correct_ffe_usrp
		if self.correct_ffe_usrp:
			print "--> correcting FFE on USRP"
			self.run_correct_ffe_thread = True
			self.ffe_updater = threading.Timer(0.1, self.correct_ffe)
			self.ffe_updater.setDaemon(True)
			self.ffe_updater.start()