Settings in config.yaml file
This commit is contained in:
parent
8086e3298e
commit
3b9eae2893
2 changed files with 31 additions and 17 deletions
9
config.yaml
Normal file
9
config.yaml
Normal file
|
|
@ -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
|
||||
39
scanner.py
39
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<Va>-?\d+\.?\d*)\s+"
|
||||
|
|
@ -37,6 +29,19 @@ PATTERN = re.compile(
|
|||
r"(?P<adc_imax>[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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue