mirror of
https://codeberg.org/SiB64/blinkenlights.git
synced 2026-05-01 06:44:23 +02:00
Compare commits
3 commits
40ca706ec8
...
d99e5587d1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d99e5587d1 | ||
|
|
77b23571c5 | ||
|
|
56514e0e3f |
2 changed files with 56 additions and 28 deletions
|
|
@ -136,3 +136,9 @@ endif
|
||||||
|
|
||||||
mux_uart: mux_uart.c
|
mux_uart: mux_uart.c
|
||||||
gcc -Wall -O2 -g -DWITH_ARGS $< -o $@
|
gcc -Wall -O2 -g -DWITH_ARGS $< -o $@
|
||||||
|
|
||||||
|
bate%.filt: bate%.txt
|
||||||
|
./bate.py recalibrate < $< \
|
||||||
|
| awk 'NF==15 && $$6<1100 && $$6>900 {print $$2,$$4,$$6}' \
|
||||||
|
| derive.py -p3 -s60 -W30 \
|
||||||
|
> $@
|
||||||
|
|
|
||||||
78
src/bate.py
78
src/bate.py
|
|
@ -33,7 +33,7 @@ def calibrate(Word, D):
|
||||||
D2 = %d
|
D2 = %d
|
||||||
UT1 = %d
|
UT1 = %d
|
||||||
dT = %d
|
dT = %d
|
||||||
TEMP = %.1f °C
|
TEMP = %.2f °C
|
||||||
""" % (D[2], UT1, dT, TEMP*0.1))
|
""" % (D[2], UT1, dT, TEMP*0.1))
|
||||||
|
|
||||||
OFF = C[2]*4 + ((C[4]-512)*dT)/4096
|
OFF = C[2]*4 + ((C[4]-512)*dT)/4096
|
||||||
|
|
@ -47,36 +47,58 @@ def calibrate(Word, D):
|
||||||
OFF = %d
|
OFF = %d
|
||||||
SENS = %d
|
SENS = %d
|
||||||
X = %d
|
X = %d
|
||||||
P = %.1f mbar
|
P = %.2f mbar
|
||||||
""" % (D[1], OFF, SENS, X, P*0.1))
|
""" % (D[1], OFF, SENS, X, P*0.1))
|
||||||
|
|
||||||
return (TEMP/10, P/10)
|
return (TEMP/10, P/10)
|
||||||
|
|
||||||
port = "/dev/ttyUSB1"
|
port = "/dev/ttyUSB1"
|
||||||
if len(sys.argv)==2:
|
|
||||||
port = sys.argv[1]
|
def read_bate(port):
|
||||||
tty = serial.Serial(port=port, baudrate=2400)
|
tty = serial.Serial(port=port, baudrate=2400)
|
||||||
r = b''
|
r = b''
|
||||||
nx = 0
|
|
||||||
while True:
|
|
||||||
r += tty.read_all()
|
|
||||||
if len(r)<16:
|
|
||||||
r += tty.read(16-len(r))
|
|
||||||
while r and r[0] != 0x7e or r[1:] and r[1] != 0xba:
|
|
||||||
sys.stdout.write(f" {r[0]:02x}")
|
|
||||||
r = r[1:]
|
|
||||||
nx += 1
|
|
||||||
if nx >= 32:
|
|
||||||
sys.stdout.write("\n")
|
|
||||||
sys.stdout.flush()
|
|
||||||
nx = 0
|
|
||||||
if len(r)<16:
|
|
||||||
continue
|
|
||||||
w = struct.unpack("<8H", r[:16])
|
|
||||||
r = r[16:]
|
|
||||||
T,p = calibrate(w[1:],w[5:])
|
|
||||||
t = time.time()
|
|
||||||
sys.stdout.write(f"\nPT {t:.1f} {time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(t))} {T:+4.1f} °C {p:6.1f} mbar ")
|
|
||||||
sys.stdout.write(" ".join([f"{x:04x}" for x in w]))
|
|
||||||
sys.stdout.flush()
|
|
||||||
nx = 0
|
nx = 0
|
||||||
|
while True:
|
||||||
|
r += tty.read_all()
|
||||||
|
if len(r)<16:
|
||||||
|
r += tty.read(16-len(r))
|
||||||
|
while r and r[0] != 0x7e or r[1:] and r[1] != 0xba:
|
||||||
|
sys.stdout.write(f" {r[0]:02x}")
|
||||||
|
r = r[1:]
|
||||||
|
nx += 1
|
||||||
|
if nx >= 32:
|
||||||
|
sys.stdout.write("\n")
|
||||||
|
sys.stdout.flush()
|
||||||
|
nx = 0
|
||||||
|
if len(r)<16:
|
||||||
|
continue
|
||||||
|
w = struct.unpack("<8H", r[:16])
|
||||||
|
r = r[16:]
|
||||||
|
T,p = calibrate(w[1:],w[5:])
|
||||||
|
t = time.time()
|
||||||
|
sys.stdout.write(f"\nPT {t:.1f} {time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(t))} {T:+5.2f} °C {p:7.2f} mbar ")
|
||||||
|
sys.stdout.write(" ".join([f"{x:04x}" for x in w]))
|
||||||
|
sys.stdout.flush()
|
||||||
|
nx = 0
|
||||||
|
|
||||||
|
def recalibrate(f):
|
||||||
|
for l in f.readlines():
|
||||||
|
ll = l.split()
|
||||||
|
if len(ll) != 15:
|
||||||
|
continue
|
||||||
|
if ll[0] != "PT":
|
||||||
|
continue
|
||||||
|
w = [int(lll,16) for lll in ll[-8:]]
|
||||||
|
t = float(ll[1])
|
||||||
|
T,p = calibrate(w[1:],w[5:])
|
||||||
|
sys.stdout.write(f"\nPT {t:.1f} {time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(t))} {T:+5.2f} °C {p:7.2f} mbar ")
|
||||||
|
sys.stdout.write(" ".join([f"{x:04x}" for x in w]))
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
if len(sys.argv) == 2:
|
||||||
|
port = sys.argv[1]
|
||||||
|
if port == "recalibrate":
|
||||||
|
recalibrate(sys.stdin)
|
||||||
|
else:
|
||||||
|
read_bate(port)
|
||||||
|
sys.stdout.write("\n")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue