Commit ef40e1ad authored by Tammo Jan Dijkema's avatar Tammo Jan Dijkema
Browse files

Implement waitForFirstUpdate in constructor

parent eb0ed67d
from __future__ import print_function
import socket
import logging
import time
......@@ -23,7 +21,7 @@ _ELEVATION_GEAR = 44803.125
class Telescope:
def __init__(self, setmode=None, consoleHost=None):
def __init__(self, setmode=None, consoleHost=None, waitForFirstUpdate=False):
"""
Initializes a telescope instance
:param setmode: The mode for writing. Can be 'J2000' or 'AZEL'
......@@ -57,10 +55,16 @@ class Telescope:
self.tracking_enabled = None
self.refraction_enabled = None
self.model_enabled = None
self.model = None
self.tle1 = None
self.tle2 = None
self.satname = None
self.tracker = None
self.offset_az = None
self.offset_el = None
self._first_poll_condition = threading.Condition()
try:
testsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
test_port = 11010
......@@ -143,6 +147,25 @@ class Telescope:
thread_read_sat.daemon = True
thread_read_sat.start()
if waitForFirstUpdate:
with self._first_poll_condition:
while not self._event_status.is_set():
self._first_poll_condition.wait()
# Threads look at self.tracker (set by status thread) to set
# self.model_enabled, self.refraction_enabled, etc.
self._event_j2000.clear()
self._event_sun.clear()
self._event_moon.clear()
self._event_sat.clear()
while not (self._event_sun.is_set() and \
self._event_traces.is_set() and \
self._event_j2000.is_set() and \
self._event_sat.is_set() and \
self._event_model.is_set() and \
self._event_moon.is_set()):
self._first_poll_condition.wait()
def _readj2000(self, consoleHost, j2000_read_port):
"""
Poll the socket with the J2000 info, store its values in class members
......@@ -176,12 +199,15 @@ class Telescope:
# Read the flags, they look like "enabled=0,refraction=1,dt_model=0"
switches = [kv.split("=") for kv in vals[5].split(",")]
if self.tracker == "console/j2000tracker":
self.tracking_enabled = bool(int(switches[0][1]))
self.refraction_enabled = bool(int(switches[1][1]))
self.model_enabled = bool(int(switches[2][1]))
self._event_j2000.set()
with self._first_poll_condition:
self._first_poll_condition.notify()
def _readtraces(self, tracehost, traceport):
"""
......@@ -215,6 +241,8 @@ class Telescope:
self.speed_el = ((float(vals[5]) * u.rad / u.s) / _ELEVATION_GEAR).to(u.deg / u.s)
self.focusbox_pos = float(vals[6])
self._event_traces.set()
with self._first_poll_condition:
self._first_poll_condition.notify()
def _readstatus(self, host, port):
"""
......@@ -240,6 +268,8 @@ class Telescope:
self.offset_az = (float(vals[1]) * u.rad).to(u.deg)
self.offset_el = (float(vals[2]) * u.rad).to(u.deg)
self._event_status.set()
with self._first_poll_condition:
self._first_poll_condition.notify()
def _readsun(self, host, port):
"""
......@@ -268,6 +298,8 @@ class Telescope:
self.model_enabled = bool(int(switches[1][1]))
self._event_sun.set()
with self._first_poll_condition:
self._first_poll_condition.notify()
def _readsat(self, host, port):
"""
......@@ -302,6 +334,8 @@ class Telescope:
self.tle2 = switches[4][1][69:]
self._event_sat.set()
with self._first_poll_condition:
self._first_poll_condition.notify()
def _readmoon(self, host, port):
"""
......@@ -330,6 +364,8 @@ class Telescope:
self.model_enabled = bool(int(switches[1][1]))
self._event_moon.set()
with self._first_poll_condition:
self._first_poll_condition.notify()
def _readmodel(self, host, port):
"""
......@@ -353,6 +389,8 @@ class Telescope:
vals = msg.strip().split(',')
self.model = vals[0].split('=')[1]
self._event_model.set()
with self._first_poll_condition:
self._first_poll_condition.notify()
def setRaDec(self, setpoint):
"""
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment