Blame view

src/devices/TelescopeRemoteControlDefault.py 2.58 KB
c78dc38b   Quentin Durand   Classe abstraite ...
1
2
3
4
5
6
7
from django.conf import settings
from common.models import Log
from devices.TelescopeRemoteControlAbstract import TelescopeRemoteControlAbstract
from devices.Telescope import TelescopeController
import os

class TelescopeRemoteControlDefault(TelescopeRemoteControlAbstract):
d3faf327   Quentin Durand   Command control D...
8
9
10
11
12
    #
    ##  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
    #

c78dc38b   Quentin Durand   Classe abstraite ...
13
14
    def __init__(self, command, expert_mode):
        super().__init__(command, expert_mode)
d3faf327   Quentin Durand   Command control D...
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
        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
        }
c78dc38b   Quentin Durand   Classe abstraite ...
38
39
40

    def exec_command(self):

d3faf327   Quentin Durand   Command control D...
41
42
43
44
45
46
47
        #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
c78dc38b   Quentin Durand   Classe abstraite ...
48
        else: return "KO: Unknown command"
d3faf327   Quentin Durand   Command control D...
49
50
51
52
53
54
55
56
57
        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
    '''
c78dc38b   Quentin Durand   Classe abstraite ...
58
59

    def do(self):
d3faf327   Quentin Durand   Command control D...
60
61
        definitive_command = "DO " + self._command[1] + ' ' + ' '.join(self._command[2:])
        response = self._telescope.send_command(definitive_command)
c78dc38b   Quentin Durand   Classe abstraite ...
62
63
64
        return response

    def set(self):
d3faf327   Quentin Durand   Command control D...
65
66
        definitive_command = "SET " + self._command[1] + ' ' + ' '.join(self._command[2:])
        response = self._telescope.send_command(definitive_command)
c78dc38b   Quentin Durand   Classe abstraite ...
67
68
69
        return response

    def get(self):
d3faf327   Quentin Durand   Command control D...
70
71
72
        definitive_command = "GET " + self._command[1] #+ ' ' + ' '.join(self._command[2:])
        response = self._telescope.send_command(definitive_command)
        return response