def __init__(self, rate=None, txserial="RF3E000008", rxserial="RF3E000018", freq=None, bw=None, txGain=None, rxGain=None, chained=False, ): self.sdrs = [] if txserial is not None: self.txsdr = SoapySDR.Device(dict(driver="iris", serial = txserial)) self.sdrs.append(self.txsdr) else: self.txsdr = None if rxserial is not None: self.rxsdr = SoapySDR.Device(dict(driver="iris", serial = rxserial)) self.sdrs.append(self.rxsdr) else: self.rxsdr = None self.trig_sdr = self.txsdr if txserial is not None else self.rxsdr self.rate = rate ### Setup channel rates, ports, gains, and filters ### for sdr in self.sdrs: info = sdr.getHardwareInfo() for chan in [0]: if rate is not None: sdr.setSampleRate(SOAPY_SDR_RX, chan, rate) if bw is not None: sdr.setBandwidth(SOAPY_SDR_RX, chan, bw) if rxGain is not None: sdr.setGain(SOAPY_SDR_RX, chan, rxGain) if freq is not None: sdr.setFrequency(SOAPY_SDR_RX, chan, "RF", freq) sdr.setAntenna(SOAPY_SDR_RX, chan, "TRX") sdr.setFrequency(SOAPY_SDR_RX, chan, "BB", 0) #don't use cordic sdr.setDCOffsetMode(SOAPY_SDR_RX, chan, False) #dc removal on rx #we'll remove this in post-processing if rate is not None: sdr.setSampleRate(SOAPY_SDR_TX, chan, rate) if bw is not None: sdr.setBandwidth(SOAPY_SDR_TX, chan, bw) if txGain is not None: sdr.setGain(SOAPY_SDR_TX, chan, txGain) if freq is not None: sdr.setFrequency(SOAPY_SDR_TX, chan, "RF", freq) print("Set frequency to %f" % sdr.getFrequency(SOAPY_SDR_TX,chan)) sdr.setAntenna(SOAPY_SDR_TX, chan, "TRX") sdr.setFrequency(SOAPY_SDR_TX, chan, "BB", 0) #don't use cordic if chained: self.trig_sdr.writeSetting('SYNC_DELAYS', "") for sdr in self.sdrs: sdr.setHardwareTime(0, "TRIGGER") self.trig_sdr.writeSetting("TRIGGER_GEN", "") else: for sdr in self.sdrs: sdr.setHardwareTime(0) #they'll be a bit off... #create streams if rxserial is not None: self.rxsdr.writeSetting(SOAPY_SDR_RX, 0, 'CALIBRATE', 'SKLK') self.rxStream = self.rxsdr.setupStream(SOAPY_SDR_RX, SOAPY_SDR_CF32, [0], {}) if txserial is not None: self._txing = False self.txsdr.writeSetting(SOAPY_SDR_TX, 0, 'CALIBRATE', 'SKLK') self.txStream = None #we set this up in the tx so it can be continuous
def get_iris_sensor_readings(): """ Read the temperatures of all Irises on the network. :return irises_sensors: A list of Irises and theirs temperatures. """ irises = get_iris_serial_numbers_on_network() SoapySDR.Device.enumerate({"remote:timeout": "500000"}) sdrs = [SoapySDR.Device(dict(driver="iris", serial=s)) for s in irises] irises_sensors = [] status = {} for i, sdr in enumerate(sdrs): sensors = sdr.listSensors() for sensor in sensors: info = sdr.getSensorInfo(sensor) try: status[info.name] = sdr.readSensor(sensor) except Exception: status[info.name] = '-1.0' pass irises_sensors.append([irises[i], "{:.2f}".format(float(status[LMS7])), "{:.2f}".format(float(status[ZYNQ])), "{:.2f}".format(float(status[TX])), "{:.2f}".format(float(status[RX]))]) return irises_sensors
def __init__(self, center_freq, freqspan=1e5): """ init-method :param center_freq: [Hz] Defines the center frequency where to listen (between 27MHz and 1.7GHz) :param freqspan: [Hz] span within the the algorithm is looking for amplitude peaks """ # connect to sdr args = dict(driver="airspy") ##### self.__sdr = SoapySDR.Device(args) # RtlSdr() ##### self.__sdr.gain = 1 self.__sdr.sample_rate = 2.048e6 # 2.048 MS/s self.__centerfreq = center_freq self.set_sdr_centerfreq(self.__centerfreq) self.__freqspan = freqspan self.__samplesize = 32 self.__btxparamsavailable = False self.__freqtx = 0 self.__numoftx = 0 self.__txpos = [] self.__bcalparamsavailable = False self.__txalpha = [] self.__txgamma = []
def _snoopChannels(self, device): dev = self._devices[device] nextUpdate = time.time() while self._running: if dev is None: print('Attempting to re-establish connection...') try: dev = SoapySDR.Device(self._handles[device]) except Exception as ex: print('Failed to connect %s, retrying in several seconds...'%str(ex)) time.sleep(3) continue if nextUpdate < time.time(): self._sampleRate[device] = dev.getSampleRate(SOAPY_SDR_RX, 0) self._centerFreq[device] = dev.getFrequency(SOAPY_SDR_RX, 0) self._rxGain[device] = [dev.getGain(SOAPY_SDR_RX, chan) for chan in range(2)] self._txGain[device] = [dev.getGain(SOAPY_SDR_TX, chan) for chan in range(2)] nextUpdate = time.time() + 1.5 sampleses = list() for ch in [0, 1]: if "AB"[ch] not in self._chans: continue try: samps = dev.readRegisters('RX_SNOOPER', ch, 1024) except Exception as ex: print('readRegisters error %s, attempting to close connection...'%str(ex)) self._device = None break samps = np.array([complex(float(np.int16(s & 0xffff)), float(np.int16(s >> 16))) for s in samps])/float(1 << 15) sampleses.append(samps) if dev is None: continue with self._mutex[device]: self._dataInFlight[device] += 1 self.snooperComplete.emit(sampleses, device) while self._dataInFlight[device] and self._running: time.sleep(.05)
def __enter__(self): #enumerate devices # results = SoapySDR.Device.enumerate() # for result in results: print(result) #create device instance #args can be user defined or from the enumeration result args = dict(driver="rtlsdr") self.sdr = SoapySDR.Device(args) #query device info # print(self.sdr.listAntennas(SOAPY_SDR_RX, 0)) # print(self.sdr.listGains(SOAPY_SDR_RX, 0)) freqs = self.sdr.getFrequencyRange(SOAPY_SDR_RX, 0) # for freqRange in freqs: print(freqRange) #apply settings self.sdr.setSampleRate(SOAPY_SDR_RX, 0, self.sample_rate) self.sdr.setFrequency(SOAPY_SDR_RX, 0, self.carrier_freq) self.sdr.setBandwidth(SOAPY_SDR_RX, 0, self.bandwidth) #setup a stream (complex floats) self.rxStream = self.sdr.setupStream(SOAPY_SDR_RX, SOAPY_SDR_CF32) self.sdr.activateStream(self.rxStream) #start streaming #create a re-usable buffer for rx samples self.buff = np.array([0] * 1024, np.complex64) return self._generator
def __init__(self, device_str=""): self.device_str = device_str self.verbose = True self.conf = None self.th = None self.stream_break = False self.state = 'init' self.config_name = '' self.rssi = 0.0 self.rssi_log = [] # self.spectr_F = None self.spectr_PSD = None self.FFT_PERIOD = 0.5 #set to 0 to disable FFT calculation self.FFT_SIZE = 1024 self.FFT_AVERAGE = 4 #defines number of FFT_SIZE samples passed to fft() self.fft_samples = numpy.array([0] * self.FFT_SIZE, numpy.complex64) # try: self.sdr = SoapySDR.Device(device_str) except Exception as e: print "ERROR: OSMO_SDR failed to init device: {} ( {} )".format( device_str, e) self.state = 'NO DEVICE' raise Exception(e) if self.verbose: print "Init SDR device [{}]".format(device_str) print "|-sample rates: " + str( self.sdr.listSampleRates(SOAPY_SDR_RX, 0)) print "|-BW:" + str(self.sdr.getBandwidthRange(SOAPY_SDR_RX, 0)) print "|-Gains:" + str(self.sdr.listGains(SOAPY_SDR_RX, 0))
def sweep_bw( args, chan, dir, start, stop, step, ): sdr = SoapySDR.Device(args) fails = list() bandwidth = start while True: print('#' * 50) print('## Set channel %d %s bandwidth to %g MHz' % (chan, dir, bandwidth / 1e6)) print('#' * 50) try: sdr.setBandwidth(SOAPY_SDR_RX if dir == "RX" else SOAPY_SDR_TX, chan, bandwidth) except Exception as ex: print(ex) fails.append((bandwidth, str(ex))) bandwidth += step if bandwidth > stop: break if fails: print('#' * 50) print('## Failure summary') print('#' * 50) for bw, err in fails: print(" * %g MHz - %s" % (bw / 1e6, err)) print("Done!")
def init_devices(self): self.sdr_device = SoapySDR.Device({'driver': 'remote'}) # self.sdr_device = SoapySDR.Device({'driver': 'lime'}) if self.sdr_device is None: print("[ERROR] No SDR device!", file=sys.stderr) return self.sdr_device.setAntenna(SOAPY_SDR_RX, 0, 'LNAH') self.sdr_device.setFrequency(SOAPY_SDR_RX, 0, self.fc) self.sdr_device.setSampleRate(SOAPY_SDR_RX, 0, self.fs) self.sdr_device.setBandwidth(SOAPY_SDR_RX, 0, self.bandwidth) self.sdr_device.setDCOffsetMode(SOAPY_SDR_RX, 0, True) if self.sdr_device.hasGainMode(SOAPY_SDR_RX, 0): self.sdr_device.setGainMode(SOAPY_SDR_RX, 0, False) gains = {"LNA": 0, "TIA": 0, "PGA": -12} for gain, value in gains.items(): self.sdr_device.setGain(SOAPY_SDR_RX, 0, gain, value) # MTU is hardcoded to get 512 samples i.e. one FFT frame. self.rx_stream = self.sdr_device.setupStream(SOAPY_SDR_RX, SOAPY_SDR_CS16, [0], {'remote:mtu': '2120', 'remote:prot': 'tcp'}) assert self.sdr_device.getStreamMTU(self.rx_stream) == self.fft_size self.sdr_device.activateStream(self.rx_stream)
def transmit_tone(freq, chan=0, fs=31.25, gain=-20, buff_len=16384): """ Transmit a tone out of the AIR-T """ # Generate tone buffer that can be repeated without phase discontunity bb_freq = fs / 8 # baseband frequency of tone tx_buff = make_tone(buff_len, bb_freq, fs) lo_freq = freq - bb_freq # Calc LO freq to put tone at tone_rf # Setup Radio sdr = SoapySDR.Device() # Create AIR-T instance sdr.setSampleRate(SOAPY_SDR_TX, chan, fs) # Set sample rate sdr.setFrequency(SOAPY_SDR_TX, chan, lo_freq) # Tune the LO sdr.setGain(SOAPY_SDR_TX, chan, gain) tx_stream = sdr.setupStream(SOAPY_SDR_TX, SOAPY_SDR_CS16, [chan]) sdr.activateStream(tx_stream) # this turns the radio on # Transmit print('Now Transmitting') while True: try: rc = sdr.writeStream(tx_stream, [tx_buff], buff_len) if rc.ret != buff_len: print('TX Error {}: {}'.format(rc.ret, errToStr(rc.ret))) except KeyboardInterrupt: break # Stop streaming sdr.deactivateStream(tx_stream) sdr.closeStream(tx_stream)
def rxsamples_app(srl, freq, gain, num_samps, recorder, agc_en, wait_trigger): """ Initialize IRIS parameters and animation kick-off """ # Global declarations global sdr, rxStream, freqScale, Rate # Instantiate device sdr = SoapySDR.Device(dict(serial=srl)) info = sdr.getHardwareInfo() print(info) # Set gains to very high value if AGC enabled (AGC only supports CBRS RF frontend at the moment). if agc_en and "CBRS" in info["frontend"]: gain = 100 rssi_target_idx = 20 agc_init(sdr, rssi_target_idx) else: # Make sure AGC is disabled if any of the previous checks fails agc_en = 0 # Set params on both channels (both RF chains) for ch in [0, 1]: sdr.setBandwidth(SOAPY_SDR_RX, ch, 2.5*Rate) sdr.setBandwidth(SOAPY_SDR_TX, ch, 2.5*Rate) sdr.setFrequency(SOAPY_SDR_RX, ch, freq) sdr.setSampleRate(SOAPY_SDR_RX, ch, Rate) sdr.setFrequency(SOAPY_SDR_TX, ch, freq) sdr.setSampleRate(SOAPY_SDR_TX, ch, Rate) sdr.setAntenna(SOAPY_SDR_RX, ch, "TRX") sdr.setDCOffsetMode(SOAPY_SDR_RX, ch, True) if "CBRS" in info["frontend"]: sdr.setGain(SOAPY_SDR_RX, ch, gain) else: # No CBRS board gains, only changing LMS7 gains sdr.setGain(SOAPY_SDR_RX, ch, "LNA", gain) # [0:1:30] sdr.setGain(SOAPY_SDR_RX, ch, "TIA", 0) # [0, 3, 9, 12] sdr.setGain(SOAPY_SDR_RX, ch, "PGA", -10) # [-12:1:19] print("Number of Samples %d " % num_samps) print("Frequency has been set to %f" % sdr.getFrequency(SOAPY_SDR_RX, 0)) sdr.writeRegister("RFCORE", 120, 0) # Setup RX stream rxStream = sdr.setupStream(SOAPY_SDR_RX, SOAPY_SDR_CF32, [0, 1]) # RSSI read setup setUpDigitalRssiMode(sdr) # There's a bug in the FuncAnimation function, we replaced it with a fixed version # anim = animation.FuncAnimation(fig, animate, init_func=init, fargs=(num_samps, recorder, agc_en, wait_trigger), # frames=100, interval=100, blit=True) anim = MyFuncAnimation(fig, animate, init_func=init, fargs=(num_samps, recorder, agc_en, wait_trigger, info), frames=100, interval=100, blit=True) plt.show()
def getSdrs(self): 'Get a list of devices based on serials' sdrs = {} for serial in self.serials: try: sdrs[serial] = SoapySDR.Device(dict(driver='iris', serial=serial, timeout="1000000")) except RuntimeError: sdrs[serial] = None return sdrs
def setUp(self): self.sdr = SoapySDR.Device(SDR_ARGS) for ch in [0, 1]: self.sdr.setSampleRate(SOAPY_SDR_RX, ch, 10e6) self.sdr.setSampleRate(SOAPY_SDR_TX, ch, 10e6) self.rxStream = self.sdr.setupStream(SOAPY_SDR_RX, SOAPY_SDR_CF32, [0, 1]) self.txStream = self.sdr.setupStream(SOAPY_SDR_TX, SOAPY_SDR_CF32, [0, 1])
def __init__( self, args, rate, freq=None, bw=None, txSerial=None, rxSerial=None, txGain=None, rxGain=None, rxAnt=None, txAnt=None, ): self.txSDR = SoapySDR.Device(dict(driver="iris", serial=txSerial)) self.rxSDR = SoapySDR.Device(dict(driver="iris", serial=rxSerial)) # print("Using Iris: {} for tx and Iris: {} for rx.", txSerial, rxSerial) for sdr in [self.txSDR, self.rxSDR]: chan = 0 if rate is not None: sdr.setSampleRate(SOAPY_SDR_RX, chan, rate) if bw is not None: sdr.setBandwidth(SOAPY_SDR_RX, chan, bw) if rxGain is not None: sdr.setGain(SOAPY_SDR_RX, chan, rxGain) if freq is not None: sdr.setFrequency(SOAPY_SDR_RX, chan, "RF", freq) if rxAnt is not None: sdr.setAntenna(SOAPY_SDR_RX, chan, rxAnt) sdr.setFrequency(SOAPY_SDR_RX, chan, "BB", 0) #don't use cordic sdr.setDCOffsetMode(SOAPY_SDR_RX, chan, True) #dc removal on rx if rate is not None: sdr.setSampleRate(SOAPY_SDR_TX, chan, rate) if bw is not None: sdr.setBandwidth(SOAPY_SDR_TX, chan, bw) if txGain is not None: sdr.setGain(SOAPY_SDR_TX, chan, txGain) if freq is not None: sdr.setFrequency(SOAPY_SDR_TX, chan, "RF", freq) if txAnt is not None: sdr.setAntenna(SOAPY_SDR_TX, chan, txAnt) sdr.setFrequency(SOAPY_SDR_TX, chan, "BB", 0) #don't use cordic sdr.writeSetting(SOAPY_SDR_RX, chan, 'CALIBRATE', 'SKLK') sdr.writeSetting(SOAPY_SDR_TX, chan, 'CALIBRATE', 'SKLK') sdr.writeSetting('SPI_TDD_MODE', 'MIMO') self.txSDR.writeSetting('SYNC_DELAYS', "") self.txSDR.setHardwareTime(0, "TRIGGER") self.rxSDR.setHardwareTime(0, "TRIGGER")
def prepare_irises(uut_serials, golden_serial, rm_from_uut_serials): handles = SoapySDR.Device.enumerate({"remote:timeout": "250000"}) if not uut_serials: sdrs = SoapySDR.Device( handles) # Instantiate all devices on the network. else: uut_serials.append(golden_serial) sdrs = [ SoapySDR.Device(dict(driver="iris", serial=s)) for s in uut_serials ] # Remove non-Iris instances, e.g. hub serial. uut_sdrs = list(sdrs) for sdr in sdrs: if "Iris" not in sdr.getHardwareInfo()["revision"]: uut_sdrs.remove(sdr) # Find all Iris serials and frontend types. uut_serials = [sdr.getHardwareInfo()["serial"] for sdr in uut_sdrs] uut_frontends = [] for sdr in uut_sdrs: if "CBRS" in sdr.getHardwareInfo()["frontend"]: uut_frontends.append("CBRS") else: uut_frontends.append("") # Pick the golden Iris and remove it from the UUT list. if golden_serial == "": golden_serial = uut_serials[0] index = uut_serials.index(golden_serial) golden_sdr = uut_sdrs.pop(index) uut_serials.pop(index) # Decide on the UUT list. for serial in rm_from_uut_serials: index = uut_serials.index(serial) uut_sdrs.pop(index) uut_serials.pop(index) uut_frontends.pop(index) uut_sdrs = tuple(uut_sdrs) return uut_sdrs, uut_serials, uut_frontends, golden_sdr, golden_serial
def __init__( self, serial_id=None, ): if serial_id is not None: self.sdr = SoapySDR.Device(dict(driver="remote", serial=serial_id)) self.serial_id = serial_id else: self.sdr = None
def config_radio(sample_rate, center_frequency): sdr = sp.Device({ 'driver': 'bladerf', 'serial': u.BLADE_2 }) print(sample_rate) print(center_frequency) sdr.setSampleRate(sp.SOAPY_SDR_RX, 0, sample_rate) sdr.setFrequency(sp.SOAPY_SDR_RX, 0, center_frequency) return sdr
def __init__( self, serial_id=None, ): if serial_id is not None: self.sdr = SoapySDR.Device(dict(driver="remote", serial=serial_id)) if self.sdr == None: print("Error in initializing the hub!") else: self.sdr = None
def setDevice(self, device): device = toDevice(device) print("[DEMOD] Activating {} device.".format(device["label"])) self.sdr = SoapySDR.Device(device) self.sdr.setGainMode(SOAPY_SDR_RX, 0, True) self.sdr.setSampleRate(SOAPY_SDR_RX, 0, self.sfs) self.sdr.setFrequency(SOAPY_SDR_RX, 0, self.freq) self.device = str(device)
def __init__(self, bbdev): self.bbdev = bbdev self.sdr = SoapySDR.Device(bbdev) self.rxStreamActiveState = False self.txStreamActiveState = False self.rxStream = None self.txStream = None #print dir(self.sdr) #print help(self.sdr.setGainMode) self.sdr.setGainMode(SOAPY_SDR_RX, 0, False) self.sdr.setGain(SOAPY_SDR_RX, 0, 0 + 0 * 100)
def setUp(self): self.sdr = SoapySDR.Device(SDR_ARGS) #some default sample rates self.sdr.setSampleRate(SOAPY_SDR_RX, 0, RATE) self.sdr.setSampleRate(SOAPY_SDR_RX, 1, RATE) self.sdr.setSampleRate(SOAPY_SDR_TX, 0, RATE) self.sdr.setSampleRate(SOAPY_SDR_TX, 1, RATE) self.sdr.writeSetting("FPGA_DIQ_MODE", "LOOPB") #tx deframer -> rx framer
def FindDevice(): # enumerate devices results = SoapySDR.Device.enumerate() print("Devices Found: ") for result in results: print(result) # create device instance # args can be user defined or from the enumeration result args = dict(driver="lime") #args = results[0] print("Instantiating device: ") return SoapySDR.Device(args)
def main(): pars = parse_command_line_arguments() # Initialize the AIR-T receiver, set sample rate, gain, and frequency sdr = SoapySDR.Device() sdr.setSampleRate(SOAPY_SDR_RX, pars.channel, pars.samp_rate) if pars.rx_gain.lower() == 'agc': # Turn on AGC sdr.setGainMode(SOAPY_SDR_RX, pars.channel, True) else: # set manual gain sdr.setGain(SOAPY_SDR_RX, pars.channel, float(pars.rx_gain)) sdr.setFrequency(SOAPY_SDR_RX, pars.channel, pars.freq) # Initialize the AIR-T transmitter, set sample rate, gain, and frequency sdr.setSampleRate(SOAPY_SDR_TX, pars.channel, pars.samp_rate) sdr.setGain(SOAPY_SDR_TX, pars.channel, float(pars.tx_gain)) sdr.setFrequency(SOAPY_SDR_TX, pars.channel, pars.freq) # Create SDR shared memory buffer, detector buff = cusignal.get_shared_mem(pars.buff_len, dtype=cp.complex64) detr = PowerDetector(buff, pars.threshold) # Turn on the transmitter tx_stream = sdr.setupStream(SOAPY_SDR_TX, SOAPY_SDR_CF32, [pars.channel]) sdr.activateStream(tx_stream) # Setup thread subclass to asynchronously execute transmit requests tx_executor = concurrent.futures.ThreadPoolExecutor(max_workers=1) # Turn on the receiver rx_stream = sdr.setupStream(SOAPY_SDR_RX, SOAPY_SDR_CF32, [pars.channel]) sdr.activateStream(rx_stream) # Start processing Data print('Looking for signals to repeat. Press ctrl-c to exit.') while True: try: sr = sdr.readStream(rx_stream, [buff], pars.buff_len) # Read data if sr.ret == SOAPY_SDR_OVERFLOW: # Data was dropped print('O', end='', flush=True) continue detected_sig = detr.detect(buff) if detected_sig is not None: # AIR-T transmitter currently only accepts numpy arrays or lists tx_sig = cp.asnumpy(detected_sig) tx_executor.submit(tx_task_fn, sdr, tx_stream, tx_sig, pars.buff_len) detr.plot_envelope(buff) # Plot the signal end envelope except KeyboardInterrupt: break sdr.closeStream(rx_stream) sdr.closeStream(tx_stream)
def __init__(self, dev, audio_sr): self.radio = sdr.Device(dev) if dev["driver"] == "sdrplay": self.radio.setSampleRate(RX, 0, 768000) elif dev['driver'] == 'rfspace': self.radio.setGain(RX, 0, 0) else: self.radio.setSampleRate(RX, 0, 1536000) self.socket = socketio.Client() # fill out radio hardware info self.hardware = JavaDict() self.hardware.key = self.radio.getHardwareKey() self.hardware.info = dict(self.radio.getHardwareInfo()) self.hardware.sampleRates = self.radio.listSampleRates(RX, 0) self.hardware.bandwidths = self.radio.listBandwidths(RX, 0) self.hardware.gains = self.radio.listGains(RX, 0) self.hardware.frequencies = self.radio.listFrequencies(RX, 0) self.hardware.antennas = self.radio.listAntennas(RX, 0) self.hardware.hasDCOffsetMode = self.radio.hasDCOffsetMode(RX, 0) self.hardware.hasGainMode = self.radio.hasGainMode(RX, 0) self.hardware.hasFreqCorrection =\ self.radio.hasFrequencyCorrection(RX, 0) # Transfer ArgsKeys to JavaDicts self.settings = [] self.readSettingsDefaults() self.readSettings() self.config = JavaDict() self.config.driver = dev['driver'] self.config.audio_sr = audio_sr self.readConfig() self.config.frameRate = 60 # milliseconds self.config.iqdatalength = 1024 self.config.offset = 0 self.config.tunerFreq = self.config.centerFreq + self.config.offset self.running = Event() self.running.clear() self.collecting = Event() self.collecting.set() self.modem = AMModem(self.config) self.spectrum = PowerSpectrum(self.config) self.tones = ToneGenerator([], self.config) self.task = None self.dataQueue = Fifo(5) self.changeQueue = Fifo() self.ackQueue = Fifo() self.sid = None
def __init__(self, settings): # Some general setup self.settings = settings self.rx_freq_offset = -settings['samplerate'] * settings[ 'offset'] / settings['samples_meas'] print(self.rx_freq_offset) # Generate the TX buffer samples_tx = settings['samples_begin'] + settings[ 'samples_meas'] + settings['samples_end'] self.txburst = np.ones(samples_tx, dtype=np.complex64) * settings['tx_amplitude'] # Preallocate the RX buffer too self.rxbuffer = np.zeros(settings['samples_rx'], dtype=np.complex64) # Initialize the SDR self.sdr = SoapySDR.Device(settings['device_args']) self.sdr.setSampleRate(SOAPY_SDR_RX, settings['rx_channel'], settings['samplerate']) self.sdr.setSampleRate(SOAPY_SDR_TX, settings['tx_channel'], settings['samplerate']) self.sdr.setAntenna(SOAPY_SDR_RX, settings['rx_channel'], settings['rx_antenna']) self.sdr.setAntenna(SOAPY_SDR_TX, settings['tx_channel'], settings['tx_antenna']) for g in self.sdr.listGains(SOAPY_SDR_RX, settings['rx_channel']): print( 'RX gain range:', g, self.sdr.getGainRange(SOAPY_SDR_RX, settings['rx_channel'], g)) for g in self.sdr.listGains(SOAPY_SDR_TX, settings['tx_channel']): print( 'TX gain range:', g, self.sdr.getGainRange(SOAPY_SDR_TX, settings['tx_channel'], g)) # In gain settings, use the combined gain if a single-element tuple. # If there are two, the first element is the name of the gain and the second is the value. self.sdr.setGain(SOAPY_SDR_RX, 0, 'LNA', 0.0) for g in settings['rx_gains']: self.sdr.setGain(SOAPY_SDR_RX, settings['rx_channel'], *g) for g in settings['tx_gains']: self.sdr.setGain(SOAPY_SDR_TX, settings['tx_channel'], *g) self.rxstream = self.sdr.setupStream(SOAPY_SDR_RX, SOAPY_SDR_CF32) self.txstream = self.sdr.setupStream(SOAPY_SDR_TX, SOAPY_SDR_CF32)
def Init_CollectSDRInstantNeeded(self, clockRate=80e6): self.sdrs = {} self.odered_serials = [] self.clockRate = clockRate # first collect what sdr has been included (it's possible that some only use one antenna) for ele in self.rx_serials_ant + self.tx_serials_ant: serial = Format_SplitSerialAnt(ele)[0] self.sdrs[serial] = None if serial not in self.odered_serials: self.odered_serials.append(serial) # then create SoapySDR objects for these serial numbers, as they are now all 'None' object for serial in self.sdrs: sdr = SoapySDR.Device(dict(driver="iris", serial=serial)) self.sdrs[serial] = sdr if clockRate is not None: sdr.setMasterClockRate(clockRate) # set master clock
def __init__(self,verbose=0): self.verbose = verbose SDR_ARGS = {'driver': 'lime'} self.sdr = SoapySDR.Device(SDR_ARGS) self._tdd = False self.fRef = 0 if self.sdr.__str__()=="FT601:LimeSDR-Mini": self.boardName = "LimeSDRMini" elif self.sdr.__str__()=="FX3:LimeSDR-USB": self.boardName = "LimeSDR" else: raise ValueError("Unsupported board : "+boardName) self.LMS7002 = LMS7002(SPIwriteFn=Proxy(self.LMS7002_Write), SPIreadFn=Proxy(self.LMS7002_Read) , verbose=verbose, MCUProgram=Proxy(self.MCUProgram), fRef = self.fRef) self.channel = 0 self.previousBand = [None,None]
def main(args, semaphore): # Create an SDR device instance try: sdr = SoapySDR.Device(dict(driver="lime")) except: sys.stderr.write("Failed to create an SDR device instance.\n") return False if not sdr: sys.stderr.write("Could not find any SDR devices.\n") return False # Setup the Tx channel 0 sdr.setSampleRate(SoapySDR.SOAPY_SDR_TX, 0, SAMPLE_RATE) sdr.setBandwidth(SoapySDR.SOAPY_SDR_TX, 0, args.bandwidth) sdr.setAntenna(SoapySDR.SOAPY_SDR_TX, 0, args.tx_antenna) sdr.setGain(SoapySDR.SOAPY_SDR_TX, 0, "PAD", args.tx_gain) sdr.setFrequency(SoapySDR.SOAPY_SDR_TX, 0, args.rf) # Setup the Rx channel 0 sdr.setSampleRate(SoapySDR.SOAPY_SDR_RX, 0, SAMPLE_RATE) sdr.setBandwidth(SoapySDR.SOAPY_SDR_RX, 0, args.bandwidth) sdr.setAntenna(SoapySDR.SOAPY_SDR_RX, 0, args.rx_antenna) sdr.setGain(SoapySDR.SOAPY_SDR_RX, 0, "LNA", args.rx_gain) sdr.setFrequency(SoapySDR.SOAPY_SDR_RX, 0, args.rf) # Initialize an SDR interface iface = SdrInterface(sdr, args.my_address) # Initialize a new connection conn = iface.newConnection(args.remote_address) if not conn: return False while True: with semaphore: global messages if messages: msg = messages.pop(0) msg = msg.strip() print("Sending: {}".format(msg)) conn.send(bytes(msg, "utf8")) ret = iface.recv() if ret: print("Received: {}".format(ret["payload"])) return True
def __init__(self, soapy_device_data=soapy1, channels=[0], rate=1024 * 1024 * 2): self.soapy = SoapySDR.Device(soapy_device_data) self.channels = channels for channel in channels: self.soapy.setSampleRate(SOAPY_SDR_RX, channel, rate) # self.soapy.setGain(SOAPY_SDR_RX, channel, gain) # self.soapy.setBandwidth(SOAPY_SDR_RX, channel, bw) ## self.soapy.setFrequency(SOAPY_SDR_RX, channel, frequency) self.rate = self.soapy.getSampleRate(SOAPY_SDR_RX, 0) self.stream = self.soapy.setupStream(SOAPY_SDR_RX, SOAPY_SDR_CF32, channels) mtu = self.soapy.getStreamMTU(self.stream) self.buf = np.array([[0] * mtu] * len(channels), np.complex64) # np.complex64 is 2 floats self.tuner = Tuner(self)
def __init__(self, width, height): """Create main FreqShow application model. Must provide the width and height of the screen in pixels. """ # Set properties that will be used by views. self.width = width self.height = height # Initialize auto scaling both min and max intensity (Y axis of plots). self.min_auto_scale = True self.max_auto_scale = True self.set_min_intensity(-10) self.set_max_intensity(50) # Initialize RTL-SDR library. self.sdr = SoapySDR.Device(dict(driver="rtlsdr")) self.rxstream = self.sdr.setupStream(SOAPY_SDR_RX, SOAPY_SDR_CF32) self.sdr.activateStream(self.rxstream) self.set_freq_correction( 0 ) # (58ppm for unenhanced)can run test to determine this value, via regular antenna, not IF frequency! self.set_swap_iq(True) self.set_sample_rate( .230 ) # in MHz, must be within (.225001 <= sample_rate_mhz <= .300000) OR (.900001 <= sample_rate_mhz <= 3.200000) self.set_decimate(1) self.set_zoom_fac( .05 ) # equal to the frequency span you want to display on the screen in MHz self.set_lo_offset( 0.03 ) # Local Oscillator offset in MHz, slide the DC spike out of the window by this amount. self.set_center_freq(70.451500) self.set_gain('AUTO') self.set_fft_ave(3) self.set_tune_rate(.001) # in MHz self.set_sig_strength(0.00) self.set_kaiser_beta(8.6) self.set_peak(True) # Set true for peaks, set False for averaging. self.set_filter('nuttall') # set default windowing filter. self.target_time = 0
def setDevice(self, device): device = toDevice(device) print("[DEMOD] Activating {} device.".format(device["label"])) self.sdr = SoapySDR.Device(device) self.sdr.setGainMode(SOAPY_SDR_RX, 0, True) self.sdr.setFrequency(SOAPY_SDR_RX, 0, self.freq) supported_fs = self.sdr.getSampleRateRange(SOAPY_SDR_RX, 0) avfs = [ [240e3, 256e3, 1.024e6, 2.5e6, 3.0e6], [960e3, 480e3, 240e3, 256e3, 768e3, 1.024e6, 2.5e6, 3.0e6], ] self.sfs = int(768e3) self.mfs = int(240e3) self.afs = int(48e3) for fs in reversed(supported_fs): for pfs in avfs[self.pmode]: if pfs >= fs.minimum() and pfs <= fs.maximum(): self.sfs = int(pfs) break print("[DEMOD] Sampling Rate: {}".format(self.sfs)) self.sdr_buff = 1024 self.dsp_buff = self.sdr_buff * 8 self.dec_out = int(np.ceil(self.dsp_buff / (self.sfs / self.mfs))) self.dsp_out = int(np.ceil(self.dec_out / (self.mfs / self.afs))) print(self.sdr_buff / self.sfs) self.dec = Decimator(self.sfs, self.mfs, self.dec_out, cuda=self.cuda) self.wbfm = WBFM(self.tau, self.mfs, self.afs, self.dec_out, cuda=self.cuda, numba=self.numba) self.sdr.setSampleRate(SOAPY_SDR_RX, 0, self.sfs) self.device = str(device)