TelescopeRemoteControlDefault.py 2.59 KB
from django.conf import settings
from dashboard.models import Log
from devices.TelescopeRemoteControlAbstract import TelescopeRemoteControlAbstract
from devices.Telescope import TelescopeController
import os

class TelescopeRemoteControlDefault(TelescopeRemoteControlAbstract):
    #
    ##  Pour les classes a venir qui implémenteront des grammaires outils les commands matchers pointeront sur des méthodes fournies par AK
    ##  et le exec_command appellera la méthode correspondante
    #

    def __init__(self, command, expert_mode):
        super().__init__(command, expert_mode)
        self._command_matcher_set = {
            "COORD_RADEC": self.set,
            "COORD_HADEC": self.set,
            "COORD_ALTAZ": self.set,
            "DRIFT_HADEC": self.set,
            "ROTATOR_ANGLE": self.set
        }
        self._command_matcher_get = {
            "INFORMATIONS": self.get,
            "COORD_RADEC": self.get,
            "COORD_HADEC": self.get,
            "COORD_ALTAZ": self.get
        }
        self._command_matcher_do = {
            "EVAL": self.do,
            "HOMING": self.do,
            "ZENITH": self.do,
            "GOTO": self.do,
            "STOP": self.do,
            "DRIFT_ON": self.do,
            "DRIFT_OFF": self.do,
            "ROTATOR_GOTO": self.do
        }

    def exec_command(self):

        #os.system("echo \"status :" + str(self._command) + "\" >> /home/portos/IRAP/pyros/src/commande_recu")
        if self._command[0] == "GET":
            self._current_matcher = self._command_matcher_get
        elif self._command[0] == "SET":
            self._current_matcher = self._command_matcher_set
        elif self._command[0] == "DO":
            self._current_matcher = self._command_matcher_do
        else: return "KO: Unknown command"
        if self._command[1] in self._current_matcher:
            return self._current_matcher[self._command[1]]()
        else:
            return "KO: Unknown command"


    '''
        Locals methods for the generic grammar
    '''

    def do(self):
        definitive_command = "DO " + self._command[1] + ' ' + ' '.join(self._command[2:])
        response = self._telescope.send_command(definitive_command)
        return response

    def set(self):
        definitive_command = "SET " + self._command[1] + ' ' + ' '.join(self._command[2:])
        response = self._telescope.send_command(definitive_command)
        return response

    def get(self):
        definitive_command = "GET " + self._command[1] #+ ' ' + ' '.join(self._command[2:])
        response = self._telescope.send_command(definitive_command)
        return response