def test_error_codes(monkeypatch): import testlibrtlsdr for attr in ['p_rtlsdr_dev', 'librtlsdr', 'rtlsdr_read_async_cb_t']: lib_attr = '.'.join(['rtlsdr', 'rtlsdr', attr]) override = getattr(testlibrtlsdr, attr) monkeypatch.setattr(lib_attr, override) def fake_callback(*args): pass TEST_METHODS = [ ('set_center_freq', [100e6]), ('get_center_freq', []), ('set_freq_correction', [0]), ('get_freq_correction', []), ('set_sample_rate', [1.024e6]), ('get_sample_rate', []), ('set_bandwidth', [1.024e6]), ('set_gain', [10]), ('set_manual_gain_enabled', [True]), ('set_agc_mode', [True]), ('set_direct_sampling', ['q']), ('get_tuner_type', []), ('read_bytes', []), ('read_samples', []), ('read_bytes_async', [fake_callback]), ('read_samples_async', [fake_callback]), ('cancel_read_async', []), ] from rtlsdr.rtlsdr import RtlSdr, LibUSBError for errno in LibUSBError._errno_map.keys(): err_id, err_msg = LibUSBError._errno_map[errno] # Ensure no errors are thrown during initialization monkeypatch.setattr(testlibrtlsdr, 'ERROR_CODE', 0) sdr = RtlSdr() # Now tell our mocked librtlsdr to always throw errors monkeypatch.setattr(testlibrtlsdr, 'ERROR_CODE', errno) for meth_name, meth_args in TEST_METHODS: m = getattr(sdr, meth_name) print(m) with pytest.raises(LibUSBError) as exc: if len(meth_args): m(*meth_args) else: m() assert exc.value.errno == errno assert err_id in str(exc.value) assert err_msg in str(exc.value)
def __init__(self): self._monitors = [] self._freqs = [] self._levels = numpy.zeros(BINS, dtype=numpy.float32) self._settings = Settings() self._filename = None self._receive = None self._dialogTimeline = None self._dialogSpectrum = None self._gps = None self._location = None self._ui = load_ui('FrameMain.xrc') handlerToolbar = XrcHandlerToolbar() self._ui.AddHandler(handlerToolbar) self._frame = self._ui.LoadFrame(None, 'FrameMain') self.__set_title() self._window = xrc.XRCCTRL(self._frame, 'window') self._status = xrc.XRCCTRL(self._frame, 'statusBar') self._toolbar = xrc.XRCCTRL(self._frame, 'PanelToolbar') self._sizerWindow = self._window.GetSizer() sdr = RtlSdr() gains = sdr.get_gains() gains = [float(gain) / 10. for gain in gains] sdr.close() self._toolbar.set_callbacks(self.__on_freq, self.__on_start, self.__on_rec, self.__on_stop, self.__on_add) self._toolbar.enable_start(True) self._toolbar.set_freq(self._settings.get_freq()) self._toolbar.set_gains(gains) self._toolbar.set_gain(self._settings.get_gain()) self.__add_monitors() self._server = Server(self._frame) self.__start_gps() self._menu = self._frame.GetMenuBar() idOpen = xrc.XRCID('menuOpen') self._menuOpen = self._menu.FindItemById(idOpen) self._frame.Bind(wx.EVT_MENU, self.__on_open, id=idOpen) idSave = xrc.XRCID('menuSave') self._menuSave = self._menu.FindItemById(idSave) self._frame.Bind(wx.EVT_MENU, self.__on_save, id=idSave) idSaveAs = xrc.XRCID('menuSaveAs') self._menuSaveAs = self._menu.FindItemById(idSaveAs) self._frame.Bind(wx.EVT_MENU, self.__on_save_as, id=idSaveAs) idClear = xrc.XRCID('menuClear') self._menuClear = self._menu.FindItemById(idClear) self._frame.Bind(wx.EVT_MENU, self.__on_clear, id=idClear) idGps = xrc.XRCID('menuGps') self._menuGps = self._menu.FindItemById(idGps) self._frame.Bind(wx.EVT_MENU, self.__on_gps, id=idGps) idTimeline = xrc.XRCID('menuTimeline') self._frame.Bind(wx.EVT_MENU, self.__on_timeline, id=idTimeline) self._menuTimeline = self._menu.FindItemById(idTimeline) idSpectrum = xrc.XRCID('menuSpectrum') self._frame.Bind(wx.EVT_MENU, self.__on_spectrum, id=idSpectrum) self._menuSpectrum = self._menu.FindItemById(idSpectrum) idExit = xrc.XRCID('menuExit') self._menuExit = self._menu.FindItemById(idExit) self._frame.Bind(wx.EVT_MENU, self.__on_exit, id=idExit) idAbout = xrc.XRCID('menuAbout') self._frame.Bind(wx.EVT_MENU, self.__on_about, id=idAbout) self._frame.Bind(EVT_TIMELINE_CLOSE, self.__on_timeline_close) self._frame.Bind(EVT_SPECTRUM_CLOSE, self.__on_spectrum_close) self._frame.Bind(wx.EVT_CLOSE, self.__on_exit) self._frame.Connect(-1, -1, EVENT_THREAD, self.__on_event) self._frame.Show()
def __init__(self): wx.Frame.__init__(self, None) self._monitors = [] self._freqs = [] self._levels = numpy.zeros(BINS, dtype=numpy.float32) self._settings = Settings() self._filename = None self._receive = None self._dialogTimeline = None self._dialogSpectrum = None self._gps = None self._location = None self._isSaved = True self._warnedPush = False cmap = cm.get_cmap('Set1') self._colours = [cmap(float(i) / COLOURS) for i in range(COLOURS)] self._ui = load_ui('FrameMain.xrc') self._menu = self._ui.LoadMenuBar('menuBar') self._panelMonitors = self._ui.LoadObject(self, 'scrolled', 'wxScrolledWindow') self._status = self._ui.LoadObject(self, 'statusBar', 'wxStatusBar') self._status.SetMinHeight(25) self._rssi = WidgetMeter(self._status) self._rssi.SetToolTipString('Max and mean signal strength (dB)') self._rssi.Show(self._settings.get_show_rssi()) self._sizerMonitors = self._panelMonitors.GetSizer() self._toolbar = Toolbar(self) self.SetMenuBar(self._menu) self.SetStatusBar(self._status) self._mgr = aui.AuiManager(self) self._mgr.AddPane(self._panelMonitors, aui.AuiPaneInfo(). Centre(). CentrePane()) self._mgr.AddPane(self._toolbar, aui.AuiPaneInfo(). Bottom(). ToolbarPane(). LeftDockable(False). RightDockable(False). NotebookDockable(False). MinSize(self._toolbar.GetMinSize())) self._mgr.Update() width = self._toolbar.GetBestSize().GetWidth() self.SetSize((width, -1)) self.SetMinSize((width, 300)) self.__set_icon() try: sdr = RtlSdr() gains = sdr.get_gains() gains = [float(gain) / 10. for gain in gains] sdr.close() except IOError: wx.MessageBox('No radio found', APP_NAME, wx.OK | wx.ICON_ERROR) exit(1) self._toolbar.set_callbacks(self.__on_freq, self.__on_start, self.__on_rec, self.__on_stop, self.__on_add) self._toolbar.enable_start(True) self._toolbar.set_freq(self._settings.get_freq()) self._toolbar.set_gains(gains) self._toolbar.set_gain(self._settings.get_gain()) self._toolbar.set_cal(self._settings.get_cal()) self._toolbar.set_dynamic_percentile(self._settings. get_dynamic_percentile()) self.__on_freq(self._settings.get_freq()) self._push = Push(self) self._server = Server(self) self.__start_gps() idOpen = xrc.XRCID('menuOpen') self._menuOpen = self._menu.FindItemById(idOpen) self.Bind(wx.EVT_MENU, self.__on_open, id=idOpen) idSave = xrc.XRCID('menuSave') self._menuSave = self._menu.FindItemById(idSave) self.Bind(wx.EVT_MENU, self.__on_save, id=idSave) idSaveAs = xrc.XRCID('menuSaveAs') self.Bind(wx.EVT_MENU, self.__on_save_as, id=idSaveAs) idClear = xrc.XRCID('menuClear') self._menuClear = self._menu.FindItemById(idClear) self.Bind(wx.EVT_MENU, self.__on_clear, id=idClear) idGps = xrc.XRCID('menuGps') self._menuGps = self._menu.FindItemById(idGps) self.Bind(wx.EVT_MENU, self.__on_gps, id=idGps) idRssi = xrc.XRCID('menuRssi') self.Bind(wx.EVT_MENU, self.__on_rssi, id=idRssi) self._menuRssi = self._menu.FindItemById(idRssi) self._menuRssi.Check(self._settings.get_show_rssi()) idTimeline = xrc.XRCID('menuTimeline') self.Bind(wx.EVT_MENU, self.__on_timeline, id=idTimeline) self._menuTimeline = self._menu.FindItemById(idTimeline) idSpectrum = xrc.XRCID('menuSpectrum') self.Bind(wx.EVT_MENU, self.__on_spectrum, id=idSpectrum) self._menuSpectrum = self._menu.FindItemById(idSpectrum) idExit = xrc.XRCID('menuExit') self._menuExit = self._menu.FindItemById(idExit) self.Bind(wx.EVT_MENU, self.__on_exit, id=idExit) idPush = xrc.XRCID('menuPush') self.Bind(wx.EVT_MENU, self.__on_push, id=idPush) idAbout = xrc.XRCID('menuAbout') self.Bind(wx.EVT_MENU, self.__on_about, id=idAbout) self._alert = load_sound('alert.wav') self._alertLast = 0 self.__set_title() self.__enable_controls(True) self._status.Bind(wx.EVT_SIZE, self.__on_size) self.Bind(EVT_TIMELINE_CLOSE, self.__on_timeline_close) self.Bind(EVT_SPECTRUM_CLOSE, self.__on_spectrum_close) self.Bind(wx.EVT_CLOSE, self.__on_exit) self.Connect(-1, -1, EVENT_THREAD, self.__on_event) self.Show() self.__clear_levels()
def __init__(self): wx.Frame.__init__(self, None) self._monitors = [] self._freqs = [] self._levels = numpy.zeros(BINS, dtype=numpy.float32) self._settings = Settings() self._filename = None self._receive = None self._dialogTimeline = None self._dialogSpectrum = None self._gps = None self._location = None self._isSaved = True self._warnedPush = False cmap = cm.get_cmap('Set1') self._colours = [cmap(float(i) / COLOURS) for i in range(COLOURS)] self._ui = load_ui('FrameMain.xrc') self._menu = self._ui.LoadMenuBar('menuBar') self._panelMonitors = self._ui.LoadObject(self, 'scrolled', 'wxScrolledWindow') self._status = self._ui.LoadObject(self, 'statusBar', 'wxStatusBar') self._sizerMonitors = self._panelMonitors.GetSizer() self._toolbar = Toolbar(self) self.SetMenuBar(self._menu) self.SetStatusBar(self._status) self._mgr = aui.AuiManager(self) self._mgr.AddPane(self._panelMonitors, aui.AuiPaneInfo(). Centre(). CentrePane()) self._mgr.AddPane(self._toolbar, aui.AuiPaneInfo(). Bottom(). ToolbarPane(). LeftDockable(False). RightDockable(False). NotebookDockable(False). MinSize(self._toolbar.GetMinSize())) self._mgr.Update() width = self._toolbar.GetBestSize().GetWidth() self.SetSize((width, -1)) self.SetMinSize((width, 300)) self.__set_icon() try: sdr = RtlSdr() gains = sdr.get_gains() gains = [float(gain) / 10. for gain in gains] sdr.close() except IOError: wx.MessageBox('No radio found', APP_NAME, wx.OK | wx.ICON_ERROR) exit(1) self._toolbar.set_callbacks(self.__on_freq, self.__on_start, self.__on_rec, self.__on_stop, self.__on_add) self._toolbar.enable_start(True) self._toolbar.set_freq(self._settings.get_freq()) self._toolbar.set_gains(gains) self._toolbar.set_gain(self._settings.get_gain()) self._toolbar.set_cal(self._settings.get_cal()) self._toolbar.set_dynamic_percentile(self._settings. get_dynamic_percentile()) self.__on_freq(self._settings.get_freq()) self._push = Push(self) self._server = Server(self) self.__start_gps() idOpen = xrc.XRCID('menuOpen') self._menuOpen = self._menu.FindItemById(idOpen) self.Bind(wx.EVT_MENU, self.__on_open, id=idOpen) idSave = xrc.XRCID('menuSave') self._menuSave = self._menu.FindItemById(idSave) self.Bind(wx.EVT_MENU, self.__on_save, id=idSave) idSaveAs = xrc.XRCID('menuSaveAs') self.Bind(wx.EVT_MENU, self.__on_save_as, id=idSaveAs) idClear = xrc.XRCID('menuClear') self._menuClear = self._menu.FindItemById(idClear) self.Bind(wx.EVT_MENU, self.__on_clear, id=idClear) idGps = xrc.XRCID('menuGps') self._menuGps = self._menu.FindItemById(idGps) self.Bind(wx.EVT_MENU, self.__on_gps, id=idGps) idTimeline = xrc.XRCID('menuTimeline') self.Bind(wx.EVT_MENU, self.__on_timeline, id=idTimeline) self._menuTimeline = self._menu.FindItemById(idTimeline) idSpectrum = xrc.XRCID('menuSpectrum') self.Bind(wx.EVT_MENU, self.__on_spectrum, id=idSpectrum) self._menuSpectrum = self._menu.FindItemById(idSpectrum) idExit = xrc.XRCID('menuExit') self._menuExit = self._menu.FindItemById(idExit) self.Bind(wx.EVT_MENU, self.__on_exit, id=idExit) idPush = xrc.XRCID('menuPush') self.Bind(wx.EVT_MENU, self.__on_push, id=idPush) idAbout = xrc.XRCID('menuAbout') self.Bind(wx.EVT_MENU, self.__on_about, id=idAbout) self._alert = load_sound('alert.wav') self._alertLast = 0 self.__set_title() self.__enable_controls(True) self.Bind(EVT_TIMELINE_CLOSE, self.__on_timeline_close) self.Bind(EVT_SPECTRUM_CLOSE, self.__on_spectrum_close) self.Bind(wx.EVT_CLOSE, self.__on_exit) self.Connect(-1, -1, EVENT_THREAD, self.__on_event) self.Show() self.__clear_levels()