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
252a8b01   Alexis Koralewski   Changing few guit...
21
import vendor.guitastro.src.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 ...
215
        return guitastro.Angle(longitude).sexagesimal("d:+0180.0")
ac0e5c70   Etienne Pallier   nouveau devices_c...
216
    def get_celme_latitude(self, latitude):
6cc7afa4   Alexis Koralewski   Adding Guitastro ...
217
        return guitastro.Angle(latitude).sexagesimal("d:+090.0")
ac0e5c70   Etienne Pallier   nouveau devices_c...
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283


    
    '''
    TELESCOPE COMMANDS (abstract methods)
    '''


    
    '''
    ****************************
    ****************************
    GENERIC TELESCOPE COMMANDS (abstract methods)
    ****************************
    ****************************
    '''



    '''
    ****************************
     GENERIC GET & SET commands 
    **************************** 
    '''
    
    # @abstract
    @generic_cmd
    def get_ack(self): pass
    #return self.execute_generic_cmd("get_ack")

    # RA/DEC
    # @abstract
    '''
    Sets the object's Right Ascension and the object status to "Not Selected". 
    The :Sd# command has to follow to complete the selection. 
    The subsequent use of the :ON...# command is recommended (p106)
    :Sr<hh>:<mm>.<m># 
    or 
    :Sr<hh>:<mm>:<ss>#   
    0 if invalid
    1 if valid
    '''
    @generic_cmd
    def get_ra(self): pass
    #def get_ra(self):               return self.execute_generic_cmd("get_ra")
    @generic_cmd
    def set_ra(self, ra): pass        
    #return self._set("ra", ra)

    '''
    Sets the object's declination. 
    It is important that the :Sr# command has been send prior. 
    Internal calculations are done that may take up to 0.5 seconds. 
    If the coordinate selection is valid the object status is set to "Selected"
    :Sd{+-}<dd>{*°}<mm># 
    or
    :Sd{+- }<dd>{*°:}<mm>:<ss>
    0 if invalid
    1 if valid
    '''
    @generic_cmd
    def get_dec(self): pass
    #def get_dec(self):              return self.execute_generic_cmd("get_dec")
    @generic_cmd
    def set_dec(self, dec): pass
    #def set_dec(self, dec):         return self._set("dec", dec)
38bead5a   Etienne Pallier   Gros bugfix de Ag...
284

ac0e5c70   Etienne Pallier   nouveau devices_c...
285
286
287
    # MACRO radec
    #def get_radec(self):            return self._get("RADEC")
    #def get_radec(self)->tuple:     return ((self.get_ra()), (self.get_dec()))
38bead5a   Etienne Pallier   Gros bugfix de Ag...
288
    def get_radec(self)->GenericResult:
ac0e5c70   Etienne Pallier   nouveau devices_c...
289
        return GenericResult(self.get_ra().txt + "," + self.get_dec().txt)
38bead5a   Etienne Pallier   Gros bugfix de Ag...
290

ac0e5c70   Etienne Pallier   nouveau devices_c...
291
    # MACRO
38bead5a   Etienne Pallier   Gros bugfix de Ag...
292
    def set_radec(self, ra, dec)->GenericResult:
ac0e5c70   Etienne Pallier   nouveau devices_c...
293
294
295
        self.set_ra(ra)
        self.set_dec(dec)
        return GenericResult("OK")
38bead5a   Etienne Pallier   Gros bugfix de Ag...
296

ac0e5c70   Etienne Pallier   nouveau devices_c...
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
    @generic_cmd
    def get_long(self): pass
    @generic_cmd
    def set_long(self, longitude): pass
    
    @generic_cmd
    def get_lat(self): pass
    @generic_cmd
    def set_lat(self, latitude): pass
    
    @generic_cmd
    def get_vel(self): pass




    '''
    ****************************
     GENERIC DO commands 
    **************************** 
    '''

    # @abstract
    #def do_INIT(self):              return self._do("INIT")

    ''' do_PARK() (p103)
    - STARTUP position = CWD
        - :hC#
        - position required for a Cold or Warm Start, pointing to the celestial pole of the given hemisphere (north or south), 
        with the counterweight pointing downwards (CWD position). From L4, V1.0 up
    - HOME position parking => par defaut, c'est CWD, mais ca peut etre different
        - :hP#
        - defaults to the celestial pole visible at the given hemisphere (north or south) and can be set by the user
    '''

    @generic_cmd
    def do_move(self): pass
    @generic_cmd
    def do_movenorth(self): pass
    @generic_cmd
    def do_movesouth(self): pass
    @generic_cmd
    def do_movewest(self): pass
    @generic_cmd
    def do_moveeast(self): pass

    # @abstract
    #def do_GOTO(self, pos:Position):    return self._do("GOTO")
    #def do_WARM_START(self):         return self._do("WARM_START")
    @generic_cmd
    def do_warm_start(self): pass

    @generic_cmd
    def do_prec_refr(self): pass        

ea13de96   Etienne Pallier   NEW general cmd f...
352

ac0e5c70   Etienne Pallier   nouveau devices_c...
353
354
    # MACRO generic command
    def do_init(self):
ea13de96   Etienne Pallier   NEW general cmd f...
355

2d3d3ee8   Etienne Pallier   clean log message...
356
        self.printd("...STARTING TELESCOPE INITIALIZATION...")
ea13de96   Etienne Pallier   NEW general cmd f...
357
        time.sleep(1)
2d3d3ee8   Etienne Pallier   clean log message...
358
        self.printd("...TELESCOPE INITIALIZATION ENDED")
ea13de96   Etienne Pallier   NEW general cmd f...
359
360
        return GenericResult("OK")

ac0e5c70   Etienne Pallier   nouveau devices_c...
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
        '''
        1) Send cde ACK ('06') and check answer to see if telescope is ready (see doc page 100)
        (utile pour savoir si tout est ok ; par ex, si une raquette est branchée sur le tele, ça peut bloquer le protocole)
        Usable for testing the serial link and determining the type of mount (German equatorial).
        Return code can be:
        - B# while the initial startup message is being displayed (new in L4),
        - b# while waiting for the selection of the Startup Mode,
        - S# during a Cold Start (new in L4),
        - G# after completed startup ==> MEANS ALL IS OK
        '''
        #ACK = self.get("ACK")
        ACK = self.get_ack()
           
        ''' 
        2) IF telescope is not ready (still starting up), ask it to do a Warm Start ('bW#') 
        During Startup, with a "b#" being returned, the PC can select the startup mode by sending a
            • bC# for selecting the Cold Start,
            • bW# for selecting the Warm Start,
            • bR# for selecting the Warm Restart
        If not ok (still starting up, no 'G#' in return), send 'bW#' (see above) for selecting the Warm Start
        '''
        #if ACK != 'G':
        if not ACK.ok:
            self.do_warm_start()
            ACK = self.get_ack()
            elapsed_time = 0
            while not ACK.ok:
                time.sleep(1)
                elapsed_time += 1
                if elapsed_time == TIMEOUT_RECEIVE: raise TimeoutException()
                ACK = self.get_ack()
                
        
        '''
        3) Set timezone, date, and time (p109)
        '''

        '''
        a) set TIMEZONE
        Set the number of hours by which your local time differs from UTC. 
        If your local time is earlier than UTC set a positive value, 
        if later than UTC set a negative value. The time difference has to be set before setting the calendar date (SC) and local time (SL), since the Real Time Clock is running at UTC
        => :SG{+-}hh#        
        '''
        res = self.get_timezone()
2d3d3ee8   Etienne Pallier   clean log message...
406
        self.printd("Current timezone is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
407
        res = self.set_timezone('+00')
e0098e4f   Etienne Pallier   Ajout du traiteme...
408
409
        #if res != '1': raise UnknownNativeResException(res)
        if not res.ok: raise UnknownNativeResException(res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
410
        res = self.get_timezone()
e0098e4f   Etienne Pallier   Ajout du traiteme...
411
        if res.txt != '+00': raise UnknownNativeResException(res)
2d3d3ee8   Etienne Pallier   clean log message...
412
        self.printd("NEW timezone set is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
413
414
415
416
417
418
419
420
421
422
423
424
425
426
        

        '''
        b) set DATE
        Set Calendar Date: 
        months mm, days dd, year yy of the civil time according to the timezone set. 
        The internal calendar/clock uses GMT
        :SC<mm>/<dd>/<yy>#
        0 if invalid 
        or
        TODO:
        1Updating planetary data#<24 blanks>#            
        '''
        res = self.get_date()
2d3d3ee8   Etienne Pallier   clean log message...
427
        self.printd("Current date is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
428
429
430
431
        # format is 2018-09-26T17:50:21
        d = self.get_utc_date()
        # format to mm/dd/yy
        now_utc_mm_dd_yy = d[5:7] + '/' + d[8:10] + '/' + d[2:4]
1cf4a67f   Etienne Pallier   Affichage console...
432
        #printd("date is", now_utc_mm_dd_yy)
ac0e5c70   Etienne Pallier   nouveau devices_c...
433
434
        res = self.set_date(now_utc_mm_dd_yy)
        #res = self.set_DATE(self.get_utc_date())
e0098e4f   Etienne Pallier   Ajout du traiteme...
435
436
437
        #if res[0] != '1': raise UnknownNativeResException(res)
        #if not res.startswith('1Updating planetary data'): raise UnknownNativeResException(res)
        if not res.ok: raise UnknownNativeResException(res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
438
        res = self.get_date()
e0098e4f   Etienne Pallier   Ajout du traiteme...
439
        if res.txt != now_utc_mm_dd_yy: raise UnknownNativeResException(res)
2d3d3ee8   Etienne Pallier   clean log message...
440
        self.printd("NEW DATE set is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
441
442
443
444
445
446
447
448

        '''
        c) set TIME
        Set RTC Time from the civil time hours hh, minutes mm and seconds ss. 
        The timezone must be set before using this command
        :SL<hh>:<mm>:<ss>#
        '''
        res = self.get_time()
2d3d3ee8   Etienne Pallier   clean log message...
449
        self.printd("Current time is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
450
        _,now_utc_hh_mm_ss = d.split('T')
1cf4a67f   Etienne Pallier   Affichage console...
451
        #printd("time is", now_utc_hh_mm_ss[:5])
ac0e5c70   Etienne Pallier   nouveau devices_c...
452
        res = self.set_time(now_utc_hh_mm_ss)
e0098e4f   Etienne Pallier   Ajout du traiteme...
453
454
        #if res != '1': raise UnknownNativeResException(res)
        if not res.ok: raise UnknownNativeResException(res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
455
        res = self.get_time()
e0098e4f   Etienne Pallier   Ajout du traiteme...
456
        if res.txt[:5] != now_utc_hh_mm_ss[:5]: raise UnknownNativeResException(res)
2d3d3ee8   Etienne Pallier   clean log message...
457
        self.printd("NEW TIME set is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477

            
        '''
        4) Set LOCATION (lat,long) (p103,110)
        Pour l'observatoire de Guitalens:
        Sg = 2.0375 E 
        St = 43.6443 N
        (attention, 2.0375 E = - 2.0375) 
        '''
        
        '''
        a) set Longitude
        Sets the longitude of the observing site to ddd degrees and mm minutes. 
        The longitude has to be specified positively for western latitudes 
        (west of Greenwich, the plus sign may be omitted) and negatively for eastern longitudes. 
        Alternatively, 360 degrees may be added to eastern longitudes.
        => :Sg{+-}<ddd>*<mm>#
        '''
        # TELE format is -002°02 (I convert it to -002:02)
        res = self.get_long()
2d3d3ee8   Etienne Pallier   clean log message...
478
        self.printd("Current longitude is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
479
480
481
482
483
484
485
        
        # CELME format is -002:02:15
        res = self.get_celme_longitude("-2.0375")
        res_ddd_mm = res[:-3]
        #res_ddd_mm = res[:-3].replace(':','*')
        #res_ddd_mm = '-002:03'
        
1cf4a67f   Etienne Pallier   Affichage console...
486
        #printd("celme longitude is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
487
488
489
        ddd,mm,ss = res.split(':')
        #dddmm = '-002*03'
        res = self.set_long(ddd+'*'+mm)
e0098e4f   Etienne Pallier   Ajout du traiteme...
490
491
        #if res != '1': raise UnknownNativeResException(res)
        if not res.ok: raise UnknownNativeResException(res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
492
        res = self.get_long()
e0098e4f   Etienne Pallier   Ajout du traiteme...
493
        if res.txt != res_ddd_mm: raise UnknownNativeResException(res_ddd_mm, res.txt)
2d3d3ee8   Etienne Pallier   clean log message...
494
        self.printd("NEW longitude set is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
495
496
497
498
499
500
501
502
503

        '''
        b) set Latitude
        Sets the latitude of the observing site to dd degrees, mm minutes. 
        The minus sign indicates southern latitudes, the positive sign may be omitted.
        => :St{+-}<dd>*<mm>#
        '''
        # TELE format is +43°38 (I convert it to +43:38)
        res = self.get_lat()
2d3d3ee8   Etienne Pallier   clean log message...
504
        self.printd("Current latitude is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
505
506
507
508
509
        
        # CELME format is +43:38:15
        res = self.get_celme_latitude("+43.6443")
        res_dd_mm = res[:-3]
        #res_dd_mm = res[:-3].replace(':','*')
2d3d3ee8   Etienne Pallier   clean log message...
510
        self.printd("res is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
511
512
        #res_dd_mm = '+43:50'
        
1cf4a67f   Etienne Pallier   Affichage console...
513
        #printd("celme longitude is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
514
515
516
517
        dd,mm,ss = res.split(':')
        ddmm = dd+'*'+mm
        #ddmm = '+43*50'
        res = self.set_lat(ddmm)
e0098e4f   Etienne Pallier   Ajout du traiteme...
518
519
        #if res != '1': raise UnknownNativeResException(res)
        if not res.ok: raise UnknownNativeResException(res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
520
        res = self.get_lat()
e0098e4f   Etienne Pallier   Ajout du traiteme...
521
        if res.txt != res_dd_mm: raise UnknownNativeResException(res_dd_mm,res.txt)
2d3d3ee8   Etienne Pallier   clean log message...
522
        self.printd("NEW latitude set is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547


        '''
        5) Send cde ':p3#' : Precession & Refraction (see page 107)
        Ask Gemini to do Precession calculation 
        Coordinates transferred to the Gemini refer to the standard epoch J2000.0. 
        Refraction is calculated (From L4, V1.0 up)
        ''' 
        self.do_prec_refr()
        
        return GenericResult("OK")

    
    # @abstract
    def set_speed(self, speed_rate):
        pass


    ''' GOTO (p105)
        - GOTO(position, blocking=Y/N):
            (MS = move start)
            = Goto RA=18h23m45s Dec=+34d00m00s J2000
        - radec.goto()
    '''
    # MACRO generic command
ea13de96   Etienne Pallier   NEW general cmd f...
548
    def do_goto_radec(self, ra, dec, speed_rate=None): return self.do_goto(ra, dec, speed_rate)
ac0e5c70   Etienne Pallier   nouveau devices_c...
549
    def do_goto(self, ra, dec, speed_rate=None):
38bead5a   Etienne Pallier   Gros bugfix de Ag...
550

ea13de96   Etienne Pallier   NEW general cmd f...
551
        # TODO: remove
2d3d3ee8   Etienne Pallier   clean log message...
552
        self.printd("...Starting GOTO...")
ea13de96   Etienne Pallier   NEW general cmd f...
553
554
        time.sleep(3)
        radec = self.get_radec()
2d3d3ee8   Etienne Pallier   clean log message...
555
        self.printd("...GOTO ended OK")
ea13de96   Etienne Pallier   NEW general cmd f...
556
557
        return GenericResult("OK")

ac0e5c70   Etienne Pallier   nouveau devices_c...
558
        # 1) set speed
ea13de96   Etienne Pallier   NEW general cmd f...
559
        if speed_rate : self.set_speed(speed_rate)
38bead5a   Etienne Pallier   Gros bugfix de Ag...
560

ac0e5c70   Etienne Pallier   nouveau devices_c...
561
        radec = self.get_radec()
2d3d3ee8   Etienne Pallier   clean log message...
562
        self.printd("Current position is", radec)
ac0e5c70   Etienne Pallier   nouveau devices_c...
563
564
565
566
567
568

        # 2) set RA-DEC
        '''
        :Sr18:23:45#:Sd+34:00:00#:MS#
        '''
        res = self.set_ra(ra)
e0098e4f   Etienne Pallier   Ajout du traiteme...
569
570
571
572
        #if res != '1': raise UnknownNativeResException(res)
        ##if res.ko: raise UnknownNativeResException(res)
        if res.unknown_command: raise UnknownNativeCmdException("set_ra")
        if res.unknown_result: raise UnknownNativeResException(res.txt)
ac0e5c70   Etienne Pallier   nouveau devices_c...
573
        res = self.set_dec(dec)
e0098e4f   Etienne Pallier   Ajout du traiteme...
574
575
576
        #if res != '1': raise UnknownNativeResException(res)
        ##if res.ko: raise UnknownNativeResException(res)
        if res.unknown_result: raise UnknownNativeResException(res)
38bead5a   Etienne Pallier   Gros bugfix de Ag...
577

483003c1   Etienne Pallier   Derniers renommag...
578
        # 3) MOVE (non blocking by default for Gemini)
ac0e5c70   Etienne Pallier   nouveau devices_c...
579
        self.do_move()
38bead5a   Etienne Pallier   Gros bugfix de Ag...
580

ac0e5c70   Etienne Pallier   nouveau devices_c...
581
582
583
584
585
586
587
588
589
590
591
592
593
        # 4) Test velocity until it is "Tracking"
        '''
        After MOVE, test velocity with ':Gv#' (p103) : we should have 'S', then 'C', then 'T'
            - N (for "no tracking") 
            - T (for Tracking)
            - G (for Guiding)
            - C (for Centering)
            - S (for Slewing)
        '''
        vel = None
        while vel != 'T':
            v = self.get_vel()
            vel = v.txt
2d3d3ee8   Etienne Pallier   clean log message...
594
            self.printd("Velocity is", v)
ac0e5c70   Etienne Pallier   nouveau devices_c...
595
            time.sleep(2)
38bead5a   Etienne Pallier   Gros bugfix de Ag...
596

ac0e5c70   Etienne Pallier   nouveau devices_c...
597
598
        time.sleep(2)
        radec= self.get_radec()
2d3d3ee8   Etienne Pallier   clean log message...
599
        self.printd("Current position is", radec)
38bead5a   Etienne Pallier   Gros bugfix de Ag...
600

ac0e5c70   Etienne Pallier   nouveau devices_c...
601
602
        return GenericResult("OK")

38bead5a   Etienne Pallier   Gros bugfix de Ag...
603

ac0e5c70   Etienne Pallier   nouveau devices_c...
604
605
606
607
608
609
610
611
    # @abstract MACRO
    def do_move_dir(self, dir, nbsec, speed_rate=None):
        dir = dir.upper()
        if speed_rate: self.set_speed(speed_rate)
        if dir=="NORTH": self.do_movenorth() 
        elif dir=="SOUTH": self.do_movesouth() 
        elif dir=="WEST": self.do_movewest() 
        elif dir=="EAST": self.do_moveeast()
57621753   Etienne Pallier   NOUVELLE ARCHI un...
612
        else: raise UnknownGenericCmdArgException(dir)
ac0e5c70   Etienne Pallier   nouveau devices_c...
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
        time.sleep(int(nbsec))
        self.do_stop()
        return GenericResult("OK")




    
    
# TODO: empecher de creer une instance de cette classe abstraite
# Avec ABC ?

'''
if __name__ == "__main__":
    
    #HOST, PORT = "localhost", 9999
    #HOST, PORT = "localhost", 20001
    HOST, PORT = "localhost", 11110

    # Classic usage:
    #tsock = SocketClient_UDP_TCP(HOST, PORT, "UDP")
    # More elegant usage, using "with":
    with SocketClient_ABSTRACT(HOST, PORT, "UDP") as tsock:
        
        # 0) CONNECT to server (only for TCP, does nothing for UDP)
        tsock._connect_to_server()
        
        while True:
            
            # 1) SEND REQUEST data to server
            # saisie de la requête au clavier et suppression des espaces des 2 côtés
            data = input("REQUEST TO SERVER [ex: ':GD#' (Get Dec), ':GR#' (Get RA)']: ").strip()
            # test d'arrêt
            if data=="": break
            #data_to_send = bytes(data + "\n", "utf-8")
            tsock.send_data(data)
            #mysock.sendto("%s" % data, (HOST, PORT))
1cf4a67f   Etienne Pallier   Affichage console...
650
            #printd("Sent: {}".format(data))
ac0e5c70   Etienne Pallier   nouveau devices_c...
651
652
653
654
    
            # 2) RECEIVE REPLY data from server
            data_received = tsock.receive_data()
            #reponse, adr = mysock.recvfrom(buf)
1cf4a67f   Etienne Pallier   Affichage console...
655
656
657
            #printd("Received: {}".format(data_received))
            #printd("Useful data received: {}".format(data_useful))
            printd('\n')
ac0e5c70   Etienne Pallier   nouveau devices_c...
658
659
660

        #tsock.close()
'''