Blame view

src/device_controller/abstract_component/mount.py 18.8 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
32
        UnknownNativeCmdException, UnknownNativeResException, UnknownGenericCmdArgException, 
        DeviceTimeoutException
bcf29d0f   Etienne Pallier   update controller...
33
34
    )

ac0e5c70   Etienne Pallier   nouveau devices_c...
35
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




# 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...
65

ac0e5c70   Etienne Pallier   nouveau devices_c...
66
67
68
69
70
71
72
73
74
75
76
77
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...
78
79
#class TelescopeControllerAbstract(DeviceController):
class DC_Mount(DeviceController):
2d3d3ee8   Etienne Pallier   clean log message...
80

ac0e5c70   Etienne Pallier   nouveau devices_c...
81
82
    # @abstract (to be overriden)
    _cmd_device_concrete = {}
57621753   Etienne Pallier   NOUVELLE ARCHI un...
83
    ##_cmd_device_abstract = {
bcf29d0f   Etienne Pallier   update controller...
84
    GEN2NAT_CMDS = {
ac0e5c70   Etienne Pallier   nouveau devices_c...
85
        # GET-SET commands:
57621753   Etienne Pallier   NOUVELLE ARCHI un...
86
87
88
89

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

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

ac0e5c70   Etienne Pallier   nouveau devices_c...
92
93
94
95
        'get_ra': [],
        'set_ra': [],
        'get_dec': [],
        'set_dec': [],
f098fd90   Etienne Pallier   bugfix client et ...
96
        #'get_radec': [get_radec],
ac0e5c70   Etienne Pallier   nouveau devices_c...
97
98
        'get_radec': ['get_radec'],
        'set_radec': ['set_radec'],
57621753   Etienne Pallier   NOUVELLE ARCHI un...
99

ac0e5c70   Etienne Pallier   nouveau devices_c...
100
101
102
103
        'get_longitude': [],
        'set_longitude': [],
        'get_latitude': [],
        'set_latitude': [],
f098fd90   Etienne Pallier   bugfix client et ...
104

ac0e5c70   Etienne Pallier   nouveau devices_c...
105
106
        'get_velocity': [],
        'set_velocity': [],
f098fd90   Etienne Pallier   bugfix client et ...
107

ac0e5c70   Etienne Pallier   nouveau devices_c...
108
109
110
        # DO commands:
        ##'do_init': ['do_init'],
        ##'do_park': [],
ea13de96   Etienne Pallier   NEW general cmd f...
111
        'do_goto': ['do_goto'],
57621753   Etienne Pallier   NOUVELLE ARCHI un...
112
113
114
115

        # for test only
        'mount_only':[],

ea13de96   Etienne Pallier   NEW general cmd f...
116
        'do_goto_radec': ['do_goto_radec'],
ac0e5c70   Etienne Pallier   nouveau devices_c...
117
118
119
120
121
122
123
124
125
126
127
128
        '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...
129
    ##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...
130
    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...
131
132
133
        '''
        :param device_host: server IP or hostname
        :param device_port: server port
57621753   Etienne Pallier   NOUVELLE ARCHI un...
134
        :param CHANNEL: "UDP" or "TCP"
ac0e5c70   Etienne Pallier   nouveau devices_c...
135
        '''
57621753   Etienne Pallier   NOUVELLE ARCHI un...
136

bcf29d0f   Etienne Pallier   update controller...
137
138
        # _my_gen2nat_cmds = GEN2NAT_CMDS + gen2nat_cmds
        #self._my_gen2nat_cmds = self.GEN2NAT_CMDS
57621753   Etienne Pallier   NOUVELLE ARCHI un...
139
        #self._my_gen2nat_cmds.update(gen2nat_cmds)
1cf4a67f   Etienne Pallier   Affichage console...
140
141
        #printd("(mount 1) my cmds (before):", self.GEN2NAT_CMDS)
        #printd("(mount 2) given cmds (before):", gen2nat_cmds)
bcf29d0f   Etienne Pallier   update controller...
142
143
        ##self._my_gen2nat_cmds = { **self.GEN2NAT_CMDS, **gen2nat_cmds }
        my_gen2nat_cmds = { **self.GEN2NAT_CMDS, **gen2nat_cmds }
1cf4a67f   Etienne Pallier   Affichage console...
144
        #printd("(mount 3) my cmds (after):", self._my_gen2nat_cmds)
57621753   Etienne Pallier   NOUVELLE ARCHI un...
145
146

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

ac0e5c70   Etienne Pallier   nouveau devices_c...
153

ac0e5c70   Etienne Pallier   nouveau devices_c...
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
    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...
224

ac0e5c70   Etienne Pallier   nouveau devices_c...
225
226
227
    # 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...
228
    def get_radec(self)->GenericResult:
ac0e5c70   Etienne Pallier   nouveau devices_c...
229
        return GenericResult(self.get_ra().txt + "," + self.get_dec().txt)
38bead5a   Etienne Pallier   Gros bugfix de Ag...
230

ac0e5c70   Etienne Pallier   nouveau devices_c...
231
    # MACRO
38bead5a   Etienne Pallier   Gros bugfix de Ag...
232
    def set_radec(self, ra, dec)->GenericResult:
ac0e5c70   Etienne Pallier   nouveau devices_c...
233
234
235
        self.set_ra(ra)
        self.set_dec(dec)
        return GenericResult("OK")
38bead5a   Etienne Pallier   Gros bugfix de Ag...
236

ac0e5c70   Etienne Pallier   nouveau devices_c...
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
284
285
286
287
288
289
290
291
    @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...
292

ac0e5c70   Etienne Pallier   nouveau devices_c...
293
294
    # MACRO generic command
    def do_init(self):
ea13de96   Etienne Pallier   NEW general cmd f...
295

2d3d3ee8   Etienne Pallier   clean log message...
296
        self.printd("...STARTING TELESCOPE INITIALIZATION...")
ea13de96   Etienne Pallier   NEW general cmd f...
297
        time.sleep(1)
2d3d3ee8   Etienne Pallier   clean log message...
298
        self.printd("...TELESCOPE INITIALIZATION ENDED")
ea13de96   Etienne Pallier   NEW general cmd f...
299
300
        return GenericResult("OK")

ac0e5c70   Etienne Pallier   nouveau devices_c...
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
        '''
        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...
346
        self.printd("Current timezone is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
347
        res = self.set_timezone('+00')
e0098e4f   Etienne Pallier   Ajout du traiteme...
348
349
        #if res != '1': raise UnknownNativeResException(res)
        if not res.ok: raise UnknownNativeResException(res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
350
        res = self.get_timezone()
e0098e4f   Etienne Pallier   Ajout du traiteme...
351
        if res.txt != '+00': raise UnknownNativeResException(res)
2d3d3ee8   Etienne Pallier   clean log message...
352
        self.printd("NEW timezone set is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
353
354
355
356
357
358
359
360
361
362
363
364
365
366
        

        '''
        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...
367
        self.printd("Current date is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
368
369
370
371
        # 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...
372
        #printd("date is", now_utc_mm_dd_yy)
ac0e5c70   Etienne Pallier   nouveau devices_c...
373
374
        res = self.set_date(now_utc_mm_dd_yy)
        #res = self.set_DATE(self.get_utc_date())
e0098e4f   Etienne Pallier   Ajout du traiteme...
375
376
377
        #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...
378
        res = self.get_date()
e0098e4f   Etienne Pallier   Ajout du traiteme...
379
        if res.txt != now_utc_mm_dd_yy: raise UnknownNativeResException(res)
2d3d3ee8   Etienne Pallier   clean log message...
380
        self.printd("NEW DATE set is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
381
382
383
384
385
386
387
388

        '''
        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...
389
        self.printd("Current time is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
390
        _,now_utc_hh_mm_ss = d.split('T')
1cf4a67f   Etienne Pallier   Affichage console...
391
        #printd("time is", now_utc_hh_mm_ss[:5])
ac0e5c70   Etienne Pallier   nouveau devices_c...
392
        res = self.set_time(now_utc_hh_mm_ss)
e0098e4f   Etienne Pallier   Ajout du traiteme...
393
394
        #if res != '1': raise UnknownNativeResException(res)
        if not res.ok: raise UnknownNativeResException(res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
395
        res = self.get_time()
e0098e4f   Etienne Pallier   Ajout du traiteme...
396
        if res.txt[:5] != now_utc_hh_mm_ss[:5]: raise UnknownNativeResException(res)
2d3d3ee8   Etienne Pallier   clean log message...
397
        self.printd("NEW TIME set is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417

            
        '''
        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...
418
        self.printd("Current longitude is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
419
420
421
422
423
424
425
        
        # 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...
426
        #printd("celme longitude is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
427
428
429
        ddd,mm,ss = res.split(':')
        #dddmm = '-002*03'
        res = self.set_long(ddd+'*'+mm)
e0098e4f   Etienne Pallier   Ajout du traiteme...
430
431
        #if res != '1': raise UnknownNativeResException(res)
        if not res.ok: raise UnknownNativeResException(res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
432
        res = self.get_long()
e0098e4f   Etienne Pallier   Ajout du traiteme...
433
        if res.txt != res_ddd_mm: raise UnknownNativeResException(res_ddd_mm, res.txt)
2d3d3ee8   Etienne Pallier   clean log message...
434
        self.printd("NEW longitude set is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
435
436
437
438
439
440
441
442
443

        '''
        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...
444
        self.printd("Current latitude is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
445
446
447
448
449
        
        # 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...
450
        self.printd("res is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
451
452
        #res_dd_mm = '+43:50'
        
1cf4a67f   Etienne Pallier   Affichage console...
453
        #printd("celme longitude is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
454
455
456
457
        dd,mm,ss = res.split(':')
        ddmm = dd+'*'+mm
        #ddmm = '+43*50'
        res = self.set_lat(ddmm)
e0098e4f   Etienne Pallier   Ajout du traiteme...
458
459
        #if res != '1': raise UnknownNativeResException(res)
        if not res.ok: raise UnknownNativeResException(res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
460
        res = self.get_lat()
e0098e4f   Etienne Pallier   Ajout du traiteme...
461
        if res.txt != res_dd_mm: raise UnknownNativeResException(res_dd_mm,res.txt)
2d3d3ee8   Etienne Pallier   clean log message...
462
        self.printd("NEW latitude set is", res)
ac0e5c70   Etienne Pallier   nouveau devices_c...
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487


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

ea13de96   Etienne Pallier   NEW general cmd f...
491
        # TODO: remove
2d3d3ee8   Etienne Pallier   clean log message...
492
        self.printd("...Starting GOTO...")
ea13de96   Etienne Pallier   NEW general cmd f...
493
494
        time.sleep(3)
        radec = self.get_radec()
2d3d3ee8   Etienne Pallier   clean log message...
495
        self.printd("...GOTO ended OK")
ea13de96   Etienne Pallier   NEW general cmd f...
496
497
        return GenericResult("OK")

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

ac0e5c70   Etienne Pallier   nouveau devices_c...
501
        radec = self.get_radec()
2d3d3ee8   Etienne Pallier   clean log message...
502
        self.printd("Current position is", radec)
ac0e5c70   Etienne Pallier   nouveau devices_c...
503
504
505
506
507
508

        # 2) set RA-DEC
        '''
        :Sr18:23:45#:Sd+34:00:00#:MS#
        '''
        res = self.set_ra(ra)
e0098e4f   Etienne Pallier   Ajout du traiteme...
509
510
511
512
        #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...
513
        res = self.set_dec(dec)
e0098e4f   Etienne Pallier   Ajout du traiteme...
514
515
516
        #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...
517

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

ac0e5c70   Etienne Pallier   nouveau devices_c...
521
522
523
524
525
526
527
528
529
530
531
532
533
        # 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...
534
            self.printd("Velocity is", v)
ac0e5c70   Etienne Pallier   nouveau devices_c...
535
            time.sleep(2)
38bead5a   Etienne Pallier   Gros bugfix de Ag...
536

ac0e5c70   Etienne Pallier   nouveau devices_c...
537
538
        time.sleep(2)
        radec= self.get_radec()
2d3d3ee8   Etienne Pallier   clean log message...
539
        self.printd("Current position is", radec)
38bead5a   Etienne Pallier   Gros bugfix de Ag...
540

ac0e5c70   Etienne Pallier   nouveau devices_c...
541
542
        return GenericResult("OK")

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

ac0e5c70   Etienne Pallier   nouveau devices_c...
544
545
546
547
548
549
550
551
    # @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...
552
        else: raise UnknownGenericCmdArgException(dir)
ac0e5c70   Etienne Pallier   nouveau devices_c...
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
        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...
590
            #printd("Sent: {}".format(data))
ac0e5c70   Etienne Pallier   nouveau devices_c...
591
592
593
594
    
            # 2) RECEIVE REPLY data from server
            data_received = tsock.receive_data()
            #reponse, adr = mysock.recvfrom(buf)
1cf4a67f   Etienne Pallier   Affichage console...
595
596
597
            #printd("Received: {}".format(data_received))
            #printd("Useful data received: {}".format(data_useful))
            printd('\n')
ac0e5c70   Etienne Pallier   nouveau devices_c...
598
599
600

        #tsock.close()
'''