mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-05-30 05:52:24 -04:00
REST API Python examples: source formatting and exception Python3 compatibility
This commit is contained in:
parent
7e97f62615
commit
5dfc60331c
@ -5,6 +5,7 @@ from optparse import OptionParser
|
|||||||
|
|
||||||
base_url = "http://127.0.0.1:8091/sdrangel"
|
base_url = "http://127.0.0.1:8091/sdrangel"
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def getInputOptions():
|
def getInputOptions():
|
||||||
|
|
||||||
@ -43,7 +44,7 @@ def main():
|
|||||||
print("Error adding channel. HTTP: %d" % r.status_code)
|
print("Error adding channel. HTTP: %d" % r.status_code)
|
||||||
print json.dumps(r.json(), indent=4, sort_keys=True)
|
print json.dumps(r.json(), indent=4, sort_keys=True)
|
||||||
|
|
||||||
except Exception, msg:
|
except Exception as ex:
|
||||||
tb = traceback.format_exc()
|
tb = traceback.format_exc()
|
||||||
print >> sys.stderr, tb
|
print >> sys.stderr, tb
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ def main():
|
|||||||
|
|
||||||
print("All done!")
|
print("All done!")
|
||||||
|
|
||||||
except Exception, msg:
|
except Exception as ex:
|
||||||
tb = traceback.format_exc()
|
tb = traceback.format_exc()
|
||||||
print >> sys.stderr, tb
|
print >> sys.stderr, tb
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ requests_methods = {
|
|||||||
"DELETE": requests.delete
|
"DELETE": requests.delete
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def getInputOptions():
|
def getInputOptions():
|
||||||
|
|
||||||
@ -30,6 +31,7 @@ def getInputOptions():
|
|||||||
|
|
||||||
return options
|
return options
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def printResponse(response):
|
def printResponse(response):
|
||||||
content_type = response.headers.get("Content-Type", None)
|
content_type = response.headers.get("Content-Type", None)
|
||||||
@ -39,6 +41,7 @@ def printResponse(response):
|
|||||||
elif "text/plain" in content_type:
|
elif "text/plain" in content_type:
|
||||||
print(response.text)
|
print(response.text)
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def callAPI(url, method, params, json, text):
|
def callAPI(url, method, params, json, text):
|
||||||
request_method = requests_methods.get(method, None)
|
request_method = requests_methods.get(method, None)
|
||||||
@ -53,6 +56,7 @@ def callAPI(url, method, params, json, text):
|
|||||||
printResponse(r)
|
printResponse(r)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def main():
|
def main():
|
||||||
try:
|
try:
|
||||||
@ -109,7 +113,7 @@ def main():
|
|||||||
if r is None:
|
if r is None:
|
||||||
exit(-1)
|
exit(-1)
|
||||||
|
|
||||||
except Exception, msg:
|
except Exception as ex:
|
||||||
tb = traceback.format_exc()
|
tb = traceback.format_exc()
|
||||||
print >> sys.stderr, tb
|
print >> sys.stderr, tb
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ requests_methods = {
|
|||||||
"DELETE": requests.delete
|
"DELETE": requests.delete
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def getInputOptions():
|
def getInputOptions():
|
||||||
|
|
||||||
@ -26,6 +27,7 @@ def getInputOptions():
|
|||||||
|
|
||||||
return options
|
return options
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def printResponse(response):
|
def printResponse(response):
|
||||||
content_type = response.headers.get("Content-Type", None)
|
content_type = response.headers.get("Content-Type", None)
|
||||||
@ -35,6 +37,7 @@ def printResponse(response):
|
|||||||
elif "text/plain" in content_type:
|
elif "text/plain" in content_type:
|
||||||
print(response.text)
|
print(response.text)
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def callAPI(url, method, params, json, text):
|
def callAPI(url, method, params, json, text):
|
||||||
request_method = requests_methods.get(method, None)
|
request_method = requests_methods.get(method, None)
|
||||||
@ -49,6 +52,7 @@ def callAPI(url, method, params, json, text):
|
|||||||
printResponse(r)
|
printResponse(r)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def main():
|
def main():
|
||||||
try:
|
try:
|
||||||
@ -86,7 +90,7 @@ def main():
|
|||||||
if r is None:
|
if r is None:
|
||||||
exit(-1)
|
exit(-1)
|
||||||
|
|
||||||
except Exception, msg:
|
except Exception as ex:
|
||||||
tb = traceback.format_exc()
|
tb = traceback.format_exc()
|
||||||
print >> sys.stderr, tb
|
print >> sys.stderr, tb
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ from optparse import OptionParser
|
|||||||
|
|
||||||
base_url = "http://127.0.0.1:8091/sdrangel"
|
base_url = "http://127.0.0.1:8091/sdrangel"
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def getInputOptions():
|
def getInputOptions():
|
||||||
|
|
||||||
@ -34,6 +35,7 @@ def getInputOptions():
|
|||||||
|
|
||||||
return options
|
return options
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def startDevice(deviceIndex):
|
def startDevice(deviceIndex):
|
||||||
dev_run_url = base_url + ("/deviceset/%d/device/run" % deviceIndex)
|
dev_run_url = base_url + ("/deviceset/%d/device/run" % deviceIndex)
|
||||||
@ -55,6 +57,7 @@ def startDevice(deviceIndex):
|
|||||||
else:
|
else:
|
||||||
print("Error getting device %d running state" % deviceIndex)
|
print("Error getting device %d running state" % deviceIndex)
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def stopDevice(deviceIndex):
|
def stopDevice(deviceIndex):
|
||||||
dev_run_url = base_url + ("/deviceset/%d/device/run" % deviceIndex)
|
dev_run_url = base_url + ("/deviceset/%d/device/run" % deviceIndex)
|
||||||
@ -76,6 +79,7 @@ def stopDevice(deviceIndex):
|
|||||||
else:
|
else:
|
||||||
print("Error getting device %d running state" % deviceIndex)
|
print("Error getting device %d running state" % deviceIndex)
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def setFocus(deviceIndex):
|
def setFocus(deviceIndex):
|
||||||
dev_focus_url = base_url + ("/deviceset/%d/focus" % deviceIndex)
|
dev_focus_url = base_url + ("/deviceset/%d/focus" % deviceIndex)
|
||||||
@ -87,6 +91,7 @@ def setFocus(deviceIndex):
|
|||||||
else:
|
else:
|
||||||
print("Error setting focus on device set %d" % deviceIndex)
|
print("Error setting focus on device set %d" % deviceIndex)
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def main():
|
def main():
|
||||||
try:
|
try:
|
||||||
@ -122,7 +127,7 @@ def main():
|
|||||||
else:
|
else:
|
||||||
print("Error getting device sets configuration")
|
print("Error getting device sets configuration")
|
||||||
|
|
||||||
except Exception, msg:
|
except Exception as ex:
|
||||||
tb = traceback.format_exc()
|
tb = traceback.format_exc()
|
||||||
print >> sys.stderr, tb
|
print >> sys.stderr, tb
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ requests_methods = {
|
|||||||
"DELETE": requests.delete
|
"DELETE": requests.delete
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def getHwType():
|
def getHwType():
|
||||||
r = requests.get(url=base_url + "/deviceset/0")
|
r = requests.get(url=base_url + "/deviceset/0")
|
||||||
if r.status_code / 100 == 2:
|
if r.status_code / 100 == 2:
|
||||||
@ -23,6 +24,7 @@ def getHwType():
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def selectRtlSdr():
|
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:
|
if r.status_code / 100 == 2:
|
||||||
@ -31,6 +33,7 @@ def selectRtlSdr():
|
|||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def getRtlSdrSettings():
|
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:
|
if r.status_code / 100 == 2:
|
||||||
@ -44,6 +47,7 @@ def getRtlSdrSettings():
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def patchRtlSdrSettings(settings):
|
def patchRtlSdrSettings(settings):
|
||||||
new_settings = {"deviceHwType": "RTLSDR", "tx": 0, "rtlSdrSettings": 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)
|
||||||
@ -52,6 +56,7 @@ def patchRtlSdrSettings(settings):
|
|||||||
else:
|
else:
|
||||||
print "Error HTTP:", r.status_code
|
print "Error HTTP:", r.status_code
|
||||||
|
|
||||||
|
|
||||||
def deviceRun(run):
|
def deviceRun(run):
|
||||||
if run:
|
if run:
|
||||||
r = requests.post(url=base_url + "/deviceset/0/device/run")
|
r = requests.post(url=base_url + "/deviceset/0/device/run")
|
||||||
@ -83,4 +88,3 @@ def main():
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
@ -358,10 +358,7 @@ def main():
|
|||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
setup_audio(options)
|
setup_audio(options)
|
||||||
|
|
||||||
# if options.channel_id == "BFMDemod":
|
except Exception as ex:
|
||||||
# channelsReport(deviceset_url)
|
|
||||||
|
|
||||||
except Exception, msg:
|
|
||||||
tb = traceback.format_exc()
|
tb = traceback.format_exc()
|
||||||
print >> sys.stderr, tb
|
print >> sys.stderr, tb
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ requests_methods = {
|
|||||||
"DELETE": requests.delete
|
"DELETE": requests.delete
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def getInputOptions():
|
def getInputOptions():
|
||||||
|
|
||||||
@ -59,6 +60,7 @@ def getInputOptions():
|
|||||||
|
|
||||||
return options
|
return options
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def printResponse(response):
|
def printResponse(response):
|
||||||
content_type = response.headers.get("Content-Type", None)
|
content_type = response.headers.get("Content-Type", None)
|
||||||
@ -68,6 +70,7 @@ def printResponse(response):
|
|||||||
elif "text/plain" in content_type:
|
elif "text/plain" in content_type:
|
||||||
print(response.text)
|
print(response.text)
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def callAPI(url, method, params, json, text):
|
def callAPI(url, method, params, json, text):
|
||||||
request_method = requests_methods.get(method, None)
|
request_method = requests_methods.get(method, None)
|
||||||
@ -82,6 +85,7 @@ def callAPI(url, method, params, json, text):
|
|||||||
printResponse(r)
|
printResponse(r)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def main():
|
def main():
|
||||||
try:
|
try:
|
||||||
@ -244,8 +248,7 @@ def main():
|
|||||||
if r is None:
|
if r is None:
|
||||||
exit(-1)
|
exit(-1)
|
||||||
|
|
||||||
|
except Exception as ex:
|
||||||
except Exception, msg:
|
|
||||||
tb = traceback.format_exc()
|
tb = traceback.format_exc()
|
||||||
print >> sys.stderr, tb
|
print >> sys.stderr, tb
|
||||||
|
|
||||||
|
@ -28,8 +28,10 @@ requests_methods = {
|
|||||||
"DELETE": requests.delete
|
"DELETE": requests.delete
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
class ScanControl:
|
class ScanControl:
|
||||||
|
|
||||||
def __init__(self, num_channels, channel_step, start_freq, stop_freq, log2_decim):
|
def __init__(self, num_channels, channel_step, start_freq, stop_freq, log2_decim):
|
||||||
self.channel_shifts = []
|
self.channel_shifts = []
|
||||||
if num_channels < 2:
|
if num_channels < 2:
|
||||||
@ -43,6 +45,7 @@ class ScanControl:
|
|||||||
self.device_step_freq = 2 * limit + channel_step
|
self.device_step_freq = 2 * limit + channel_step
|
||||||
self.device_sample_rate = (2 * limit + channel_step) * (1 << log2_decim)
|
self.device_sample_rate = (2 * limit + channel_step) * (1 << log2_decim)
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def getInputOptions():
|
def getInputOptions():
|
||||||
|
|
||||||
@ -95,6 +98,7 @@ def getInputOptions():
|
|||||||
|
|
||||||
return options
|
return options
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def setupDevice(scan_control, options):
|
def setupDevice(scan_control, options):
|
||||||
settings = callAPI(deviceset_url + "/device/settings", "GET", None, None, "Get device settings")
|
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:
|
if r is None:
|
||||||
exit(-1)
|
exit(-1)
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def changeDeviceFrequency(fc, options):
|
def changeDeviceFrequency(fc, options):
|
||||||
settings = callAPI(deviceset_url + "/device/settings", "GET", None, None, "Get device settings")
|
settings = callAPI(deviceset_url + "/device/settings", "GET", None, None, "Get device settings")
|
||||||
@ -168,6 +173,7 @@ def changeDeviceFrequency(fc, options):
|
|||||||
if r is None:
|
if r is None:
|
||||||
exit(-1)
|
exit(-1)
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def setupChannels(scan_control, options):
|
def setupChannels(scan_control, options):
|
||||||
i = 0
|
i = 0
|
||||||
@ -212,6 +218,7 @@ def setupChannels(scan_control, options):
|
|||||||
|
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def checkScanning(fc, options, display_message):
|
def checkScanning(fc, options, display_message):
|
||||||
reports = callAPI(deviceset_url + "/channels/report", "GET", None, None, "Get channels report")
|
reports = callAPI(deviceset_url + "/channels/report", "GET", None, None, "Get channels report")
|
||||||
@ -235,6 +242,7 @@ def checkScanning(fc, options, display_message):
|
|||||||
return False # stop scanning
|
return False # stop scanning
|
||||||
return True # continue scanning
|
return True # continue scanning
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def printResponse(response):
|
def printResponse(response):
|
||||||
content_type = response.headers.get("Content-Type", None)
|
content_type = response.headers.get("Content-Type", None)
|
||||||
@ -244,6 +252,7 @@ def printResponse(response):
|
|||||||
elif "text/plain" in content_type:
|
elif "text/plain" in content_type:
|
||||||
print(response.text)
|
print(response.text)
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def callAPI(url, method, params, json, text):
|
def callAPI(url, method, params, json, text):
|
||||||
request_method = requests_methods.get(method, None)
|
request_method = requests_methods.get(method, None)
|
||||||
@ -262,6 +271,7 @@ def callAPI(url, method, params, json, text):
|
|||||||
printResponse(r)
|
printResponse(r)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def main():
|
def main():
|
||||||
try:
|
try:
|
||||||
@ -361,7 +371,7 @@ def main():
|
|||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
pass
|
pass
|
||||||
except Exception, msg:
|
except Exception as ex:
|
||||||
tb = traceback.format_exc()
|
tb = traceback.format_exc()
|
||||||
print >> sys.stderr, tb
|
print >> sys.stderr, tb
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ from optparse import OptionParser
|
|||||||
|
|
||||||
base_url = "http://127.0.0.1:8091/sdrangel"
|
base_url = "http://127.0.0.1:8091/sdrangel"
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def getInputOptions():
|
def getInputOptions():
|
||||||
|
|
||||||
@ -32,6 +33,7 @@ def getInputOptions():
|
|||||||
|
|
||||||
return options
|
return options
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def startDevice(deviceIndex):
|
def startDevice(deviceIndex):
|
||||||
dev_run_url = base_url + ("/deviceset/%d/device/run" % deviceIndex)
|
dev_run_url = base_url + ("/deviceset/%d/device/run" % deviceIndex)
|
||||||
@ -53,6 +55,7 @@ def startDevice(deviceIndex):
|
|||||||
else:
|
else:
|
||||||
print("Error getting device %d running state" % deviceIndex)
|
print("Error getting device %d running state" % deviceIndex)
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def stopDevice(deviceIndex):
|
def stopDevice(deviceIndex):
|
||||||
dev_run_url = base_url + ("/deviceset/%d/device/run" % deviceIndex)
|
dev_run_url = base_url + ("/deviceset/%d/device/run" % deviceIndex)
|
||||||
@ -74,6 +77,7 @@ def stopDevice(deviceIndex):
|
|||||||
else:
|
else:
|
||||||
print("Error getting device %d running state" % deviceIndex)
|
print("Error getting device %d running state" % deviceIndex)
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def main():
|
def main():
|
||||||
try:
|
try:
|
||||||
@ -97,7 +101,7 @@ def main():
|
|||||||
else:
|
else:
|
||||||
print("Error getting device sets configuration")
|
print("Error getting device sets configuration")
|
||||||
|
|
||||||
except Exception, msg:
|
except Exception as ex:
|
||||||
tb = traceback.format_exc()
|
tb = traceback.format_exc()
|
||||||
print >> sys.stderr, tb
|
print >> sys.stderr, tb
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ requests_methods = {
|
|||||||
"DELETE": requests.delete
|
"DELETE": requests.delete
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def getInputOptions():
|
def getInputOptions():
|
||||||
|
|
||||||
@ -26,6 +27,7 @@ def getInputOptions():
|
|||||||
|
|
||||||
return options
|
return options
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def printResponse(response):
|
def printResponse(response):
|
||||||
content_type = response.headers.get("Content-Type", None)
|
content_type = response.headers.get("Content-Type", None)
|
||||||
@ -35,6 +37,7 @@ def printResponse(response):
|
|||||||
elif "text/plain" in content_type:
|
elif "text/plain" in content_type:
|
||||||
print(response.text)
|
print(response.text)
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def callAPI(url, method, params, json, text):
|
def callAPI(url, method, params, json, text):
|
||||||
request_method = requests_methods.get(method, None)
|
request_method = requests_methods.get(method, None)
|
||||||
@ -49,6 +52,7 @@ def callAPI(url, method, params, json, text):
|
|||||||
printResponse(r)
|
printResponse(r)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def main():
|
def main():
|
||||||
try:
|
try:
|
||||||
@ -61,7 +65,7 @@ def main():
|
|||||||
if settings is None:
|
if settings is None:
|
||||||
exit(-1)
|
exit(-1)
|
||||||
|
|
||||||
except Exception, msg:
|
except Exception as ex:
|
||||||
tb = traceback.format_exc()
|
tb = traceback.format_exc()
|
||||||
print >> sys.stderr, tb
|
print >> sys.stderr, tb
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ requests_methods = {
|
|||||||
"DELETE": requests.delete
|
"DELETE": requests.delete
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def getInputOptions():
|
def getInputOptions():
|
||||||
|
|
||||||
@ -64,6 +65,7 @@ def getInputOptions():
|
|||||||
|
|
||||||
return options
|
return options
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def printResponse(response):
|
def printResponse(response):
|
||||||
content_type = response.headers.get("Content-Type", None)
|
content_type = response.headers.get("Content-Type", None)
|
||||||
@ -73,6 +75,7 @@ def printResponse(response):
|
|||||||
elif "text/plain" in content_type:
|
elif "text/plain" in content_type:
|
||||||
print(response.text)
|
print(response.text)
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def callAPI(url, method, params, json, text):
|
def callAPI(url, method, params, json, text):
|
||||||
request_method = requests_methods.get(method, None)
|
request_method = requests_methods.get(method, None)
|
||||||
@ -87,6 +90,7 @@ def callAPI(url, method, params, json, text):
|
|||||||
printResponse(r)
|
printResponse(r)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def setupBladeRFXB200(fc):
|
def setupBladeRFXB200(fc):
|
||||||
if fc < 50000:
|
if fc < 50000:
|
||||||
@ -104,6 +108,7 @@ def setupBladeRFXB200(fc):
|
|||||||
else:
|
else:
|
||||||
return 5 # BLADERF_XB200_AUTO_3DB
|
return 5 # BLADERF_XB200_AUTO_3DB
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def setupDevice(options):
|
def setupDevice(options):
|
||||||
settings = callAPI(deviceset_url + "/device/settings", "GET", None, None, "Get device settings")
|
settings = callAPI(deviceset_url + "/device/settings", "GET", None, None, "Get device settings")
|
||||||
@ -158,6 +163,7 @@ def setupDevice(options):
|
|||||||
if r is None:
|
if r is None:
|
||||||
exit(-1)
|
exit(-1)
|
||||||
|
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
||||||
def setupChannel(options):
|
def setupChannel(options):
|
||||||
r = callAPI(deviceset_url + "/channel", "POST", None, {"channelType": options.channel_id, "tx": 1}, "Create modulator")
|
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:
|
if r is None:
|
||||||
exit(-1)
|
exit(-1)
|
||||||
|
|
||||||
except Exception, msg:
|
except Exception as ex:
|
||||||
tb = traceback.format_exc()
|
tb = traceback.format_exc()
|
||||||
print >> sys.stderr, tb
|
print >> sys.stderr, tb
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user