Blame view

src/device_controller/abstract_component/mount.py 20.4 KB
ac0e5c70   Etienne Pallier   nouveau devices_c...
1
2
3
4
5
6
7
8
9
10
#!/usr/bin/env python3

"""Socket Client Telescope (abstract) implementation

To be used as a base class (interface) for any concrete socket client telescope class
"""


# Standard library imports
#from enum import Enum
ac0e5c70   Etienne Pallier   nouveau devices_c...
11
12
13
14
15
16
import sys
import time

# Third party imports

# from sockets_tele/
57621753   Etienne Pallier   NOUVELLE ARCHI un...
17
#sys.path.append("..")
ac0e5c70   Etienne Pallier   nouveau devices_c...
18
# from src_socket/client/
b23417b8   Etienne Pallier   Restructuration d...
19
sys.path.append("../../../..")
c6c8be74   Etienne Pallier   Restructuration d...
20
#import src.core.pyros_django.utils.celme as celme
ad0e45ec   Alexis Koralewski   Moving guitastro ...
21
import vendor.guitastro as guitastro
ac0e5c70   Etienne Pallier   nouveau devices_c...
22
23
24
25
26
27


# Local application imports
#sys.path.append('../..')
#from src.client.socket_client_abstract import UnknownCommandException, SocketClientAbstract
##from src_socket.client.socket_client_abstract import *
bcf29d0f   Etienne Pallier   update controller...
28
29
#from device_controller.abstract_component.device_controller import *
from device_controller.abstract_component.device_controller import (
1cf4a67f   Etienne Pallier   Affichage console...
30
        printd, DeviceController, generic_cmd, GenericResult, 
1957c45d   Etienne Pallier   Simuler lecture c...
31
        UnknownNativeCmdException, UnknownNativeResException, UnknownGenericCmdArgException, 
6ba000cd   Etienne Pallier   Transition en cou...
32
33
        DeviceTimeoutException,
        Cmd, Gen2NatCmds
bcf29d0f   Etienne Pallier   update controller...
34
35
    )

ac0e5c70   Etienne Pallier   nouveau devices_c...
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65




# Execute also "set" and "do" commands
#GET_ONLY=False
# Execute only "get" commands
#GET_ONLY=True

# Default timeouts
TIMEOUT_SEND = 10
TIMEOUT_RECEIVE = 10


'''
class c(Enum):

    # GET, SET
    DEC = 'DEC'
    RA = 'RA'
    RA_DEC = 'RA_DEC'
    
    # DO
    PARK = 'PARK'
    WARM_START = 'WARM_START'
'''




1cf4a67f   Etienne Pallier   Affichage console...
66

ac0e5c70   Etienne Pallier   nouveau devices_c...
67
68
69
70
71
72
73
74
75
76
77
78
class Position():
    x = 0
    y = 0
    def __init__(self, x,y):
        self.x = x 
        self.y = y
    def get_values(self):
        return self.x, self.y    
    


#class SocketClientTelescopeAbstract(SocketClientAbstract):
e0853b2e   Etienne Pallier   Bugfixes assert t...
79
80
#class TelescopeControllerAbstract(DeviceController):
class DC_Mount(DeviceController):
2d3d3ee8   Etienne Pallier   clean log message...
81

ac0e5c70   Etienne Pallier   nouveau devices_c...
82
83
    # @abstract (to be overriden)
    _cmd_device_concrete = {}
57621753   Etienne Pallier   NOUVELLE ARCHI un...
84
    ##_cmd_device_abstract = {
e3278284   Etienne Pallier   Nouveau format co...
85
    GEN2NAT_CMDS_obj = Gen2NatCmds([
6ba000cd   Etienne Pallier   Transition en cou...
86
87
88
89
90
91
92
93
94
95
96
        # GET-SET commands:

        # (test only) will raise a NotImplementedException
        Cmd('do_unimplemented'),

        Cmd('get_ack'),

        Cmd('get_ra'),
        Cmd('set_ra'),
        Cmd('get_dec'),
        Cmd('set_dec'),
1d7f9921   Etienne Pallier   transition (7) ve...
97
98
        Cmd('get_radec', 'get_radec'),
        Cmd('set_radec', 'set_radec'),
6ba000cd   Etienne Pallier   Transition en cou...
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124

        Cmd('get_longitude'),
        Cmd('set_longitude'),
        Cmd('get_latitude'),
        Cmd('set_latitude'),

        Cmd('get_velocity'),
        Cmd('set_velocity'),

        # DO commands:
        ##'do_init': ['do_init'],
        ##'do_park': [],
        Cmd('do_goto','do_goto'),

        # for test only
        Cmd('mount_only'),

        Cmd('do_goto_radec','do_goto_radec'),
        Cmd('do_move'),
        Cmd('do_movenorth'),
        Cmd('do_movesouth'),
        Cmd('do_movewest'),
        Cmd('do_moveeast'),
        Cmd('do_move_dir'),
        Cmd('do_warm_start'),
        Cmd('do_prec_refr'),
e3278284   Etienne Pallier   Nouveau format co...
125
    ])
1d7f9921   Etienne Pallier   transition (7) ve...
126
    '''
6ba000cd   Etienne Pallier   Transition en cou...
127
    my_cmds2 = Gen2NatCmds()
dbe19111   Etienne Pallier   transition (step ...
128
    my_cmds2.add_cmds(GEN2NAT_CMDS_obj)
52df9a16   Etienne Pallier   transition (6) ve...
129
    '''
1d7f9921   Etienne Pallier   transition (7) ve...
130
    '''
6ba000cd   Etienne Pallier   Transition en cou...
131
132
133
134
    print("******************************")
    print("(MOUNT) Mes commandes")
    my_cmds2.print_mes_commandes()
    print("******************************")
52df9a16   Etienne Pallier   transition (6) ve...
135
136
    '''

dbe19111   Etienne Pallier   transition (step ...
137
    GEN2NAT_CMDS_dict = {
ac0e5c70   Etienne Pallier   nouveau devices_c...
138
        # GET-SET commands:
57621753   Etienne Pallier   NOUVELLE ARCHI un...
139
140
141
142

        # (test only) will raise a NotImplementedException
        'do_unimplemented': [],

ac0e5c70   Etienne Pallier   nouveau devices_c...
143
        'get_ack': [],
57621753   Etienne Pallier   NOUVELLE ARCHI un...
144

ac0e5c70   Etienne Pallier   nouveau devices_c...
145
146
147
148
        'get_ra': [],
        'set_ra': [],
        'get_dec': [],
        'set_dec': [],
f098fd90   Etienne Pallier   bugfix client et ...
149
        #'get_radec': [get_radec],
ac0e5c70   Etienne Pallier   nouveau devices_c...
150
151
        'get_radec': ['get_radec'],
        'set_radec': ['set_radec'],
57621753   Etienne Pallier   NOUVELLE ARCHI un...
152

ac0e5c70   Etienne Pallier   nouveau devices_c...
153
154
155
156
        'get_longitude': [],
        'set_longitude': [],
        'get_latitude': [],
        'set_latitude': [],
f098fd90   Etienne Pallier   bugfix client et ...
157

ac0e5c70   Etienne Pallier   nouveau devices_c...
158
159
        'get_velocity': [],
        'set_velocity': [],
f098fd90   Etienne Pallier   bugfix client et ...
160

ac0e5c70   Etienne Pallier   nouveau devices_c...
161
162
163
        # DO commands:
        ##'do_init': ['do_init'],
        ##'do_park': [],
ea13de96   Etienne Pallier   NEW general cmd f...
164
        'do_goto': ['do_goto'],
57621753   Etienne Pallier   NOUVELLE ARCHI un...
165
166
167
168

        # for test only
        'mount_only':[],

ea13de96   Etienne Pallier   NEW general cmd f...
169
        'do_goto_radec': ['do_goto_radec'],
ac0e5c70   Etienne Pallier   nouveau devices_c...
170
171
172
173
174
175
176
177
178
        'do_move': [],
        'do_movenorth': [],
        'do_movesouth': [],
        'do_movewest': [],
        'do_moveeast': [],
        'do_move_dir': [],
        'do_warm_start': [],
        'do_prec_refr': [],
    }
dbe19111   Etienne Pallier   transition (step ...
179
    
1d7f9921   Etienne Pallier   transition (7) ve...
180
    #GEN2NAT_CMDS = my_cmds2.get_as_dict()
dbe19111   Etienne Pallier   transition (step ...
181
    GEN2NAT_CMDS = GEN2NAT_CMDS_dict
e3278284   Etienne Pallier   Nouveau format co...
182
183
    #GEN2NAT_CMDS = Gen2NatCmds(GEN2NAT_CMDS_obj).get_as_dict()
    GEN2NAT_CMDS = GEN2NAT_CMDS_obj
ac0e5c70   Etienne Pallier   nouveau devices_c...
184

ac0e5c70   Etienne Pallier   nouveau devices_c...
185
    #TODO: remplacer PROTOCOL par "SOCKET-TCP", "SOCKET-UDP", "SERIAL", ou "USB"
57621753   Etienne Pallier   NOUVELLE ARCHI un...
186
    ##def __init__(self, device_host:str="localhost", device_port:int=11110, PROTOCOL:str="TCP", buffer_size=1024, DEBUG=False, device_sim=None):
ce74dbbb   Etienne Pallier   LOGGER unique : p...
187
    def __init__(self, device_host:str="localhost", device_port:int=11110, channel:str=None, buffer_size=None, protoc=None, gen2nat_cmds={}, device_sim=None):
ac0e5c70   Etienne Pallier   nouveau devices_c...
188
189
190
        '''
        :param device_host: server IP or hostname
        :param device_port: server port
57621753   Etienne Pallier   NOUVELLE ARCHI un...
191
        :param CHANNEL: "UDP" or "TCP"
ac0e5c70   Etienne Pallier   nouveau devices_c...
192
        '''
57621753   Etienne Pallier   NOUVELLE ARCHI un...
193

bcf29d0f   Etienne Pallier   update controller...
194
195
        # _my_gen2nat_cmds = GEN2NAT_CMDS + gen2nat_cmds
        #self._my_gen2nat_cmds = self.GEN2NAT_CMDS
57621753   Etienne Pallier   NOUVELLE ARCHI un...
196
        #self._my_gen2nat_cmds.update(gen2nat_cmds)
1cf4a67f   Etienne Pallier   Affichage console...
197
198
        #printd("(mount 1) my cmds (before):", self.GEN2NAT_CMDS)
        #printd("(mount 2) given cmds (before):", gen2nat_cmds)
bcf29d0f   Etienne Pallier   update controller...
199
        ##self._my_gen2nat_cmds = { **self.GEN2NAT_CMDS, **gen2nat_cmds }
e3278284   Etienne Pallier   Nouveau format co...
200
201
202
203
        #v3
        #my_gen2nat_cmds = { **self.GEN2NAT_CMDS, **gen2nat_cmds }
        #v4
        my_gen2nat_cmds = Gen2NatCmds({ **(self.GEN2NAT_CMDS.get_as_dict()), **(gen2nat_cmds.get_as_dict()) })
1d7f9921   Etienne Pallier   transition (7) ve...
204
        #print("(mount 3) my cmds (after):", my_gen2nat_cmds)
57621753   Etienne Pallier   NOUVELLE ARCHI un...
205
206

        ##super().__init__(device_host, device_port, channel, buffer_size, DEBUG, device_sim)
ce74dbbb   Etienne Pallier   LOGGER unique : p...
207
        super().__init__(device_host, device_port, channel, buffer_size, protoc=protoc, gen2nat_cmds=my_gen2nat_cmds, device_sim=device_sim)
2d3d3ee8   Etienne Pallier   clean log message...
208
        self.printd("IN DC_Mount")
ac0e5c70   Etienne Pallier   nouveau devices_c...
209
210
        # overwrite abstract _cmd dictionary with subclass native _cmd_native dictionary:
        #self._cmd = {**self._cmd, **self._cmd_native}
57621753   Etienne Pallier   NOUVELLE ARCHI un...
211
        ##if gen2nat_qa: self._cmd_device_concrete = {**self._cmd_device_concrete, **gen2nat_qa}
ac0e5c70   Etienne Pallier   nouveau devices_c...
212

ac0e5c70   Etienne Pallier   nouveau devices_c...
213

ac0e5c70   Etienne Pallier   nouveau devices_c...
214
    def get_celme_longitude(self, longitude):
6cc7afa4   Alexis Koralewski   Adding Guitastro .