Compare commits

...

7 commits

Author SHA1 Message Date
Stephan I. Böttcher
5a00dbbc05 turbo startup scripts 2024-11-11 22:21:45 +01:00
Stephan I. Böttcher
9c75c40d9b turbo.py: fix ADC_mV global{}, fix clock 2024-11-11 22:20:54 +01:00
Stephan I. Böttcher
aaea5efc6d turbo.awk: clock speed precision 2024-11-11 22:19:18 +01:00
Stephan I. Böttcher
b1897d28c1 turbo.py: misc fixes and improvements
- open/read files _and_ --tty
- more precision for clock fit parameters
- s/data[c]/Data[c]/
- clear old ADC_mV{} results.
  In case of noise, invalid entries may stay around and cause spurious
  warnings
- when reparsing files, prune original lines for checksumming
- when reparsing, silently drop parser output
2024-11-11 20:39:39 +01:00
Stephan I. Böttcher
3f7875d7a7 turbo.gpt: fix ranges 2024-11-11 20:38:57 +01:00
Stephan I. Böttcher
8208747a63 ntc.py: R(), VntcT() 2024-11-11 20:37:56 +01:00
Stephan I. Böttcher
e6d8d5a080 .gitignore src/data/ 2024-11-11 20:36:49 +01:00
7 changed files with 69 additions and 16 deletions

1
.gitignore vendored
View file

@ -21,3 +21,4 @@ src/mul
*.bin
*.eeprom
*.elf
src/data

View file

@ -51,3 +51,13 @@ class ntc:
see `turbo.sch`
"""
return self.Tntc(a + b, b * (1 + self.R1/self.R25))
def R(self, T):
"""R(T)"""
return self.R25*math.exp(self.β/(T + self.T0) - self.β/self.T25)
def VntcT(self, T, V1=None):
"""V(T)"""
if not V1:
V1 = self.V1
return V1 / (1 + self.R1/self.R(T))

8
src/rc.local Executable file
View file

@ -0,0 +1,8 @@
#! /bin/bash -v
date --utc +"Turbo reboot at %FT%TZ"
SRC=~stephan/turbo_weather/src
[ -d "$SRC" ] || exit 0
mount /data/blaulicht
[ -d /data/blaulicht/temperature ] || exit 0
sudo -inu stephan screen -S turbo -d -m $SRC/turbo.sh

View file

@ -50,6 +50,6 @@ function emit() {
Vbat = A["BAT/1V"]
Vdd = A["VDD/1V"]
Vrf = A["RFP/2.5V"]
printf "%.0f %.1f %.1f %.3f %.2f %.2f %.2f %.2f %.2f %.4f %.4f %.4f\n", \
printf "%.0f %.1f %.1f %.6f %.2f %.2f %.2f %.2f %.2f %.4f %.4f %.4f\n", \
tT, tU, tF, dt, p, Tp, Tc, Tn, Tb, Vbat, Vdd, Vrf
}

View file

@ -11,7 +11,6 @@ set grid x
set format x "" time
set ytics nomirror
set y2tics
set xrange [*:*] writeback
# set margin 12,12,0,0
set multiplot title fn noenh layout 3,1 margin char 12,13,5,2 spacing char 1
@ -19,10 +18,12 @@ set multiplot title fn noenh layout 3,1 margin char 12,13,5,2 spacing char 1
set ylab "Δt [s]"
set y2lab "dt/dt_{UTC}"
set y2ra [0.98<*:*<1.02]
set yra [*:*]
plot fn u 2:($1-$2) t "clock offset" w l, \
"" u 2:($3-$2) t "clock offset fit" w l, \
"" u 2:4 axis x1y2 t "clock speed" w l
set yra [*:*]
set y2ra [*:*]
set xrange restore

View file

@ -59,17 +59,16 @@ for o,v in options:
if not out:
out = sys.stdout
if tty and files:
raise ValueError("cannot do tty and files")
if len(files)==1:
if "/dev/tty" in files[0]:
tty = files[0]
files = []
inp = []
if tty:
inp = serial.Serial(port=tty, baudrate=baud)
else:
inp = fileinput.input(files, mode="rb")
inp = [serial.Serial(port=tty, baudrate=baud)]
if files or not inp:
inp[0:0] = [fileinput.input(files, mode="rb")]
checksum = 0
@ -158,12 +157,12 @@ def clock(line):
return noise(line, "t")
s = None
t = None
if do_clock:
t = time.time()
try:
t = float(ll[3])
except:
pass
if do_clock:
t = time.time()
if t is not None:
freq.add(t, c)
s = freq.solve()
@ -171,7 +170,7 @@ def clock(line):
if t is None:
t = time.time()
return echo(line, f"{c} {t:.1f}")
return echo(line, f"{c} {t:.1f}", *("%.4g" % ss for ss in s[0]))
return echo(ll[0]+b' '+ll[1], f"{c} {t:.1f}", *("%.6g" % ss for ss in s[0]))
Data = {}
@ -181,7 +180,7 @@ def data(line):
c = ll[0]
d = [int(l, 16) for l in ll[1:]]
if ll[1:]:
data[c] = d
Data[c] = d
emit_data(c)
return echo(line)
except Exception as e:
@ -234,6 +233,7 @@ ADC_mV = {}
def emit_adc(c, cc):
if len(cc) > 8:
return
ADC_mV.clear()
for n, a in enumerate(cc):
C = ADC_CONFIG[n]
if C is None:
@ -456,6 +456,11 @@ processes = {
b'X': echo,
}
splits = {
b'Q': 1,
b'T': 2,
}
class batecmd(cmdsocket.cmd_receiver):
def msg(self, m):
echo(b'r '+m)
@ -467,19 +472,22 @@ if socket:
raise ValueError("cannot have socket without tty")
cmd.open(socket, force=True)
while True:
while inp:
try:
line = inp.readline()
line = inp[0].readline()
except KeyboardInterrupt:
break
if not line:
break
inp[:1] = []
continue
line_key = line[0:1]
is_noise = line_key not in processes
if not is_noise and min(line.strip()) < 32:
is_noise = True
if line_key in b"apcufse":
continue
if is_noise:
if do_noise:
noise(line)
@ -487,6 +495,8 @@ while True:
continue
if processes[line_key](line):
if line_key in splits:
line = b" ".join(line.split()[:splits[line_key]])+b"\n"
add_checksum(line)
if tty:

23
src/turbo.sh Executable file
View file

@ -0,0 +1,23 @@
#! /bin/bash
TTY=/dev/ttyUSB0,1200
DATA=/data/blaulicht/temperature
NEWDATA=$(date --utc +$DATA/turbo-%FT%TZ.txt)
OLDDATA=$(ls -1 $DATA/turbo-????-??-??*.txt | tail -1)
LINKDATA=$DATA/turbo.txt
SRC=~/turbo_weather/src
[ -e $NEWDATA ] && exit
if [ "$(stat -c %h $LINKDATA)" -eq "2" ]
then
rm -vf $LINKDATA
touch $NEWDATA || exit 0
ln -v $NEWDATA $LINKDATA
fi
echo $NEWDATA
echo $OLDDATA
$SRC/turbo.py --tty="$TTY" $OLDDATA | tee --append "$NEWDATA"