diff --git a/config.yaml b/config.yaml index 6e3e2c2..5a2cb4e 100644 --- a/config.yaml +++ b/config.yaml @@ -1,9 +1,9 @@ # Configuration file for scanner service # it is automatically re-loaded between scans -start_freq: 10000.0 -stop_freq: 0.1 +start_freq: 1000 +stop_freq: 0.2 freq_step_multiply: 0.95 +allowed_noise_level: 9 +skip_scans_for_noisy_freqs: 5 ampl: 1600 -interference_freq: 0.052 -interference_bandwidth: 0.008 noise_scan: False diff --git a/scanner.py b/scanner.py index 2fecf56..0e952c9 100644 --- a/scanner.py +++ b/scanner.py @@ -14,6 +14,8 @@ import os data_rows = [] # global 2-D list state = {} +blacklist = [] +Inoise_baseline = 0.1 PATTERN = re.compile( r"Va=(?P-?\d+\.?\d*)\s+" @@ -196,24 +198,27 @@ class TelnetReader: except KeyboardInterrupt: print("Interrupted by user.") print(data_rows) - if state["freq"]>0.00001: # check if scan endeed normally (e.g. no abort due to clipping) - #dump_csv("measurements.csv") - dump_into_database() - #append_line_to_file(0, "scan_freq.csv") - #append_line_to_file(1, "scan_Va.csv") - #append_line_to_file(2, "scan_Vp.csv") - #append_line_to_file(3, "scan_Ia.csv") - #append_line_to_file(4, "scan_Ip.csv") - #append_line_to_file(5, "scan_ZR.csv") - #append_line_to_file(6, "scan_ZX.csv") - #append_Nyquist_run("scan_Nyquist.csv") - #state["noise_scan"] = not state["noise_scan"] + if state["freq"]>0.00001: # check if scan ended normally (e.g. no abort due to clipping) + if True: # XXXDB + dump_into_database() + else: + dump_csv("measurements.csv") + #append_line_to_file(0, "scan_freq.csv") + #append_line_to_file(1, "scan_Va.csv") + #append_line_to_file(2, "scan_Vp.csv") + #append_line_to_file(3, "scan_Ia.csv") + #append_line_to_file(4, "scan_Ip.csv") + #append_line_to_file(5, "scan_ZR.csv") + #append_line_to_file(6, "scan_ZX.csv") + #append_Nyquist_run("scan_Nyquist.csv") + #state["noise_scan"] = not state["noise_scan"] else: print("scan aborted\r") gc.collect() # clean up internal memory (garbage collect) def process_line(self, line): global state + global Inoise_baseline # print(f"RAW: {line}") if not line.startswith("Va="): # skip lines that are not to be analyzed return @@ -236,12 +241,17 @@ class TelnetReader: # there will be a lot of lines, but they will be skipped as they do not match the pattern else: # regular loop (not initializing) extract_to_dataframe(line) # capture the measurement -# print(f"minmax: {data_rows[7]},{data_rows[8]},{data_rows[9]},{data_rows[10] }\n") - if data_rows and (data_rows[-1][7]<5 or data_rows[-1][8]>250 or data_rows[-1][9]<5 or data_rows[-1][10]>250): - #response = f"a{state["ampl"]:.1f}\r" # send ampl to trigger sweep - #self.tn.write(response.encode("utf-8")) - # there will be a lot of lines, but they will be skipped as they do not match the pattern - state["freq"] = 0 # force ending of the scan, and write no data in the database + if state["freq"]>3.0: + Inoise_baseline = 0.8*Inoise_baseline + 0.2*data_rows[-1][12] # remember last baseline around 3Hz (assuming top-down scanning) + if data_rows and (data_rows[-1][11]>state["allowed_noise_level"] or data_rows[-1][12]>state["allowed_noise_level"] or (state["freq"]<3.0 and data_rows[-1][12]>1.25*Inoise_baseline)): + # Too much noise: add to blacklist + print("Too much noise - adding to blacklist") + blacklist.append({"Freq": state["freq"], "NrToSkip": state["skip_scans_for_noisy_freqs"]}) + print(f"Blacklist: {blacklist}\r") + del data_rows[-1] # remove this last entry from the list (for DB it is okay, but for CSV things will shift) + else: + if data_rows and (data_rows[-1][7]<5 or data_rows[-1][8]>250 or data_rows[-1][9]<5 or data_rows[-1][10]>250): # XXXDB + state["freq"] = 0 # force ending of the scan, and write no data in the database # calculate next freq if state["freq"] > 1.0: freq_multiplier = state["freq_step_multiply"] # calc next freq @@ -302,6 +312,11 @@ if __name__ == "__main__": state["initializing"] = 1; reader.read_loop() + # decrement all freq's in blacklist: + for item in blacklist: + item["NrToSkip"] -= 1 + blacklist = [item for item in blacklist if item["NrToSkip"] != 0] # remove all zero items + print(f"Blacklist: {blacklist}") finally: reader.disconnect()