Newer
Older
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''REST API for Telescope related operations'''
Davide Ricci
committed
# System modules
from datetime import datetime
# Third-party modules
from config import constants
from utils.coordinates import to_hms, to_hms_dms, to_radec
Davide Ricci
committed
'''Petals covering the primary mirror.'''
Davide Ricci
committed
'''Retrieve the petals position.'''
"response": self.dev.cover,
"error": self.dev.error,
}
return res
Davide Ricci
committed
'''Manage the primary mirror cover petals.'''
Davide Ricci
committed
# '''Check if petals are moving.'''
# return
def post(self):
'''Set a new position for cover petals
Davide Ricci
committed
(open or closed).'''
target = request.json # api.payload
self.dev.open = target
"response": self.dev.open,
"error": self.dev.error,
}
return res
Davide Ricci
committed
# '''Stop the movement.'''
Davide Ricci
committed
'''Manage the cabinet errors.'''
Davide Ricci
committed
'''Check if there are errors.'''
"response": self.dev.state, # state is global
"error": self.dev.error,
}
return res
Davide Ricci
committed
'''Try to clean the errors.'''
"response": self.dev.clear(error_number),
"error": self.dev.error,
}
return res
Davide Ricci
committed
'''Get the global status to have more info.'''
def get(self):
'''Check if there are errors.'''
res = {
"response": self.dev.status, # state is global
"error": self.dev.error,
Davide Ricci
committed
}
return res
Davide Ricci
committed
'''Telescope time from GPS.'''
Davide Ricci
committed
'''Get the telescope time from GPS.'''
res = {
"response": self.dev.clock,
"error": self.dev.error,
Davide Ricci
committed
return res
Davide Ricci
committed
'''Telescope coordinates.'''
'''Get the telescope coordinates.'''
Davide Ricci
committed
coor = self.dev.coordinates
lst = coor["lst"]
ra = coor["radec"][0]
coor["ha"] = to_hms(lst-ra)
coor["radec"] = to_hms_dms(coor["radec"])
coor["lst"] = to_hms(coor["lst"])
utc = coor["utc"]
coor["utc"] = datetime.fromtimestamp(utc).isoformat()
Davide Ricci
committed
res = {
Davide Ricci
committed
"response": coor,
Davide Ricci
committed
return res
# @api.route("/coordinates/movement")
Davide Ricci
committed
'''Manage the pointing of the telescope.'''
Davide Ricci
committed
'''Check the status of the telescope movement.'''
res = {
"response": self.dev.is_moving,
"error": self.dev.error,
Davide Ricci
committed
return res
Davide Ricci
committed
'''Stop the telescope movement.'''
Davide Ricci
committed
res = {
"response": self.dev.abort(),
"error": self.dev.error,
Davide Ricci
committed
}
return res
# @api.route("/coordinates/movement/radec")
Davide Ricci
committed
'''Point the telescope in Ra, Dec.'''
Davide Ricci
committed
'''Set new Ra and Dec coordinates.'''
radec = to_radec(target)
res = {
"response": self.dev.radec,
"error": self.dev.error,
}
return res
# @api.route("/coordinates/movement/altaz")
Davide Ricci
committed
'''Point the telescope in Alt, Az.'''
Davide Ricci
committed
'''Set new Alt and Az coordinates.'''
Davide Ricci
committed
res = {
"error": self.dev.error,
"timestamp": self.timestamp,
Davide Ricci
committed
return res
# @api.route("/coordinates/movement/atpark")
'''Park the telescope.'''
def get(self):
'''Send the telescope to park position.'''
"raw": parked,
"response": constants.yes_no[parked],
# @api.route("/coordinates/movement/park")
Davide Ricci
committed
'''Park the telescope.'''
Davide Ricci
committed
'''Send the telescope to park position.'''
res = {
"response": self.dev.park,
"error": self.dev.error,
Davide Ricci
committed
return res
# @api.route("/coordinates/movement/unpark")
Davide Ricci
committed
'''Unpark the telescope.'''
Davide Ricci
committed
'''Remove the telescope from park position.'''
res = {
"response": self.dev.park,
"error": self.dev.error,
"timestamp": self.timestamp,
Davide Ricci
committed
return res
# @api.route("/coordinates/offset")
Davide Ricci
committed
'''Manage the coordinates offset.'''
Davide Ricci
committed
'''Retrieve the telescope offset in Zdist, Az.'''
res = {
"response": self.dev.offset,
"error": self.dev.error,
}
return res
Davide Ricci
committed
'''Apply to the telescope new offsets in degrees.'''
res = {
"response": self.dev.offset,
"error": self.dev.error,
}
return res
# @api.route("/coordinates/tracking")
Davide Ricci
committed
'''Enable or disable the telescope tracking.'''
Davide Ricci
committed
'''Check if the telescope is tracking or not.'''
res = {
"raw": self.dev.tracking,
"response": constants.yes_no[self.dev.tracking],
}
return res
Davide Ricci
committed
'''Set the telescope in tracking mode or not'''
res = {
"response": self.dev.tracking,
"error": self.dev.error,
}
return res
'''Manage the connection to ASCOM.'''
def get(self):
'''Check if the telescope is connected to ASCOM.'''
"raw": self.dev.connection,
"response": constants.yes_no[self.dev.connection],
}
return res
def put(self):
'''Connect or disconnect the telescope to ASCOM.'''
self.dev.connection = connection
"raw": self.dev.connection,
"response": constants.yes_no[self.dev.connection],
# clock = Clock(dev=self.dev).get()
# if clock["response"] and type(clock["response"]) != str:
# connection = Connection(dev=self.dev).get()
# if connection["response"]: