import SoapySDR as soapy import prefixed class Radio: def __init__(self, device_info): self.device_info = device_info self.stream = None self.buffer = None self.device = soapy.Device(device_info) if self.device is None: raise RuntimeError("Failed to connect to radio device") def configure(self, frequency): frequency = int(prefixed.Float(frequency)) sample_rate = 384000 bandwidth = 200000 self.device.setFrequency(soapy.SOAPY_SDR_RX, 0, frequency) self.device.setSampleRate(soapy.SOAPY_SDR_RX, 0, sample_rate) self.device.setBandwidth(soapy.SOAPY_SDR_RX, 0, bandwidth) # Set automatic gain self.device.setGainMode(soapy.SOAPY_SDR_RX, 0, True) return { 'frequency': self.device.getFrequency(soapy.SOAPY_SDR_RX, 0), 'sample-rate': self.device.getSampleRate(soapy.SOAPY_SDR_RX, 0), 'bandwidth': self.device.getBandwidth(soapy.SOAPY_SDR_RX, 0), 'gain-mode': 'auto' if self.device.getGainMode(soapy.SOAPY_SDR_RX, 0) else 'manual', }