TelescopeRemoteControl.py 1.42 KB
from django.conf import settings
from common.models import Log
from devices.Telescope import TelescopeController


'''
    Class managing the input from the remote commands sent by the dashboard
    the command is parsed and sent to the Telescope via an instance of TelescopeController

'''

class TelescopeRemoteControl():
    _command = []
    _command_matcher = {}
    def __init__(self, command, expert_mode):
        self._command = command
        if expert_mode:
            self._command = str(command).split()
        self._telescope = TelescopeController()
        self._command_matcher = {
            "GET": self.get,
            "SET": self.set,
            "DO": self.do,
        }

    def exec_command(self):
        if self._command[0] in self._command_matcher:
            response = self._command_matcher[self._command[0]]()
        else:
            return "KO: Unknown command"
        return response

    def get(self):
        param_a = {"POSITION", "STATUS", "SETUP"}
        if self._command[1] in param_a:
            response = self._telescope.get(self._command[1])
            return response
        return "KO: Unknown command"

    def set(self):
        response = self._telescope.set(' '.join(self._command[1:]))
        return "OK Command sent"

    def do(self):
        response = self._telescope.do(' '.join(self._command[1:]))
        return "OK command sent"

    def expert_command(self):
        return True