First commit
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Hauptprogramm Phase 2: Koordinaten von der Montierung pollen und anzeigen.
|
||||
|
||||
Fragt zyklisch RA/DEC von der 10Micron-Montierung ab und schreibt sie ueber die
|
||||
Grossanzeige. Bei Verbindungsproblemen wird eine Hinweiszeile angezeigt und im
|
||||
Hintergrund erneut verbunden.
|
||||
|
||||
python3 run_display.py # Montierung aus config.py
|
||||
python3 run_display.py --host 10.0.0.42
|
||||
python3 run_display.py --mock # lokalen Mock starten und nutzen
|
||||
python3 run_display.py --mock --move --once # einmalig, mit laufender RA
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
import time
|
||||
|
||||
import config
|
||||
import coords
|
||||
from display import open_display
|
||||
from mount_client import MountClient, MountError
|
||||
|
||||
|
||||
def _format(ra_raw, dec_raw):
|
||||
"""Rohstrings der Montierung fuer die Anzeige aufbereiten."""
|
||||
return coords.format_ra(ra_raw), coords.format_dec(dec_raw)
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
p = argparse.ArgumentParser(description=__doc__,
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||
p.add_argument("--host", default=config.MOUNT_HOST)
|
||||
p.add_argument("--port", type=int, default=config.MOUNT_PORT)
|
||||
p.add_argument("--interval", type=float, default=config.POLL_INTERVAL)
|
||||
p.add_argument("--once", action="store_true", help="nur eine Abfrage, dann Ende")
|
||||
p.add_argument("--mock", action="store_true",
|
||||
help="lokalen Mock starten und gegen ihn laufen")
|
||||
p.add_argument("--move", action="store_true",
|
||||
help="nur mit --mock: RA laeuft mit der Zeit")
|
||||
p.add_argument("--dry-run", action="store_true",
|
||||
help="Anzeige nur als Hex mitschreiben (keine serielle Hardware)")
|
||||
args = p.parse_args(argv)
|
||||
|
||||
host, port = args.host, args.port
|
||||
mock = None
|
||||
if args.mock:
|
||||
from mount_mock import MountMock
|
||||
mock = MountMock(host="127.0.0.1", port=0, move=args.move)
|
||||
mock.start()
|
||||
host, port = mock.host, mock.port
|
||||
print("Mock-Montierung laeuft auf %s:%d" % (host, port))
|
||||
|
||||
d = open_display(fake=args.dry_run)
|
||||
client = MountClient(host, port, timeout=config.MOUNT_TIMEOUT)
|
||||
last_shown = None
|
||||
|
||||
try:
|
||||
while True:
|
||||
try:
|
||||
if not client.connected:
|
||||
client.connect()
|
||||
ra_raw, dec_raw = client.get_coordinates()
|
||||
ra_line, dec_line = _format(ra_raw, dec_raw)
|
||||
|
||||
if (ra_line, dec_line) != last_shown:
|
||||
# Bei jeder Aenderung beide Zeilen neu zeichnen. Kein Vollbild-
|
||||
# Loeschen (kein Flimmern); die umgekehrte Zeilenreihenfolge in
|
||||
# show_lines schuetzt die Home-Zelle vor dem Gradzeichen-
|
||||
# Zeichensatzwechsel, auch bei staendiger Aktualisierung.
|
||||
first = last_shown is None or last_shown == config.NOLINK_LINES
|
||||
d.show_lines(ra_line, dec_line, clear=first)
|
||||
last_shown = (ra_line, dec_line)
|
||||
print("RA %-11s DEC %-12s -> %s | %s"
|
||||
% (ra_raw, dec_raw, ra_line, dec_line))
|
||||
except (MountError, ValueError) as e:
|
||||
print("Montierung: %s" % e, file=sys.stderr)
|
||||
client.close()
|
||||
if config.NOLINK_LINES != last_shown:
|
||||
d.show_lines(*config.NOLINK_LINES, clear=True)
|
||||
last_shown = config.NOLINK_LINES
|
||||
|
||||
if args.once:
|
||||
break
|
||||
time.sleep(args.interval)
|
||||
except KeyboardInterrupt:
|
||||
print("\nbeendet")
|
||||
finally:
|
||||
client.close()
|
||||
d.close()
|
||||
if mock is not None:
|
||||
mock.stop()
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user