Fixed bug of first scanned frequency
This commit is contained in:
parent
b07edd3839
commit
390dccedfe
1 changed files with 39 additions and 36 deletions
75
scanner.py
75
scanner.py
|
|
@ -189,7 +189,7 @@ class TelnetReader:
|
|||
# Main loop: reads incoming lines forever
|
||||
try:
|
||||
while state["freq"] > state["stop_freq"]:
|
||||
if state["initializing"] == 1:
|
||||
if state["initializing"]>0:
|
||||
self.process_line("Va=")
|
||||
else:
|
||||
line = self.tn.read_until(b"\n") # read line
|
||||
|
|
@ -240,43 +240,46 @@ class TelnetReader:
|
|||
response = f"a{state["ampl"]:.1f}\r" # set amplitude
|
||||
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
|
||||
else: # regular loop (not initializing)
|
||||
extract_to_dataframe(line) # capture the measurement
|
||||
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 (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)):
|
||||
# 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
|
||||
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
|
||||
state["initializing"] = 2
|
||||
else: # regular loop (initializing is 0 (normal) or 2 (first sample))
|
||||
if state["initializing"] == 0:
|
||||
extract_to_dataframe(line) # capture the measurement
|
||||
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 (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)):
|
||||
# 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:
|
||||
n_clip_events=0
|
||||
# calculate next freq
|
||||
if state["freq"] > 1.0:
|
||||
freq_multiplier = state["freq_step_multiply"] # calc next freq
|
||||
else:
|
||||
if state["freq"] > 0.01:
|
||||
freq_multiplier = state["freq_step_multiply"] ** 2 # skip 1/2 steps to speed up
|
||||
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
|
||||
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:
|
||||
n_clip_events=0
|
||||
# calculate next freq
|
||||
if state["freq"] > 1.0:
|
||||
freq_multiplier = state["freq_step_multiply"] # calc next freq
|
||||
else:
|
||||
freq_multiplier = state["freq_step_multiply"] ** 4 # skip 3/4 steps to speed up
|
||||
state["freq"] *= freq_multiplier
|
||||
while (any(item["Freq"] == state["freq"] for item in blacklist)):
|
||||
print("skipping freq")
|
||||
state["freq"] *= freq_multiplier # skip all frequencies that are blacklisted
|
||||
if state["freq"] <= state["stop_freq"]:
|
||||
print("Reached stop frequency")
|
||||
else:
|
||||
# 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
|
||||
if state["freq"] > 0.01:
|
||||
freq_multiplier = state["freq_step_multiply"] ** 2 # skip 1/2 steps to speed up
|
||||
else:
|
||||
freq_multiplier = state["freq_step_multiply"] ** 4 # skip 3/4 steps to speed up
|
||||
state["freq"] *= freq_multiplier
|
||||
while (any(item["Freq"] == state["freq"] for item in blacklist)):
|
||||
print("skipping freq")
|
||||
state["freq"] *= freq_multiplier # skip all frequencies that are blacklisted
|
||||
|
||||
if state["freq"] <= state["stop_freq"]:
|
||||
print("Reached stop frequency")
|
||||
else:
|
||||
# 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:
|
||||
# value = self.extract_value(line)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue