#!/usr/bin/python from __future__ import print_function from __future__ import absolute_import from __future__ import division ################################################## # AFEDRI Class module # Title: afedri.py # Author: k3it # Adopted to work with Quisk # by 4Z5LV # Last Changes: Sat Feb 02 2013 # Version: 2.2 # Adapted to work with Python3 # by N2ADR # Last Changes: January 2020 ################################################## from socket import * import wave import sys import struct import time import datetime import string import math class afedri(object): """ class definition for the Afedri SDR-NET """ def __init__(self,sdr_address="0.0.0.0", sdr_port=50000): if sdr_address == "0.0.0.0": __sdr_address,self.sdr_port = self.__discover_afedri() if __sdr_address is None: self.s = None return else: __sdr_address = sdr_address self.sdr_port = sdr_port self.s = socket(AF_INET, SOCK_STREAM) self.s.settimeout(2) try: self.s.connect((__sdr_address,self.sdr_port)) #print ("Established control connection with AFEDRI") except: print ("Error connecting to SDR") ##sys.exit() self.s.close() self.s = None def close(self): if self.s: self.s.close() self.s = None def set_center_freq(self,target_freq): if not self.s: return 1 __next_freq = target_freq __next_freq = struct.pack(">3) return __rf_gain def set_gain_indx(self,indx): if not self.s: return 1 __gain = (indx << 3) + 1 # special afedri calculation for the gain byte #__gain = ((__gain+10)/3 << 3) + 1 __set_gain_cmd = b"\x06\x00\x38\x00\x00" + struct.pack("B",__gain) self.s.send(__set_gain_cmd) __data = self.s.recv(6) __rf_gain = -10 + 3 * (struct.unpack("B",__data[5:6])[0]>>3) return __rf_gain def get_gain(self): """ NOT IMPLEMENTED IN AFEDRI?. DON'T USE """ if not self.s: return 1 __get_gain_cmd = b"\x05\x20\x38\x00\x00" self.s.send(__get_gain_cmd) __data = self.s.recv(6) __rf_gain = -10 + 3 * (struct.unpack("B",__data[5:])[0]>>3) return __rf_gain def get_fe_clock(self): if not self.s: return 1 __get_lword_cmd = b"\x09\xE0\x02\x55\x00\x00\x00\x00\x00" __get_hword_cmd = b"\x09\xE0\x02\x55\x01\x00\x00\x00\x00" self.s.send(__get_lword_cmd) __data_l = self.s.recv(9) self.s.send(__get_hword_cmd) __data_h = self.s.recv(9) __fe_clock = struct.unpack("',__DISCOVER_SERVER_PORT)) try: __msg=self.sin.recv(256,0) __devname=__msg[5:20] __devname=__devname.decode('utf-8') __sn=__msg[21:36] __sn=__sn.decode('utf-8') __ip=inet_ntoa(__msg[40:36:-1]) __port=struct.unpack("= 0.5): floor_div += 1 if floor_div < 15: floor_div = 15 #print ("Warning: Max supported sampling rate is", math.floor(fe_main_clock_freq / (4 * floor_div))) elif floor_div > 625: floor_div = 625 #print ("Warning: Min supported sampling rate is", math.floor(fe_main_clock_freq / (4 * floor_div))) dSR = fe_main_clock_freq / (4 * floor_div) floor_SR = math.floor(dSR) if (dSR - floor_SR >= 0.5): floor_SR += 1 if floor_SR != samp_rate: print ("Warning: invalid sample rate selected for the AFEDRI main clock (", fe_main_clock_freq, "Hz )") print (" setting to the next valid value", samp_rate, " => ", floor_SR) samp_rate = floor_SR """