Blame view

devices_channel/telescope_controller_gemini_run.py 6.89 KB
fc6ea9bc   Etienne Pallier   socket client pou...
1
2
#!/usr/bin/env python3

62e41b8f   Etienne Pallier   BIG REORGANIZATIO...
3
4
##from src_socket.client.socket_client_telescope_gemini import SocketClientTelescopeGEMINI
from src_device.client.telescope_controller_gemini import TelescopeControllerGEMINI
fc6ea9bc   Etienne Pallier   socket client pou...
5

f6e5fcb2   Etienne Pallier   abstract commands...
6
import pprint
fc6ea9bc   Etienne Pallier   socket client pou...
7
8
import sys

7d8f698f   Etienne Pallier   get() set() do()
9
10
#DEBUG = False
DEBUG = True
ca2504aa   Etienne Pallier   Nouvelle version ...
11

a494f372   Etienne Pallier   clean code AND mo...
12

62e41b8f   Etienne Pallier   BIG REORGANIZATIO...
13
"""
23b4fbc5   Etienne Pallier   move do_init() to...
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
class essai:
    a = 'a'
    c = 'c'
    def __init__(self):
        self.b = 'bB'
    def __get__(self, instance, owner):
        return self.b
    '''
    def __set__(self, instance, value):
        self.b = value
    def __str__(self):
        return self.b
    '''
class user:
    e = essai()

class GenericResult:
    ''' Usage:
        res = execute(command)
        print("result is", res)
        if res.ko: raise UnexpectedReturnCode()
        if res.ok:
            ...
    '''
    # By default, bad result
    ok = False
    ko = True
    
    def __init__(self, native_result:str, ok=False):
        self.txt = native_result
        self.ok = ok
        self.ko = not ok
    '''
    def __str__(self):
        return self.native_result
    def __repr__(self):
        return self.native_result
    def __get__(self, instance, owner):
        return self.b
    def __set__(self, instance, value):
        self.b = value
    '''
62e41b8f   Etienne Pallier   BIG REORGANIZATIO...
56
"""
23b4fbc5   Etienne Pallier   move do_init() to...
57
58
59
60


        

a494f372   Etienne Pallier   clean code AND mo...
61
def main():
23b4fbc5   Etienne Pallier   move do_init() to...
62
    
a494f372   Etienne Pallier   clean code AND mo...
63
64
65
66
67
68
69
70
71
    # No argument => connexion to REAL TELESCOPE (DISTANT)
    if len(sys.argv) == 1: 
        # Port local AK 8085 = redirigé sur l’IP du tele 192.168.0.12 sur port 11110
        HOST, PORT = "82.64.28.71", 11110
    
    # Args given => connexion to LOCAL simulator server
    else:
        HOST, PORT = "localhost", 11110

62e41b8f   Etienne Pallier   BIG REORGANIZATIO...
72
73
    #tele_ctrl = SocketClient_UDP_TCP(HOST, PORT)
    with TelescopeControllerGEMINI(HOST, PORT, DEBUG) as tele_ctrl:
a494f372   Etienne Pallier   clean code AND mo...
74
    
a494f372   Etienne Pallier   clean code AND mo...
75
        # (optional) Only useful for TCP (does nothing for UDP)
62e41b8f   Etienne Pallier   BIG REORGANIZATIO...
76
        tele_ctrl._connect_to_device()
b7dc5536   Etienne Pallier   decorator @generi...
77
        
737e50e9   Etienne Pallier   updated README
78
        #execute_commands_before_init(tele_ctrl)
a494f372   Etienne Pallier   clean code AND mo...
79
80
    
        # Initialize telescope config (ack, date, time)
737e50e9   Etienne Pallier   updated README
81
        #tele_ctrl.do_init()
62e41b8f   Etienne Pallier   BIG REORGANIZATIO...
82

737e50e9   Etienne Pallier   updated README
83
        #execute_commands_after_init(tele_ctrl)
a494f372   Etienne Pallier   clean code AND mo...
84
    
62e41b8f   Etienne Pallier   BIG REORGANIZATIO...
85
        #_mes_tests_temporaires_avirer(tele_ctrl)
fc6ea9bc   Etienne Pallier   socket client pou...
86
        
a494f372   Etienne Pallier   clean code AND mo...
87
88
89
        # Do MANUAL mode execution
        while True:
     
62e41b8f   Etienne Pallier   BIG REORGANIZATIO...
90
            tele_ctrl.print_available_commands()
a494f372   Etienne Pallier   clean code AND mo...
91
            #req = input("\n(EXPERT MODE) REQUEST TO SERVER [ex: '6' (ACK), ':GD#' (Get Dec), ':GR#' (Get RA)'], (ENTER to quit): ").strip()
7e82f0aa   Etienne Pallier   interpreteur de c...
92
93
            cmd = input("REQUEST TO SERVER (ENTER to quit): >>> ").strip()
            if not cmd: break
a494f372   Etienne Pallier   clean code AND mo...
94
    
62e41b8f   Etienne Pallier   BIG REORGANIZATIO...
95
96
97
            res = tele_ctrl.execute_cmd(cmd)
            print("result is", str(res))
            if res.ok: print("OK")
23b4fbc5   Etienne Pallier   move do_init() to...
98
            #print("result.txt is", res.txt)
a494f372   Etienne Pallier   clean code AND mo...
99
100
            
        # END: park telescope    
62e41b8f   Etienne Pallier   BIG REORGANIZATIO...
101
        ###tele_ctrl.do_PARK()
a494f372   Etienne Pallier   clean code AND mo...
102
    
62e41b8f   Etienne Pallier   BIG REORGANIZATIO...
103
104
        #tele_ctrl.close()

a494f372   Etienne Pallier   clean code AND mo...
105
106


62e41b8f   Etienne Pallier   BIG REORGANIZATIO...
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
134
135
136
def execute_commands_before_init(tele_ctrl):
        print("RA is", tele_ctrl.get_ra())
        
        ack = tele_ctrl.get_ack()
        print("ack is", ack)
        print("ack.txt is", ack)
        if ack.ok: print("ack is ok")
        if ack.ko: print("ack is ko")
        
        
def execute_commands_after_init(tele_ctrl):
    
        #radec = tele_ctrl.get("RA-DEC")
        res = tele_ctrl.get_radec()
        print("RA-DEC is", res)
        
        '''
        GOTO and MOVE:
        -------------
        '''
        '''
        tele_ctrl.do_goto(ra='21:00:00',dec='+20:00:00')
        tele_ctrl.do_goto(ra='22:00:00',dec='+30:00:00')
        tele_ctrl.do_move_dir('east','4', 'slew')
        '''
        
        # In order to execute a GEMINI (non generic) command:
        res = tele_ctrl.execute_native_cmd(':GR#')
        print("res is", res)

a494f372   Etienne Pallier   clean code AND mo...
137

23b4fbc5   Etienne Pallier   move do_init() to...
138
# @private
a494f372   Etienne Pallier   clean code AND mo...
139
140
141
def _mes_tests_temporaires_avirer(tele_client):
    
    print("\n...Execution de mes tests temporaires...\n")
f6e5fcb2   Etienne Pallier   abstract commands...
142
143
144
145

    print("res is", tele_client.run_func('formated_cmd','GD'))
    print("dict is")
    pprint.pprint(tele_client._cmd)
a494f372   Etienne Pallier   clean code AND mo...
146
    
62e41b8f   Etienne Pallier   BIG REORGANIZATIO...
147
    '''
23b4fbc5   Etienne Pallier   move do_init() to...
148
149
150
151
152
153
154
155
    u = user()
    print(u.e)

    res = GenericResult('G',False)
    print("res is", res)
    if res.ok: print("res is ok")
    if not res.ko: print("res is not ko")
    if res.txt == 'G': print("res is G")
62e41b8f   Etienne Pallier   BIG REORGANIZATIO...
156
    '''
23b4fbc5   Etienne Pallier   move do_init() to...
157

a494f372   Etienne Pallier   clean code AND mo...
158
159
    tele_client.do_move_dir('EAST','4', 'slew')
    tele_client.do_goto(ra='21:00:00',dec='+20:00:00')
fc6ea9bc   Etienne Pallier   socket client pou...
160
161
162
163
164
165
166
167
168
169
    '''
    TEST ENVOI DIRECT:
    
    #data = 0x01000000:06#
    data = b'01000000:06#'
    
    ##data = b'01000000:GD#'
    #data = 0x010000003a474423
    #data = b'010000003a474423'
    
54cb16da   Etienne Pallier   implementation du...
170
171
172
173
    #data_to_send = tele_client._format_data_to_send(data)
    tele_client._send_data(data)
    #data_received = tele_client.receive_data()
    data_received = tele_client.mysock.recv(1024)
fc6ea9bc   Etienne Pallier   socket client pou...
174
175
176
177
    print("data rec = ", data_received)
    '''
    
    # Send some commands to the Telescope
54cb16da   Etienne Pallier   implementation du...
178
179
180
    #pos = tele_client.get_position()
    #dec = tele_client.get("DEC")
    #ra = tele_client.get("RA")
f886f7c6   Etienne Pallier   Telescope Generic...
181
    '''
54cb16da   Etienne Pallier   implementation du...
182
183
184
    tele_client.get("NONE")
    tele_client.set("NONE", 1)
    tele_client.do("NONE")
f886f7c6   Etienne Pallier   Telescope Generic...
185
    '''
a494f372   Etienne Pallier   clean code AND mo...
186
    
7438afff   Etienne Pallier   bientot le ACK 06...
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
    # TEST BAS NIVEAU POUR ACK 06:
    '''
    >>> a=b'\x3A'
    >>> a
    b':'
    >>> a.decode()
    ':'

    >>> a=b'\x47'
    >>> a
    b'G'
    >>> a.decode()
    'G'

    >>> a=b'\x44'
    >>> a
    b'D'
    >>> a.decode()
    'D'
    
    >>> a=b'\x23'
    >>> a
    b'#'
    >>> a.decode()
    '#'
54cb16da   Etienne Pallier   implementation du...
212
    >>> tele_client.mysock.sendto(b'\x00\x00\x00\x01\x00\x00\x00\x00\x3A\x47\x44\x23\x00', (HOST, PORT))
7438afff   Etienne Pallier   bientot le ACK 06...
213
214
215
216
217
218
219
    RECEIVED (ALL BYTES): b'\x00\x00\x00\x01\x00\x00\x00\x00+90.000000#\x00'
    
    >>> a=b'\x52'
    >>> a
    b'R'
    >>> a.decode()
    'R'
54cb16da   Etienne Pallier   implementation du...
220
    >>> tele_client.mysock.sendto(b'\x00\x00\x00\x01\x00\x00\x00\x00\x3A\x47\x52\x23\x00', (HOST, PORT))
7438afff   Etienne Pallier   bientot le ACK 06...
221
    RECEIVED (ALL BYTES): b'\x00\x00\x00\x01\x00\x00\x00\x008.911844#\x00'
fc6ea9bc   Etienne Pallier   socket client pou...
222
    
54cb16da   Etienne Pallier   implementation du...
223
    >>> tele_client.mysock.sendto(b'\x00\x00\x00\x01\x00\x00\x00\x00\x00\x06\x00\x00', (HOST, PORT))
7438afff   Etienne Pallier   bientot le ACK 06...
224
225
    RECEIVED (ALL BYTES): b'\x00\x00\x00\x01\x00\x00\x00\x00G#\x00'

3f616717   Etienne Pallier   Nombreuses petite...
226
    '''
54cb16da   Etienne Pallier   implementation du...
227
228
229
230
231
    #tele_client.mysock.sendto(b'00030000:GD#\x00', (HOST, PORT))
    #tele_client.mysock.sendto(b'00030000\x06\x00', (HOST, PORT))
    #tele_client.mysock.sendto(b'00030000\x00\x06\x00', (HOST, PORT))
    #tele_client.mysock.sendto(b'00030000\0x06\x00', (HOST, PORT))
    #tele_client.mysock.sendto(b'00010000\0x06\x00', (HOST, PORT))
6861c77e   Etienne Pallier   ACK implemented (...
232
    '''
7438afff   Etienne Pallier   bientot le ACK 06...
233
    # :GD#
54cb16da   Etienne Pallier   implementation du...
234
    ###tele_client.mysock.sendto(b'\x00\x00\x00\x01\x00\x00\x00\x00\x3A\x47\x44\x23\x00', (HOST, PORT))
6861c77e   Etienne Pallier   ACK implemented (...
235
    
7438afff   Etienne Pallier   bientot le ACK 06...
236
    # :GR#
54cb16da   Etienne Pallier   implementation du...
237
    ###tele_client.mysock.sendto(b'\x00\x00\x00\x01\x00\x00\x00\x00\x3A\x47\x52\x23\x00', (HOST, PORT))
6861c77e   Etienne Pallier   ACK implemented (...
238
239
240
    
    # ACK 06 OK !!! :
    
54cb16da   Etienne Pallier   implementation du...
241
    tele_client.mysock.sendto(b'\x00\x00\x00\x01\x00\x00\x00\x00\x00\x06\x00\x00', (HOST, PORT))
6861c77e   Etienne Pallier   ACK implemented (...
242
243
    RECEIVED (ALL BYTES): b'\x00\x00\x00\x01\x00\x00\x00\x00G#\x00'
    
54cb16da   Etienne Pallier   implementation du...
244
    tele_client.mysock.sendto(b'00010000\x00\x06\x00\x00', (HOST, PORT))
6861c77e   Etienne Pallier   ACK implemented (...
245
246
    RECEIVED (ALL BYTES): b'00010000G#\x00'
    '''
7438afff   Etienne Pallier   bientot le ACK 06...
247
    '''
6861c77e   Etienne Pallier   ACK implemented (...
248
249
    # wrong: b'00010000\\x00\\x06\\x00\x00'
    # ok:
9e82d12e   Etienne Pallier   new procedure ini...
250
    \x05\x00\x00\
54cb16da   Etienne Pallier   implementation du...
251
252
253
254
    #tele_client.mysock.sendto(b'\x00\x00\x00\x01\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00', (HOST, PORT))
    #tele_client.mysock.sendto(b'00010000\x00\x05\x00\x00', (HOST, PORT))
    tele_client.mysock.sendto(b'00010000\x00\x06\x00\x00', (HOST, PORT))
    data_received = tele_client.receive_data()
3f616717   Etienne Pallier   Nombreuses petite...
255
    '''
fc6ea9bc   Etienne Pallier   socket client pou...
256

fc6ea9bc   Etienne Pallier   socket client pou...
257

fc6ea9bc   Etienne Pallier   socket client pou...
258

a494f372   Etienne Pallier   clean code AND mo...
259
260
# Execution
main()