# This is the hardware file for the FiFiSDR radio. Thanks to Joe, LA6GRA. #import sys, struct, time, traceback, math import struct, traceback from softrock import hardware_usb as SoftRock GET_FIFI_EXTRA = 0xAB SET_FIFI_EXTRA = 0xAC EXTRA_READ_SVN_VERSION = 0 EXTRA_READ_FW_VERSION = 1 EXTRA_WRITE_PREAMP = 19 EXTRA_READ_PREAMP = 19 try: import usb import usb.core, usb.util except: if sys.platform == 'win32': dlg = wx.MessageDialog(None, "The Python pyusb module is required but not installed. Do you want me to install it?", "Install Python pyusb", style = wx.YES|wx.NO) if dlg.ShowModal() == wx.ID_YES: import subprocess subprocess.call([sys.executable, "-m", "pip", "install", "pyusb"]) try: import usb import usb.core, usb.util except: dlg = wx.MessageDialog(None, "Installation of Python pyusb failed. Please install it by hand.", "Installation failed", style=wx.OK) dlg.ShowModal() else: dlg = wx.MessageDialog(None, "The Python pyusb module is required but not installed. Please install package python-usb.", "Install Python pyusb", style = wx.OK) dlg.ShowModal() DEBUG = 1 IN = usb.util.build_request_type(usb.util.CTRL_IN, usb.util.CTRL_TYPE_VENDOR, usb.util.CTRL_RECIPIENT_DEVICE) OUT = usb.util.build_request_type(usb.util.CTRL_OUT, usb.util.CTRL_TYPE_VENDOR, usb.util.CTRL_RECIPIENT_DEVICE) UBYTE2 = struct.Struct(' 50: sound = sound[0:30] + '|||' + sound[-17:] if DEBUG: print("Sound = %s" % (sound)) try: #res = self.handle.controlMsg(requestType = DEVICE2HOST, #request = GET_FIFI_EXTRA, #buffer = 4, #value=0, #index=EXTRA_READ_SVN_VERSION, #timeout=100) res = self.usb_dev.ctrl_transfer(IN, GET_FIFI_EXTRA, 0, EXTRA_READ_SVN_VERSION, 4) except: if DEBUG: traceback.print_exc() svn = (((((res[3]<<8) + res[2])<<8) + res[1])<<8) + res[0] if DEBUG: print ("FiFi_SVN = %d" % svn) try: res = self.usb_dev.ctrl_transfer(IN, GET_FIFI_EXTRA, 0, EXTRA_READ_FW_VERSION, 20) except: if DEBUG: traceback.print_exc() fifi_ver = res if DEBUG: print ("FiFi_ver = %s" % res) #fifi_ver_str = ''.join([chr(i) for i in res]) # får ikkje med null terminering fifi_ver_str = '' for i in fifi_ver: if not i: break fifi_ver_str += chr(i) print ("FiFi_ver = %s" % fifi_ver_str) #text = 'Capture from SoftRock USB on %s, Firmware %s' % (sound, ver) text = "Capture from FiFi-SDR USB (%d, %s), on %s, (SR ver. %s)" % (svn, fifi_ver_str, sound, ver) if DEBUG: print ('Quisk_title_line = "%s"' % text) #self.application.bottom_widgets.info_text.SetLabel(text) if DEBUG and usb_dev: print ('Startup freq', self.GetStartupFreq()) print ('Run freq', self.GetFreq()) print ('Address 0x%X' % usb_dev.ctrl_transfer(IN, 0x41, 0, 0, 1)[0]) sm = usb_dev.ctrl_transfer(IN, 0x3B, 0, 0, 2) sm = UBYTE2.unpack(sm)[0] print ('Smooth tune', sm) return text def OnButtonRfGain(self, event): btn = event.GetEventObject() value = btn.index # value == 0: -6dB # value == 1: 0dB msg = bytearray() msg.append(value) self.usb_dev.ctrl_transfer(OUT, SET_FIFI_EXTRA, self.si570_i2c_address + 0x700, EXTRA_WRITE_PREAMP, msg)