1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2025-05-29 21:42:26 -04:00

REST API Python examples: source formatting and exception Python3 compatibility

This commit is contained in:
f4exb 2018-09-09 19:52:27 +02:00
parent 7e97f62615
commit 5dfc60331c
12 changed files with 347 additions and 305 deletions

View File

@ -5,6 +5,7 @@ from optparse import OptionParser
base_url = "http://127.0.0.1:8091/sdrangel"
# ======================================================================
def getInputOptions():
@ -43,7 +44,7 @@ def main():
print("Error adding channel. HTTP: %d" % r.status_code)
print json.dumps(r.json(), indent=4, sort_keys=True)
except Exception, msg:
except Exception as ex:
tb = traceback.format_exc()
print >> sys.stderr, tb

View File

@ -73,7 +73,7 @@ def main():
print("All done!")
except Exception, msg:
except Exception as ex:
tb = traceback.format_exc()
print >> sys.stderr, tb

View File

@ -13,6 +13,7 @@ requests_methods = {
"DELETE": requests.delete
}
# ======================================================================
def getInputOptions():
@ -30,6 +31,7 @@ def getInputOptions():
return options
# ======================================================================
def printResponse(response):
content_type = response.headers.get("Content-Type", None)
@ -39,11 +41,12 @@ def printResponse(response):
elif "text/plain" in content_type:
print(response.text)
# ======================================================================
def callAPI(url, method, params, json, text):
request_method = requests_methods.get(method, None)
if request_method is not None:
r = request_method(url=base_url+url, params=params, json=json)
r = request_method(url=base_url + url, params=params, json=json)
if r.status_code / 100 == 2:
print(text + " succeeded")
printResponse(r)
@ -53,6 +56,7 @@ def callAPI(url, method, params, json, text):
printResponse(r)
return None
# ======================================================================
def main():
try:
@ -109,7 +113,7 @@ def main():
if r is None:
exit(-1)
except Exception, msg:
except Exception as ex:
tb = traceback.format_exc()
print >> sys.stderr, tb

View File

@ -13,6 +13,7 @@ requests_methods = {
"DELETE": requests.delete
}
# ======================================================================
def getInputOptions():
@ -26,6 +27,7 @@ def getInputOptions():
return options
# ======================================================================
def printResponse(response):
content_type = response.headers.get("Content-Type", None)
@ -35,11 +37,12 @@ def printResponse(response):
elif "text/plain" in content_type:
print(response.text)
# ======================================================================
def callAPI(url, method, params, json, text):
request_method = requests_methods.get(method, None)
if request_method is not None:
r = request_method(url=base_url+url, params=params, json=json)
r = request_method(url=base_url + url, params=params, json=json)
if r.status_code / 100 == 2:
print(text + " succeeded")
printResponse(r)
@ -49,6 +52,7 @@ def callAPI(url, method, params, json, text):
printResponse(r)
return None
# ======================================================================
def main():
try:
@ -86,7 +90,7 @@ def main():
if r is None:
exit(-1)
except Exception, msg:
except Exception as ex:
tb = traceback.format_exc()
print >> sys.stderr, tb

View File

@ -16,6 +16,7 @@ from optparse import OptionParser
base_url = "http://127.0.0.1:8091/sdrangel"
# ======================================================================
def getInputOptions():
@ -34,9 +35,10 @@ def getInputOptions():
return options
# ======================================================================
def startDevice(deviceIndex):
dev_run_url = base_url+("/deviceset/%d/device/run" % deviceIndex)
dev_run_url = base_url + ("/deviceset/%d/device/run" % deviceIndex)
r = requests.get(url=dev_run_url)
if r.status_code / 100 == 2:
rj = r.json()
@ -55,9 +57,10 @@ def startDevice(deviceIndex):
else:
print("Error getting device %d running state" % deviceIndex)
# ======================================================================
def stopDevice(deviceIndex):
dev_run_url = base_url+("/deviceset/%d/device/run" % deviceIndex)
dev_run_url = base_url + ("/deviceset/%d/device/run" % deviceIndex)
r = requests.get(url=dev_run_url)
if r.status_code / 100 == 2:
rj = r.json()
@ -76,9 +79,10 @@ def stopDevice(deviceIndex):
else:
print("Error getting device %d running state" % deviceIndex)
# ======================================================================
def setFocus(deviceIndex):
dev_focus_url = base_url+("/deviceset/%d/focus" % deviceIndex)
dev_focus_url = base_url + ("/deviceset/%d/focus" % deviceIndex)
r = requests.patch(url=dev_focus_url)
if r.status_code / 100 == 2:
print("Focus set on device set %d" % deviceIndex)
@ -87,34 +91,35 @@ def setFocus(deviceIndex):
else:
print("Error setting focus on device set %d" % deviceIndex)
# ======================================================================
def main():
try:
options = getInputOptions()
global base_url
base_url = "http://%s/sdrangel" % options.address
r = requests.get(url=base_url+"/devicesets")
r = requests.get(url=base_url + "/devicesets")
if r.status_code / 100 == 2:
rj = r.json()
deviceSets = rj.get("deviceSets", None)
if deviceSets is not None:
if len(deviceSets) > 1:
if options.transmit:
if deviceSets[options.deviceset_index]["samplingDevice"]["tx"] == 0 and deviceSets[options.deviceset_index+1]["samplingDevice"]["tx"] == 1:
if deviceSets[options.deviceset_index]["samplingDevice"]["tx"] == 0 and deviceSets[options.deviceset_index + 1]["samplingDevice"]["tx"] == 1:
stopDevice(options.deviceset_index)
time.sleep(1)
startDevice(options.deviceset_index+1)
setFocus(options.deviceset_index+1)
startDevice(options.deviceset_index + 1)
setFocus(options.deviceset_index + 1)
else:
print("Incorrect configuration expecting Rx%d and Tx%d" % (options.deviceset_index, options.deviceset_index+1))
print("Incorrect configuration expecting Rx%d and Tx%d" % (options.deviceset_index, options.deviceset_index + 1))
else:
if deviceSets[options.deviceset_index-1]["samplingDevice"]["tx"] == 0 and deviceSets[options.deviceset_index]["samplingDevice"]["tx"] == 1:
if deviceSets[options.deviceset_index - 1]["samplingDevice"]["tx"] == 0 and deviceSets[options.deviceset_index]["samplingDevice"]["tx"] == 1:
stopDevice(options.deviceset_index)
time.sleep(1)
startDevice(options.deviceset_index-1)
setFocus(options.deviceset_index-1)
startDevice(options.deviceset_index - 1)
setFocus(options.deviceset_index - 1)
else:
print("Incorrect configuration expecting Rx%d and Tx%d" % (options.deviceset_index-1, options.deviceset_index))
print("Incorrect configuration expecting Rx%d and Tx%d" % (options.deviceset_index - 1, options.deviceset_index))
else:
print("Need at least a Rx and a Tx device set")
else:
@ -122,7 +127,7 @@ def main():
else:
print("Error getting device sets configuration")
except Exception, msg:
except Exception as ex:
tb = traceback.format_exc()
print >> sys.stderr, tb

View File

@ -11,28 +11,31 @@ requests_methods = {
"DELETE": requests.delete
}
def getHwType():
r = requests.get(url=base_url+"/deviceset/0")
r = requests.get(url=base_url + "/deviceset/0")
if r.status_code / 100 == 2:
rj = r.json()
devj = rj.get('samplingDevice', None)
if devj is not None:
return devj.get('hwType' ,None)
return devj.get('hwType' , None)
else:
return None
else:
return None
def selectRtlSdr():
r = requests.put(url=base_url+"/deviceset/0/device", json={"hwType": "RTLSDR"})
r = requests.put(url=base_url + "/deviceset/0/device", json={"hwType": "RTLSDR"})
if r.status_code / 100 == 2:
print json.dumps(r.json(), indent=4, sort_keys=True)
return True
else:
return False
def getRtlSdrSettings():
r = requests.get(url=base_url+"/deviceset/0/device/settings")
r = requests.get(url=base_url + "/deviceset/0/device/settings")
if r.status_code / 100 == 2:
rj = r.json()
hwType = rj.get('deviceHwType', None)
@ -44,19 +47,21 @@ def getRtlSdrSettings():
else:
return None
def patchRtlSdrSettings(settings):
new_settings = {"deviceHwType": "RTLSDR", "tx": 0, "rtlSdrSettings": settings}
r = requests.patch(url=base_url+"/deviceset/0/device/settings", json=new_settings)
r = requests.patch(url=base_url + "/deviceset/0/device/settings", json=new_settings)
if r.status_code / 100 == 2:
print json.dumps(r.json(), indent=4, sort_keys=True)
else:
print "Error HTTP:", r.status_code
def deviceRun(run):
if run:
r = requests.post(url=base_url+"/deviceset/0/device/run")
r = requests.post(url=base_url + "/deviceset/0/device/run")
else:
r = requests.delete(url=base_url+"/deviceset/0/device/run")
r = requests.delete(url=base_url + "/deviceset/0/device/run")
if r.status_code / 100 == 2:
print json.dumps(r.json(), indent=4, sort_keys=True)
else:
@ -83,4 +88,3 @@ def main():
if __name__ == "__main__":
main()

View File

@ -358,10 +358,7 @@ def main():
time.sleep(1)
setup_audio(options)
# if options.channel_id == "BFMDemod":
# channelsReport(deviceset_url)
except Exception, msg:
except Exception as ex:
tb = traceback.format_exc()
print >> sys.stderr, tb

View File

@ -13,6 +13,7 @@ requests_methods = {
"DELETE": requests.delete
}
# ======================================================================
def getInputOptions():
@ -59,6 +60,7 @@ def getInputOptions():
return options
# ======================================================================
def printResponse(response):
content_type = response.headers.get("Content-Type", None)
@ -68,11 +70,12 @@ def printResponse(response):
elif "text/plain" in content_type:
print(response.text)
# ======================================================================
def callAPI(url, method, params, json, text):
request_method = requests_methods.get(method, None)
if request_method is not None:
r = request_method(url=base_url+url, params=params, json=json)
r = request_method(url=base_url + url, params=params, json=json)
if r.status_code / 100 == 2:
print(text + " succeeded")
printResponse(r)
@ -82,6 +85,7 @@ def callAPI(url, method, params, json, text):
printResponse(r)
return None
# ======================================================================
def main():
try:
@ -101,7 +105,7 @@ def main():
if r1 is None:
exit(-1)
### Rx setup
# ## Rx setup
deviceset_index_rx = 0
deviceset_url = "/deviceset/%d" % deviceset_index_rx
@ -116,10 +120,10 @@ def main():
if options.device_hwid_rx == "LimeSDR":
settings["limeSdrInputSettings"]["antennaPath"] = options.antenna_path_rx
settings["limeSdrInputSettings"]["devSampleRate"] = options.sample_rate_rx*1000
settings["limeSdrInputSettings"]["devSampleRate"] = options.sample_rate_rx * 1000
settings["limeSdrInputSettings"]["log2HardDecim"] = 4
settings["limeSdrInputSettings"]["log2SoftDecim"] = 3
settings["limeSdrInputSettings"]["centerFrequency"] = options.device_freq*1000 + 500000
settings["limeSdrInputSettings"]["centerFrequency"] = options.device_freq * 1000 + 500000
settings["limeSdrInputSettings"]["ncoEnable"] = 1
settings["limeSdrInputSettings"]["ncoFrequency"] = -500000
settings["limeSdrInputSettings"]["lpfBW"] = 1450000
@ -127,17 +131,17 @@ def main():
settings["limeSdrInputSettings"]["lpfFIREnable"] = 1
settings['limeSdrInputSettings']['dcBlock'] = 1
elif options.device_hwid_rx == "RTLSDR":
settings['rtlSdrSettings']['devSampleRate'] = options.sample_rate_rx*1000
settings['rtlSdrSettings']['centerFrequency'] = options.device_freq*1000
settings['rtlSdrSettings']['devSampleRate'] = options.sample_rate_rx * 1000
settings['rtlSdrSettings']['centerFrequency'] = options.device_freq * 1000
settings['rtlSdrSettings']['gain'] = 496
settings['rtlSdrSettings']['log2Decim'] = 4
settings['rtlSdrSettings']['dcBlock'] = 1
settings['rtlSdrSettings']['agc'] = 1
elif options.device_hwid_rx == "HackRF":
settings['hackRFInputSettings']['LOppmTenths'] = -51
settings['hackRFInputSettings']['centerFrequency'] = options.device_freq*1000
settings['hackRFInputSettings']['centerFrequency'] = options.device_freq * 1000
settings['hackRFInputSettings']['dcBlock'] = 1
settings['hackRFInputSettings']['devSampleRate'] = options.sample_rate_rx*1000
settings['hackRFInputSettings']['devSampleRate'] = options.sample_rate_rx * 1000
settings['hackRFInputSettings']['lnaExt'] = 1
settings['hackRFInputSettings']['lnaGain'] = 32
settings['hackRFInputSettings']['log2Decim'] = 4
@ -179,7 +183,7 @@ def main():
if r is None:
exit(-1)
### Tx setup
# ## Tx setup
r = callAPI("/deviceset", "POST", {"tx": 1}, None, "Add Tx device set")
if r is None:
@ -197,10 +201,10 @@ def main():
if options.device_hwid_tx == "LimeSDR":
settings["limeSdrOutputSettings"]["antennaPath"] = options.antenna_path_tx
settings["limeSdrOutputSettings"]["devSampleRate"] = options.sample_rate_tx*1000
settings["limeSdrOutputSettings"]["devSampleRate"] = options.sample_rate_tx * 1000
settings["limeSdrOutputSettings"]["log2HardInterp"] = 4
settings["limeSdrOutputSettings"]["log2SoftInterp"] = 4
settings["limeSdrOutputSettings"]["centerFrequency"] = options.device_freq*1000 + 500000
settings["limeSdrOutputSettings"]["centerFrequency"] = options.device_freq * 1000 + 500000
settings["limeSdrOutputSettings"]["ncoEnable"] = 1
settings["limeSdrOutputSettings"]["ncoFrequency"] = -500000
settings["limeSdrOutputSettings"]["lpfBW"] = 4050000
@ -208,8 +212,8 @@ def main():
settings["limeSdrOutputSettings"]["lpfFIREnable"] = 1
elif options.device_hwid_tx == "HackRF":
settings['hackRFOutputSettings']['LOppmTenths'] = -51
settings['hackRFOutputSettings']['centerFrequency'] = options.device_freq*1000
settings['hackRFOutputSettings']['devSampleRate'] = options.sample_rate_tx*1000
settings['hackRFOutputSettings']['centerFrequency'] = options.device_freq * 1000
settings['hackRFOutputSettings']['devSampleRate'] = options.sample_rate_tx * 1000
settings['hackRFOutputSettings']['lnaExt'] = 0
settings['hackRFOutputSettings']['log2Interp'] = 4
settings['hackRFOutputSettings']['vgaGain'] = 24
@ -244,8 +248,7 @@ def main():
if r is None:
exit(-1)
except Exception, msg:
except Exception as ex:
tb = traceback.format_exc()
print >> sys.stderr, tb

View File

@ -28,20 +28,23 @@ requests_methods = {
"DELETE": requests.delete
}
# ======================================================================
class ScanControl:
def __init__(self, num_channels, channel_step, start_freq, stop_freq, log2_decim):
self.channel_shifts = []
if num_channels < 2:
self.channel_shifts = [0]
limit = 0
else:
limit = ((num_channels-1)*channel_step) / 2
limit = ((num_channels - 1) * channel_step) / 2
self.channel_shifts = list(np.linspace(-limit, limit, num_channels))
self.device_start_freq = start_freq + limit
self.device_stop_freq = stop_freq - limit
self.device_step_freq = 2*limit + channel_step
self.device_sample_rate = (2*limit + channel_step)*(1<<log2_decim)
self.device_step_freq = 2 * limit + channel_step
self.device_sample_rate = (2 * limit + channel_step) * (1 << log2_decim)
# ======================================================================
def getInputOptions():
@ -56,7 +59,7 @@ def getInputOptions():
parser.add_option("-s", "--freq-step", dest="freq_step", help="frequency step (Hz)", metavar="FREQUENCY", type="float", default=12500)
parser.add_option("-S", "--freq-start", dest="freq_start", help="frequency start (Hz)", metavar="FREQUENCY", type="int", default=446006250)
parser.add_option("-T", "--freq-stop", dest="freq_stop", help="frequency stop (Hz)", metavar="FREQUENCY", type="int", default=446193750)
parser.add_option("-b", "--af-bw", dest="af_bw", help="audio babdwidth (kHz)", metavar="FREQUENCY_KHZ", type="int" ,default=3)
parser.add_option("-b", "--af-bw", dest="af_bw", help="audio babdwidth (kHz)", metavar="FREQUENCY_KHZ", type="int" , default=3)
parser.add_option("-r", "--rf-bw", dest="rf_bw", help="RF babdwidth (Hz). Sets to nearest available", metavar="FREQUENCY", type="int", default=10000)
parser.add_option("--vol", dest="volume", help="audio volume", metavar="VOLUME", type="float", default=1.0)
parser.add_option("-c", "--create", dest="create", help="create a new device set", metavar="BOOLEAN", action="store_true", default=False)
@ -71,8 +74,8 @@ def getInputOptions():
parser.add_option("--re-run", dest="rerun", help="re run with given parameters without setting up device and channels", metavar="BOOLEAN", action="store_true", default=False)
parser.add_option("-x", "--excl-list", dest="excl_fstr", help="frequencies (in Hz) exclusion comma separated list", metavar="LIST", type="string")
parser.add_option("--excl-tol", dest="excl_tol", help="match tolerance interval (in Hz) for exclusion frequencies", metavar="FREQUENCY", type="float", default=10.0)
parser.add_option("-v", "--verbosity", dest="verbosity", help="verbosity level", metavar="LEVEL_INT", type="int", default = 0)
parser.add_option("-L", "--delay", dest="delay", help="delay in number of settling time periods before resuming scan", metavar="NUMBER", type="int", default = 5)
parser.add_option("-v", "--verbosity", dest="verbosity", help="verbosity level", metavar="LEVEL_INT", type="int", default=0)
parser.add_option("-L", "--delay", dest="delay", help="delay in number of settling time periods before resuming scan", metavar="NUMBER", type="int", default=5)
(options, args) = parser.parse_args()
@ -82,7 +85,7 @@ def getInputOptions():
if options.excl_fstr is not None:
excl_flist_str = options.excl_fstr.split(',')
try:
options.excl_flist = list(map(lambda x:round(float(x)/options.excl_tol), excl_flist_str))
options.excl_flist = list(map(lambda x:round(float(x) / options.excl_tol), excl_flist_str))
print(options.excl_flist)
except ValueError:
print("Invalid exclusion frequencies list: %s" % options.excl_fstr)
@ -95,6 +98,7 @@ def getInputOptions():
return options
# ======================================================================
def setupDevice(scan_control, options):
settings = callAPI(deviceset_url + "/device/settings", "GET", None, None, "Get device settings")
@ -149,6 +153,7 @@ def setupDevice(scan_control, options):
if r is None:
exit(-1)
# ======================================================================
def changeDeviceFrequency(fc, options):
settings = callAPI(deviceset_url + "/device/settings", "GET", None, None, "Get device settings")
@ -168,6 +173,7 @@ def changeDeviceFrequency(fc, options):
if r is None:
exit(-1)
# ======================================================================
def setupChannels(scan_control, options):
i = 0
@ -212,6 +218,7 @@ def setupChannels(scan_control, options):
i += 1
# ======================================================================
def checkScanning(fc, options, display_message):
reports = callAPI(deviceset_url + "/channels/report", "GET", None, None, "Get channels report")
@ -227,14 +234,15 @@ def checkScanning(fc, options, display_message):
else:
stopCondition = channel["report"][reportKey]["squelch"] == 1
if stopCondition:
f_channel = channel["deltaFrequency"]+fc
f_frac = round(f_channel/options.excl_tol)
f_channel = channel["deltaFrequency"] + fc
f_frac = round(f_channel / options.excl_tol)
if f_frac not in options.excl_flist:
if display_message: # display message only when stopping for the first time
print("%s Stopped at %d Hz" % (datetime.datetime.now().strftime("%H:%M:%S"),f_frac*options.excl_tol))
print("%s Stopped at %d Hz" % (datetime.datetime.now().strftime("%H:%M:%S"), f_frac * options.excl_tol))
return False # stop scanning
return True # continue scanning
# ======================================================================
def printResponse(response):
content_type = response.headers.get("Content-Type", None)
@ -244,11 +252,12 @@ def printResponse(response):
elif "text/plain" in content_type:
print(response.text)
# ======================================================================
def callAPI(url, method, params, json, text):
request_method = requests_methods.get(method, None)
if request_method is not None:
r = request_method(url=base_url+url, params=params, json=json)
r = request_method(url=base_url + url, params=params, json=json)
if r.status_code / 100 == 2:
if verbosity >= 1:
print(text + " succeeded")
@ -262,6 +271,7 @@ def callAPI(url, method, params, json, text):
printResponse(r)
return None
# ======================================================================
def main():
try:
@ -284,7 +294,7 @@ def main():
nb_steps = 0
fc = scan_control.device_start_freq
while fc <= scan_control.device_stop_freq:
freqs += [x+fc for x in scan_control.channel_shifts]
freqs += [x + fc for x in scan_control.channel_shifts]
fc += scan_control.device_step_freq
nb_steps += 1
print("Scanned frequencies: %s" % freqs)
@ -361,7 +371,7 @@ def main():
except KeyboardInterrupt:
pass
except Exception, msg:
except Exception as ex:
tb = traceback.format_exc()
print >> sys.stderr, tb

View File

@ -5,6 +5,7 @@ from optparse import OptionParser
base_url = "http://127.0.0.1:8091/sdrangel"
# ======================================================================
def getInputOptions():
@ -32,9 +33,10 @@ def getInputOptions():
return options
# ======================================================================
def startDevice(deviceIndex):
dev_run_url = base_url+("/deviceset/%d/device/run" % deviceIndex)
dev_run_url = base_url + ("/deviceset/%d/device/run" % deviceIndex)
r = requests.get(url=dev_run_url)
if r.status_code / 100 == 2:
rj = r.json()
@ -53,9 +55,10 @@ def startDevice(deviceIndex):
else:
print("Error getting device %d running state" % deviceIndex)
# ======================================================================
def stopDevice(deviceIndex):
dev_run_url = base_url+("/deviceset/%d/device/run" % deviceIndex)
dev_run_url = base_url + ("/deviceset/%d/device/run" % deviceIndex)
r = requests.get(url=dev_run_url)
if r.status_code / 100 == 2:
rj = r.json()
@ -74,13 +77,14 @@ def stopDevice(deviceIndex):
else:
print("Error getting device %d running state" % deviceIndex)
# ======================================================================
def main():
try:
options = getInputOptions()
global base_url
base_url = "http://%s/sdrangel" % options.address
r = requests.get(url=base_url+"/devicesets")
r = requests.get(url=base_url + "/devicesets")
if r.status_code / 100 == 2:
rj = r.json()
deviceSets = rj.get("deviceSets", None)
@ -97,7 +101,7 @@ def main():
else:
print("Error getting device sets configuration")
except Exception, msg:
except Exception as ex:
tb = traceback.format_exc()
print >> sys.stderr, tb

View File

@ -13,6 +13,7 @@ requests_methods = {
"DELETE": requests.delete
}
# ======================================================================
def getInputOptions():
@ -26,6 +27,7 @@ def getInputOptions():
return options
# ======================================================================
def printResponse(response):
content_type = response.headers.get("Content-Type", None)
@ -35,11 +37,12 @@ def printResponse(response):
elif "text/plain" in content_type:
print(response.text)
# ======================================================================
def callAPI(url, method, params, json, text):
request_method = requests_methods.get(method, None)
if request_method is not None:
r = request_method(url=base_url+url, params=params, json=json)
r = request_method(url=base_url + url, params=params, json=json)
if r.status_code / 100 == 2:
print(text + " succeeded")
printResponse(r)
@ -49,6 +52,7 @@ def callAPI(url, method, params, json, text):
printResponse(r)
return None
# ======================================================================
def main():
try:
@ -61,7 +65,7 @@ def main():
if settings is None:
exit(-1)
except Exception, msg:
except Exception as ex:
tb = traceback.format_exc()
print >> sys.stderr, tb

View File

@ -14,6 +14,7 @@ requests_methods = {
"DELETE": requests.delete
}
# ======================================================================
def getInputOptions():
@ -64,6 +65,7 @@ def getInputOptions():
return options
# ======================================================================
def printResponse(response):
content_type = response.headers.get("Content-Type", None)
@ -73,11 +75,12 @@ def printResponse(response):
elif "text/plain" in content_type:
print(response.text)
# ======================================================================
def callAPI(url, method, params, json, text):
request_method = requests_methods.get(method, None)
if request_method is not None:
r = request_method(url=base_url+url, params=params, json=json)
r = request_method(url=base_url + url, params=params, json=json)
if r.status_code / 100 == 2:
print(text + " succeeded")
printResponse(r)
@ -87,6 +90,7 @@ def callAPI(url, method, params, json, text):
printResponse(r)
return None
# ======================================================================
def setupBladeRFXB200(fc):
if fc < 50000:
@ -104,6 +108,7 @@ def setupBladeRFXB200(fc):
else:
return 5 # BLADERF_XB200_AUTO_3DB
# ======================================================================
def setupDevice(options):
settings = callAPI(deviceset_url + "/device/settings", "GET", None, None, "Get device settings")
@ -111,15 +116,15 @@ def setupDevice(options):
exit(-1)
# calculate RF analog and FIR optimal bandpass filters bandwidths
lpFIRBW = options.sample_rate / (1<<options.log2_interp)
lpFIRBW = options.sample_rate / (1 << options.log2_interp)
lpfBW = lpFIRBW * 1.2
if options.device_hwid == "BladeRF":
settings['bladeRFOutputSettings']['centerFrequency'] = options.device_freq*1000
settings['bladeRFOutputSettings']['centerFrequency'] = options.device_freq * 1000
settings['bladeRFOutputSettings']['devSampleRate'] = options.sample_rate
settings['bladeRFOutputSettings']['vga1'] = -20
settings['bladeRFOutputSettings']['vga2'] = 6
settings['bladeRFOutputSettings']['bandwidth'] = 1500*1000
settings['bladeRFOutputSettings']['bandwidth'] = 1500 * 1000
settings['bladeRFOutputSettings']['log2Interp'] = options.log2_interp
settings['bladeRFOutputSettings']['xb200'] = 1 # assume XB200 is mounted
settings['bladeRFOutputSettings']['xb200Path'] = 1 if options.device_freq < 300000 else 0
@ -129,7 +134,7 @@ def setupDevice(options):
settings["limeSdrOutputSettings"]["devSampleRate"] = options.sample_rate
settings["limeSdrOutputSettings"]["log2HardInterp"] = options.log2_interp_hard
settings["limeSdrOutputSettings"]["log2SoftInterp"] = options.log2_interp
settings["limeSdrOutputSettings"]["centerFrequency"] = options.device_freq*1000 + 500000
settings["limeSdrOutputSettings"]["centerFrequency"] = options.device_freq * 1000 + 500000
settings["limeSdrOutputSettings"]["ncoEnable"] = 1
settings["limeSdrOutputSettings"]["ncoFrequency"] = -500000
settings["limeSdrOutputSettings"]["lpfBW"] = 4050000
@ -141,14 +146,14 @@ def setupDevice(options):
settings["plutoSdrOutputSettings"]["devSampleRate"] = options.sample_rate
settings["plutoSdrOutputSettings"]["lpfFIRlog2Interp"] = options.log2_interp_hard
settings["plutoSdrOutputSettings"]["log2Interp"] = options.log2_interp
settings["plutoSdrOutputSettings"]["centerFrequency"] = options.device_freq*1000
settings["plutoSdrOutputSettings"]["centerFrequency"] = options.device_freq * 1000
settings["plutoSdrOutputSettings"]["lpfBW"] = lpfBW
settings["plutoSdrOutputSettings"]["lpfFIRBW"] = lpFIRBW
settings["plutoSdrOutputSettings"]["lpfFIREnable"] = 1
settings["plutoSdrOutputSettings"]["att"] = -24 # -6 dB
elif options.device_hwid == "HackRF":
settings['hackRFOutputSettings']['LOppmTenths'] = round(options.lo_ppm*10)
settings['hackRFOutputSettings']['centerFrequency'] = options.device_freq*1000
settings['hackRFOutputSettings']['LOppmTenths'] = round(options.lo_ppm * 10)
settings['hackRFOutputSettings']['centerFrequency'] = options.device_freq * 1000
settings['hackRFOutputSettings']['devSampleRate'] = options.sample_rate
settings['hackRFOutputSettings']['lnaExt'] = 0
settings['hackRFOutputSettings']['log2Interp'] = options.log2_interp
@ -158,6 +163,7 @@ def setupDevice(options):
if r is None:
exit(-1)
# ======================================================================
def setupChannel(options):
r = callAPI(deviceset_url + "/channel", "POST", None, {"channelType": options.channel_id, "tx": 1}, "Create modulator")
@ -278,7 +284,7 @@ def main():
if r is None:
exit(-1)
except Exception, msg:
except Exception as ex:
tb = traceback.format_exc()
print >> sys.stderr, tb