mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 10:04:33 +02:00
Merge pull request #660 from DJ2LS/develop
adjusted rigctld and config handling
This commit is contained in:
commit
c64ea890d1
|
@ -2,7 +2,7 @@
|
|||
"name": "FreeDATA",
|
||||
"description": "FreeDATA Client application for connecting to FreeDATA server",
|
||||
"private": true,
|
||||
"version": "0.13.6-alpha",
|
||||
"version": "0.13.7-alpha",
|
||||
"main": "dist-electron/main/index.js",
|
||||
"scripts": {
|
||||
"start": "vite",
|
||||
|
|
|
@ -713,15 +713,16 @@ def get_flag(byte, flag_name, flag_dict):
|
|||
return get_bit(byte, position)
|
||||
|
||||
|
||||
def find_binary_path(binary_name="rigctld", search_system_wide=False):
|
||||
def find_binary_paths(binary_name="rigctld", search_system_wide=False):
|
||||
"""
|
||||
Search for a binary within the current working directory and its subdirectories.
|
||||
Optionally, check system-wide locations and PATH environment variable if not found.
|
||||
Search for a binary within the current working directory, its subdirectories, and optionally,
|
||||
system-wide locations and the PATH environment variable.
|
||||
|
||||
:param binary_name: The base name of the binary to search for, without extension.
|
||||
:param search_system_wide: Boolean flag to enable or disable system-wide search.
|
||||
:return: The full path to the binary if found, otherwise None.
|
||||
:return: A list of full paths to the binary if found, otherwise an empty list.
|
||||
"""
|
||||
binary_paths = [] # Initialize an empty list to store found paths
|
||||
# Adjust binary name for Windows
|
||||
if platform.system() == 'Windows':
|
||||
binary_name += ".exe"
|
||||
|
@ -730,7 +731,7 @@ def find_binary_path(binary_name="rigctld", search_system_wide=False):
|
|||
root_path = os.getcwd()
|
||||
for dirpath, dirnames, filenames in os.walk(root_path):
|
||||
if binary_name in filenames:
|
||||
return os.path.join(dirpath, binary_name)
|
||||
binary_paths.append(os.path.join(dirpath, binary_name))
|
||||
|
||||
# If system-wide search is enabled, look in system locations and PATH
|
||||
if search_system_wide:
|
||||
|
@ -739,13 +740,16 @@ def find_binary_path(binary_name="rigctld", search_system_wide=False):
|
|||
if platform.system() != 'Windows':
|
||||
system_paths.extend(['/usr/bin', '/usr/local/bin', '/bin'])
|
||||
else:
|
||||
system_paths.extend(glob.glob("C:\\Program Files\\Hamlib*\\bin"))
|
||||
system_paths.extend(glob.glob("C:\\Program Files (x86)\\Hamlib*\\bin"))
|
||||
|
||||
system_paths.extend(glob.glob("C:\\Program Files\\Hamlib*\\bin"))
|
||||
system_paths.extend(glob.glob("C:\\Program Files (x86)\\Hamlib*\\bin"))
|
||||
|
||||
for path in system_paths:
|
||||
potential_path = os.path.join(path, binary_name)
|
||||
if os.path.isfile(potential_path):
|
||||
return potential_path
|
||||
binary_paths.append(potential_path)
|
||||
|
||||
return binary_paths
|
||||
|
||||
|
||||
|
||||
def kill_and_execute(binary_path, additional_args=None):
|
||||
|
|
|
@ -76,7 +76,11 @@ class radio:
|
|||
self.connection.sendall(command.encode('utf-8') + b"\n")
|
||||
response = self.connection.recv(1024)
|
||||
self.await_response.set()
|
||||
return response.decode('utf-8').strip()
|
||||
stripped_result = response.decode('utf-8').strip()
|
||||
if 'RPRT' in stripped_result:
|
||||
return None
|
||||
return stripped_result
|
||||
|
||||
except Exception as err:
|
||||
self.log.warning(f"[RIGCTLD] Error sending command [{command}] to rigctld: {err}")
|
||||
self.connected = False
|
||||
|
@ -189,36 +193,93 @@ class radio:
|
|||
self.connect()
|
||||
|
||||
if self.connected:
|
||||
self.parameters['frequency'] = self.send_command('f')
|
||||
response = self.send_command(
|
||||
'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
|
||||
except ValueError:
|
||||
self.get_frequency()
|
||||
self.get_mode_bandwidth()
|
||||
self.get_alc()
|
||||
self.get_strength()
|
||||
self.get_rf()
|
||||
|
||||
return self.parameters
|
||||
|
||||
def get_frequency(self):
|
||||
try:
|
||||
frequency_response = self.send_command('f')
|
||||
self.parameters['frequency'] = frequency_response if frequency_response is not None else 'err'
|
||||
except Exception as e:
|
||||
self.log.warning(f"Error getting frequency: {e}")
|
||||
self.parameters['frequency'] = 'err'
|
||||
|
||||
def get_mode_bandwidth(self):
|
||||
try:
|
||||
response = self.send_command('m')
|
||||
if response is not None:
|
||||
response = response.strip()
|
||||
mode, bandwidth = response.split('\n', 1)
|
||||
else:
|
||||
mode = 'err'
|
||||
bandwidth = 'err'
|
||||
|
||||
except ValueError:
|
||||
mode = 'err'
|
||||
bandwidth = 'err'
|
||||
except Exception as e:
|
||||
self.log.warning(f"Error getting mode and bandwidth: {e}")
|
||||
mode = 'err'
|
||||
bandwidth = 'err'
|
||||
finally:
|
||||
self.parameters['mode'] = mode
|
||||
self.parameters['bandwidth'] = bandwidth
|
||||
|
||||
self.parameters['alc'] = self.send_command('l ALC')
|
||||
self.parameters['strength'] = self.send_command('l STRENGTH')
|
||||
self.parameters['rf'] = int(float(self.send_command('l RFPOWER')) * 100) # RF, RFPOWER
|
||||
def get_alc(self):
|
||||
try:
|
||||
alc_response = self.send_command('l ALC')
|
||||
self.parameters['alc'] = alc_response if alc_response is not None else 'err'
|
||||
except Exception as e:
|
||||
self.log.warning(f"Error getting ALC: {e}")
|
||||
self.parameters['alc'] = 'err'
|
||||
|
||||
"""Return the latest fetched parameters."""
|
||||
return self.parameters
|
||||
def get_strength(self):
|
||||
try:
|
||||
strength_response = self.send_command('l STRENGTH')
|
||||
self.parameters['strength'] = strength_response if strength_response is not None else 'err'
|
||||
except Exception as e:
|
||||
self.log.warning(f"Error getting strength: {e}")
|
||||
self.parameters['strength'] = 'err'
|
||||
|
||||
def get_rf(self):
|
||||
try:
|
||||
rf_response = self.send_command('l RFPOWER')
|
||||
if rf_response is not None:
|
||||
self.parameters['rf'] = int(float(rf_response) * 100)
|
||||
else:
|
||||
self.parameters['rf'] = 'err'
|
||||
except ValueError:
|
||||
self.parameters['rf'] = 'err'
|
||||
except Exception as e:
|
||||
self.log.warning(f"Error getting RF power: {e}")
|
||||
self.parameters['rf'] = 'err'
|
||||
|
||||
def start_service(self):
|
||||
binary_name = "rigctld"
|
||||
binary_path = helpers.find_binary_path(binary_name, search_system_wide=True)
|
||||
binary_paths = helpers.find_binary_paths(binary_name, search_system_wide=True)
|
||||
additional_args = self.format_rigctld_args()
|
||||
if binary_path:
|
||||
self.log.info(f"Rigctld binary found at: {binary_path}")
|
||||
helpers.kill_and_execute(binary_path, additional_args)
|
||||
self.log.info(f"Executed rigctld...")
|
||||
|
||||
if binary_paths:
|
||||
for binary_path in binary_paths:
|
||||
try:
|
||||
self.log.info(f"Attempting to start rigctld using binary found at: {binary_path}")
|
||||
helpers.kill_and_execute(binary_path, additional_args)
|
||||
self.log.info("Successfully executed rigctld.")
|
||||
break # Exit the loop after successful execution
|
||||
except Exception as e:
|
||||
pass
|
||||
# let's keep this hidden for the user to avoid confusion
|
||||
# self.log.warning(f"Failed to start rigctld with binary at {binary_path}: {e}")
|
||||
else:
|
||||
self.log.warning("Failed to start rigctld with all found binaries.", binaries=binary_paths)
|
||||
else:
|
||||
self.log.warning("Rigctld binary not found.")
|
||||
|
||||
|
||||
def format_rigctld_args(self):
|
||||
config = self.config['RADIO'] # Accessing the 'RADIO' section of the INI file
|
||||
config_rigctld = self.config['RIGCTLD'] # Accessing the 'RIGCTLD' section of the INI file for custom args
|
||||
|
|
|
@ -29,7 +29,7 @@ app = Flask(__name__)
|
|||
CORS(app)
|
||||
CORS(app, resources={r"/*": {"origins": "*"}})
|
||||
sock = Sock(app)
|
||||
MODEM_VERSION = "0.13.6-alpha"
|
||||
MODEM_VERSION = "0.13.7-alpha"
|
||||
|
||||
# set config file to use
|
||||
def set_config():
|
||||
|
@ -96,6 +96,10 @@ def index():
|
|||
@app.route('/config', methods=['GET', 'POST'])
|
||||
def config():
|
||||
if request.method in ['POST']:
|
||||
# check if config already exists
|
||||
if app.config_manager.read() == request.json:
|
||||
return api_response(request.json)
|
||||
|
||||
set_config = app.config_manager.write(request.json)
|
||||
if not set_config:
|
||||
response = api_response(None, 'error writing config')
|
||||
|
|
Loading…
Reference in a new issue