Пример #1
0
 def __init__(self, traffic_msgq=None, key=None):
     gr.hier_block2.__init__(self, "op25_decoder",
                           gr.io_signature(1, 1, gr.sizeof_float),
                           gr.io_signature(1, 1, gr.sizeof_float))
     
     self.traffic_msgq = traffic_msgq
     self.key = key
     
     if self.traffic_msgq is None:
         self.traffic_msgq = gr.msg_queue(2)
     
     self.slicer = None
     try:
         levels = [ -2.0, 0.0, 2.0, 4.0 ]
         self.slicer = _op25.fsk4_slicer_fb(levels)
         self.p25_decoder = _op25.decoder_bf()
         self.p25_decoder.set_msgq(self.traffic_msgq)
         if _verbose:
             print "Using new decoder_bf"
     except:
         try:
             self.p25_decoder = _op25.decoder_ff(self.traffic_msgq)   # LEGACY
             if _verbose:
                 print "Using legacy decoder_ff"
         except:
             raise Exception("Could not find a decoder to use")
     
     if (self.key is not None) and (len(self.key) > 0): # Relates to key string passed in from GRC block
         self.set_key(self.key)
     
     if self.slicer:
         self.connect(self, self.slicer, self.p25_decoder)
     else:
         self.connect(self, self.p25_decoder)
     self.connect(self.p25_decoder, self)
Пример #2
0
    def __init__(self, traffic_msgq=None, key=None):
        gr.hier_block2.__init__(self, "op25_decoder",
                                gr.io_signature(1, 1, gr.sizeof_float),
                                gr.io_signature(1, 1, gr.sizeof_float))

        self.traffic_msgq = traffic_msgq
        self.key = key

        if self.traffic_msgq is None:
            self.traffic_msgq = gr.msg_queue(2)

        self.slicer = None
        try:
            levels = [-2.0, 0.0, 2.0, 4.0]
            self.slicer = _op25.fsk4_slicer_fb(levels)
            self.p25_decoder = _op25.decoder_bf()
            self.p25_decoder.set_msgq(self.traffic_msgq)
            if _verbose:
                print "Using new decoder_bf"
        except:
            try:
                self.p25_decoder = _op25.decoder_ff(
                    self.traffic_msgq)  # LEGACY
                if _verbose:
                    print "Using legacy decoder_ff"
            except:
                raise Exception("Could not find a decoder to use")

        if (self.key is not None) and (
                len(self.key) >
                0):  # Relates to key string passed in from GRC block
            self.set_key(self.key)

        if self.slicer:
            self.connect(self, self.slicer, self.p25_decoder)
        else:
            self.connect(self, self.p25_decoder)
        self.connect(self.p25_decoder, self)
Пример #3
0
    def __init__(self, subdev_spec, center_freq, offset_freq, decim, squelch, gain):

        gr.top_block.__init__(self)

        # configure USRP
        u = usrp.source_c()
        u.set_decim_rate(decim)
        capture_rate = u.adc_freq() / u.decim_rate()
        if subdev_spec is None:
            subdev_spec = usrp.pick_rx_subdevice(u)
        subdev = usrp.selected_subdev(u, subdev_spec)
        u.set_mux(usrp.determine_rx_mux_value(u, subdev_spec))
        print "Using RX d'board %s" % (subdev.side_and_name(),)

        if gain is None:
            g = subdev.gain_range()
            gain = float(g[0] + g[1]) / 2
        subdev.set_gain(gain)
        u.tune(0, subdev, center_freq)
                
        # setup receiver attributes
        channel_rate = 125000
        symbol_rate = 4800
        
        # channel filter
        self.channel_offset = offset_freq
        channel_decim = capture_rate // channel_rate
        channel_rate = capture_rate // channel_decim
        trans_width = 12.5e3 / 2;
        trans_centre = trans_width + (trans_width / 2)
        coeffs = gr.firdes.low_pass(1.0, capture_rate, trans_centre, trans_width, gr.firdes.WIN_HANN)
        self.channel_filter = gr.freq_xlating_fir_filter_ccf(channel_decim, coeffs, self.channel_offset, capture_rate)
        self.connect(u, self.channel_filter)

        # power squelch
        power_squelch = gr.pwr_squelch_cc(squelch, 1e-3, 0, True)
        self.connect(self.channel_filter, power_squelch)

        # FM demodulator
        self.symbol_deviation = 600.0
        fm_demod_gain = channel_rate / (2.0 * pi * self.symbol_deviation)
        fm_demod = gr.quadrature_demod_cf(fm_demod_gain)
        self.connect(power_squelch, fm_demod)

        # symbol filter        
        symbol_decim = 1
        samples_per_symbol = channel_rate // symbol_rate
        symbol_coeffs = (1.0/samples_per_symbol,) * samples_per_symbol
        symbol_filter = gr.fir_filter_fff(symbol_decim, symbol_coeffs)
        self.connect(fm_demod, symbol_filter)

        # C4FM demodulator
        autotuneq = gr.msg_queue(2)
        self.demod_watcher = demod_watcher(autotuneq, self.adjust_channel_offset)
        demod_fsk4 = op25.fsk4_demod_ff(autotuneq, channel_rate, symbol_rate)
        self.connect(symbol_filter, demod_fsk4)

        # symbol slicer
        levels = [ -2.0, 0.0, 2.0, 4.0 ]
        slicer = op25.fsk4_slicer_fb(levels)
        self.connect(demod_fsk4, slicer)

        # frame decoder
        decoder = op25.decoder_bf()
        self.connect(slicer, decoder)

        # try to connect audio output device
        try:
            audio_sink = audio.sink(8000, "plughw:0,0", True)
            self.connect(decoder, audio_sink)
        except Exception:
            sink = gr.null_sink(gr.sizeof_float)
            self.connect(decoder, sink)
Пример #4
0
    def __init_gui(self, frame, panel, vbox):
        self.frame = frame
        self.frame.CreateStatusBar()
        self.panel = panel
        self.vbox = vbox

        # setup the menu bar
        menubar = self.frame.GetMenuBar()

        # setup the "File" menu
        file_menu = menubar.GetMenu(0)
        self.file_new = file_menu.Insert(0, wx.ID_NEW)
        self.frame.Bind(wx.EVT_MENU, self._on_file_new, self.file_new)
        self.file_open = file_menu.Insert(1, wx.ID_OPEN)
        self.frame.Bind(wx.EVT_MENU, self._on_file_open, self.file_open)
        file_menu.InsertSeparator(2)
        self.file_properties = file_menu.Insert(3, wx.ID_PROPERTIES)
        self.frame.Bind(wx.EVT_MENU, self._on_file_properties,
                        self.file_properties)
        file_menu.InsertSeparator(4)
        self.file_close = file_menu.Insert(5, wx.ID_CLOSE)
        self.frame.Bind(wx.EVT_MENU, self._on_file_close, self.file_close)

        # setup the "Edit" menu
        edit_menu = wx.Menu()
        self.edit_undo = edit_menu.Insert(0, wx.ID_UNDO)
        self.frame.Bind(wx.EVT_MENU, self._on_edit_undo, self.edit_undo)
        self.edit_redo = edit_menu.Insert(1, wx.ID_REDO)
        self.frame.Bind(wx.EVT_MENU, self._on_edit_redo, self.edit_redo)
        edit_menu.InsertSeparator(2)
        self.edit_cut = edit_menu.Insert(3, wx.ID_CUT)
        self.frame.Bind(wx.EVT_MENU, self._on_edit_cut, self.edit_cut)
        self.edit_copy = edit_menu.Insert(4, wx.ID_COPY)
        self.frame.Bind(wx.EVT_MENU, self._on_edit_copy, self.edit_copy)
        self.edit_paste = edit_menu.Insert(5, wx.ID_PASTE)
        self.frame.Bind(wx.EVT_MENU, self._on_edit_paste, self.edit_paste)
        self.edit_delete = edit_menu.Insert(6, wx.ID_DELETE)
        self.frame.Bind(wx.EVT_MENU, self._on_edit_delete, self.edit_delete)
        edit_menu.InsertSeparator(7)
        self.edit_select_all = edit_menu.Insert(8, wx.ID_SELECTALL)
        self.frame.Bind(wx.EVT_MENU, self._on_edit_select_all,
                        self.edit_select_all)
        edit_menu.InsertSeparator(9)
        self.edit_prefs = edit_menu.Insert(10, wx.ID_PREFERENCES)
        self.frame.Bind(wx.EVT_MENU, self._on_edit_prefs, self.edit_prefs)
        menubar.Append(edit_menu, "&Edit")
        # ToDo use wx.ID_EDIT stuff

        # setup the toolbar
        if True:
            self.toolbar = wx.ToolBar(frame,
                                      -1,
                                      style=wx.TB_DOCKABLE | wx.TB_HORIZONTAL)
            frame.SetToolBar(self.toolbar)
            icon_size = wx.Size(24, 24)
            new_icon = wx.ArtProvider.GetBitmap(wx.ART_NEW, wx.ART_TOOLBAR,
                                                icon_size)
            toolbar_new = self.toolbar.AddSimpleTool(wx.ID_NEW, new_icon,
                                                     "New Capture")
            open_icon = wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN,
                                                 wx.ART_TOOLBAR, icon_size)
            toolbar_open = self.toolbar.AddSimpleTool(wx.ID_OPEN, open_icon,
                                                      "Open")
            #
            self.toolbar.AddSeparator()
            self.gain_control = wx.Slider(self.toolbar,
                                          11101,
                                          1,
                                          1,
                                          150,
                                          size=(200, 50),
                                          style=wx.SL_HORIZONTAL)
            self.gain_control.SetTickFreq(5, 1)
            wx.EVT_SLIDER(self.toolbar, 11101, self.gain_slider_chg)
            self.toolbar.AddControl(self.gain_control)
            #
            self.gain_field = wx.TextCtrl(self.toolbar,
                                          -1,
                                          "",
                                          size=(50, -1),
                                          style=wx.TE_READONLY)
            self.gain_field.SetValue(str(1))
            self.toolbar.AddSeparator()
            self.toolbar.AddControl(self.gain_field)  # , pos=(1,2))

            self.toolbar.Realize()
        else:
            self.toolbar = None

        # setup the notebook
        self.notebook = wx.Notebook(self.panel)
        self.vbox.Add(self.notebook, 1, wx.EXPAND)
        # add spectrum scope
        self.spectrum = fftsink2.fft_sink_c(self.notebook,
                                            fft_size=512,
                                            fft_rate=2,
                                            average=True,
                                            peak_hold=True)
        self.spectrum_plotter = self.spectrum.win.plot
        self.spectrum_plotter.Bind(wx.EVT_LEFT_DOWN,
                                   self._on_spectrum_left_click)
        self.notebook.AddPage(self.spectrum.win, "RF Spectrum")
        # add C4FM scope
        self.signal_scope = scopesink2.scope_sink_f(
            self.notebook,
            sample_rate=self.channel_rate,
            v_scale=5,
            t_scale=0.001)
        self.signal_plotter = self.signal_scope.win.graph
        self.notebook.AddPage(self.signal_scope.win, "C4FM Signal")
        # add datascope
        self.data_scope = datascope_sink_f(
            self.notebook,
            samples_per_symbol=self.channel_rate // self.symbol_rate,
            num_plots=100)
        self.data_plotter = self.data_scope.win.graph
        wx.EVT_RADIOBOX(self.data_scope.win.radio_box, 11103,
                        self.filter_select)
        self.notebook.AddPage(self.data_scope.win, "Datascope")
        # add symbol scope
        self.symbol_scope = scopesink2.scope_sink_f(
            self.notebook,
            frame_decim=1,
            sample_rate=self.symbol_rate,
            v_scale=1,
            t_scale=0.05)
        self.symbol_plotter = self.symbol_scope.win.graph
        self.symbol_scope.win.set_format_plus()
        self.notebook.AddPage(self.symbol_scope.win, "Demodulated Symbols")
        # Traffic snapshot
        self.traffic = TrafficPane(self.notebook)
        self.notebook.AddPage(self.traffic, "Traffic")
        # symbol slicer
        levels = [-2.0, 0.0, 2.0, 4.0]
        self.slicer = op25.fsk4_slicer_fb(levels)
        # Setup the decoder and report the TUN/TAP device name
        self.msgq = gr.msg_queue(2)
        self.decode_watcher = decode_watcher(self.msgq, self.traffic)
        self.p25_decoder = op25.decoder_bf()
        self.p25_decoder.set_msgq(self.msgq)
        self.frame.SetStatusText("TUN/TAP: " + self.p25_decoder.destination())
Пример #5
0
    def create(self):
        self.op25_msgq = gr.msg_queue(2)
        self.slicer = None
        try:
            levels = [ -2.0, 0.0, 2.0, 4.0 ]
            self.slicer = _op25.fsk4_slicer_fb(levels)
            self.p25_decoder = _op25.decoder_bf()   # FIXME: Message queue?
            if _verbose:
				print "Using new decoder_bf"
        except:
            try:
                self.p25_decoder = _op25.decoder_ff(self.op25_msgq)   # LEGACY
                if _verbose:
					print "Using legacy decoder_ff"
            except:
                raise Exception("Could not find a decoder to use")
        
        # Reference code
        #self.decode_watcher = decode_watcher(self.op25_msgq, self.traffic)
        
        if (self.key is not None) and (len(self.key) > 0): # Relates to key string passed in from GRC block
            self.set_key(self.key)
        
        # Reference code
        #trans_width = 12.5e3 / 2;
        #trans_centre = trans_width + (trans_width / 2)
        # discriminator tap doesn't do freq. xlation, FM demodulation, etc.
        #    coeffs = gr.firdes.low_pass(1.0, capture_rate, trans_centre, trans_width, gr.firdes.WIN_HANN)
        #    self.channel_filter = gr.freq_xlating_fir_filter_ccf(channel_decim, coeffs, 0.0, capture_rate)
        #    self.set_channel_offset(0.0, 0, self.spectrum.win._units)
        #    # power squelch
        #    squelch_db = 0
        #    self.squelch = gr.pwr_squelch_cc(squelch_db, 1e-3, 0, True)
        #    self.set_squelch_threshold(squelch_db)
        #    # FM demodulator
        #    fm_demod_gain = channel_rate / (2.0 * pi * self.symbol_deviation)
        #    fm_demod = gr.quadrature_demod_cf(fm_demod_gain)
        # symbol filter        
        #symbol_decim = 1
        #symbol_coeffs = gr.firdes.root_raised_cosine(1.0, channel_rate, self.symbol_rate, 0.2, 500)
        # boxcar coefficients for "integrate and dump" filter
        #samples_per_symbol = channel_rate // self.symbol_rate
        #symbol_duration = float(self.symbol_rate) / channel_rate
        #print "Symbol duration:", symbol_duration
        #print "Samples per symbol:", samples_per_symbol
        #symbol_coeffs = (1.0/samples_per_symbol,)*samples_per_symbol
        #self.symbol_filter = gr.fir_filter_fff(symbol_decim, symbol_coeffs)
        
        # C4FM demodulator
        #print "Symbol rate:", self.symbol_rate
        if self.auto_tune_msgq is None:
            self.auto_tune_msgq = gr.msg_queue(2)
        try:
            self.demod_fsk4 = _op25.fsk4_demod_ff(self.auto_tune_msgq, self.channel_rate, self.symbol_rate)
            if _verbose:
				print "Using new fsk4_demod_ff"
        except:
            try:
                self.demod_fsk4 = fsk4.demod_ff(self.auto_tune_msgq, self.channel_rate, self.symbol_rate)   # LEGACY
                if _verbose:
					print "Using legacy fsk4.demod_ff"
            except:
                raise Exception("Could not find a FSK4 demodulator to use")
        
        # Reference code
        #self.demod_watcher = demod_watcher(autotuneq, self.adjust_channel_offset)
        #list = [[self, self.channel_filter, self.squelch, fm_demod, self.symbol_filter, demod_fsk4, self.p25_decoder, self.sink]]
        
        self.connect(self, self.demod_fsk4)
        if self.slicer:
            self.connect(self.demod_fsk4, self.slicer)
            self.connect(self.slicer, self.p25_decoder)
        else:
            self.connect(self.demod_fsk4, self.p25_decoder)
        self.connect(self.p25_decoder, (self, 0))
        
        if self.output_dibits:
            self.connect(self.demod_fsk4, (self, 1))
Пример #6
0
    def __init__(self, subdev_spec, center_freq, offset_freq, decim, squelch,
                 gain):

        gr.top_block.__init__(self)

        # configure USRP
        u = usrp.source_c()
        u.set_decim_rate(decim)
        capture_rate = u.adc_freq() / u.decim_rate()
        if subdev_spec is None:
            subdev_spec = usrp.pick_rx_subdevice(u)
        subdev = usrp.selected_subdev(u, subdev_spec)
        u.set_mux(usrp.determine_rx_mux_value(u, subdev_spec))
        print "Using RX d'board %s" % (subdev.side_and_name(), )

        if gain is None:
            g = subdev.gain_range()
            gain = float(g[0] + g[1]) / 2
        subdev.set_gain(gain)
        u.tune(0, subdev, center_freq)

        # setup receiver attributes
        channel_rate = 125000
        symbol_rate = 4800

        # channel filter
        self.channel_offset = offset_freq
        channel_decim = capture_rate // channel_rate
        channel_rate = capture_rate // channel_decim
        trans_width = 12.5e3 / 2
        trans_centre = trans_width + (trans_width / 2)
        coeffs = gr.firdes.low_pass(1.0, capture_rate, trans_centre,
                                    trans_width, gr.firdes.WIN_HANN)
        self.channel_filter = gr.freq_xlating_fir_filter_ccf(
            channel_decim, coeffs, self.channel_offset, capture_rate)
        self.connect(u, self.channel_filter)

        # power squelch
        power_squelch = gr.pwr_squelch_cc(squelch, 1e-3, 0, True)
        self.connect(self.channel_filter, power_squelch)

        # FM demodulator
        self.symbol_deviation = 600.0
        fm_demod_gain = channel_rate / (2.0 * pi * self.symbol_deviation)
        fm_demod = gr.quadrature_demod_cf(fm_demod_gain)
        self.connect(power_squelch, fm_demod)

        # symbol filter
        symbol_decim = 1
        samples_per_symbol = channel_rate // symbol_rate
        symbol_coeffs = (1.0 / samples_per_symbol, ) * samples_per_symbol
        symbol_filter = gr.fir_filter_fff(symbol_decim, symbol_coeffs)
        self.connect(fm_demod, symbol_filter)

        # C4FM demodulator
        autotuneq = gr.msg_queue(2)
        self.demod_watcher = demod_watcher(autotuneq,
                                           self.adjust_channel_offset)
        demod_fsk4 = op25.fsk4_demod_ff(autotuneq, channel_rate, symbol_rate)
        self.connect(symbol_filter, demod_fsk4)

        # symbol slicer
        levels = [-2.0, 0.0, 2.0, 4.0]
        slicer = op25.fsk4_slicer_fb(levels)
        self.connect(demod_fsk4, slicer)

        # frame decoder
        decoder = op25.decoder_bf()
        self.connect(slicer, decoder)

        # try to connect audio output device
        try:
            audio_sink = audio.sink(8000, "plughw:0,0", True)
            self.connect(decoder, audio_sink)
        except Exception:
            sink = gr.null_sink(gr.sizeof_float)
            self.connect(decoder, sink)
Пример #7
0
    def __init__(self, filename, offset_freq, squelch):

        gr.top_block.__init__(self)

        # open file and info
        f = open(filename + ".info", "r")
        info = cPickle.load(f)
        capture_rate = info["capture-rate"]
        f.close()
        file = gr.file_source(gr.sizeof_gr_complex, filename, True)
        throttle = gr.throttle(gr.sizeof_gr_complex, capture_rate)
        self.connect(file, throttle)
                
        # setup receiver attributes
        channel_rate = 125000
        symbol_rate = 4800
        
        # channel filter
        self.channel_offset = offset_freq
        channel_decim = capture_rate // channel_rate
        channel_rate = capture_rate // channel_decim
        trans_width = 12.5e3 / 2;
        trans_centre = trans_width + (trans_width / 2)
        coeffs = gr.firdes.low_pass(1.0, capture_rate, trans_centre, trans_width, gr.firdes.WIN_HANN)
        self.channel_filter = gr.freq_xlating_fir_filter_ccf(channel_decim, coeffs, self.channel_offset, capture_rate)
        self.connect(throttle, self.channel_filter)

        # power squelch
        power_squelch = gr.pwr_squelch_cc(squelch, 1e-3, 0, True)
        self.connect(self.channel_filter, power_squelch)

        # FM demodulator
        self.symbol_deviation = 600.0
        fm_demod_gain = channel_rate / (2.0 * pi * self.symbol_deviation)
        fm_demod = gr.quadrature_demod_cf(fm_demod_gain)
        self.connect(power_squelch, fm_demod)

        # symbol filter        
        symbol_decim = 1
        samples_per_symbol = channel_rate // symbol_rate
        symbol_coeffs = (1.0/samples_per_symbol,) * samples_per_symbol
        symbol_filter = gr.fir_filter_fff(symbol_decim, symbol_coeffs)
        self.connect(fm_demod, symbol_filter)

        # C4FM demodulator
        autotuneq = gr.msg_queue(2)
        self.demod_watcher = demod_watcher(autotuneq, self.adjust_channel_offset)
        demod_fsk4 = op25.fsk4_demod_ff(autotuneq, channel_rate, symbol_rate)
        self.connect(symbol_filter, demod_fsk4)

        # symbol slicer
        levels = [ -2.0, 0.0, 2.0, 4.0 ]
        slicer = op25.fsk4_slicer_fb(levels)
        self.connect(demod_fsk4, slicer)

        # frame decoder
        decoder = op25.decoder_bf()
        self.connect(slicer, decoder)

        # try to connect default output device
        try:
            audio_sink = audio.sink(8000, "plughw:0,0", True)
            self.connect(decoder, audio_sink)
        except Exception:
            sink = gr.null_sink(gr.sizeof_float)
            self.connect(decoder, sink)
Пример #8
0
    def __init__(self, interface, address, center_freq, offset_freq, decim,
                 squelch, gain):

        gr.top_block.__init__(self)

        # setup USRP2
        u = usrp2.source_32fc(interface, address)
        u.set_decim(decim)
        capture_rate = u.adc_rate() / decim
        u.set_center_freq(center_freq)
        if gain is None:
            g = u.gain_range()
            gain = float(g[0] + g[1]) / 2
        u.set_gain(gain)

        # Setup receiver attributes
        channel_rate = 125000
        symbol_rate = 4800

        # channel filter
        self.channel_offset = offset_freq
        channel_decim = capture_rate // channel_rate
        channel_rate = capture_rate // channel_decim
        trans_width = 12.5e3 / 2
        trans_centre = trans_width + (trans_width / 2)
        coeffs = gr.firdes.low_pass(1.0, capture_rate, trans_centre,
                                    trans_width, gr.firdes.WIN_HANN)
        self.channel_filter = gr.freq_xlating_fir_filter_ccf(
            channel_decim, coeffs, self.channel_offset, capture_rate)
        self.connect(u, self.channel_filter)

        # power squelch
        power_squelch = gr.pwr_squelch_cc(squelch, 1e-3, 0, True)
        self.connect(self.channel_filter, power_squelch)

        # FM demodulator
        self.symbol_deviation = 600.0
        fm_demod_gain = channel_rate / (2.0 * pi * self.symbol_deviation)
        fm_demod = gr.quadrature_demod_cf(fm_demod_gain)
        self.connect(power_squelch, fm_demod)

        # symbol filter
        symbol_decim = 1
        samples_per_symbol = channel_rate // symbol_rate
        symbol_coeffs = (1.0 / samples_per_symbol, ) * samples_per_symbol
        symbol_filter = gr.fir_filter_fff(symbol_decim, symbol_coeffs)
        self.connect(fm_demod, symbol_filter)

        # C4FM demodulator
        autotuneq = gr.msg_queue(2)
        self.demod_watcher = demod_watcher(autotuneq,
                                           self.adjust_channel_offset)
        demod_fsk4 = op25.fsk4_demod_ff(autotuneq, channel_rate, symbol_rate)
        self.connect(symbol_filter, demod_fsk4)

        # symbol slicer
        levels = [-2.0, 0.0, 2.0, 4.0]
        slicer = op25.fsk4_slicer_fb(levels)
        self.connect(demod_fsk4, slicer)

        # frame decoder
        decoder = op25.decoder_bf()
        self.connect(slicer, decoder)

        # try to connect audio output device
        try:
            audio_sink = audio.sink(8000, "plughw:0,0", True)
            self.connect(decoder, audio_sink)
        except Exception:
            sink = gr.null_sink(gr.sizeof_float)
            self.connect(decoder, null)
Пример #9
0
    def create(self):
        self.op25_msgq = gr.msg_queue(2)
        self.slicer = None
        try:
            levels = [-2.0, 0.0, 2.0, 4.0]
            self.slicer = _op25.fsk4_slicer_fb(levels)
            self.p25_decoder = _op25.decoder_bf()  # FIXME: Message queue?
            if _verbose:
                print "Using new decoder_bf"
        except:
            try:
                self.p25_decoder = _op25.decoder_ff(self.op25_msgq)  # LEGACY
                if _verbose:
                    print "Using legacy decoder_ff"
            except:
                raise Exception("Could not find a decoder to use")

        # Reference code
        #self.decode_watcher = decode_watcher(self.op25_msgq, self.traffic)

        if (self.key is not None) and (
                len(self.key) >
                0):  # Relates to key string passed in from GRC block
            self.set_key(self.key)

        # Reference code
        #trans_width = 12.5e3 / 2;
        #trans_centre = trans_width + (trans_width / 2)
        # discriminator tap doesn't do freq. xlation, FM demodulation, etc.
        #    coeffs = gr.firdes.low_pass(1.0, capture_rate, trans_centre, trans_width, gr.firdes.WIN_HANN)
        #    self.channel_filter = gr.freq_xlating_fir_filter_ccf(channel_decim, coeffs, 0.0, capture_rate)
        #    self.set_channel_offset(0.0, 0, self.spectrum.win._units)
        #    # power squelch
        #    squelch_db = 0
        #    self.squelch = gr.pwr_squelch_cc(squelch_db, 1e-3, 0, True)
        #    self.set_squelch_threshold(squelch_db)
        #    # FM demodulator
        #    fm_demod_gain = channel_rate / (2.0 * pi * self.symbol_deviation)
        #    fm_demod = gr.quadrature_demod_cf(fm_demod_gain)
        # symbol filter
        #symbol_decim = 1
        #symbol_coeffs = gr.firdes.root_raised_cosine(1.0, channel_rate, self.symbol_rate, 0.2, 500)
        # boxcar coefficients for "integrate and dump" filter
        #samples_per_symbol = channel_rate // self.symbol_rate
        #symbol_duration = float(self.symbol_rate) / channel_rate
        #print "Symbol duration:", symbol_duration
        #print "Samples per symbol:", samples_per_symbol
        #symbol_coeffs = (1.0/samples_per_symbol,)*samples_per_symbol
        #self.symbol_filter = gr.fir_filter_fff(symbol_decim, symbol_coeffs)

        # C4FM demodulator
        #print "Symbol rate:", self.symbol_rate
        if self.auto_tune_msgq is None:
            self.auto_tune_msgq = gr.msg_queue(2)
        try:
            self.demod_fsk4 = _op25.fsk4_demod_ff(self.auto_tune_msgq,
                                                  self.channel_rate,
                                                  self.symbol_rate)
            if _verbose:
                print "Using new fsk4_demod_ff"
        except:
            try:
                self.demod_fsk4 = fsk4.demod_ff(self.auto_tune_msgq,
                                                self.channel_rate,
                                                self.symbol_rate)  # LEGACY
                if _verbose:
                    print "Using legacy fsk4.demod_ff"
            except:
                raise Exception("Could not find a FSK4 demodulator to use")

        # Reference code
        #self.demod_watcher = demod_watcher(autotuneq, self.adjust_channel_offset)
        #list = [[self, self.channel_filter, self.squelch, fm_demod, self.symbol_filter, demod_fsk4, self.p25_decoder, self.sink]]

        self.connect(self, self.demod_fsk4)
        if self.slicer:
            self.connect(self.demod_fsk4, self.slicer)
            self.connect(self.slicer, self.p25_decoder)
        else:
            self.connect(self.demod_fsk4, self.p25_decoder)
        self.connect(self.p25_decoder, (self, 0))

        if self.output_dibits:
            self.connect(self.demod_fsk4, (self, 1))
Пример #10
0
    def __init__(self, filename, offset_freq, squelch):

        gr.top_block.__init__(self)

        # open file and info
        f = open(filename + ".info", "r")
        info = cPickle.load(f)
        capture_rate = info["capture-rate"]
        f.close()
        file = gr.file_source(gr.sizeof_gr_complex, filename, True)
        throttle = gr.throttle(gr.sizeof_gr_complex, capture_rate)
        self.connect(file, throttle)

        # setup receiver attributes
        channel_rate = 125000
        symbol_rate = 4800

        # channel filter
        self.channel_offset = offset_freq
        channel_decim = capture_rate // channel_rate
        channel_rate = capture_rate // channel_decim
        trans_width = 12.5e3 / 2
        trans_centre = trans_width + (trans_width / 2)
        coeffs = gr.firdes.low_pass(1.0, capture_rate, trans_centre,
                                    trans_width, gr.firdes.WIN_HANN)
        self.channel_filter = gr.freq_xlating_fir_filter_ccf(
            channel_decim, coeffs, self.channel_offset, capture_rate)
        self.connect(throttle, self.channel_filter)

        # power squelch
        power_squelch = gr.pwr_squelch_cc(squelch, 1e-3, 0, True)
        self.connect(self.channel_filter, power_squelch)

        # FM demodulator
        self.symbol_deviation = 600.0
        fm_demod_gain = channel_rate / (2.0 * pi * self.symbol_deviation)
        fm_demod = gr.quadrature_demod_cf(fm_demod_gain)
        self.connect(power_squelch, fm_demod)

        # symbol filter
        symbol_decim = 1
        samples_per_symbol = channel_rate // symbol_rate
        symbol_coeffs = (1.0 / samples_per_symbol, ) * samples_per_symbol
        symbol_filter = gr.fir_filter_fff(symbol_decim, symbol_coeffs)
        self.connect(fm_demod, symbol_filter)

        # C4FM demodulator
        autotuneq = gr.msg_queue(2)
        self.demod_watcher = demod_watcher(autotuneq,
                                           self.adjust_channel_offset)
        demod_fsk4 = op25.fsk4_demod_ff(autotuneq, channel_rate, symbol_rate)
        self.connect(symbol_filter, demod_fsk4)

        # symbol slicer
        levels = [-2.0, 0.0, 2.0, 4.0]
        slicer = op25.fsk4_slicer_fb(levels)
        self.connect(demod_fsk4, slicer)

        # frame decoder
        decoder = op25.decoder_bf()
        self.connect(slicer, decoder)

        # try to connect default output device
        try:
            audio_sink = audio.sink(8000, "plughw:0,0", True)
            self.connect(decoder, audio_sink)
        except Exception:
            sink = gr.null_sink(gr.sizeof_float)
            self.connect(decoder, sink)
Пример #11
0
    def __init__(self, interface, address, center_freq, offset_freq, decim, squelch, gain):

        gr.top_block.__init__(self)

        # setup USRP2
        u = usrp2.source_32fc(interface, address)
        u.set_decim(decim)
        capture_rate = u.adc_rate() / decim
        u.set_center_freq(center_freq)
        if gain is None:
            g = u.gain_range()
            gain = float(g[0] + g[1]) / 2
        u.set_gain(gain)

        # Setup receiver attributes
        channel_rate = 125000
        symbol_rate = 4800
      
        # channel filter
        self.channel_offset = offset_freq
        channel_decim = capture_rate // channel_rate
        channel_rate = capture_rate // channel_decim
        trans_width = 12.5e3 / 2;
        trans_centre = trans_width + (trans_width / 2)
        coeffs = gr.firdes.low_pass(1.0, capture_rate, trans_centre, trans_width, gr.firdes.WIN_HANN)
        self.channel_filter = gr.freq_xlating_fir_filter_ccf(channel_decim, coeffs, self.channel_offset, capture_rate)
        self.connect(u, self.channel_filter)

        # power squelch
        power_squelch = gr.pwr_squelch_cc(squelch, 1e-3, 0, True)
        self.connect(self.channel_filter, power_squelch)

        # FM demodulator
        self.symbol_deviation = 600.0
        fm_demod_gain = channel_rate / (2.0 * pi * self.symbol_deviation)
        fm_demod = gr.quadrature_demod_cf(fm_demod_gain)
        self.connect(power_squelch, fm_demod)

        # symbol filter        
        symbol_decim = 1
        samples_per_symbol = channel_rate // symbol_rate
        symbol_coeffs = (1.0/samples_per_symbol,) * samples_per_symbol
        symbol_filter = gr.fir_filter_fff(symbol_decim, symbol_coeffs)
        self.connect(fm_demod, symbol_filter)

        # C4FM demodulator
        autotuneq = gr.msg_queue(2)
        self.demod_watcher = demod_watcher(autotuneq, self.adjust_channel_offset)
        demod_fsk4 = op25.fsk4_demod_ff(autotuneq, channel_rate, symbol_rate)
        self.connect(symbol_filter, demod_fsk4)

        # symbol slicer
        levels = [ -2.0, 0.0, 2.0, 4.0 ]
        slicer = op25.fsk4_slicer_fb(levels)
        self.connect(demod_fsk4, slicer)

        # frame decoder
        decoder = op25.decoder_bf()
        self.connect(slicer, decoder)

        # try to connect audio output device
        try:
            audio_sink = audio.sink(8000, "plughw:0,0", True)
            self.connect(decoder, audio_sink)
        except Exception:
            sink = gr.null_sink(gr.sizeof_float)
            self.connect(decoder, null);
Пример #12
0
    def __init_gui(self, frame, panel, vbox):
        self.frame = frame
        self.frame.CreateStatusBar()
        self.panel = panel
        self.vbox = vbox
        
        # setup the menu bar
        menubar = self.frame.GetMenuBar()

        # setup the "File" menu
        file_menu = menubar.GetMenu(0)
        self.file_new = file_menu.Insert(0, wx.ID_NEW)
        self.frame.Bind(wx.EVT_MENU, self._on_file_new, self.file_new)
        self.file_open = file_menu.Insert(1, wx.ID_OPEN)
        self.frame.Bind(wx.EVT_MENU, self._on_file_open, self.file_open)
        file_menu.InsertSeparator(2)
        self.file_properties = file_menu.Insert(3, wx.ID_PROPERTIES)
        self.frame.Bind(wx.EVT_MENU, self._on_file_properties, self.file_properties)
        file_menu.InsertSeparator(4)
        self.file_close = file_menu.Insert(5, wx.ID_CLOSE)
        self.frame.Bind(wx.EVT_MENU, self._on_file_close, self.file_close)

        # setup the "Edit" menu
        if False:
            edit_menu = wx.Menu()
            self.edit_undo = edit_menu.Insert(0, wx.ID_UNDO)
            self.frame.Bind(wx.EVT_MENU, self._on_edit_undo, self.edit_undo)
            self.edit_redo = edit_menu.Insert(1, wx.ID_REDO)
            self.frame.Bind(wx.EVT_MENU, self._on_edit_redo, self.edit_redo)
            edit_menu.InsertSeparator(2)
            self.edit_cut = edit_menu.Insert(3, wx.ID_CUT)
            self.frame.Bind(wx.EVT_MENU, self._on_edit_cut, self.edit_cut)
            self.edit_copy = edit_menu.Insert(4, wx.ID_COPY)
            self.frame.Bind(wx.EVT_MENU, self._on_edit_copy, self.edit_copy)
            self.edit_paste = edit_menu.Insert(5, wx.ID_PASTE)
            self.frame.Bind(wx.EVT_MENU, self._on_edit_paste, self.edit_paste)
            self.edit_delete = edit_menu.Insert(6, wx.ID_DELETE)
            self.frame.Bind(wx.EVT_MENU, self._on_edit_delete, self.edit_delete)
            edit_menu.InsertSeparator(7)
            self.edit_select_all = edit_menu.Insert(8, wx.ID_SELECTALL)
            self.frame.Bind(wx.EVT_MENU, self._on_edit_select_all, self.edit_select_all)
            edit_menu.InsertSeparator(9)
            self.edit_prefs = edit_menu.Insert(10, wx.ID_PREFERENCES)
            self.frame.Bind(wx.EVT_MENU, self._on_edit_prefs, self.edit_prefs)
            menubar.Append(edit_menu, "&Edit"); # ToDo use wx.ID_EDIT stuff

        # setup the toolbar
        if True:
            self.toolbar = wx.ToolBar(frame, -1, style = wx.TB_DOCKABLE | wx.TB_HORIZONTAL)
            frame.SetToolBar(self.toolbar)
            icon_size = wx.Size(24, 24)
            new_icon = wx.ArtProvider.GetBitmap(wx.ART_NEW, wx.ART_TOOLBAR, icon_size)
            toolbar_new = self.toolbar.AddSimpleTool(wx.ID_NEW, new_icon, "New Capture")
            open_icon = wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_TOOLBAR, icon_size)
            toolbar_open = self.toolbar.AddSimpleTool(wx.ID_OPEN, open_icon, "Open")
##            open_icon = wx.ArtProvider.GetBitmap(wx.ART_FILE_CLOSE, wx.ART_TOOLBAR, icon_size)
##            toolbar_open = self.toolbar.AddSimpleTool(wx.ID_CLOSE, open_icon, "Open")
            #
            # self.toolbar.AddSeparator()
            # self.gain_control = wx.Slider(self.toolbar, 100, 50, 1, 100, style=wx.SL_HORIZONTAL)
            # slider.SetTickFreq(5, 1)
            # self.toolbar.AddControl(self.gain_control)
            #
            self.toolbar.Realize()
        else:
            self.toolbar = None

        # setup the notebook
        self.notebook = wx.Notebook(self.panel)
        self.vbox.Add(self.notebook, 1, wx.EXPAND)     
        # add spectrum scope
        self.spectrum = fftsink2.fft_sink_c(self.notebook, fft_size=512, average=True, peak_hold=True)
        self.spectrum_plotter = self.spectrum.win.plotter
        self.spectrum_plotter.enable_point_label(False)
        self.spectrum_plotter.Bind(wx.EVT_LEFT_DOWN, self._on_spectrum_left_click)
        self.notebook.AddPage(self.spectrum.win, "RF Spectrum")
        # add C4FM scope
        self.signal_scope = scopesink2.scope_sink_f(self.notebook, sample_rate = self.channel_rate, v_scale=5, t_scale=0.001)
        self.signal_scope.win.plotter.enable_point_label(False)
        self.notebook.AddPage(self.signal_scope.win, "C4FM Signal")
        # add symbol scope
        self.symbol_scope = scopesink2.scope_sink_f(self.notebook, frame_decim=1, sample_rate=self.symbol_rate, v_scale=1, t_scale=0.05)
        self.symbol_scope.win.plotter.enable_point_label(False)
##        self.symbol_plotter.set_format_plus()
        self.notebook.AddPage(self.symbol_scope.win, "Demodulated Symbols")
        # Traffic snapshot
        self.traffic = TrafficPane(self.notebook)
        self.notebook.AddPage(self.traffic, "Traffic")
        # Setup the decoder and report the TUN/TAP device name
        msgq = gr.msg_queue(2)
        self.decode_watcher = decode_watcher(msgq, self.traffic)
        self.p25_decoder = op25.decoder_bf()
        self.p25_decoder.set_msgq(msgq)
        self.frame.SetStatusText("Destination: " + self.p25_decoder.destination())