def __init__(self, config): self.description = "devices module" self.settings = {} self.thread_timeout = 3 gammarf_util.console_message("Loaded {}".format(self.description)) devs = OrderedDict() devidx = 0 hackrf = pylibhackrf.HackRf() r = hackrf.setup() if r != pylibhackrf.HackRfError.HACKRF_SUCCESS: self.have_hackrf = False gammarf_util.console_message("no hackrf found", MOD_NAME) else: self.have_hackrf = True hackrf.set_amp_enable(False) hrfdev = HackRfDev() hrfdev.devid = HACKRF_DEVNUM hrfdev.name = "{} HackRF".format(hrfdev.devid, hrfdev.devid) hrfdev.job = "Virtual Provider" if 'hackrfdevs' in config: if 'lna_gain' in config['hackrfdevs']: hrfdev.lna_gain = int(config['hackrfdevs']['lna_gain']) if 'vga_gain' in config['hackrfdevs']: hrfdev.vga_gain = int(config['hackrfdevs']['vga_gain']) if 'minfreq' in config['hackrfdevs']: hrfdev.minfreq = int(config['hackrfdevs']['minfreq']) if 'maxfreq' in config['hackrfdevs']: hrfdev.maxfreq = int(config['hackrfdevs']['maxfreq']) if 'step' in config['hackrfdevs']: hrfdev.step = int(config['hackrfdevs']['step']) devs[HACKRF_DEVNUM] = hrfdev devidx += 1 hackrf.close() rtlsdr_devcount = rtlsdr.librtlsdr.rtlsdr_get_device_count() if not rtlsdr_devcount and not hackrf: gammarf_util.console_message("found no usable devices", MOD_NAME) exit() for rtl_devid in range(rtlsdr_devcount): rtldev = RtlSdrDev() rtldev.devid = rtl_devid buffer1 = (c_ubyte * 256)() buffer2 = (c_ubyte * 256)() serial = (c_ubyte * 256)() rtlsdr.librtlsdr.rtlsdr_get_device_usb_strings( rtl_devid, buffer1, buffer2, serial) serial = string_at(serial) tmp = rtlsdr.librtlsdr.rtlsdr_get_device_name(rtl_devid) devname = "{} {} {}".format(devidx, tmp.decode('utf-8'), serial.decode('utf-8')) rtldev.name = devname rtldev.serial = serial gammarf_util.console_message(devname, MOD_NAME) if 'rtldevs' in config: try: frangestr = config['rtldevs']['range_{}'.format( serial.decode('utf-8'))] except KeyError: pass else: try: minfreq, maxfreq = frangestr.split(None, 2) minfreq = int(float(minfreq) * 1e6) maxfreq = int(float(maxfreq) * 1e6) except Exception as e: raise Exception( "Invalid frequency range string: {}: {}".format( frangestr, e)) rtldev.minfreq = minfreq rtldev.maxfreq = maxfreq if rtldev.minfreq >= rtldev.maxfreq: raise Exception("Maximum devicefreq must be larger than "\ "minimum device freq") try: stickgain = config['rtldevs']['gain_{}'.format( serial.decode('utf-8'))] except KeyError: pass else: rtldev.gain = float(stickgain) try: stickppm = config['rtldevs']['ppm_{}'.format( serial.decode('utf-8'))] except KeyError: pass else: rtldev.ppm = int(stickppm) try: stickoffset = config['rtldevs']['offset_{}'.format( serial.decode('utf-8'))] except KeyError: pass else: rtldev.offset = int(stickoffset) devs[devidx] = rtldev devidx += 1 self.devs = devs self.numdevs = devidx
import pylibhackrf, ctypes import queue import time import numpy import math import sys import pyaudio import threading import pyaudio2iq hackrf = pylibhackrf.HackRf() a2iq = pyaudio2iq.audio2iq() DACfreq = int(2.56e6) if hackrf.is_open == False: hackrf.setup() if (len(sys.argv) >= 2): hackrf.set_freq(int(float(sys.argv[1]))) else: hackrf.set_freq(int(99.4e6)) hackrf.set_sample_rate(DACfreq) hackrf.set_amp_enable(False) hackrf.set_lna_gain(40) hackrf.set_vga_gain(62) hackrf.set_txvga_gain(47) count = 0 def callback_fun(hackrf_transfer): global count, times, q, a2iq, delta