mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
RADIO MANAGER - WIP adjusted rigctld - set mode broken
This commit is contained in:
parent
baae3a5bb4
commit
4a1b2849fa
|
@ -1,5 +1,7 @@
|
||||||
import socket
|
import socket
|
||||||
import structlog
|
import structlog
|
||||||
|
import time
|
||||||
|
import threading
|
||||||
|
|
||||||
class radio:
|
class radio:
|
||||||
"""rigctld (hamlib) communication class"""
|
"""rigctld (hamlib) communication class"""
|
||||||
|
@ -14,6 +16,8 @@ class radio:
|
||||||
|
|
||||||
self.connection = None
|
self.connection = None
|
||||||
self.connected = False
|
self.connected = False
|
||||||
|
self.await_response = threading.Event()
|
||||||
|
self.await_response.set()
|
||||||
|
|
||||||
self.parameters = {
|
self.parameters = {
|
||||||
'frequency': '---',
|
'frequency': '---',
|
||||||
|
@ -57,13 +61,20 @@ class radio:
|
||||||
|
|
||||||
def send_command(self, command) -> str:
|
def send_command(self, command) -> str:
|
||||||
if self.connected:
|
if self.connected:
|
||||||
|
# wait if we have another command awaiting its response...
|
||||||
|
self.await_response.wait()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
self.await_response = threading.Event()
|
||||||
self.connection.sendall(command.encode('utf-8') + b"\n")
|
self.connection.sendall(command.encode('utf-8') + b"\n")
|
||||||
response = self.connection.recv(1024)
|
response = self.connection.recv(1024)
|
||||||
|
self.await_response.set()
|
||||||
return response.decode('utf-8').strip()
|
return response.decode('utf-8').strip()
|
||||||
except Exception as err:
|
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
|
self.connected = False
|
||||||
|
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def set_ptt(self, state):
|
def set_ptt(self, state):
|
||||||
|
@ -176,7 +187,12 @@ class radio:
|
||||||
self.parameters['frequency'] = self.send_command('f')
|
self.parameters['frequency'] = self.send_command('f')
|
||||||
response = self.send_command(
|
response = self.send_command(
|
||||||
'm').strip() # Get the mode/bandwidth response and remove leading/trailing spaces
|
'm').strip() # Get the mode/bandwidth response and remove leading/trailing spaces
|
||||||
|
try:
|
||||||
mode, bandwidth = response.split('\n', 1) # Split the response into mode and bandwidth
|
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['mode'] = mode
|
||||||
self.parameters['bandwidth'] = bandwidth
|
self.parameters['bandwidth'] = bandwidth
|
||||||
|
|
|
@ -246,7 +246,7 @@ def post_modem_send_raw_stop():
|
||||||
def get_post_radio():
|
def get_post_radio():
|
||||||
if request.method in ['POST']:
|
if request.method in ['POST']:
|
||||||
app.radio_manager.set_frequency(request.json['radio_frequency'])
|
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)
|
return api_response(request.json)
|
||||||
elif request.method == 'GET':
|
elif request.method == 'GET':
|
||||||
|
|
Loading…
Reference in a new issue