Fixed bug of first scanned frequency

This commit is contained in:
gertjan 2026-03-27 13:21:15 +01:00
parent b07edd3839
commit 390dccedfe

View file

@ -189,7 +189,7 @@ class TelnetReader:
# Main loop: reads incoming lines forever # Main loop: reads incoming lines forever
try: try:
while state["freq"] > state["stop_freq"]: while state["freq"] > state["stop_freq"]:
if state["initializing"] == 1: if state["initializing"]>0:
self.process_line("Va=") self.process_line("Va=")
else: else:
line = self.tn.read_until(b"\n") # read line line = self.tn.read_until(b"\n") # read line
@ -240,43 +240,46 @@ class TelnetReader:
response = f"a{state["ampl"]:.1f}\r" # set amplitude response = f"a{state["ampl"]:.1f}\r" # set amplitude
self.tn.write(response.encode("utf-8")) 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 # there will be a lot of lines, but they will be skipped as they do not match the pattern
else: # regular loop (not initializing) state["initializing"] = 2
extract_to_dataframe(line) # capture the measurement else: # regular loop (initializing is 0 (normal) or 2 (first sample))
if state["freq"]>3.0: if state["initializing"] == 0:
Inoise_baseline = 0.8*Inoise_baseline + 0.2*data_rows[-1][12] # remember last baseline around 3Hz (assuming top-down scanning) extract_to_dataframe(line) # capture the measurement
if data_rows and (state["freq"]>10) 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)): if state["freq"]>3.0:
# Too much noise: add to blacklist Inoise_baseline = 0.8*Inoise_baseline + 0.2*data_rows[-1][12] # remember last baseline around 3Hz (assuming top-down scanning)
print("Too much noise - adding to blacklist") if data_rows and (state["freq"]>10) 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)):
blacklist.append({"Freq": state["freq"], "NrToSkip": state["skip_scans_for_noisy_freqs"]}) # Too much noise: add to blacklist
print(f"Blacklist: {blacklist}\r") print("Too much noise - adding to blacklist")
del data_rows[-1] # remove this last entry from the list (for DB it is okay, but for CSV things will shift) blacklist.append({"Freq": state["freq"], "NrToSkip": state["skip_scans_for_noisy_freqs"]})
else: print(f"Blacklist: {blacklist}\r")
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 del data_rows[-1] # remove this last entry from the list (for DB it is okay, but for CSV things will shift)
if (++n_clip_events > 2): # react only after multiple clip events (solves startup issue)
if data_rows[-1][9]>0: # make exception (for our broken hardware?)
state["freq"] = 0 # force ending of the scan, and write no data in the database
else: else:
n_clip_events=0 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
# calculate next freq if (++n_clip_events > 2): # react only after multiple clip events (solves startup issue)
if state["freq"] > 1.0: if data_rows[-1][9]>0: # make exception (for our broken hardware?)
freq_multiplier = state["freq_step_multiply"] # calc next freq state["freq"] = 0 # force ending of the scan, and write no data in the database
else: else:
if state["freq"] > 0.01: n_clip_events=0
freq_multiplier = state["freq_step_multiply"] ** 2 # skip 1/2 steps to speed up # calculate next freq
if state["freq"] > 1.0:
freq_multiplier = state["freq_step_multiply"] # calc next freq
else: else:
freq_multiplier = state["freq_step_multiply"] ** 4 # skip 3/4 steps to speed up if state["freq"] > 0.01:
state["freq"] *= freq_multiplier freq_multiplier = state["freq_step_multiply"] ** 2 # skip 1/2 steps to speed up
while (any(item["Freq"] == state["freq"] for item in blacklist)): else:
print("skipping freq") freq_multiplier = state["freq_step_multiply"] ** 4 # skip 3/4 steps to speed up
state["freq"] *= freq_multiplier # skip all frequencies that are blacklisted state["freq"] *= freq_multiplier
if state["freq"] <= state["stop_freq"]: while (any(item["Freq"] == state["freq"] for item in blacklist)):
print("Reached stop frequency") print("skipping freq")
else: state["freq"] *= freq_multiplier # skip all frequencies that are blacklisted
# program the health monitor to go to the next frequency:
response = f"\rQ{state["freq"]:.3f}\r" # new freq if state["freq"] <= state["stop_freq"]:
self.tn.write(response.encode("utf-8")) print("Reached stop frequency")
# print(state) else:
state["initializing"] = 0 # program the health monitor to go to the next frequency:
response = f"\rQ{state["freq"]:.3f}\r" # new freq
self.tn.write(response.encode("utf-8"))
# print(state)
state["initializing"] = 0
# Example: # Example:
# value = self.extract_value(line) # value = self.extract_value(line)