Blame view

src/devices/TelescopeRemoteControl.py 1.42 KB
7e40048f   Quentin Durand   Implementation ba...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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