From 4b45dfa6da7adc791fe622a2a155cee496ba8b70 Mon Sep 17 00:00:00 2001 From: Al Date: Wed, 3 Feb 2016 12:56:38 +0000 Subject: [PATCH] Limit dwell time --- src/cli.py | 28 +++++++++++++++------------- src/constants.py | 12 ------------ src/main_window.py | 13 +++++++------ src/misc.py | 19 +++++++++++++++++++ src/version-timestamp | 2 +- 5 files changed, 42 insertions(+), 32 deletions(-) diff --git a/src/cli.py b/src/cli.py index 438a3d8..24898aa 100644 --- a/src/cli.py +++ b/src/cli.py @@ -37,7 +37,7 @@ from events import Event from file import save_plot, export_plot, ScanInfo, File from location import ThreadLocation -from misc import nearest, calc_real_dwell, next_2_to_pow +from misc import nearest, calc_real_dwell, next_2_to_pow, get_dwells from scan import ThreadScan, update_spectrum, ThreadProcess from settings import Settings @@ -77,6 +77,8 @@ def __init__(self, args): error = "Start should be lower than end" elif dwell <= 0: error = "Dwell should be positive" + elif dwell > max(get_dwells()[1::2]): + error = "Dwell should equal lower than {}s".format(max(get_dwells()[1::2])) elif nfft <= 0: error = "FFT bins should be positive" elif ext != ".rfs" and File.get_type_index(ext) == -1: @@ -107,19 +109,19 @@ def __init__(self, args): self.settings.devicesRtl.append(device) index = len(self.settings.devicesRtl) - 1 - if args.conf is not None: - if os.path.exists(args.conf): - error = self.settings.load_conf(args.conf) - else: - error = 'Cannot find {}'.format(args.conf) + if args.conf is not None: + if os.path.exists(args.conf): + error = self.settings.load_conf(args.conf) + else: + error = 'Cannot find {}'.format(args.conf) - if end - 1 < start: - end = start + 1 - if remote is None: - if len(self.settings.devicesRtl): - gain = nearest(gain, self.settings.devicesRtl[index].gains) - else: - error = 'No devices found' + if end - 1 < start: + end = start + 1 + if remote is None: + if len(self.settings.devicesRtl): + gain = nearest(gain, self.settings.devicesRtl[index].gains) + else: + error = 'No devices found' if error is not None: print "Error: {}".format(error) diff --git a/src/constants.py b/src/constants.py index b90ef6a..1f72505 100644 --- a/src/constants.py +++ b/src/constants.py @@ -54,18 +54,6 @@ 16384, 32768] -DWELL = ["8 ms", 0.008, - "16 ms", 0.016, - "32 ms", 0.032, - "65 ms", 0.065, - "131 ms", 0.131, - "262 ms", 0.262, - "524 ms", 0.524, - "1 s", 1.048, - "2 s", 2.097, - "4 s", 4.194, - "8 s", 8.388] - DISPLAY = ["Plot", 0, "Spectrogram", 1, "3D Spectrogram", 2, diff --git a/src/main_window.py b/src/main_window.py index eea3eac..440e029 100644 --- a/src/main_window.py +++ b/src/main_window.py @@ -37,7 +37,7 @@ import wx from wx.lib.masked.numctrl import NumCtrl -from constants import F_MIN, F_MAX, MODE, DWELL, NFFT, DISPLAY, Warn, \ +from constants import F_MIN, F_MAX, MODE, NFFT, DISPLAY, Warn, \ Cal, Mode, APP_NAME, LOCATION_PORT from devices import get_devices_rtl from dialogs_devices import DialogDevicesRTL, DialogDevicesGPS @@ -53,7 +53,7 @@ export_map, extension_add, File, run_file, export_gpx, Backups from location import ThreadLocation, LocationServer from menus import MenuMain, PopMenuMain -from misc import RemoteControl, calc_samples, calc_real_dwell, \ +from misc import RemoteControl, calc_samples, get_dwells, calc_real_dwell, \ get_version_timestamp, get_version_timestamp_repo, format_iso_time, limit from panels import PanelGraph from printer import PrintOut @@ -253,7 +253,7 @@ def __create_toolbars(self): self.choiceMode.SetToolTipString('Scanning mode') textDwell = wx.StaticText(self.toolbar2, label="Dwell") - self.choiceDwell = wx.Choice(self.toolbar2, choices=DWELL[::2]) + self.choiceDwell = wx.Choice(self.toolbar2, choices=get_dwells()[::2]) self.choiceDwell.SetToolTipString('Scan time per step') textNfft = wx.StaticText(self.toolbar2, label="FFT size") @@ -1261,10 +1261,11 @@ def __set_controls(self): self.spinCtrlStop.SetValue(self.settings.stop) self.choiceMode.SetSelection(MODE[1::2].index(self.settings.mode)) dwell = calc_real_dwell(self.settings.dwell) + dwells = get_dwells() try: - sel = DWELL[1::2].index(dwell) + sel = dwells[1::2].index(dwell) except ValueError: - sel = DWELL[1::2][len(DWELL) / 4] + sel = dwells[1::2][len(dwells) / 4] self.choiceDwell.SetSelection(sel) self.choiceNfft.SetSelection(NFFT.index(self.settings.nfft)) self.choiceDisplay.SetSelection(DISPLAY[1::2].index(self.settings.display)) @@ -1299,7 +1300,7 @@ def __get_controls(self): self.settings.startOption = self.buttonStart.GetSelected() self.settings.stopOption = self.buttonStop.GetSelected() self.settings.mode = MODE[1::2][self.choiceMode.GetSelection()] - self.settings.dwell = DWELL[1::2][self.choiceDwell.GetSelection()] + self.settings.dwell = get_dwells()[1::2][self.choiceDwell.GetSelection()] self.settings.nfft = NFFT[self.choiceNfft.GetSelection()] self.settings.display = DISPLAY[1::2][self.choiceDisplay.GetSelection()] diff --git a/src/misc.py b/src/misc.py index 0f5933f..0cd8092 100644 --- a/src/misc.py +++ b/src/misc.py @@ -128,6 +128,25 @@ def calc_samples(dwell): return samples +def get_dwells(): + dwells = ["8 ms", 0.008, + "16 ms", 0.016, + "32 ms", 0.032, + "65 ms", 0.065, + "131 ms", 0.131, + "262 ms", 0.262, + "524 ms", 0.524, + "1 s", 1.048, + "2 s", 2.097, + "4 s", 4.194, + "8 s", 8.388] + + if sys.platform == 'linux' or sys.platform == "linux2": + del dwells[-4:] + + return dwells + + def calc_real_dwell(dwell): samples = calc_samples(dwell) dwellReal = samples / SAMPLE_RATE diff --git a/src/version-timestamp b/src/version-timestamp index fb014dc..9ba4757 100644 --- a/src/version-timestamp +++ b/src/version-timestamp @@ -1 +1 @@ -1453648562 \ No newline at end of file +1454502628 \ No newline at end of file