RADIO MANAGER - WIP adjusted rigctld - set mode broken

This commit is contained in:
DJ2LS 2024-01-12 17:00:28 +01:00
parent baae3a5bb4
commit 4a1b2849fa
2 changed files with 19 additions and 3 deletions

View file

@ -1,5 +1,7 @@
import socket
import structlog
import time
import threading
class radio:
"""rigctld (hamlib) communication class"""
@ -14,6 +16,8 @@ class radio:
self.connection = None
self.connected = False
self.await_response = threading.Event()
self.await_response.set()
self.parameters = {
'frequency': '---',
@ -57,13 +61,20 @@ class radio:
def send_command(self, command) -> str:
if self.connected:
# wait if we have another command awaiting its response...
self.await_response.wait()
try:
self.await_response = threading.Event()
self.connection.sendall(command.encode('utf-8') + b"\n")
response = self.connection.recv(1024)
self.await_response.set()
return response.decode('utf-8').strip()
except Exception as err:
self.log.warning(f"[RIGCTLD] Error sending command to rigctld: {err}")
self.log.warning(f"[RIGCTLD] Error sending command [{command}] to rigctld: {err}")
self.connected = False
return ""
def set_ptt(self, state):
@ -176,7 +187,12 @@ class radio:
self.parameters['frequency'] = self.send_command('f')
response = self.send_command(
'm').strip() # Get the mode/bandwidth response and remove leading/trailing spaces
mode, bandwidth = response.split('\n', 1) # Split the response into mode and bandwidth
try:
mode, bandwidth = response.split('\n', 1) # Split the response into mode and bandwidth
except ValueError:
print(response)
mode = 'err'
bandwidth = 'err'
self.parameters['mode'] = mode
self.parameters['bandwidth'] = bandwidth

View file

@ -246,7 +246,7 @@ def post_modem_send_raw_stop():
def get_post_radio():
if request.method in ['POST']:
app.radio_manager.set_frequency(request.json['radio_frequency'])
app.radio_manager.set_mode(request.json['radio_mode'])
#app.radio_manager.set_mode(request.json['radio_mode'])
return api_response(request.json)
elif request.method == 'GET':