From 12d1010da9f3e790db896da4c576a2ed9b40cb4d Mon Sep 17 00:00:00 2001 From: Mashintime Date: Mon, 12 Feb 2024 16:17:24 -0500 Subject: [PATCH 01/12] Bump version --- gui/package.json | 2 +- modem/server.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gui/package.json b/gui/package.json index d165507e..ac0b4088 100644 --- a/gui/package.json +++ b/gui/package.json @@ -2,7 +2,7 @@ "name": "FreeDATA", "description": "FreeDATA Client application for connecting to FreeDATA server", "private": true, - "version": "0.13.4-alpha", + "version": "0.13.5-alpha", "main": "dist-electron/main/index.js", "scripts": { "start": "vite", diff --git a/modem/server.py b/modem/server.py index 3fb046f4..43b4e8ee 100644 --- a/modem/server.py +++ b/modem/server.py @@ -29,7 +29,7 @@ app = Flask(__name__) CORS(app) CORS(app, resources={r"/*": {"origins": "*"}}) sock = Sock(app) -MODEM_VERSION = "0.13.4-alpha" +MODEM_VERSION = "0.13.5-alpha" # set config file to use def set_config(): From 0e1986b2da283d4850bdfd9d785c480a15806c21 Mon Sep 17 00:00:00 2001 From: DJ2LS <75909252+DJ2LS@users.noreply.github.com> Date: Wed, 14 Feb 2024 09:13:39 +0100 Subject: [PATCH 02/12] removed possibly obsolete arq state at wrong position --- modem/arq_session.py | 1 - 1 file changed, 1 deletion(-) diff --git a/modem/arq_session.py b/modem/arq_session.py index 4fd424d4..8bae69af 100644 --- a/modem/arq_session.py +++ b/modem/arq_session.py @@ -98,7 +98,6 @@ class ARQSession(): if isinstance(received_data, bytearray) and isinstance(type_byte, int): self.arq_data_type_handler.dispatch(type_byte, received_data) - self.states.setARQ(False) return self.log(f"Ignoring unknown transition from state {self.state.name} with frame {frame['frame_type']}") From 4f50b802acabe414e3eef6e9cca88533fc6cd8a8 Mon Sep 17 00:00:00 2001 From: DJ2LS <75909252+DJ2LS@users.noreply.github.com> Date: Wed, 14 Feb 2024 09:27:20 +0100 Subject: [PATCH 03/12] adjusted state manager in data type handler --- modem/arq_data_type_handler.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/modem/arq_data_type_handler.py b/modem/arq_data_type_handler.py index 4de79f13..8745056a 100644 --- a/modem/arq_data_type_handler.py +++ b/modem/arq_data_type_handler.py @@ -54,6 +54,9 @@ class ARQDataTypeHandler: def dispatch(self, type_byte: int, data: bytearray): session_type = self.get_session_type_from_value(type_byte) + + self.state_manager.setARQ(False) + if session_type and session_type in self.handlers and 'handle' in self.handlers[session_type]: return self.handlers[session_type]['handle'](data) else: @@ -61,6 +64,9 @@ class ARQDataTypeHandler: def failed(self, type_byte: int, data: bytearray): session_type = self.get_session_type_from_value(type_byte) + + self.state_manager.setARQ(False) + if session_type in self.handlers and 'failed' in self.handlers[session_type]: return self.handlers[session_type]['failed'](data) else: @@ -74,6 +80,9 @@ class ARQDataTypeHandler: def transmitted(self, type_byte: int, data: bytearray): session_type = self.get_session_type_from_value(type_byte) + + self.state_manager.setARQ(False) + if session_type in self.handlers and 'transmitted' in self.handlers[session_type]: return self.handlers[session_type]['transmitted'](data) else: From b569cbc3156900a6561a24ad0a62e5e6ddc4d482 Mon Sep 17 00:00:00 2001 From: DJ2LS <75909252+DJ2LS@users.noreply.github.com> Date: Wed, 14 Feb 2024 16:20:00 +0100 Subject: [PATCH 04/12] adjusted a rigctld command --- modem/rigctld.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modem/rigctld.py b/modem/rigctld.py index 79ca0108..471d7469 100644 --- a/modem/rigctld.py +++ b/modem/rigctld.py @@ -246,12 +246,16 @@ class radio: if not should_ignore(config.get('serial_dcd', "0")): args += ['--set-dcd', config['serial_dcd']] if not should_ignore(config.get('serial_dtr', "0")): - args += ['--set-dtr', config['serial_dtr']] + args += ['--set-conf', f'dtr_state={config["serial_dtr"]}'] - # Handling Stop Bits with the corrected --set-conf syntax + # Handling Data Bits and Stop Bits + if not should_ignore(config.get('data_bits', "0")): + args += ['--set-conf', f'data_bits={config["data_bits"]}'] if not should_ignore(config.get('stop_bits', "0")): args += ['--set-conf', f'stop_bits={config["stop_bits"]}'] + # Fixme #rts_state + # Handle custom arguments for rigctld # Custom args are split via ' ' so python doesn't add extranaeous quotes on windows args += config_rigctld["arguments"].split(" ") From 8d47d4890eb1d829d2a94c914ed8643c43ef7978 Mon Sep 17 00:00:00 2001 From: DJ2LS <75909252+DJ2LS@users.noreply.github.com> Date: Wed, 14 Feb 2024 16:29:18 +0100 Subject: [PATCH 05/12] removed rigctld typo --- modem/rigctld.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/modem/rigctld.py b/modem/rigctld.py index 471d7469..fc4628dd 100644 --- a/modem/rigctld.py +++ b/modem/rigctld.py @@ -229,29 +229,29 @@ class radio: return value in ['ignore', 0] # Model ID, Serial Port, and Speed - if not should_ignore(config.get('model_id', "0")): + if not should_ignore(config.get('model_id')): args += ['-m', str(config['model_id'])] - if not should_ignore(config.get('serial_port', "0")): + if not should_ignore(config.get('serial_port')): args += ['-r', config['serial_port']] - if not should_ignore(config.get('serial_speed', "0")): + if not should_ignore(config.get('serial_speed')): args += ['-s', str(config['serial_speed'])] # PTT Port and Type - if not should_ignore(config.get('ptt_port', "0")): + if not should_ignore(config.get('ptt_port')): args += ['--ptt-port', config['ptt_port']] - if not should_ignore(config.get('ptt_type', "0")): + if not should_ignore(config.get('ptt_type')): args += ['--ptt-type', config['ptt_type']] # Serial DCD and DTR - if not should_ignore(config.get('serial_dcd', "0")): + if not should_ignore(config.get('serial_dcd')): args += ['--set-dcd', config['serial_dcd']] - if not should_ignore(config.get('serial_dtr', "0")): + if not should_ignore(config.get('serial_dtr')): args += ['--set-conf', f'dtr_state={config["serial_dtr"]}'] # Handling Data Bits and Stop Bits - if not should_ignore(config.get('data_bits', "0")): + if not should_ignore(config.get('data_bits')): args += ['--set-conf', f'data_bits={config["data_bits"]}'] - if not should_ignore(config.get('stop_bits', "0")): + if not should_ignore(config.get('stop_bits')): args += ['--set-conf', f'stop_bits={config["stop_bits"]}'] # Fixme #rts_state From 916c2a4a634a93f51079b0e9fe1fde3793b679fa Mon Sep 17 00:00:00 2001 From: DJ2LS <75909252+DJ2LS@users.noreply.github.com> Date: Wed, 14 Feb 2024 16:45:19 +0100 Subject: [PATCH 06/12] delete beacons older than 2 days --- modem/schedule_manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modem/schedule_manager.py b/modem/schedule_manager.py index 93b62823..2bc22adf 100644 --- a/modem/schedule_manager.py +++ b/modem/schedule_manager.py @@ -70,7 +70,7 @@ class ScheduleManager: cmd.run(self.event_manager, self.modem) def delete_beacons(self): - DatabaseManagerBeacon(self.event_manager).beacon_cleanup_older_than_days(14) + DatabaseManagerBeacon(self.event_manager).beacon_cleanup_older_than_days(2) def push_to_explorer(self): self.config = self.config_manager.read() From fc055671cbdb06583f680fa67208cfdcbe24e7d9 Mon Sep 17 00:00:00 2001 From: Mashintime Date: Sat, 17 Feb 2024 10:41:09 -0500 Subject: [PATCH 07/12] Adjustments to rigctld arguments --- modem/rigctld.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modem/rigctld.py b/modem/rigctld.py index fc4628dd..0d988a9d 100644 --- a/modem/rigctld.py +++ b/modem/rigctld.py @@ -244,7 +244,7 @@ class radio: # Serial DCD and DTR 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')): args += ['--set-conf', f'dtr_state={config["serial_dtr"]}'] @@ -255,6 +255,8 @@ class radio: args += ['--set-conf', f'stop_bits={config["stop_bits"]}'] # 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 # Custom args are split via ' ' so python doesn't add extranaeous quotes on windows From 7eaac1cc298b2af57f6b3e0c4f4f57e7991fbd41 Mon Sep 17 00:00:00 2001 From: Mashintime Date: Sat, 17 Feb 2024 11:03:59 -0500 Subject: [PATCH 08/12] Fix typos/remove rts --- modem/rigctld.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/modem/rigctld.py b/modem/rigctld.py index 9b171c18..7e987d18 100644 --- a/modem/rigctld.py +++ b/modem/rigctld.py @@ -244,8 +244,7 @@ class radio: # Serial DCD and DTR if not should_ignore(config.get('serial_dcd')): - - args += ['--dcd-type', config['serial_dcd']] + args += ['--dcd-type', config.get('serial_dcd')] if not should_ignore(config.get('serial_dtr')): args += ['--set-conf', f'dtr_state={config["serial_dtr"]}'] @@ -257,9 +256,8 @@ class radio: args += ['--set-conf', f'stop_bits={config["stop_bits"]}'] # Fixme #rts_state - - if not should_ignore(config.get('rts_state')): - args += ['--set-conf', f'stop_bits={config["rts_state"]}'] + # if not should_ignore(config.get('rts_state')): + # args += ['--set-conf', f'stop_bits={config["rts_state"]}'] # Handle custom arguments for rigctld # Custom args are split via ' ' so python doesn't add extranaeous quotes on windows From c26f9cb9ba4f23bfd21ba2c0568800e5d108979f Mon Sep 17 00:00:00 2001 From: Mashintime Date: Sat, 17 Feb 2024 12:55:10 -0500 Subject: [PATCH 09/12] Incr Next Version --- gui/package.json | 2 +- modem/server.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gui/package.json b/gui/package.json index ac0b4088..34cc15e2 100644 --- a/gui/package.json +++ b/gui/package.json @@ -2,7 +2,7 @@ "name": "FreeDATA", "description": "FreeDATA Client application for connecting to FreeDATA server", "private": true, - "version": "0.13.5-alpha", + "version": "0.13.6-alpha", "main": "dist-electron/main/index.js", "scripts": { "start": "vite", diff --git a/modem/server.py b/modem/server.py index 43b4e8ee..00ef9f86 100644 --- a/modem/server.py +++ b/modem/server.py @@ -29,7 +29,7 @@ app = Flask(__name__) CORS(app) CORS(app, resources={r"/*": {"origins": "*"}}) sock = Sock(app) -MODEM_VERSION = "0.13.5-alpha" +MODEM_VERSION = "0.13.6-alpha" # set config file to use def set_config(): From 404585ebe02187f9fa9ade7a86b108e4857c9bd0 Mon Sep 17 00:00:00 2001 From: DJ2LS Date: Sat, 17 Feb 2024 20:42:07 +0100 Subject: [PATCH 10/12] auto update server config --- modem/config.py | 62 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 5 deletions(-) diff --git a/modem/config.py b/modem/config.py index 62851a68..d156c166 100644 --- a/modem/config.py +++ b/modem/config.py @@ -56,7 +56,6 @@ class CONFIG: 'enable_protocol': bool, }, 'MODEM': { - 'enable_fft': bool, 'tuning_range_fmax': int, 'tuning_range_fmin': int, 'enable_fsk': bool, @@ -73,7 +72,7 @@ class CONFIG: def __init__(self, configfile: str): # set up logger - self.log = structlog.get_logger("CONFIG") + self.log = structlog.get_logger(type(self).__name__) # init configparser self.parser = configparser.ConfigParser(inline_comment_prefixes="#", allow_no_value=True) @@ -88,6 +87,9 @@ class CONFIG: # check if config file exists self.config_exists() + # validate config structure + self.validate_config() + def config_exists(self): """ check if config file exists @@ -99,7 +101,7 @@ class CONFIG: return False # Validates config data - def validate(self, data): + def validate_data(self, data): for section in data: for setting in data[section]: if not isinstance(data[section][setting], self.config_types[section][setting]): @@ -107,6 +109,53 @@ class CONFIG: f" '{data[section][setting]}' {type(data[section][setting])} given.") 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.get_default_value_for_type(value_type) + self.parser.set(section, setting, str(default_value)) + self.log.info(f"[CFG] Adding missing setting: {section}.{setting}") + + self.write_to_file() + + def get_default_value_for_type(self, value_type): + """ + Returns a default value for the given type. + """ + if value_type == list: + return '[]' # Empty list in JSON format + elif value_type == bool: + return 'False' + elif value_type == int: + return '0' + elif value_type == str: + return '' + else: + return None # You might want to handle more types or throw an error + # Handle special setting data type conversion # is_writing means data from a dict being writen to the config file # if False, it means the opposite direction @@ -132,7 +181,7 @@ class CONFIG: # Sets and writes config data from a dict containing data settings def write(self, data): # Validate config data before writing - self.validate(data) + self.validate_data(data) for section in data: # init section if it doesn't exist yet @@ -143,7 +192,10 @@ class CONFIG: new_value = self.handle_setting( section, setting, data[section][setting], True) self.parser[section][setting] = str(new_value) - + + self.write_to_file() + + def write_to_file(self): # Write config data to file try: with open(self.config_name, 'w') as configfile: From 657a6a896709ea0803eecd91432100f9b27b2047 Mon Sep 17 00:00:00 2001 From: DJ2LS Date: Sat, 17 Feb 2024 20:45:51 +0100 Subject: [PATCH 11/12] default values as list --- modem/config.py | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/modem/config.py b/modem/config.py index d156c166..b9e20636 100644 --- a/modem/config.py +++ b/modem/config.py @@ -69,6 +69,13 @@ class CONFIG: }, } + default_values = { + list: '[]', + bool: 'False', + int: '0', + str: '', + } + def __init__(self, configfile: str): # set up logger @@ -135,26 +142,14 @@ class CONFIG: 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.get_default_value_for_type(value_type) + 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() - def get_default_value_for_type(self, value_type): - """ - Returns a default value for the given type. - """ - if value_type == list: - return '[]' # Empty list in JSON format - elif value_type == bool: - return 'False' - elif value_type == int: - return '0' - elif value_type == str: - return '' - else: - return None # You might want to handle more types or throw an error + # Handle special setting data type conversion # is_writing means data from a dict being writen to the config file From 5bee82a17c979cd32559f0417a15057e105fe976 Mon Sep 17 00:00:00 2001 From: Mashintime Date: Sat, 17 Feb 2024 16:57:54 -0500 Subject: [PATCH 12/12] Further adjustment --- modem/rigctld.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modem/rigctld.py b/modem/rigctld.py index 7e987d18..be112cdc 100644 --- a/modem/rigctld.py +++ b/modem/rigctld.py @@ -244,7 +244,7 @@ class radio: # Serial DCD and DTR if not should_ignore(config.get('serial_dcd')): - args += ['--dcd-type', config.get('serial_dcd')] + args += ['--dcd-type', config['serial_dcd']] if not should_ignore(config.get('serial_dtr')): args += ['--set-conf', f'dtr_state={config["serial_dtr"]}']