103 lines
3.8 KiB
Python
103 lines
3.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Dauersenden auf der seriellen Schnittstelle, zum Messen mit dem Oszilloskop.
|
|
|
|
Es wird ohne Antworttelegramm gesendet (die Anzeige haengt ja noch nicht dran),
|
|
d.h. FC = 0x80 statt 0x81.
|
|
|
|
Muster:
|
|
telegram das echte Koordinaten-Telegramm (Vorgabe)
|
|
0x55 01010101 -- bei 8E1 die schnellste Bitfolge, ideal zum
|
|
Ausmessen der Bitzeit (1 Bit = 52,08 us bei 19200 Baud)
|
|
0xAA 10101010
|
|
0x00 / 0xFF konstant, zum Pruefen der Ruhepegel
|
|
count 0x00, 0x01, 0x02 ... fortlaufend
|
|
|
|
Beispiele:
|
|
python3 scope.py # 5 min, Telegramm alle 200 ms
|
|
python3 scope.py --pattern 0x55 --interval 0.05 --minutes 10
|
|
python3 scope.py --pattern 0x55 --interval 0 # so schnell wie moeglich
|
|
"""
|
|
|
|
import argparse
|
|
import sys
|
|
import time
|
|
|
|
import config
|
|
import coords
|
|
import migra
|
|
from transport import SerialTransport
|
|
|
|
PATTERNS = {"0x55": 0x55, "0xAA": 0xAA, "0x00": 0x00, "0xFF": 0xFF}
|
|
|
|
|
|
def build_frame(pattern, counter):
|
|
"""Die zu sendenden Bytes fuer einen Durchlauf liefern."""
|
|
if pattern == "telegram":
|
|
du = migra.DataUnit()
|
|
du.fill(config.BACKGROUND)
|
|
du.charset(config.CHARSET)
|
|
du.attributes(fg=config.COLOR, bg=config.BACKGROUND)
|
|
du.cursor(0, config.LINE_Y[0])
|
|
du.text(coords.format_ra("12h34m56s"))
|
|
du.cursor(0, config.LINE_Y[1])
|
|
du.text(coords.format_dec("+45d12m30s"))
|
|
return migra.build_telegram(du, dest=config.DISPLAY_ADDR,
|
|
src=config.HOST_ADDR,
|
|
checksum=config.USE_CHECKSUM,
|
|
response=False)
|
|
if pattern == "count":
|
|
return bytes([counter & 0xFF])
|
|
return bytes([PATTERNS[pattern]] * 16)
|
|
|
|
|
|
def main(argv=None):
|
|
p = argparse.ArgumentParser(description=__doc__,
|
|
formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
p.add_argument("--pattern", default="telegram",
|
|
choices=["telegram", "count"] + list(PATTERNS))
|
|
p.add_argument("--port", default=config.PORT)
|
|
p.add_argument("--interval", type=float, default=0.2,
|
|
help="Pause zwischen den Sendungen in Sekunden (Vorgabe: %(default)s)")
|
|
p.add_argument("--minutes", type=float, default=5.0,
|
|
help="Laufzeit in Minuten (Vorgabe: %(default)s)")
|
|
args = p.parse_args(argv)
|
|
|
|
t = SerialTransport(port=args.port, baudrate=config.BAUDRATE,
|
|
parity=config.PARITY, bytesize=config.BYTESIZE,
|
|
stopbits=config.STOPBITS, timeout=0.1)
|
|
|
|
first = build_frame(args.pattern, 0)
|
|
bit_us = 1e6 / config.BAUDRATE
|
|
print("Port : %s" % args.port)
|
|
print("Format : %d Baud, %d%s%d (1 Bit = %.2f us, 1 Byte = 11 Bit = %.1f us)"
|
|
% (config.BAUDRATE, config.BYTESIZE, config.PARITY, config.STOPBITS,
|
|
bit_us, bit_us * 11))
|
|
print("Muster : %s, %d Byte pro Durchlauf" % (args.pattern, len(first)))
|
|
print(" %s" % " ".join("%02X" % b for b in first))
|
|
print("Intervall : %s s, Laufzeit %s min" % (args.interval, args.minutes))
|
|
print("Abbruch mit Ctrl-C.\n")
|
|
|
|
deadline = time.monotonic() + args.minutes * 60
|
|
n = 0
|
|
try:
|
|
while time.monotonic() < deadline:
|
|
t.write(build_frame(args.pattern, n))
|
|
n += 1
|
|
if n % 25 == 0:
|
|
rest = deadline - time.monotonic()
|
|
print("\r%6d Sendungen, noch %4.1f min " % (n, rest / 60), end="")
|
|
sys.stdout.flush()
|
|
if args.interval:
|
|
time.sleep(args.interval)
|
|
except KeyboardInterrupt:
|
|
print("\nabgebrochen")
|
|
finally:
|
|
t.close()
|
|
|
|
print("\n%d Sendungen abgesetzt." % n)
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|