From 4a6603f47065e727bb95b24fbc88580d7dab223f Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 28 May 2019 08:57:27 +0200 Subject: [PATCH] Moved ptt_active.py to the official scripts API directory --- scriptsapi/Readme.md | 26 +++++++++++++++++++ .../examples => scriptsapi}/ptt_active.py | 18 ++++++------- 2 files changed, 35 insertions(+), 9 deletions(-) rename {swagger/sdrangel/examples => scriptsapi}/ptt_active.py (95%) mode change 100644 => 100755 diff --git a/scriptsapi/Readme.md b/scriptsapi/Readme.md index 3d0662844..b90086ee0 100644 --- a/scriptsapi/Readme.md +++ b/scriptsapi/Readme.md @@ -27,3 +27,29 @@ Normal sequence of operations: - Start `freqtracking.py` in a terminal - In SDRangel connect the Frequency Tracker plugin by clicking on the grey square at the left of the top bar of the Frequency Tracker GUI. It opens the channel settings dialog. Check the 'Reverse API' box. Next to this box is the address and port at which the channel will be connected. If you use the defaults for `freqtracking.py` you may leave it as it is else you have to adjust it to the address and port of `freqtracking.py` (options `-A` and `-P`). - In the same manner connect the channel you want to be controlled by `freqtracking.py`. You may connect any number of channels like this. When a channel is removed `freqtracking.py` will automatically remove it from its list at the first attempt to synchronize that will fail. + +

ptt_active.py

+ +PTT (Push To Talk) actively listening system. For a pair of given device set indexes it actively listens to start and stop commands on the corresponding devices to swich over to the other + +Options are: + + - `-h` or `--help` show help message and exit + - `-A` or `--address` listening IP address. Default `0.0.0.0` (all interfaces) + - `-P` or `--port` listening port. Default `8000` + - `-p` or `--port-sdr` SDRangel instance REST API listening port. Default `8091` + - `-l` or `--link` Pair of indexes of the device sets to link. Default `0 1` + - `-d` or `--delay` Switch over delay in seconds. Default `1` + - `-f` or `--freq-sync` Synchronize devices center frequencies + +Normal sequence of operations: + +In this example we have a Rx device on index 0 and a Tx device on index 1. All settings are assumed to be the default settings. + + - Start `ptt_active.py` in a terminal + - On the Rx device right click on the start/stop button and activate reverse API at address `127.0.0.1` port `8000` (default) + - On the Tx device right click on the start/stop button and activate reverse API at address `127.0.0.1` port `8000` (default) + - Start the Rx or Tx device + - Stop the running device (Rx or Tx) this will switch over automatically to the other + +Important: you should initiate switch over by stopping the active device and not by starting the other. diff --git a/swagger/sdrangel/examples/ptt_active.py b/scriptsapi/ptt_active.py old mode 100644 new mode 100755 similarity index 95% rename from swagger/sdrangel/examples/ptt_active.py rename to scriptsapi/ptt_active.py index 310f2dfc5..11b848025 --- a/swagger/sdrangel/examples/ptt_active.py +++ b/scriptsapi/ptt_active.py @@ -36,7 +36,7 @@ def start_device(device_index, sdrangel_ip, sdrangel_port): base_url = f'http://{sdrangel_ip}:{sdrangel_port}/sdrangel' dev_run_url = base_url + f'/deviceset/{device_index}/device/run' r = requests.get(url=dev_run_url) - if r.status_code / 100 == 2: + if r.status_code // 100 == 2: rj = r.json() state = rj.get("state", None) if state is not None: @@ -51,7 +51,7 @@ def start_device(device_index, sdrangel_ip, sdrangel_port): else: print(f'start_device: Cannot get device {device_index} running state') else: - print(f'start_device: Error getting device {device_index} running state') + print(f'start_device: Error {r.status_code} getting device {device_index} running state') # ====================================================================== def stop_device(device_index, sdrangel_ip, sdrangel_port): @@ -60,7 +60,7 @@ def stop_device(device_index, sdrangel_ip, sdrangel_port): base_url = f'http://{sdrangel_ip}:{sdrangel_port}/sdrangel' dev_run_url = base_url + f'/deviceset/{device_index}/device/run' r = requests.get(url=dev_run_url) - if r.status_code / 100 == 2: + if r.status_code // 100 == 2: rj = r.json() state = rj.get("state", None) if state is not None: @@ -75,7 +75,7 @@ def stop_device(device_index, sdrangel_ip, sdrangel_port): else: print(f'stop_device: Cannot get device {device_index} running state') else: - print(f'stop_device: Error getting device {device_index} running state') + print(f'stop_device: Error {r.status_code} getting device {device_index} running state') # ====================================================================== def set_focus(device_index, sdrangel_ip, sdrangel_port): @@ -84,12 +84,12 @@ def set_focus(device_index, sdrangel_ip, sdrangel_port): base_url = f'http://{sdrangel_ip}:{sdrangel_port}/sdrangel' dev_focus_url = base_url + f'/deviceset/{device_index}/focus' r = requests.patch(url=dev_focus_url) - if r.status_code / 100 == 2: + if r.status_code // 100 == 2: print(f'set_focus: Focus set on device set {device_index}') elif r.status_code == 400: print(f'set_focus: Focus on device set is not supported in a server instance') else: - print(f'set_focus: Error setting focus on device set {device_index}') + print(f'set_focus: Error {r.status_code} setting focus on device set {device_index}') # ====================================================================== def get_sdrangel_ip(request): @@ -126,7 +126,7 @@ def set_center_frequency(new_frequency, device_index, sdrangel_ip, sdrangel_port # ---------------------------------------------------------------------- base_url = f'http://{sdrangel_ip}:{sdrangel_port}/sdrangel' r = requests.get(url=base_url + f'/deviceset/{device_index}/device/settings') - if r.status_code / 100 == 2: + if r.status_code // 100 == 2: rj = r.json() frequency = get_center_frequency(rj) if new_frequency != frequency: @@ -138,11 +138,11 @@ def set_center_frequency(new_frequency, device_index, sdrangel_ip, sdrangel_port FREQ_HAS_CHANGED = True return jsonify(rj) else: - print(f'set_center_frequency: failed to change center frequency of device {device_index}. HTTP error {r.status_code}') + print(f'set_center_frequency: failed to change center frequency of device {device_index} with error {r.status_code}') else: print(f'set_center_frequency: frequency of device {device_index} is unchanged') else: - print(f'set_center_frequency: error getting settings for device {device_index}. HTTP error {r.status_code}') + print(f'set_center_frequency: error {r.status_code} getting settings for device {device_index}') return "" # ======================================================================