From f0ff5473fb52d6a906e6066b87138632c577094b Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 7 May 2019 15:35:11 +0200 Subject: [PATCH] REST API: implemented keys renaming in example scripts --- swagger/sdrangel/examples/add_channel.py | 2 +- swagger/sdrangel/examples/limesdr_tx.py | 6 +-- swagger/sdrangel/examples/nfm_test.py | 6 +-- swagger/sdrangel/examples/ptt.py | 14 +++---- swagger/sdrangel/examples/ptt_active.py | 10 ++--- swagger/sdrangel/examples/randomize_colors.py | 42 +++++++++---------- swagger/sdrangel/examples/rtlsdr_settings.py | 2 +- swagger/sdrangel/examples/rx_test.py | 8 ++-- swagger/sdrangel/examples/rx_tx_test.py | 24 +++++------ swagger/sdrangel/examples/scanner.py | 10 ++--- swagger/sdrangel/examples/test.json | 14 +++---- swagger/sdrangel/examples/tx_test.py | 6 +-- 12 files changed, 72 insertions(+), 72 deletions(-) diff --git a/swagger/sdrangel/examples/add_channel.py b/swagger/sdrangel/examples/add_channel.py index 4de12f9cc..ee35a6b4a 100644 --- a/swagger/sdrangel/examples/add_channel.py +++ b/swagger/sdrangel/examples/add_channel.py @@ -36,7 +36,7 @@ def main(): global base_url base_url = "http://%s/sdrangel" % options.address device_url = base_url + ("/deviceset/%d/channel" % options.device_index) - r = requests.post(url=device_url, json={"tx": 0, "channelType": options.channel_id}) + r = requests.post(url=device_url, json={"direction": 0, "channelType": options.channel_id}) if r.status_code / 100 == 2: print("Success") print json.dumps(r.json(), indent=4, sort_keys=True) diff --git a/swagger/sdrangel/examples/limesdr_tx.py b/swagger/sdrangel/examples/limesdr_tx.py index fa20ab6d1..d6fa7be62 100644 --- a/swagger/sdrangel/examples/limesdr_tx.py +++ b/swagger/sdrangel/examples/limesdr_tx.py @@ -65,13 +65,13 @@ def main(): global base_url base_url = "http://%s/sdrangel" % options.address - r = callAPI("/deviceset", "POST", {"tx": 1}, None, "Add Tx device set") + r = callAPI("/deviceset", "POST", {"direction": 1}, None, "Add Tx device set") if r is None: exit(-1) deviceset_url = "/deviceset/%d" % options.device_index - r = callAPI(deviceset_url + "/device", "PUT", None, {"hwType": "LimeSDR", "tx": 1}, "setup LimeSDR on Tx device set") + r = callAPI(deviceset_url + "/device", "PUT", None, {"hwType": "LimeSDR", "direction": 1}, "setup LimeSDR on Tx device set") if r is None: exit(-1) @@ -91,7 +91,7 @@ def main(): if r is None: exit(-1) - r = callAPI(deviceset_url + "/channel", "POST", None, {"channelType": "NFMMod", "tx": 1}, "Create NFM mod") + r = callAPI(deviceset_url + "/channel", "POST", None, {"channelType": "NFMMod", "direction": 1}, "Create NFM mod") if r is None: exit(-1) diff --git a/swagger/sdrangel/examples/nfm_test.py b/swagger/sdrangel/examples/nfm_test.py index 09ea421d2..aa58d561f 100644 --- a/swagger/sdrangel/examples/nfm_test.py +++ b/swagger/sdrangel/examples/nfm_test.py @@ -61,7 +61,7 @@ def main(): global base_url base_url = "http://%s/sdrangel" % options.address - settings = callAPI("/deviceset/0/channel", "POST", None, {"channelType": "NFMDemod", "tx": 0}, "Create NFM demod") + settings = callAPI("/deviceset/0/channel", "POST", None, {"channelType": "NFMDemod", "direction": 0}, "Create NFM demod") if settings is None: exit(-1) @@ -72,11 +72,11 @@ def main(): if r is None: exit(-1) - r = callAPI("/deviceset", "POST", {"tx": 1}, None, "Add Tx device set") + r = callAPI("/deviceset", "POST", {"direction": 1}, None, "Add Tx device set") if r is None: exit(-1) - settings = callAPI("/deviceset/1/channel", "POST", None, {"channelType": "NFMMod", "tx": 1}, "Create NFM mod") + settings = callAPI("/deviceset/1/channel", "POST", None, {"channelType": "NFMMod", "direction": 1}, "Create NFM mod") if settings is None: exit(-1) diff --git a/swagger/sdrangel/examples/ptt.py b/swagger/sdrangel/examples/ptt.py index 5960f531f..611a23f1f 100755 --- a/swagger/sdrangel/examples/ptt.py +++ b/swagger/sdrangel/examples/ptt.py @@ -1,13 +1,13 @@ #!/usr/bin/env python ''' PTT (Push To Talk) script example. - + Assumes Rx and Tx are contiguous device sets with Rx at index i and Tx at index i+1 - - When going from Rx to Tx (push) the device set index specified must be the Rx one + + When going from Rx to Tx (push) the device set index specified must be the Rx one When going from Tx to Rx (release) the device set index specified must be the Tx one - Defaults are Rx at index 0 and Tx at index 1 - + Defaults are Rx at index 0 and Tx at index 1 + Default web API base address is http://127.0.0.1:8091/sdrangel (default of sdrangel web API) You may change the address and port portion with the -a parameter. Ex: -a 44.168.40.128:8888 ''' @@ -105,7 +105,7 @@ def main(): 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"]["direction"] == 0 and deviceSets[options.deviceset_index + 1]["samplingDevice"]["direction"] == 1: stopDevice(options.deviceset_index) time.sleep(1) startDevice(options.deviceset_index + 1) @@ -113,7 +113,7 @@ def main(): else: 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"]["direction"] == 0 and deviceSets[options.deviceset_index]["samplingDevice"]["direction"] == 1: stopDevice(options.deviceset_index) time.sleep(1) startDevice(options.deviceset_index - 1) diff --git a/swagger/sdrangel/examples/ptt_active.py b/swagger/sdrangel/examples/ptt_active.py index 654c01849..310f2dfc5 100644 --- a/swagger/sdrangel/examples/ptt_active.py +++ b/swagger/sdrangel/examples/ptt_active.py @@ -158,12 +158,12 @@ def device_run(deviceset_index): ''' Reply with the expected reply of a working device ''' # ---------------------------------------------------------------------- originator_index = None - tx = None + direction = None content = request.get_json(silent=True) if content: originator_index = content.get('originatorIndex') - tx = content.get('tx') - if originator_index is None or tx is None: + direction = content.get('direction') + if originator_index is None or direction is None: print('device_run: SDRangel reverse API v4.5.2 or higher required. No or invalid originator information') return "" sdrangel_ip = get_sdrangel_ip(request) @@ -174,7 +174,7 @@ def device_run(deviceset_index): global RUNNING print(f'device_run: Device: {originator_index} Other device: {other_device_index} Running: {RUNNING}') if request.method == 'POST': - print(f'device_run: Device {originator_index} (tx={tx}) has started at {sdrangel_ip}:{SDRANGEL_API_PORT}') + print(f'device_run: Device {originator_index} (direction={direction}) has started at {sdrangel_ip}:{SDRANGEL_API_PORT}') if originator_index not in RUNNING: RUNNING.add(originator_index) if other_device_index in RUNNING: @@ -186,7 +186,7 @@ def device_run(deviceset_index): reply = { "state": "idle" } return jsonify(reply) elif request.method == 'DELETE': - print(f'device_run: Device {originator_index} (tx={tx}) has stopped at {sdrangel_ip}:{SDRANGEL_API_PORT}') + print(f'device_run: Device {originator_index} (direction={direction}) has stopped at {sdrangel_ip}:{SDRANGEL_API_PORT}') if originator_index in RUNNING: RUNNING.remove(originator_index) if other_device_index not in RUNNING: diff --git a/swagger/sdrangel/examples/randomize_colors.py b/swagger/sdrangel/examples/randomize_colors.py index ba3d26417..eb3611339 100755 --- a/swagger/sdrangel/examples/randomize_colors.py +++ b/swagger/sdrangel/examples/randomize_colors.py @@ -41,65 +41,65 @@ def getInputOptions(): def get_channel_static_data(channel_info): if channel_info["id"] == "AMDemod": settings_key = "AMDemodSettings" - tx = 0 + direction = 0 elif channel_info["id"] == "AMMod": settings_key = "AMModSettings" - tx = 1 + direction = 1 elif channel_info["id"] == "ATVMod": settings_key = "ATVModSettings" - tx = 1 + direction = 1 elif channel_info["id"] == "BFMDemod": settings_key = "BFMDemodSettings" - tx = 0 + direction = 0 elif channel_info["id"] == "DSDDemod": settings_key = "DSDDemodSettings" - tx = 0 + direction = 0 elif channel_info["id"] == "NFMDemod": settings_key = "NFMDemodSettings" - tx = 0 + direction = 0 elif channel_info["id"] == "NFMMod": settings_key = "NFMModSettings" - tx = 1 + direction = 1 elif channel_info["id"] == "RemoteSink": settings_key = "RemoteSinkSettings" - tx = 0 + direction = 0 elif channel_info["id"] == "RemoteSource": settings_key = "RemoteSourceSettings" - tx = 1 + direction = 1 elif channel_info["id"] == "SSBMod": settings_key = "SSBModSettings" - tx = 1 + direction = 1 elif channel_info["id"] == "SSBDemod": settings_key = "SSBDemodSettings" - tx = 0 + direction = 0 elif channel_info["id"] == "UDPSource": settings_key = "UDPSourceSettings" - tx = 1 + direction = 1 elif channel_info["id"] == "UDPSink": settings_key = "UDPSinkSettings" - tx = 0 + direction = 0 elif channel_info["id"] == "WFMDemod": settings_key = "WFMDemodSettings" - tx = 0 + direction = 0 elif channel_info["id"] == "WFMMod": settings_key = "WFMModSettings" - tx = 1 + direction = 1 else: settings_key = None - tx = None - return settings_key, tx + direction = None + return settings_key, direction # ====================================================================== def randomize_channels_colors(options, channels): for channel_info in channels: - settings_key, tx = get_channel_static_data(channel_info) + settings_key, direction = get_channel_static_data(channel_info) if settings_key is None: continue color = random.randint(0, (1<<24)) rn, gn, bn = color_to_rgb(color) payload_json = { "channelType": channel_info["id"], - "tx": tx, + "direction": direction, settings_key: { "rgbColor": color } @@ -114,7 +114,7 @@ def randomize_channels_colors(options, channels): # ====================================================================== def randomize_channels_hsv(options, channels): for channel_info in channels: - settings_key, tx = get_channel_static_data(channel_info) + settings_key, direction = get_channel_static_data(channel_info) settings_url = base_url + ("/deviceset/{0}/channel/{1}/settings".format(options.device_index, channel_info["index"])) rep = requests.get(url=settings_url) if rep.status_code / 100 == 2: @@ -139,7 +139,7 @@ def randomize_channels_hsv(options, channels): new_color = rgb_to_color(rn, gn, bn) payload_json = { "channelType": channel_info["id"], - "tx": tx, + "direction": direction, settings_key: { "rgbColor": new_color } diff --git a/swagger/sdrangel/examples/rtlsdr_settings.py b/swagger/sdrangel/examples/rtlsdr_settings.py index 069c8a5a9..a07d7ce84 100644 --- a/swagger/sdrangel/examples/rtlsdr_settings.py +++ b/swagger/sdrangel/examples/rtlsdr_settings.py @@ -49,7 +49,7 @@ def getRtlSdrSettings(): def patchRtlSdrSettings(settings): - new_settings = {"deviceHwType": "RTLSDR", "tx": 0, "rtlSdrSettings": settings} + new_settings = {"deviceHwType": "RTLSDR", "direction": 0, "rtlSdrSettings": 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) diff --git a/swagger/sdrangel/examples/rx_test.py b/swagger/sdrangel/examples/rx_test.py index aa6026dd1..5a2a34826 100755 --- a/swagger/sdrangel/examples/rx_test.py +++ b/swagger/sdrangel/examples/rx_test.py @@ -53,7 +53,7 @@ def getInputOptions(): parser.add_option("--rmt-address", dest="remote_address", help="RemoteSink: destination data address", metavar="IP_ADDRESS", type="string") parser.add_option("--rmt-port", dest="remote_port", help="RemoteSink: destination data port", metavar="PORT", type="int") parser.add_option("--rmt-fec", dest="remote_fec", help="RemoteSink: number of FEC blocks per frame", metavar="NUMBER", type="int") - parser.add_option("--rmt-tx-delay", dest="remote_tx_delay", help="RemoteSink: inter block UDP Tx delay percentage", metavar="PERCENT", type="int") + parser.add_option("--rmt-txdelay", dest="remote_tx_delay", help="RemoteSink: inter block UDP Tx delay percentage", metavar="PERCENT", type="int") (options, args) = parser.parse_args() @@ -134,7 +134,7 @@ def setup_audio(options): # ====================================================================== def setupDevice(deviceset_url, options): - r = callAPI(deviceset_url + "/device", "PUT", None, {"hwType": "%s" % options.device_hwid, "tx": 0}, "setup device on Rx device set") + r = callAPI(deviceset_url + "/device", "PUT", None, {"hwType": "%s" % options.device_hwid, "direction": 0}, "setup device on Rx device set") if r is None: exit(-1) @@ -245,7 +245,7 @@ def setupDevice(deviceset_url, options): def setupChannel(deviceset_url, options): i = 0 - settings = callAPI(deviceset_url + "/channel", "POST", None, {"channelType": options.channel_id, "tx": 0}, "Create demod") + settings = callAPI(deviceset_url + "/channel", "POST", None, {"channelType": options.channel_id, "direction": 0}, "Create demod") if settings is None: exit(-1) @@ -349,7 +349,7 @@ def main(): deviceset_url = "/deviceset/%d" % options.device_index if options.create: - r = callAPI("/deviceset", "POST", {"tx": 0}, None, "Add Rx device set") + r = callAPI("/deviceset", "POST", {"direction": 0}, None, "Add Rx device set") if r is None: exit(-1) diff --git a/swagger/sdrangel/examples/rx_tx_test.py b/swagger/sdrangel/examples/rx_tx_test.py index bb6516450..e52c2ca7c 100644 --- a/swagger/sdrangel/examples/rx_tx_test.py +++ b/swagger/sdrangel/examples/rx_tx_test.py @@ -19,15 +19,15 @@ def getInputOptions(): 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("-R", "--device-hwid-rx", dest="device_hwid_rx", help="device hardware id for Rx", metavar="HWID", type="string") - parser.add_option("-T", "--device-hwid-tx", dest="device_hwid_tx", help="device hardware id for Tx", metavar="HWID", type="string") + parser.add_option("-R", "--device-hwidrx", dest="device_hwid_rx", help="device hardware id for Rx", metavar="HWID", type="string") + parser.add_option("-T", "--device-hwidtx", dest="device_hwid_tx", help="device hardware id for Tx", metavar="HWID", type="string") parser.add_option("-F", "--device-freq", dest="device_freq", help="device center frequency (kHz)", metavar="FREQ", type="int") parser.add_option("-f", "--channel-freq", dest="channel_freq", help="channel center frequency (Hz)", metavar="FREQ", type="int") parser.add_option("-U", "--copy-to-udp", dest="udp_copy", help="UDP audio copy to
[:]", metavar="IP:PORT", type="string") - parser.add_option("-s", "--sample-rate-rx", dest="sample_rate_rx", help="device to host (Rx) sample rate (kS/s)", metavar="RATE", type="int") - parser.add_option("-S", "--sample-rate-tx", dest="sample_rate_tx", help="host to device (Tx) sample rate (kS/s)", metavar="RATE", type="int") - parser.add_option("-n", "--antenna-path-rx", dest="antenna_path_rx", help="antenna path index (Rx)", metavar="INDEX", type="int") - parser.add_option("-N", "--antenna-path-tx", dest="antenna_path_tx", help="antenna path index (Tx)", metavar="INDEX", type="int") + parser.add_option("-s", "--sample-raterx", dest="sample_rate_rx", help="device to host (Rx) sample rate (kS/s)", metavar="RATE", type="int") + parser.add_option("-S", "--sample-ratetx", dest="sample_rate_tx", help="host to device (Tx) sample rate (kS/s)", metavar="RATE", type="int") + parser.add_option("-n", "--antenna-pathrx", dest="antenna_path_rx", help="antenna path index (Rx)", metavar="INDEX", type="int") + parser.add_option("-N", "--antenna-pathtx", dest="antenna_path_tx", help="antenna path index (Tx)", metavar="INDEX", type="int") (options, args) = parser.parse_args() @@ -101,7 +101,7 @@ def main(): nb_devicesets = r['devicesetcount'] if nb_devicesets == 0: # server starts without device set so add Rx device set - r1 = callAPI("/deviceset", "POST", {"tx": 0}, None, "Add Rx device set") + r1 = callAPI("/deviceset", "POST", {"direction": 0}, None, "Add Rx device set") if r1 is None: exit(-1) @@ -110,7 +110,7 @@ def main(): deviceset_index_rx = 0 deviceset_url = "/deviceset/%d" % deviceset_index_rx - r = callAPI(deviceset_url + "/device", "PUT", None, {"hwType": "%s" % options.device_hwid_rx, "tx": 0}, "setup device on Rx device set") + r = callAPI(deviceset_url + "/device", "PUT", None, {"hwType": "%s" % options.device_hwid_rx, "direction": 0}, "setup device on Rx device set") if r is None: exit(-1) @@ -151,7 +151,7 @@ def main(): if r is None: exit(-1) - r = callAPI(deviceset_url + "/channel", "POST", None, {"channelType": "NFMDemod", "tx": 0}, "Create NFM demod") + r = callAPI(deviceset_url + "/channel", "POST", None, {"channelType": "NFMDemod", "direction": 0}, "Create NFM demod") if r is None: exit(-1) @@ -185,13 +185,13 @@ def main(): # ## Tx setup - r = callAPI("/deviceset", "POST", {"tx": 1}, None, "Add Tx device set") + r = callAPI("/deviceset", "POST", {"direction": 1}, None, "Add Tx device set") if r is None: exit(-1) deviceset_url = "/deviceset/%d" % (deviceset_index_rx + 1) - r = callAPI(deviceset_url + "/device", "PUT", None, {"hwType": "%s" % options.device_hwid_tx, "tx": 1}, "setup device on Tx device set") + r = callAPI(deviceset_url + "/device", "PUT", None, {"hwType": "%s" % options.device_hwid_tx, "direction": 1}, "setup device on Tx device set") if r is None: exit(-1) @@ -222,7 +222,7 @@ def main(): if r is None: exit(-1) - r = callAPI(deviceset_url + "/channel", "POST", None, {"channelType": "NFMMod", "tx": 1}, "Create NFM mod") + r = callAPI(deviceset_url + "/channel", "POST", None, {"channelType": "NFMMod", "direction": 1}, "Create NFM mod") if r is None: exit(-1) diff --git a/swagger/sdrangel/examples/scanner.py b/swagger/sdrangel/examples/scanner.py index cd6e16634..4b8ef07a8 100755 --- a/swagger/sdrangel/examples/scanner.py +++ b/swagger/sdrangel/examples/scanner.py @@ -2,11 +2,11 @@ """ SDRangel REST API client script - + Simple scanner for AM and NFM channels. Builds an array of equally spaced channels. Moves device center frequency so that adjacent parts of the spectrum are scanned by the array of channels. Stops when any of the channels is active. Resumes when none of the channels is active. - + Uses /sdrangel/deviceset/{deviceSetIndex}/channels/report API to get channel information (since v3.13.1) """ @@ -178,7 +178,7 @@ def changeDeviceFrequency(fc, options): def setupChannels(scan_control, options): i = 0 for shift in scan_control.channel_shifts: - settings = callAPI(deviceset_url + "/channel", "POST", None, {"channelType": options.channel_id, "tx": 0}, "Create demod") + settings = callAPI(deviceset_url + "/channel", "POST", None, {"channelType": options.channel_id, "direction": 0}, "Create demod") if settings is None: exit(-1) @@ -314,11 +314,11 @@ def main(): if not options.rerun: # Skip device and channels settings in re-run mode if options.create: - r = callAPI("/deviceset", "POST", {"tx": 0}, None, "Add Rx device set") + r = callAPI("/deviceset", "POST", {"direction": 0}, None, "Add Rx device set") if r is None: exit(-1) - r = callAPI(deviceset_url + "/device", "PUT", None, {"hwType": options.device_hwid, "tx": 0}, "setup device on Rx device set") + r = callAPI(deviceset_url + "/device", "PUT", None, {"hwType": options.device_hwid, "direction": 0}, "setup device on Rx device set") if r is None: exit(-1) diff --git a/swagger/sdrangel/examples/test.json b/swagger/sdrangel/examples/test.json index 623afe3e8..a06aa2da1 100644 --- a/swagger/sdrangel/examples/test.json +++ b/swagger/sdrangel/examples/test.json @@ -32,7 +32,7 @@ "useReverseAPI": 0, "vgaGain": 24 }, - "tx": 0 + "direction": 0 }, "Setup HackRF on Rx 0" ], @@ -42,7 +42,7 @@ null, { "channelType": "RemoteSink", - "tx": 0 + "direction": 0 }, "Add a remote sink channel" ], @@ -67,7 +67,7 @@ "useReverseAPI": 0 }, "channelType": "RemoteSink", - "tx": 0 + "direction": 0 }, "Setup remote sink on channel 0" ], @@ -77,7 +77,7 @@ null, { "channelType": "RemoteSink", - "tx": 0 + "direction": 0 }, "Add a remote sink channel" ], @@ -102,7 +102,7 @@ "useReverseAPI": 0 }, "channelType": "RemoteSink", - "tx": 0 + "direction": 0 }, "Setup remote sink on channel 1" ], @@ -112,7 +112,7 @@ null, { "channelType": "RemoteSink", - "tx": 0 + "direction": 0 }, "Add a remote sink channel" ], @@ -137,7 +137,7 @@ "useReverseAPI": 0 }, "channelType": "RemoteSink", - "tx": 0 + "direction": 0 }, "Setup remote sink on channel 2" ], diff --git a/swagger/sdrangel/examples/tx_test.py b/swagger/sdrangel/examples/tx_test.py index b5c6ee8fe..749398b87 100755 --- a/swagger/sdrangel/examples/tx_test.py +++ b/swagger/sdrangel/examples/tx_test.py @@ -166,7 +166,7 @@ def setupDevice(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, "direction": 1}, "Create modulator") if r is None: exit(-1) @@ -266,14 +266,14 @@ def main(): base_url = "http://%s/sdrangel" % options.address if options.create: - r = callAPI("/deviceset", "POST", {"tx": 1}, None, "Add Tx device set") + r = callAPI("/deviceset", "POST", {"direction": 1}, None, "Add Tx device set") if r is None: exit(-1) global deviceset_url deviceset_url = "/deviceset/%d" % options.device_index - r = callAPI(deviceset_url + "/device", "PUT", None, {"hwType": "%s" % options.device_hwid, "tx": 1}, "setup device on Tx device set") + r = callAPI(deviceset_url + "/device", "PUT", None, {"hwType": "%s" % options.device_hwid, "direction": 1}, "setup device on Tx device set") if r is None: exit(-1)