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

Prefix private variables and functions with _

parent 4182192c
...@@ -34,66 +34,67 @@ class telescope(): ...@@ -34,66 +34,67 @@ class telescope():
self.dist_az = None self.dist_az = None
self.dist_el = None self.dist_el = None
self.outsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self._outsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if self.setmode == 'J2000': if self.setmode == 'J2000':
self.outsocket.connect((consoleHost, self._outsocket.connect((consoleHost,
config.getint('Console','Port_Write_J2000'))) config.getint('Console','Port_Write_J2000')))
elif self.setmode == 'AZEL': elif self.setmode == 'AZEL':
self.outsocket.connect((consoleHost, self._outsocket.connect((consoleHost,
config.getint('Console','Port_Write_AzEl'))) config.getint('Console','Port_Write_AzEl')))
# Initialize offset socket for all modes where output is desired # Initialize offset socket for all modes where output is desired
if self.setmode is not None: if self.setmode is not None:
self.offsetsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self._offsetsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.offsetsocket.connect((consoleHost, self._offsetsocket.connect((consoleHost,
config.getint('Console','Port_Write_Offset'))) config.getint('Console','Port_Write_Offset')))
self.j2000readthread = threading.Thread(target=self.readj2000, args=( self._thread_read_j2000 = threading.Thread(target=self._readj2000, args=(
consoleHost, consoleHost,
config.getint('Console','Port_Read_J2000'))) config.getint('Console','Port_Read_J2000')))
self.j2000readthread.daemon = True self._thread_read_j2000.daemon = True
self.j2000readthread.start() self._thread_read_j2000.start()
self.tracereadthread = threading.Thread(target=self.readtraces, args=( self._thread_read_trace = threading.Thread(target=self._readtraces, args=(
config.get('Trace2Port', 'Hostname'), config.get('Trace2Port', 'Hostname'),
config.getint('Trace2Port', 'Port'))) config.getint('Trace2Port', 'Port')))
self.tracereadthread.daemon = True self._thread_read_trace.daemon = True
self.tracereadthread.start() self._thread_read_trace.start()
def readj2000(self, consolehost, j2000_read_port): def _readj2000(self, consolehost, j2000_read_port):
''' '''
Poll the socket with the j2000 info, store its values in class members Poll the socket with the j2000 info, store its values in class members
''' '''
try: try:
self.j2000socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self._j2000socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.j2000socket.connect((consolehost, j2000_read_port)) self._j2000socket.connect((consolehost, j2000_read_port))
except socket.error: except socket.error:
raise Exception("Cannot connect to j2000 status server") raise Exception("Cannot connect to j2000 status server")
while True: while True:
readable, writable, exceptional = select.select( readable, writable, exceptional = select.select(
[self.j2000socket], [], []) [self._j2000socket], [], [])
if len(exceptional)>0: if len(exceptional)>0:
raise Exception("Error with j2000 read socket") raise Exception("Error with j2000 read socket")
msg = readable[0].recv(4096) msg = readable[0].recv(4096)
vals = msg.strip().split() vals = msg.strip().split()
ra = vals[2] (ra, dec) = (vals[2], vals[3])
dec = vals[3]
self.radec = SkyCoord(ra, dec, frame='icrs') self.radec = SkyCoord(ra, dec, frame='icrs')
(setpoint_ra, setpoint_dec) = (vals[0], vals[1])
self.setpoint_radec = SkyCoord(setpoint_ra, setpoint_dec, frame='icrs')
def readtraces(self, tracehost, traceport): def _readtraces(self, tracehost, traceport):
''' '''
Poll the socket with the traces, store their values in class members Poll the socket with the traces, store their values in class members
''' '''
try: try:
self.tracesocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self._tracesocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.tracesocket.connect((tracehost, traceport)) self._tracesocket.connect((tracehost, traceport))
except socket.error: except socket.error:
raise Exception("Cannot connect to trace2port server") raise Exception("Cannot connect to trace2port server")
while True: while True:
readable, writable, exceptional = select.select( readable, writable, exceptional = select.select(
[self.tracesocket], [], []) [self._tracesocket], [], [])
if len(exceptional)>0: if len(exceptional)>0:
raise Exception("Error with trace read socket") raise Exception("Error with trace read socket")
msg = readable[0].recv(4096) msg = readable[0].recv(4096)
...@@ -123,7 +124,7 @@ class telescope(): ...@@ -123,7 +124,7 @@ class telescope():
cmd = '{:s}\t{:s}\n'.format(ra, dec.strip('+')) cmd = '{:s}\t{:s}\n'.format(ra, dec.strip('+'))
logging.info('J2000 setpoint sent to DT: {}'.format(cmd)) logging.info('J2000 setpoint sent to DT: {}'.format(cmd))
self.outsocket.send(cmd) self._outsocket.send(cmd)
def setAzEl(self, setpoint): def setAzEl(self, setpoint):
''' '''
...@@ -143,7 +144,7 @@ class telescope(): ...@@ -143,7 +144,7 @@ class telescope():
cmd = '{:f}\t{:f}\n'.format(az, el) cmd = '{:f}\t{:f}\n'.format(az, el)
logging.info('AzEl sent to DT: {}'.format(cmd)) logging.info('AzEl sent to DT: {}'.format(cmd))
self.outsocket.send(cmd) self._outsocket.send(cmd)
def setOffset(self, offset): def setOffset(self, offset):
''' '''
...@@ -166,7 +167,7 @@ class telescope(): ...@@ -166,7 +167,7 @@ class telescope():
cmd = '{:f}\t{:f}\n'.format(off_az, off_el) cmd = '{:f}\t{:f}\n'.format(off_az, off_el)
logging.info('Offset sent to DT: {}'.format(cmd)) logging.info('Offset sent to DT: {}'.format(cmd))
self.offsetsocket.send(cmd) self._offsetsocket.send(cmd)
def waitUntilThere(self): def waitUntilThere(self):
...@@ -188,3 +189,25 @@ class telescope(): ...@@ -188,3 +189,25 @@ class telescope():
while self.dist_el is None or self.dist_az is None or \ while self.dist_el is None or self.dist_az is None or \
(abs(self.dist_el)<0.01*u.deg and abs(self.dist_az)<0.01*u.deg): (abs(self.dist_el)<0.01*u.deg and abs(self.dist_az)<0.01*u.deg):
continue continue
def getJ2000(self):
'''
Generates a list of dicts with 'current_position_j2000' and
'setpoint_j2000', containing radec and setpoint_radec, at whichever
speed the console is outputting them (probably once a second).
'''
while True:
time.sleep(1)
yield({'current_position_j2000': self.radec,
'setpoint_j2000': self.setpoint_radec})
def getTraces(self):
'''
Generates a dict of all traces from trace2port at whichever
rate trace2port generates them (probably once a second).
'''
while True:
time.sleep(1)
yield({'current_position_azel': (self.az, self.el),
'distance_to_setpoint': (self.dist_az, self.dist_el),
'speed': (self.speed_az, self.speed_el)})
...@@ -6,5 +6,5 @@ Port_Write_AzEl : 11041 ...@@ -6,5 +6,5 @@ Port_Write_AzEl : 11041
Port_Write_Offset: 11011 Port_Write_Offset: 11011
[Trace2Port] [Trace2Port]
HostName: mercurius HostName: localhost
Port: 11042 Port: 11042
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