From 3b9eae2893bbbaf320363c36f9b203c3ace6f331 Mon Sep 17 00:00:00 2001 From: Gertjan Date: Thu, 12 Mar 2026 23:41:59 +0100 Subject: [PATCH] Settings in config.yaml file --- config.yaml | 9 +++++++++ scanner.py | 39 ++++++++++++++++++++++----------------- 2 files changed, 31 insertions(+), 17 deletions(-) create mode 100644 config.yaml diff --git a/config.yaml b/config.yaml new file mode 100644 index 0000000..6e3e2c2 --- /dev/null +++ b/config.yaml @@ -0,0 +1,9 @@ +# Configuration file for scanner service +# it is automatically re-loaded between scans +start_freq: 10000.0 +stop_freq: 0.1 +freq_step_multiply: 0.95 +ampl: 1600 +interference_freq: 0.052 +interference_bandwidth: 0.008 +noise_scan: False diff --git a/scanner.py b/scanner.py index 8e17457..048c5d7 100644 --- a/scanner.py +++ b/scanner.py @@ -9,19 +9,11 @@ import time import pyodbc import math from datetime import datetime +import yaml +import os data_rows = [] # global 2-D list -state = { - "ampl": 1600, - "remaining_receive_lines": 0, - "freq": 10000.0, - "freq_step_multiply": 0.85, - "stop_freq": 0.1, - "interference_freq": 0.052, - "interference_bandwidth": 0.008, - "initializing": 1, - "noise_scan": False -} +state = {} PATTERN = re.compile( r"Va=(?P-?\d+\.?\d*)\s+" @@ -37,6 +29,19 @@ PATTERN = re.compile( r"(?P[0-9a-fA-F]+)" # Fourth hex ) +config_path = '/home/bart/python-scanner/config.yaml' + +def load_yaml_config(state_dict): + if os.path.exists(config_path): + with open(config_path, 'r') as f: + # Loader=yaml.SafeLoader is the secure way to load YAML + config_data = yaml.load(f, Loader=yaml.SafeLoader) + if config_data: + state_dict.update(config_data) + else: + print(f"Error: {config_path} not found.") + +# ============================================= # Database connection parameters conn_str = ( "DRIVER={FreeTDS};" @@ -293,14 +298,14 @@ if __name__ == "__main__": reader.connect() while True: data_rows.clear() - state["ampl"] = 1600; + + load_yaml_config(state) # Load configuration settings + + state["freq"] = state["start_freq"]; state["remaining_receive_lines"] = 0; - state["freq"] = 1000; - state["freq_step_multiply"] = 0.95; - state["stop_freq"] = 0.1; state["initializing"] = 1; - state["interference_freq"] = 0.052; - state["interference_bandwidth"] = 0.008 + reader.read_loop() + finally: reader.disconnect()