1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-12-25 04:03:30 -05:00

qo100_datv.py: pass options in the controller class

This commit is contained in:
f4exb 2022-11-19 12:46:27 +01:00
parent fa338a1b34
commit aab3679722

View File

@ -42,10 +42,10 @@ def get_input_options():
class Controller:
""" Controller main class """
def __init__(self):
def __init__(self, options):
self.options = options
self.device_hwtype = None
# ======================================================================
def change_device_center_frequency(self, content, new_frequency):
""" Change device center frequency searching recursively """
@ -125,48 +125,48 @@ class Controller:
return 0 if i < 1 else i - 1
# ======================================================================
def set_device(self, options):
def set_device(self):
""" Set the device """
# ----------------------------------------------------------------------
device_settings_url = f"{BASE_URL}/deviceset/{options.device_index}/device/settings"
device_settings_url = f"{BASE_URL}/deviceset/{self.options.device_index}/device/settings"
r = requests.get(url=device_settings_url, timeout=10)
if r.status_code // 100 == 2: # OK
rj = r.json()
self.device_hwtype = rj.get("deviceHwType", None)
device_settings = rj.get(sdrangel.DEVICE_TYPES[self.device_hwtype]["settings"], None)
device_sr, device_decim = self.get_device_sr_and_decim(self.device_hwtype, device_settings)
new_decim = self.calc_decim(device_sr, options.symbol_rate)
new_decim = self.calc_decim(device_sr, self.options.symbol_rate)
print(f"sr: {device_sr} S/s decim: {device_decim} new decim: {1<<new_decim}")
if not options.no_decim:
if not self.options.no_decim:
self.change_decim(rj, new_decim)
self.change_device_center_frequency(rj, options.frequency*1000)
self.change_device_center_frequency(rj, self.options.frequency*1000)
r = requests.patch(url=device_settings_url, json=rj, timeout=10)
if r.status_code / 100 == 2:
print(f'set_device: changed #{options.device_index}: frequency: {options.frequency} kHz log2Decim: {new_decim} No decim: {options.no_decim}')
print(f'set_device: changed #{self.options.device_index}: frequency: {self.options.frequency} kHz log2Decim: {new_decim} No decim: {self.options.no_decim}')
else:
raise RuntimeError(f'set_device: failed to change device {options.device_index} with error {r.status_code}')
raise RuntimeError(f'set_device: failed to change device {self.options.device_index} with error {r.status_code}')
else:
raise RuntimeError(f"Cannot get device info for device set index {options.device_index} HTTP return code {r.status_code}")
raise RuntimeError(f"Cannot get device info for device set index {self.options.device_index} HTTP return code {r.status_code}")
# ======================================================================
def set_channel(self, options):
def set_channel(self):
""" Set the channel - assume DATV demod """
# ----------------------------------------------------------------------
channel_settings_url = f"{BASE_URL}/deviceset/{options.device_index}/channel/{options.channel_index}/settings"
channel_settings_url = f"{BASE_URL}/deviceset/{self.options.device_index}/channel/{self.options.channel_index}/settings"
r = requests.get(url=channel_settings_url, timeout=10)
if r.status_code // 100 == 2: # OK
rj = r.json()
rfbw = round(1.5*options.symbol_rate)*1000
rfbw = round(1.5*self.options.symbol_rate)*1000
self.change_channel_center_frequency(rj, 0)
self.change_rfbw(rj, rfbw)
self.change_symbol_rate(rj, options.symbol_rate*1000)
self.change_symbol_rate(rj, self.options.symbol_rate*1000)
r = requests.patch(url=channel_settings_url, json=rj, timeout=10)
if r.status_code / 100 == 2:
print(f'set_channel: changed {options.device_index}:{options.channel_index}: rfbw: {rfbw} Hz symbol rate: {options.symbol_rate} kS/s')
print(f'set_channel: changed {self.options.device_index}:{self.options.channel_index}: rfbw: {rfbw} Hz symbol rate: {self.options.symbol_rate} kS/s')
else:
raise RuntimeError(f'set_device: failed to change channel {options.device_index}:{options.channel_index} with error {r.status_code}')
raise RuntimeError(f'set_device: failed to change channel {self.options.device_index}:{self.options.channel_index} with error {r.status_code}')
else:
raise RuntimeError(f"Cannot get channel info for channel {options.device_index}:{options.channel_index} HTTP return code {r.status_code}")
raise RuntimeError(f"Cannot get channel info for channel {self.options.device_index}:{self.options.channel_index} HTTP return code {r.status_code}")
# ======================================================================
@ -179,9 +179,9 @@ def main():
global BASE_URL # pylint: disable=global-statement
BASE_URL = BASE_URL_PATTERN.format(options.address)
print(f"Frequency: 10{options.frequency/1000} MHz Symbol rate: {options.symbol_rate} kS/s")
controller = Controller()
controller.set_device(options)
controller.set_channel(options)
controller = Controller(options)
controller.set_device()
controller.set_channel()
except Exception as ex: # pylint: disable=broad-except
tb = traceback.format_exc()