mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-22 08:04:49 -05:00
Moved ptt_active.py to the official scripts API directory
This commit is contained in:
parent
b09c43f6be
commit
4a6603f470
@ -27,3 +27,29 @@ Normal sequence of operations:
|
|||||||
- Start `freqtracking.py` in a terminal
|
- 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 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.
|
- 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.
|
||||||
|
|
||||||
|
<h2>ptt_active.py</h2>
|
||||||
|
|
||||||
|
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.
|
||||||
|
18
swagger/sdrangel/examples/ptt_active.py → scriptsapi/ptt_active.py
Normal file → Executable file
18
swagger/sdrangel/examples/ptt_active.py → scriptsapi/ptt_active.py
Normal file → Executable file
@ -36,7 +36,7 @@ def start_device(device_index, sdrangel_ip, sdrangel_port):
|
|||||||
base_url = f'http://{sdrangel_ip}:{sdrangel_port}/sdrangel'
|
base_url = f'http://{sdrangel_ip}:{sdrangel_port}/sdrangel'
|
||||||
dev_run_url = base_url + f'/deviceset/{device_index}/device/run'
|
dev_run_url = base_url + f'/deviceset/{device_index}/device/run'
|
||||||
r = requests.get(url=dev_run_url)
|
r = requests.get(url=dev_run_url)
|
||||||
if r.status_code / 100 == 2:
|
if r.status_code // 100 == 2:
|
||||||
rj = r.json()
|
rj = r.json()
|
||||||
state = rj.get("state", None)
|
state = rj.get("state", None)
|
||||||
if state is not None:
|
if state is not None:
|
||||||
@ -51,7 +51,7 @@ def start_device(device_index, sdrangel_ip, sdrangel_port):
|
|||||||
else:
|
else:
|
||||||
print(f'start_device: Cannot get device {device_index} running state')
|
print(f'start_device: Cannot get device {device_index} running state')
|
||||||
else:
|
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):
|
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'
|
base_url = f'http://{sdrangel_ip}:{sdrangel_port}/sdrangel'
|
||||||
dev_run_url = base_url + f'/deviceset/{device_index}/device/run'
|
dev_run_url = base_url + f'/deviceset/{device_index}/device/run'
|
||||||
r = requests.get(url=dev_run_url)
|
r = requests.get(url=dev_run_url)
|
||||||
if r.status_code / 100 == 2:
|
if r.status_code // 100 == 2:
|
||||||
rj = r.json()
|
rj = r.json()
|
||||||
state = rj.get("state", None)
|
state = rj.get("state", None)
|
||||||
if state is not None:
|
if state is not None:
|
||||||
@ -75,7 +75,7 @@ def stop_device(device_index, sdrangel_ip, sdrangel_port):
|
|||||||
else:
|
else:
|
||||||
print(f'stop_device: Cannot get device {device_index} running state')
|
print(f'stop_device: Cannot get device {device_index} running state')
|
||||||
else:
|
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):
|
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'
|
base_url = f'http://{sdrangel_ip}:{sdrangel_port}/sdrangel'
|
||||||
dev_focus_url = base_url + f'/deviceset/{device_index}/focus'
|
dev_focus_url = base_url + f'/deviceset/{device_index}/focus'
|
||||||
r = requests.patch(url=dev_focus_url)
|
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}')
|
print(f'set_focus: Focus set on device set {device_index}')
|
||||||
elif r.status_code == 400:
|
elif r.status_code == 400:
|
||||||
print(f'set_focus: Focus on device set is not supported in a server instance')
|
print(f'set_focus: Focus on device set is not supported in a server instance')
|
||||||
else:
|
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):
|
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'
|
base_url = f'http://{sdrangel_ip}:{sdrangel_port}/sdrangel'
|
||||||
r = requests.get(url=base_url + f'/deviceset/{device_index}/device/settings')
|
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()
|
rj = r.json()
|
||||||
frequency = get_center_frequency(rj)
|
frequency = get_center_frequency(rj)
|
||||||
if new_frequency != frequency:
|
if new_frequency != frequency:
|
||||||
@ -138,11 +138,11 @@ def set_center_frequency(new_frequency, device_index, sdrangel_ip, sdrangel_port
|
|||||||
FREQ_HAS_CHANGED = True
|
FREQ_HAS_CHANGED = True
|
||||||
return jsonify(rj)
|
return jsonify(rj)
|
||||||
else:
|
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:
|
else:
|
||||||
print(f'set_center_frequency: frequency of device {device_index} is unchanged')
|
print(f'set_center_frequency: frequency of device {device_index} is unchanged')
|
||||||
else:
|
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 ""
|
return ""
|
||||||
|
|
||||||
# ======================================================================
|
# ======================================================================
|
Loading…
Reference in New Issue
Block a user