Modified for new integrated readouts (Q command) - untested
This commit is contained in:
parent
06f35acc4e
commit
f73dcd0a22
1 changed files with 50 additions and 67 deletions
117
scanner.py
117
scanner.py
|
|
@ -25,7 +25,9 @@ PATTERN = re.compile(
|
||||||
r"(?P<adc_vmin>[0-9a-fA-F]+)-(?P<adc_vmax>[0-9a-fA-F]+)\s+"
|
r"(?P<adc_vmin>[0-9a-fA-F]+)-(?P<adc_vmax>[0-9a-fA-F]+)\s+"
|
||||||
r"(?P<adc_imin>[0-9a-fA-F]+)-(?P<adc_imax>[0-9a-fA-F]+).*?\|\s+"
|
r"(?P<adc_imin>[0-9a-fA-F]+)-(?P<adc_imax>[0-9a-fA-F]+).*?\|\s+"
|
||||||
r"nv=(?P<nv>[\d.-]+)\s+ni=(?P<ni>[\d.-]+)"
|
r"nv=(?P<nv>[\d.-]+)\s+ni=(?P<ni>[\d.-]+)"
|
||||||
|
r"QZR=(?P<QZR>[\d.-]+)\s+QZX=(?P<QZX>[\d.-]+)"
|
||||||
)
|
)
|
||||||
|
Va=16.376152 Vp=5.82 | Ia=30.656820 Ip=5.84 | ZR=0.534176 ZX=-0.000190 R=516.000 | freq=1000.0 ampl=100.0 | BW=0.500| irq=59 0c-7b 18-83 | nv=4.494 ni=8.487 | QZR=0.654321 QZX=12.123456
|
||||||
|
|
||||||
config_path = '/home/bart/python-scanner/config.yaml' # XXXDB
|
config_path = '/home/bart/python-scanner/config.yaml' # XXXDB
|
||||||
#config_path = 'config.yaml'
|
#config_path = 'config.yaml'
|
||||||
|
|
@ -146,10 +148,9 @@ def extract_to_dataframe(line):
|
||||||
int(match.group("adc_imax"), 16), # row 10
|
int(match.group("adc_imax"), 16), # row 10
|
||||||
float(match.group("nv")), # row 11
|
float(match.group("nv")), # row 11
|
||||||
float(match.group("ni")), # row 12
|
float(match.group("ni")), # row 12
|
||||||
|
float(match.group("QZR")), # row 13
|
||||||
|
float(match.group("QZX")), # row 14
|
||||||
]
|
]
|
||||||
row[1] = row[1]/(2*3.14159*row[0]*0.00005 + 1) # compensate Va for pole at 20kHz
|
|
||||||
row[5] = row[1]/row[3] * math.cos(0.01745*(row[2]-row[4]))
|
|
||||||
row[6] = row[1]/row[3] * math.sin(0.01745*(row[2]-row[4]))
|
|
||||||
data_rows.append(row)
|
data_rows.append(row)
|
||||||
|
|
||||||
def process_line(line):
|
def process_line(line):
|
||||||
|
|
@ -161,7 +162,7 @@ def process_line(line):
|
||||||
def get_dataframe():
|
def get_dataframe():
|
||||||
return pd.DataFrame(
|
return pd.DataFrame(
|
||||||
data_rows,
|
data_rows,
|
||||||
columns=["Va", "Vp", "Ia", "Ip", "ZR", "ZX", "adc_vmin", "adc_vmax", "adc_imin", "adc_imax", "nv", "ni"]
|
columns=["Va", "Vp", "Ia", "Ip", "QZR", "QZX", "adc_vmin", "adc_vmax", "adc_imin", "adc_imax", "nv", "ni"]
|
||||||
)
|
)
|
||||||
|
|
||||||
class TelnetReader:
|
class TelnetReader:
|
||||||
|
|
@ -218,73 +219,56 @@ class TelnetReader:
|
||||||
def process_line(self, line):
|
def process_line(self, line):
|
||||||
global state
|
global state
|
||||||
global Inoise_baseline
|
global Inoise_baseline
|
||||||
# print(f"RAW: {line}")
|
print(line)
|
||||||
if not line.startswith("Va="): # skip lines that are not to be analyzed
|
if not line.startswith("Va="): # skip lines that are not to be analyzed
|
||||||
return
|
return
|
||||||
if state["remaining_receive_lines"] > 0 :
|
# prepare new frequency measurement
|
||||||
state["remaining_receive_lines"] -= 1 # we are waiting for settling - just skip the line
|
if state["initializing"] == 1:
|
||||||
else:
|
# since we just start a frequency scan, let's set the R, Max and Amplitude
|
||||||
# prepare new frequency measurement
|
response = f"\rr516\r" # set Resistance value for scaling HAL sensor
|
||||||
if state["initializing"] == 1:
|
self.tn.write(response.encode("utf-8"))
|
||||||
# since we just start a frequency scan, let's set the R, Max and Amplitude
|
response = f"m1600\r" # set max amplitude value
|
||||||
response = f"\rr516\r" # set Resistance value for scaling HAL sensor
|
self.tn.write(response.encode("utf-8"))
|
||||||
self.tn.write(response.encode("utf-8"))
|
# for noise scans the amplitude is zero, else the state["ampl"]
|
||||||
response = f"m1600\r" # set max amplitude value
|
if state["noise_scan"]==True:
|
||||||
self.tn.write(response.encode("utf-8"))
|
response = f"a0\r" # zero amplitude for noise measurement
|
||||||
# for noise scans the amplitude is zero, else the state["ampl"]
|
else:
|
||||||
if state["noise_scan"]==True:
|
response = f"a{state["ampl"]:.1f}\r" # set amplitude
|
||||||
response = f"a0\r" # zero amplitude for noise measurement
|
self.tn.write(response.encode("utf-8"))
|
||||||
else:
|
# there will be a lot of lines, but they will be skipped as they do not match the pattern
|
||||||
response = f"a{state["ampl"]:.1f}\r" # set amplitude
|
else: # regular loop (not initializing)
|
||||||
self.tn.write(response.encode("utf-8"))
|
extract_to_dataframe(line) # capture the measurement
|
||||||
# there will be a lot of lines, but they will be skipped as they do not match the pattern
|
if state["freq"]>3.0:
|
||||||
else: # regular loop (not initializing)
|
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 (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 (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)
|
state["freq"] = 0 # force ending of the scan, and write no data in the database
|
||||||
else:
|
# calculate next freq
|
||||||
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 state["freq"] > 1.0:
|
||||||
state["freq"] = 0 # force ending of the scan, and write no data in the database
|
freq_multiplier = state["freq_step_multiply"] # calc next freq
|
||||||
# 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
|
|
||||||
else:
|
|
||||||
freq_multiplier = state["freq_step_multiply"] ** 4 # skip 3/4 steps to speed up
|
|
||||||
state["freq"] *= freq_multiplier
|
|
||||||
# if (state["freq"]>40) and (state["freq"]<660) and ((state["freq"]%50<2.5) or (-state["freq"]%50<2.5)):
|
|
||||||
# state["freq"] *= freq_multiplier # if near a 50Hz harmonic, skip to the next frequency
|
|
||||||
# while (state["freq"]<0.6) and ((state["freq"]%state["interference_freq"]<state["interference_bandwidth"]) or (-state["freq"]<state["interference_freq"]<state["interference_bandwidth"])):
|
|
||||||
# state["freq"] *= freq_multiplier # if near a 0.052Hz harmonic, skip to the next frequency
|
|
||||||
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:
|
else:
|
||||||
# program the health monitor to go to the next frequency:
|
|
||||||
if state["freq"] > 0.01:
|
if state["freq"] > 0.01:
|
||||||
response = f"\rf{state["freq"]:.1f}\r" # new freq
|
freq_multiplier = state["freq_step_multiply"] ** 2 # skip 1/2 steps to speed up
|
||||||
else:
|
else:
|
||||||
response = f"\rf{state["freq"]:.3f}\r" # new freq
|
freq_multiplier = state["freq_step_multiply"] ** 4 # skip 3/4 steps to speed up
|
||||||
self.tn.write(response.encode("utf-8"))
|
state["freq"] *= freq_multiplier
|
||||||
bandwidth = state["freq"]/20
|
while (any(item["Freq"] == state["freq"] for item in blacklist)):
|
||||||
if bandwidth > 0.5 :
|
print("skipping freq")
|
||||||
bandwidth = 0.5
|
state["freq"] *= freq_multiplier # skip all frequencies that are blacklisted
|
||||||
response = f"b{bandwidth:.3f}\r" # new freq
|
if state["freq"] <= state["stop_freq"]:
|
||||||
self.tn.write(response.encode("utf-8"))
|
print("Reached stop frequency")
|
||||||
state["remaining_receive_lines"] = 2 + 4/bandwidth
|
else:
|
||||||
print(line)
|
# program the health monitor to go to the next frequency:
|
||||||
# print(state)
|
response = f"\rQ{state["freq"]:.3f}\r" # new freq
|
||||||
state["initializing"] = 0
|
self.tn.write(response.encode("utf-8"))
|
||||||
|
# print(state)
|
||||||
|
state["initializing"] = 0
|
||||||
|
|
||||||
# Example:
|
# Example:
|
||||||
# value = self.extract_value(line)
|
# value = self.extract_value(line)
|
||||||
|
|
@ -311,7 +295,6 @@ if __name__ == "__main__":
|
||||||
load_yaml_config(state) # Load configuration settings
|
load_yaml_config(state) # Load configuration settings
|
||||||
|
|
||||||
state["freq"] = state["start_freq"];
|
state["freq"] = state["start_freq"];
|
||||||
state["remaining_receive_lines"] = 0;
|
|
||||||
state["initializing"] = 1;
|
state["initializing"] = 1;
|
||||||
|
|
||||||
reader.read_loop()
|
reader.read_loop()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue