mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-21 23:55:13 -05:00
Update some example scripts to python3
This commit is contained in:
parent
35aa393f11
commit
b37c7f6cb9
12
swagger/sdrangel/examples/add_channel.py
Normal file → Executable file
12
swagger/sdrangel/examples/add_channel.py
Normal file → Executable file
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import requests, json, traceback, sys
|
import requests, json, traceback, sys
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
@ -12,12 +12,12 @@ def getInputOptions():
|
|||||||
parser = OptionParser(usage="usage: %%prog [-t]\n")
|
parser = OptionParser(usage="usage: %%prog [-t]\n")
|
||||||
parser.add_option("-a", "--address", dest="address", help="address and port", metavar="ADDRESS", type="string")
|
parser.add_option("-a", "--address", dest="address", help="address and port", metavar="ADDRESS", type="string")
|
||||||
parser.add_option("-d", "--device-index", dest="device_index", help="device set index", metavar="INDEX", type="int")
|
parser.add_option("-d", "--device-index", dest="device_index", help="device set index", metavar="INDEX", type="int")
|
||||||
parser.add_option("-c", "--channel-id", dest="channel_id", help="channel ID of channel to add", metavar="ID", type="string")
|
parser.add_option("-c", "--channel-id", dest="channel_id", help="channel ID of channel to add (E.g. NFMDemod)", metavar="ID", type="string")
|
||||||
|
|
||||||
(options, args) = parser.parse_args()
|
(options, args) = parser.parse_args()
|
||||||
|
|
||||||
if options.address is None:
|
if options.address is None:
|
||||||
options.address = "127.0.0.1:8888"
|
options.address = "127.0.0.1:8091"
|
||||||
|
|
||||||
if options.device_index is None or options.device_index < 0:
|
if options.device_index is None or options.device_index < 0:
|
||||||
options.device_index = 0
|
options.device_index = 0
|
||||||
@ -37,12 +37,12 @@ def main():
|
|||||||
base_url = "http://%s/sdrangel" % options.address
|
base_url = "http://%s/sdrangel" % options.address
|
||||||
device_url = base_url + ("/deviceset/%d/channel" % options.device_index)
|
device_url = base_url + ("/deviceset/%d/channel" % options.device_index)
|
||||||
r = requests.post(url=device_url, json={"direction": 0, "channelType": options.channel_id})
|
r = requests.post(url=device_url, json={"direction": 0, "channelType": options.channel_id})
|
||||||
if r.status_code / 100 == 2:
|
if r.status_code // 100 == 2:
|
||||||
print("Success")
|
print("Success")
|
||||||
print json.dumps(r.json(), indent=4, sort_keys=True)
|
print(json.dumps(r.json(), indent=4, sort_keys=True))
|
||||||
else:
|
else:
|
||||||
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 as ex:
|
except Exception as ex:
|
||||||
tb = traceback.format_exc()
|
tb = traceback.format_exc()
|
||||||
|
24
swagger/sdrangel/examples/rtlsdr_settings.py
Normal file → Executable file
24
swagger/sdrangel/examples/rtlsdr_settings.py
Normal file → Executable file
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
import requests, json
|
import requests, json
|
||||||
|
|
||||||
base_url = "http://127.0.0.1:8091/sdrangel"
|
base_url = "http://127.0.0.1:8091/sdrangel"
|
||||||
@ -14,7 +14,7 @@ requests_methods = {
|
|||||||
|
|
||||||
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:
|
||||||
rj = r.json()
|
rj = r.json()
|
||||||
devj = rj.get('samplingDevice', None)
|
devj = rj.get('samplingDevice', None)
|
||||||
if devj is not None:
|
if devj is not None:
|
||||||
@ -27,8 +27,8 @@ def getHwType():
|
|||||||
|
|
||||||
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:
|
||||||
print json.dumps(r.json(), indent=4, sort_keys=True)
|
print(json.dumps(r.json(), indent=4, sort_keys=True))
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
@ -36,7 +36,7 @@ def selectRtlSdr():
|
|||||||
|
|
||||||
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:
|
||||||
rj = r.json()
|
rj = r.json()
|
||||||
hwType = rj.get('deviceHwType', None)
|
hwType = rj.get('deviceHwType', None)
|
||||||
if hwType is not None and hwType == "RTLSDR":
|
if hwType is not None and hwType == "RTLSDR":
|
||||||
@ -51,10 +51,10 @@ def getRtlSdrSettings():
|
|||||||
def patchRtlSdrSettings(settings):
|
def patchRtlSdrSettings(settings):
|
||||||
new_settings = {"deviceHwType": "RTLSDR", "direction": 0, "rtlSdrSettings": settings}
|
new_settings = {"deviceHwType": "RTLSDR", "direction": 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:
|
if r.status_code // 100 == 2:
|
||||||
print json.dumps(r.json(), indent=4, sort_keys=True)
|
print(json.dumps(r.json(), indent=4, sort_keys=True))
|
||||||
else:
|
else:
|
||||||
print "Error HTTP:", r.status_code
|
print("Error HTTP:", r.status_code)
|
||||||
|
|
||||||
|
|
||||||
def deviceRun(run):
|
def deviceRun(run):
|
||||||
@ -62,10 +62,10 @@ def deviceRun(run):
|
|||||||
r = requests.post(url=base_url + "/deviceset/0/device/run")
|
r = requests.post(url=base_url + "/deviceset/0/device/run")
|
||||||
else:
|
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:
|
if r.status_code // 100 == 2:
|
||||||
print json.dumps(r.json(), indent=4, sort_keys=True)
|
print(json.dumps(r.json(), indent=4, sort_keys=True))
|
||||||
else:
|
else:
|
||||||
print "Error HTTP:", r.status_code
|
print("Error HTTP:", r.status_code)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@ -73,8 +73,10 @@ def main():
|
|||||||
if hwType is not None:
|
if hwType is not None:
|
||||||
if hwType != "RTLSDR":
|
if hwType != "RTLSDR":
|
||||||
if not selectRtlSdr():
|
if not selectRtlSdr():
|
||||||
|
print("Device set 0 is not an RTLSDR device")
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
print("Device set 0 does not exist")
|
||||||
return
|
return
|
||||||
settings = getRtlSdrSettings()
|
settings = getRtlSdrSettings()
|
||||||
if settings is not None:
|
if settings is not None:
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import requests, json, traceback, sys, time
|
import requests, json, traceback, sys, time
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
Loading…
Reference in New Issue
Block a user