Blame view

src/device_controller/abstract_component/mount.py 20 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
21
#import src.core.pyros_django.utils.celme as celme
import src.core.celme as celme
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 = {
6ba000cd   Etienne Pallier   Transition en cou...
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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
125
126
127
128
129
130
131
132
133
    GEN2NAT_CMDS = [
        # 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'),
        #'get_radec': [get_radec],
        Cmd('get_radec'),
        Cmd('set_radec'),

        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'),
    ]
    my_cmds2 = Gen2NatCmds()
    my_cmds2.add_cmds(GEN2NAT_CMDS)
    print("******************************")
    print("(MOUNT) Mes commandes")
    my_cmds2.print_mes_commandes()
    print("******************************")
    
bcf29d0f   Etienne Pallier   update controller...
134
    GEN2NAT_CMDS = {
ac0e5c70   Etienne Pallier   nouveau devices_c...
135
        # GET-SET commands:
57621753   Etienne Pallier   NOUVELLE ARCHI un...
136
137
138
139

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

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

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

ac0e5c70   Etienne Pallier   nouveau devices_c...
150
151
152
153
        'get_longitude': [],
        'set_longitude': [],
        'get_latitude': [],
        'set_latitude': [],
f098fd90   Etienne Pallier   bugfix client et ...
154

ac0e5c70   Etienne Pallier   nouveau devices_c...
155
156
        'get_velocity': [],
        'set_velocity': [],
f098fd90   Etienne Pallier   bugfix client et ...
157

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

        # for test only
        'mount_only':[],

ea13de96   Etienne Pallier   NEW general cmd f...
166
        'do_goto_radec': ['do_goto_radec'],
ac0e5c70   Etienne Pallier   nouveau devices_c...
167
168
169
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': [],
    }


    #TODO: remplacer PROTOCOL par "SOCKET-TCP", "SOCKET-UDP", "SERIAL", ou "USB"
57621753   Etienne Pallier   NOUVELLE ARCHI un...
179
    ##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...
180
    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...
181
182
183
        '''
        :param device_host: server IP or hostname
        :param device_port: server port
57621753   Etienne Pallier   NOUVELLE ARCHI un...
184
        :param CHANNEL: "UDP" or "TCP"
ac0e5c70   Etienne Pallier   nouveau devices_c...
185
        '''
57621753   Etienne Pallier   NOUVELLE ARCHI un...
186

bcf29d0f   Etienne Pallier   update controller...
187
188
        # _my_gen2nat_cmds = GEN2NAT_CMDS + gen2nat_cmds
        #self._my_gen2nat_cmds = self.GEN2NAT_CMDS
57621753   Etienne Pallier   NOUVELLE ARCHI un...
189
        #self._my_gen2nat_cmds.update(gen2nat_cmds)
1cf4a67f   Etienne Pallier   Affichage console...
190
191
        #printd("(mount 1) my cmds (before):", self.GEN2NAT_CMDS)
        #printd("(mount 2) given cmds (before):", gen2nat_cmds)
bcf29d0f   Etienne Pallier   update controller...
192
193
        ##self._my_gen2nat_cmds = { **self.GEN2NAT_CMDS, **gen2nat_cmds }
        my_gen2nat_cmds = { **self.GEN2NAT_CMDS, **gen2nat_cmds }
1cf4a67f   Etienne Pallier   Affichage console...
194
        #printd("(mount 3) my cmds (after):", self._my_gen2nat_cmds)
57621753   Etienne Pallier   NOUVELLE ARCHI un...
195
196

        ##super().__init__(device_host, device_port, channel, buffer_size, DEBUG, device_sim)
ce74dbbb   Etienne Pallier   LOGGER unique : p...
197
        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...
198
        self.printd("IN DC_Mount")
ac0e5c70   Etienne Pallier   nouveau devices_c...
199
200
        # overwrite abstract _cmd dictionary with subclass native _cmd_native dictionary:
        #self._cmd = {**self._cmd, **self._cmd_native}
57621753   Etienne Pallier   NOUVELLE ARCHI un...
201
        ##if gen2nat_qa: self._cmd_device_concrete = {**self._cmd_device_concrete, **gen2nat_qa}
ac0e5c70   Etienne Pallier   nouveau devices_c...
202

ac0e5c70   Etienne Pallier   nouveau devices_c...
203

ac0e5c70   Etienne Pallier   nouveau devices_c...
204
205
206
207
208
209
210
211
212
213
214
215
216
217
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
    def get_celme_longitude(self, longitude):
        return celme.Angle(longitude).sexagesimal("d:+0180.0")
    def get_celme_latitude(self, latitude):
        return celme.Angle(latitude).sexagesimal("d:+090.0")


    
    '''
    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...
274

ac0e5c70   Etienne Pallier   nouveau devices_c...
275
276
277
    # 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...
278
    def get_radec(self)->GenericResult:
ac0e5c70   Etienne Pallier   nouveau devices_c...
279
        return GenericResult(self.get_ra().txt + "," + self.get_dec().txt)
38bead5a   Etienne Pallier   Gros bugfix de Ag...
280

ac0e5c70   Etienne Pallier   nouveau devices_c...
281
    # MACRO
38bead5a   Etienne Pallier   Gros bugfix de Ag...
282
    def set_radec(self, ra, dec)->GenericResult:
ac0e5c70   Etienne Pallier   nouveau devices_c...
283
284
285
        self.set_ra(ra)
        self.set_dec(dec)
        return GenericResult("OK")
38bead5a   Etienne Pallier   Gros bugfix de Ag...
286

ac0e5c70   Etienne Pallier   nouveau devices_c...
287
288
289
290
291
292
293
294
295
296
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
    @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...
342

ac0e5c70   Etienne Pallier   nouveau devices_c...
343
344
    # MACRO generic command
    def do_init(self):
ea13de96   Etienne Pallier   NEW general cmd f...
345

2d3d3ee8   Etienne Pallier   clean log message...
346
        self.printd("...STARTING TELESCOPE INITIALIZATION...")
ea13de96   Etienne Pallier   NEW general cmd f...
347
        time.sleep(1)
2d3d3ee8   Etienne Pallier   clean log message...
348
        self.printd("...TELESCOPE INITIALIZATION ENDED")
ea13de96   Etienne Pallier   NEW general cmd f...
349
350
        return GenericResult("OK")

ac0e5c70   Etienne Pallier   nouveau devices_c...
351
352
353
354
355
356
357
358
359
360
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
        '''
        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...
396
        self.printd("Current timezone is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
397
        res = self.set_timezone('+00')
e0098e4f   Etienne Pallier   Ajout du traiteme...
398
399
        #if res != '1': raise UnknownNativeResException(res)
        if not res.ok: raise UnknownNativeResException(res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
400
        res = self.get_timezone()
e0098e4f   Etienne Pallier   Ajout du traiteme...
401
        if res.txt != '+00': raise UnknownNativeResException(res)
2d3d3ee8   Etienne Pallier   clean log message...
402
        self.printd("NEW timezone set is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
403
404
405
406
407
408
409
410
411
412
413
414
415
416
        

        '''
        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...
417
        self.printd("Current date is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
418
419
420
421
        # 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...
422
        #printd("date is", now_utc_mm_dd_yy)
ac0e5c70   Etienne Pallier   nouveau devices_c...
423
424
        res = self.set_date(now_utc_mm_dd_yy)
        #res = self.set_DATE(self.get_utc_date())
e0098e4f   Etienne Pallier   Ajout du traiteme...
425
426
427
        #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...
428
        res = self.get_date()
e0098e4f   Etienne Pallier   Ajout du traiteme...
429
        if res.txt != now_utc_mm_dd_yy: raise UnknownNativeResException(res)
2d3d3ee8   Etienne Pallier   clean log message...
430
        self.printd("NEW DATE set is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
431
432
433
434
435
436
437
438

        '''
        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...
439
        self.printd("Current time is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
440
        _,now_utc_hh_mm_ss = d.split('T')
1cf4a67f   Etienne Pallier   Affichage console...
441
        #printd("time is", now_utc_hh_mm_ss[:5])
ac0e5c70   Etienne Pallier   nouveau devices_c...
442
        res = self.set_time(now_utc_hh_mm_ss)
e0098e4f   Etienne Pallier   Ajout du traiteme...
443
444
        #if res != '1': raise UnknownNativeResException(res)
        if not res.ok: raise UnknownNativeResException(res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
445
        res = self.get_time()
e0098e4f   Etienne Pallier   Ajout du traiteme...
446
        if res.txt[:5] != now_utc_hh_mm_ss[:5]: raise UnknownNativeResException(res)
2d3d3ee8   Etienne Pallier   clean log message...
447
        self.printd("NEW TIME set is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467

            
        '''
        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...
468
        self.printd("Current longitude is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
469
470
471
472
473
474
475
        
        # 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...
476
        #printd("celme longitude is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
477
478
479
        ddd,mm,ss = res.split(':')
        #dddmm = '-002*03'
        res = self.set_long(ddd+'*'+mm)
e0098e4f   Etienne Pallier   Ajout du traiteme...
480
481
        #if res != '1': raise UnknownNativeResException(res)
        if not res.ok: raise UnknownNativeResException(res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
482
        res = self.get_long()
e0098e4f   Etienne Pallier   Ajout du traiteme...
483
        if res.txt != res_ddd_mm: raise UnknownNativeResException(res_ddd_mm, res.txt)
2d3d3ee8   Etienne Pallier   clean log message...
484
        self.printd("NEW longitude set is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
485
486
487
488
489
490
491
492
493

        '''
        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...
494
        self.printd("Current latitude is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
495
496
497
498
499
        
        # 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...
500
        self.printd("res is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
501
502
        #res_dd_mm = '+43:50'
        
1cf4a67f   Etienne Pallier   Affichage console...
503
        #printd("celme longitude is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
504
505
506
507
        dd,mm,ss = res.split(':')
        ddmm = dd+'*'+mm
        #ddmm = '+43*50'
        res = self.set_lat(ddmm)
e0098e4f   Etienne Pallier   Ajout du traiteme...
508
509
        #if res != '1': raise UnknownNativeResException(res)
        if not res.ok: raise UnknownNativeResException(res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
510
        res = self.get_lat()
e0098e4f   Etienne Pallier   Ajout du traiteme...
511
        if res.txt != res_dd_mm: raise UnknownNativeResException(res_dd_mm,res.txt)
2d3d3ee8   Etienne Pallier   clean log message...
512
        self.printd("NEW latitude set is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537


        '''
        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...
538
    def do_goto_radec(self, ra, dec, speed_rate=None): return self.do_goto(ra, dec, speed_rate)
ac0e5c70   Etienne Pallier   nouveau devices_c...
539
    def do_goto(self, ra, dec, speed_rate=None):
38bead5a   Etienne Pallier   Gros bugfix de Ag...
540

ea13de96   Etienne Pallier   NEW general cmd f...
541
        # TODO: remove
2d3d3ee8   Etienne Pallier   clean log message...
542
        self.printd("...Starting GOTO...")
ea13de96   Etienne Pallier   NEW general cmd f...
543
544
        time.sleep(3)
        radec = self.get_radec()
2d3d3ee8   Etienne Pallier   clean log message...
545
        self.printd("...GOTO ended OK")
ea13de96   Etienne Pallier   NEW general cmd f...
546
547
        return GenericResult("OK")

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

ac0e5c70   Etienne Pallier   nouveau devices_c...
551
        radec = self.get_radec()
2d3d3ee8   Etienne Pallier   clean log message...
552
        self.printd("Current position is", radec)
ac0e5c70   Etienne Pallier   nouveau devices_c...
553
554
555
556
557
558

        # 2) set RA-DEC
        '''
        :Sr18:23:45#:Sd+34:00:00#:MS#
        '''
        res = self.set_ra(ra)
e0098e4f   Etienne Pallier   Ajout du traiteme...
559
560
561
562
        #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...
563
        res = self.set_dec(dec)
e0098e4f   Etienne Pallier   Ajout du traiteme...
564
565
566
        #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...
567

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

ac0e5c70   Etienne Pallier   nouveau devices_c...
571
572
573
574
575
576
577
578
579
580
581
582
583
        # 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...
584
            self.printd("Velocity is", v)
ac0e5c70   Etienne Pallier   nouveau devices_c...
585
            time.sleep(2)
38bead5a   Etienne Pallier   Gros bugfix de Ag...
586

ac0e5c70   Etienne Pallier   nouveau devices_c...
587
588
        time.sleep(2)
        radec= self.get_radec()
2d3d3ee8   Etienne Pallier   clean log message...
589
        self.printd("Current position is", radec)
38bead5a   Etienne Pallier   Gros bugfix de Ag...
590

ac0e5c70   Etienne Pallier   nouveau devices_c...
591
592
        return GenericResult("OK")

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

ac0e5c70   Etienne Pallier   nouveau devices_c...
594
595
596
597
598
599
600
601
    # @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...
602
        else: raise UnknownGenericCmdArgException(dir)
ac0e5c70   Etienne Pallier   nouveau devices_c...
603
604
605
606
607
608
609
610
611
612
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
        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...
640
            #printd("Sent: {}".format(data))
ac0e5c70   Etienne Pallier   nouveau devices_c...
641
642
643
644
    
            # 2) RECEIVE REPLY data from server
            data_received = tsock.receive_data()
            #reponse, adr = mysock.recvfrom(buf)
1cf4a67f   Etienne Pallier   Affichage console...
645
646
647
            #printd("Received: {}".format(data_received))
            #printd("Useful data received: {}".format(data_useful))
            printd('\n')
ac0e5c70   Etienne Pallier   nouveau devices_c...
648
649
650

        #tsock.close()
'''