mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
Merge remote-tracking branch 'origin/develop' into dev-message-auto-repeat
This commit is contained in:
commit
25dedfde6c
4 changed files with 58 additions and 8 deletions
|
@ -2,7 +2,7 @@
|
||||||
"name": "FreeDATA",
|
"name": "FreeDATA",
|
||||||
"description": "FreeDATA Client application for connecting to FreeDATA server",
|
"description": "FreeDATA Client application for connecting to FreeDATA server",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.13.4-alpha",
|
"version": "0.13.6-alpha",
|
||||||
"main": "dist-electron/main/index.js",
|
"main": "dist-electron/main/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "vite",
|
"start": "vite",
|
||||||
|
|
|
@ -56,7 +56,6 @@ class CONFIG:
|
||||||
'enable_protocol': bool,
|
'enable_protocol': bool,
|
||||||
},
|
},
|
||||||
'MODEM': {
|
'MODEM': {
|
||||||
'enable_fft': bool,
|
|
||||||
'tuning_range_fmax': int,
|
'tuning_range_fmax': int,
|
||||||
'tuning_range_fmin': int,
|
'tuning_range_fmin': int,
|
||||||
'enable_fsk': bool,
|
'enable_fsk': bool,
|
||||||
|
@ -70,10 +69,17 @@ class CONFIG:
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default_values = {
|
||||||
|
list: '[]',
|
||||||
|
bool: 'False',
|
||||||
|
int: '0',
|
||||||
|
str: '',
|
||||||
|
}
|
||||||
|
|
||||||
def __init__(self, configfile: str):
|
def __init__(self, configfile: str):
|
||||||
|
|
||||||
# set up logger
|
# set up logger
|
||||||
self.log = structlog.get_logger("CONFIG")
|
self.log = structlog.get_logger(type(self).__name__)
|
||||||
|
|
||||||
# init configparser
|
# init configparser
|
||||||
self.parser = configparser.ConfigParser(inline_comment_prefixes="#", allow_no_value=True)
|
self.parser = configparser.ConfigParser(inline_comment_prefixes="#", allow_no_value=True)
|
||||||
|
@ -88,6 +94,9 @@ class CONFIG:
|
||||||
# check if config file exists
|
# check if config file exists
|
||||||
self.config_exists()
|
self.config_exists()
|
||||||
|
|
||||||
|
# validate config structure
|
||||||
|
self.validate_config()
|
||||||
|
|
||||||
def config_exists(self):
|
def config_exists(self):
|
||||||
"""
|
"""
|
||||||
check if config file exists
|
check if config file exists
|
||||||
|
@ -99,7 +108,7 @@ class CONFIG:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Validates config data
|
# Validates config data
|
||||||
def validate(self, data):
|
def validate_data(self, data):
|
||||||
for section in data:
|
for section in data:
|
||||||
for setting in data[section]:
|
for setting in data[section]:
|
||||||
if not isinstance(data[section][setting], self.config_types[section][setting]):
|
if not isinstance(data[section][setting], self.config_types[section][setting]):
|
||||||
|
@ -107,6 +116,41 @@ class CONFIG:
|
||||||
f" '{data[section][setting]}' {type(data[section][setting])} given.")
|
f" '{data[section][setting]}' {type(data[section][setting])} given.")
|
||||||
raise ValueError(message)
|
raise ValueError(message)
|
||||||
|
|
||||||
|
def validate_config(self):
|
||||||
|
"""
|
||||||
|
Updates the configuration file to match exactly what is defined in self.config_types.
|
||||||
|
It removes sections and settings not defined there and adds missing sections and settings.
|
||||||
|
"""
|
||||||
|
existing_sections = self.parser.sections()
|
||||||
|
|
||||||
|
# Remove sections and settings not defined in self.config_types
|
||||||
|
for section in existing_sections:
|
||||||
|
if section not in self.config_types:
|
||||||
|
self.parser.remove_section(section)
|
||||||
|
self.log.info(f"[CFG] Removing undefined section: {section}")
|
||||||
|
continue
|
||||||
|
existing_settings = self.parser.options(section)
|
||||||
|
for setting in existing_settings:
|
||||||
|
if setting not in self.config_types[section]:
|
||||||
|
self.parser.remove_option(section, setting)
|
||||||
|
self.log.info(f"[CFG] Removing undefined setting: {section}.{setting}")
|
||||||
|
|
||||||
|
# Add missing sections and settings from self.config_types
|
||||||
|
for section, settings in self.config_types.items():
|
||||||
|
if section not in existing_sections:
|
||||||
|
self.parser.add_section(section)
|
||||||
|
self.log.info(f"[CFG] Adding missing section: {section}")
|
||||||
|
for setting, value_type in settings.items():
|
||||||
|
if not self.parser.has_option(section, setting):
|
||||||
|
default_value = self.default_values.get(value_type, None)
|
||||||
|
|
||||||
|
self.parser.set(section, setting, str(default_value))
|
||||||
|
self.log.info(f"[CFG] Adding missing setting: {section}.{setting}")
|
||||||
|
|
||||||
|
self.write_to_file()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Handle special setting data type conversion
|
# Handle special setting data type conversion
|
||||||
# is_writing means data from a dict being writen to the config file
|
# is_writing means data from a dict being writen to the config file
|
||||||
# if False, it means the opposite direction
|
# if False, it means the opposite direction
|
||||||
|
@ -132,7 +176,7 @@ class CONFIG:
|
||||||
# Sets and writes config data from a dict containing data settings
|
# Sets and writes config data from a dict containing data settings
|
||||||
def write(self, data):
|
def write(self, data):
|
||||||
# Validate config data before writing
|
# Validate config data before writing
|
||||||
self.validate(data)
|
self.validate_data(data)
|
||||||
|
|
||||||
for section in data:
|
for section in data:
|
||||||
# init section if it doesn't exist yet
|
# init section if it doesn't exist yet
|
||||||
|
@ -143,7 +187,10 @@ class CONFIG:
|
||||||
new_value = self.handle_setting(
|
new_value = self.handle_setting(
|
||||||
section, setting, data[section][setting], True)
|
section, setting, data[section][setting], True)
|
||||||
self.parser[section][setting] = str(new_value)
|
self.parser[section][setting] = str(new_value)
|
||||||
|
|
||||||
|
self.write_to_file()
|
||||||
|
|
||||||
|
def write_to_file(self):
|
||||||
# Write config data to file
|
# Write config data to file
|
||||||
try:
|
try:
|
||||||
with open(self.config_name, 'w') as configfile:
|
with open(self.config_name, 'w') as configfile:
|
||||||
|
|
|
@ -244,7 +244,8 @@ class radio:
|
||||||
|
|
||||||
# Serial DCD and DTR
|
# Serial DCD and DTR
|
||||||
if not should_ignore(config.get('serial_dcd')):
|
if not should_ignore(config.get('serial_dcd')):
|
||||||
args += ['--set-dcd', config['serial_dcd']]
|
args += ['--dcd-type', config['serial_dcd']]
|
||||||
|
|
||||||
if not should_ignore(config.get('serial_dtr')):
|
if not should_ignore(config.get('serial_dtr')):
|
||||||
args += ['--set-conf', f'dtr_state={config["serial_dtr"]}']
|
args += ['--set-conf', f'dtr_state={config["serial_dtr"]}']
|
||||||
|
|
||||||
|
@ -255,6 +256,8 @@ class radio:
|
||||||
args += ['--set-conf', f'stop_bits={config["stop_bits"]}']
|
args += ['--set-conf', f'stop_bits={config["stop_bits"]}']
|
||||||
|
|
||||||
# Fixme #rts_state
|
# Fixme #rts_state
|
||||||
|
# if not should_ignore(config.get('rts_state')):
|
||||||
|
# args += ['--set-conf', f'stop_bits={config["rts_state"]}']
|
||||||
|
|
||||||
# Handle custom arguments for rigctld
|
# Handle custom arguments for rigctld
|
||||||
# Custom args are split via ' ' so python doesn't add extranaeous quotes on windows
|
# Custom args are split via ' ' so python doesn't add extranaeous quotes on windows
|
||||||
|
|
|
@ -29,7 +29,7 @@ app = Flask(__name__)
|
||||||
CORS(app)
|
CORS(app)
|
||||||
CORS(app, resources={r"/*": {"origins": "*"}})
|
CORS(app, resources={r"/*": {"origins": "*"}})
|
||||||
sock = Sock(app)
|
sock = Sock(app)
|
||||||
MODEM_VERSION = "0.13.4-alpha"
|
MODEM_VERSION = "0.13.6-alpha"
|
||||||
|
|
||||||
# set config file to use
|
# set config file to use
|
||||||
def set_config():
|
def set_config():
|
||||||
|
|
Loading…
Reference in a new issue