Compare commits

...

2 commits

Author SHA1 Message Date
Nicolas Rohrbeck
af7f6be448 Merge branch 'master' of ssh://forge.bexus.org/Seth/seth_tools 2025-08-21 15:02:05 +02:00
Nicolas Rohrbeck
e9fce4229d WIP 2025-08-21 15:00:24 +02:00

View file

@ -6,15 +6,28 @@ import math
import argparse
import sys
parser = argparse.ArgumentParser(prog=sys.argv[0])
plt.ion()
parser = argparse.ArgumentParser(prog=sys.argv[0], description="Searches stdin or FILE line by line for P, H and HDORN lines")
parser.add_argument('-f', '--file')
parser.add_argument('-p', '--plot', action='store_true')
args = parser.parse_args()
global fp
global plot_flag
fp = args.file
plot_flag = args.plot
global time
global p
global temps
global counts
time = []
p= []
temps = [] # [[Tfpga, Tadc, Tpa, Tbgo1, Tbgo2, Tpwr, Text], [...]]
counts = [] # [[upper, BGO1, HETA, HETB, BGO2, lower], [...]]
def do_bate():
def do_bate(l):
# P 0xba7e 0xfff7 0xaa51 0x3d97 0xa520 0xb098 0x4712 0x840a
if len(l.split()) != 9:
pass
word = [int(num, base=16) for num in l.split()[3:7]]
@ -22,23 +35,47 @@ def do_bate():
c = [word[0] >> 1, ((word[2] & 63) << 6) | (word[3] & 63), word[3] >> 6, word[2] >> 6, ((word[0] & 1) << 10) | (word[1] >> 6), word[1] & 63]
ut1 = 8*c[4]+20224
dT = d[1] - ut1
temp = 200 + dT*(c[5]+50)/1024/10
temps.append([(200 + dT*(c[5]+50)/1024)/10])
off = c[1]*4+((c[3]-512)*dT)/4096
sens = c[0] + (c[2]*dT)/1024 + 24576
x = (sens * (d[0]-7168))/16384 - off
p = (x*10/32 + 2500)/10
if not fp:
print(f'P={p} mbar')
p.append((x*10/32 + 2500)/10)
if not fp and not plot_flag:
print(f'P={p[-1]:6.2f} mbar\nT={temps[-1][0]:6.2f} °C')
else:
print(f"{time} {p} mbar")
def do_counter(l):
ll = l.split(' ')
sl0 = [int(num) for num in ll[1].split() + ll[2].split() + ll[3].split()] # slice 0 dorn channels 0-23
sl1 = [int(num) for num in ll[5].split() + ll[6].split() + ll[7].split()]
upper_count = (math.fsum(sl1)-sl1[3]-sl1[11]-sl1[20]-sl1[11])/20 # sum of all counts minus BGO and HET
BGO_upper = (sl1[3]+sl1[11]+sl1[20])/3 # just use the mean for BGO counts
HETA = sl1[11]
HETB = sl0[11]
BGO_lower = (sl0[3]+sl0[11]+sl0[20])/3
lower_count = (math.fsum(sl0)-sl0[3]-sl0[11]-sl0[20]-sl0[11])/20
global counts
counts.append([upper_count, BGO_upper, HETA, HETB, BGO_lower, lower_count])
def next_12():
lt = len(time)
lp = len(p)
lT = len(temps)
if lt == lp and lp == lT:
return True
else:
return False
def degC(a):
R1, R25, B25, res = 10e3, 10e3, 3940, 0x1000
R = R1 * a / (res - (a & (res-1)))
T = B25/(math.log(R/R25) + B25/298) - 273
return T
def do_hdorn(time: int):
def do_hdorn(l):
# HDORN 0 74 95 83 81 83 74 88 90 78 88 84 95 77 91 74 81 77 82 94 73 78 97 76 72 0 3555 1347 3551 2048 1437 3082 1239 3832 4095 4095 1500 1478 1540 1247 3105 324 327 324 323 323 323 323 323 3564 3566 3564 3564 3565 3565 3565 3564 2612 2756 2495 2631 130 2120 1289 1114
ll = l.split() # ll: list of line contents
sl = int(ll[1]) # slice
@ -50,31 +87,31 @@ def do_hdorn(time: int):
d = data[i]
if i == 3:
HK.append(f"""
{sl} 3
T = {degC(d[5]):6.2f} °C, GND = {d[0]:6.3f} V,
{sl} 3 HK ADC
Tadc = {degC(d[5]):6.2f} °C, GND = {d[0]:6.3f} V,
Vff = {d[1]:6.3f} V, Vnn = {d[2]:6.3f} V, Vpp = {d[3]:6.3f} V, Vdig = {d[4]:6.3f} V,
Vcc = {d[6]:6.3f} V, Vss = {d[7]:6.3f} V.
""")
if i == 4:
HK.append(f"""
{sl} 4
Tpa = {d[4]:6.2f} °C, Tbgo = {d[3]:6.2f} °C, {d[5]:6.2f} °C,
{sl} 4 HK PA
Tpa = {degC(d[4]):6.2f} °C, Tbgo = {degC(d[3]):6.2f} °C, {degC(d[5]):6.2f} °C,
Vbias = {d[2]:6.3f} V, Ibias = {d[1]:6.1f} nA, {d[0]:6.1f} nA,
Vcc = {d[7]:6.3f} V, Vss = {d[6]:6.3f} V.
""")
if i == 7 and sl == 0:
HK.append(f"""
{sl} 7
{sl} 7 HK PWR
na = {repr(d[:4])}
Tpwr = {d[6]:.1f} °C,
Tpwr = {degC(d[6]):.1f} °C,
Vprim = {d[5]:.1f} V, Iprim = {d[4]:.1f} mA,
Ibias = {d[7]:.1f} nA.\n
""")
elif i == 7 and sl == 1:
HK.append(f"""
{sl} 7
{sl} 7 HK PWR
na = {repr(d[:4])}
Text = {d[6]:.1f} °C,
Text = {degC(d[6]):.1f} °C,
Ibias = {d[4]:.1f} nA.
Ibias = {d[7]:.1f} nA, Vbias = {d[5]:.1f} V.\n
""")
@ -82,24 +119,47 @@ def do_hdorn(time: int):
def main(l):
def main(input):
global time
if l[:2] == 'P ':
do_bate()
if l[:2] == 'H ':
time = int(l.split()[1])
if l[:6] == 'HDORN ':
do_hdorn(time)
global counts
# H 1754740024 0 0 65472 55168 17728 65472 17600 33600 25856 65472 62464 65472
# C64 3 0 4 0 14 2 2 1 1 5 5 1 8 14 1 1 1 1 1 1 2 15 2 1 2 0 1 3 2 13 4 3 2 2 1 0 1 4 14 0 2 0 1 3 1 1 16 3 1 2 0 1087268401
for l in input:
if l[:4] == 'C64 ':
do_counter(l)
if l[:2] == 'P ':
do_bate(l)
if l[:2] == 'H ':
ts = int(l.split()[1])
if fp and fp.split()[-1] == "2025-08-14-longtime-23e.AHA" and ts > 1800000000:
ts -= 49207219200
time.append(ts)
if l[:6] == 'HDORN ':
if l.split()[1] != 0 or l.split()[1] != 1: # only operate if slice numbers are correct
pass
else:
do_hdorn(l)
if plot_flag: # only plot if -p option is True
if next_12():
if len(time) == 1:
fig, ((ax1, ax2),(ax3, ax4)) = plt.subplots(2,2)
counts = ax1.plot(time, 0)
pres = ax2.plot(time, 0)
head = ax3.plot(time, 0)
temp = ax4.plot(time, 0)
ax1.remove();ax2.remove();ax3.remove();ax4.remove()
if fp:
print(f"Using {fp.split('/')[-1]}")
with open(fp) as file:
for l in file:
time = 0
main(l)
input = file
main(input)
else:
for l in sys.stdin:
time = 0
main(l)
input = sys.stdin
main(input)