#!/usr/bin/env python3 # pylint: disable=line-too-long """ Quick control of configuration for receiving QO-100 DATV """ import traceback import sys from optparse import OptionParser # pylint: disable=deprecated-module import requests import sdrangel BASE_URL_PATTERN = "http://{0}/sdrangel" BASE_URL = None # ====================================================================== def get_input_options(): """ Parse options """ # ---------------------------------------------------------------------- parser = OptionParser(usage="usage: %%prog [-t]\n") parser.add_option("-a", "--address", dest="address", help="Address and port. Default: 127.0.0.1:8091", metavar="ADDRESS", type="string") parser.add_option("-d", "--device", dest="device_index", help="Index of device set. Default 0", metavar="INT", type="int") parser.add_option("-c", "--channel", dest="channel_index", help="Index of DATV demod channel. Default 0", metavar="INT", type="int") parser.add_option("-f", "--frequency", dest="frequency", help="Device center frequency (kHz). Mandatory", metavar="INT", type="int") parser.add_option("-s", "--symbol-rate", dest="symbol_rate", help="Symbol rate (kS/s). Mandatory", metavar="INT", type="int") parser.add_option("-n", "--no-decim", dest="no_decim", help="Do not change decimation", action="store_true") (options, args) = parser.parse_args() if options.address is None: options.address = "127.0.0.1:8091" if options.device_index is None: options.device_index = 0 if options.channel_index is None: options.channel_index = 0 if options.frequency is None: raise RuntimeError("Frequency (-f or --frequency) is mandatory") if options.symbol_rate is None: raise RuntimeError("Symbol rate (-s or --symbol-rate) is mandatory") return options class Controller: """ Controller main class """ 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 """ # ---------------------------------------------------------------------- for k in content: if isinstance(content[k], dict): self.change_device_center_frequency(content[k], new_frequency) elif k == sdrangel.DEVICE_TYPES[self.device_hwtype]["cf_key"]: content[k] = new_frequency # ====================================================================== def change_decim(self, content, new_decim): """ Change device log2 decimation searching recursively """ # ---------------------------------------------------------------------- for k in content: if isinstance(content[k], dict): self.change_decim(content[k], new_decim) elif k == sdrangel.DEVICE_TYPES[self.device_hwtype]["decim_key"]: content[k] = new_decim # ====================================================================== def change_channel_center_frequency(self, content, new_frequency): """ Change DATV channel center frequency searching recursively """ # ---------------------------------------------------------------------- for k in content: if isinstance(content[k], dict): self.change_channel_center_frequency(content[k], new_frequency) elif k == "centerFrequency": content[k] = new_frequency # ====================================================================== def change_rfbw(self, content, new_rfbw): """ Change DATV channel RF bandwidth searching recursively """ # ---------------------------------------------------------------------- for k in content: if isinstance(content[k], dict): self.change_rfbw(content[k], new_rfbw) elif k == "rfBandwidth": content[k] = new_rfbw # ====================================================================== def change_symbol_rate(self, content, new_symbol_rate): """ Change DATV channel symbol rate searching recursively """ # ---------------------------------------------------------------------- for k in content: if isinstance(content[k], dict): self.change_symbol_rate(content[k], new_symbol_rate) elif k == "symbolRate": content[k] = new_symbol_rate # ====================================================================== def get_device_sr_and_decim(self, hwtype, settings): """ Return device sample rate and decimation """ # ---------------------------------------------------------------------- decim_key = sdrangel.DEVICE_TYPES[self.device_hwtype]["decim_key"] if hwtype in ("Airspy", "AirspyHF"): sr_index = settings.get("devSampleRateIndex", 0) if sr_index == 1: sr = 3000000 else: sr = 6000000 log2_decim = settings.get(decim_key, 0) else: sr = settings.get("devSampleRate", 0) log2_decim = settings.get(decim_key, 0) return sr, 1<