telescope_controller_gemini_run.py
6.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
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
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
#!/usr/bin/env python3
##from src_socket.client.socket_client_telescope_gemini import SocketClientTelescopeGEMINI
from src_device.client.telescope_controller_gemini import TelescopeControllerGEMINI
import pprint
import sys
#DEBUG = False
DEBUG = True
"""
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
'''
"""
def main():
# 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
#tele_ctrl = SocketClient_UDP_TCP(HOST, PORT)
with TelescopeControllerGEMINI(HOST, PORT, DEBUG) as tele_ctrl:
# (optional) Only useful for TCP (does nothing for UDP)
tele_ctrl._connect_to_device()
#execute_commands_before_init(tele_ctrl)
# Initialize telescope config (ack, date, time)
#tele_ctrl.do_init()
#execute_commands_after_init(tele_ctrl)
#_mes_tests_temporaires_avirer(tele_ctrl)
# Do MANUAL mode execution
while True:
tele_ctrl.print_available_commands()
#req = input("\n(EXPERT MODE) REQUEST TO SERVER [ex: '6' (ACK), ':GD#' (Get Dec), ':GR#' (Get RA)'], (ENTER to quit): ").strip()
cmd = input("REQUEST TO SERVER (ENTER to quit): >>> ").strip()
if not cmd: break
res = tele_ctrl.execute_cmd(cmd)
print("result is", str(res))
if res.ok: print("OK")
#print("result.txt is", res.txt)
# END: park telescope
###tele_ctrl.do_PARK()
#tele_ctrl.close()
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)
# @private
def _mes_tests_temporaires_avirer(tele_client):
print("\n...Execution de mes tests temporaires...\n")
print("res is", tele_client.run_func('formated_cmd','GD'))
print("dict is")
pprint.pprint(tele_client._cmd)
'''
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")
'''
tele_client.do_move_dir('EAST','4', 'slew')
tele_client.do_goto(ra='21:00:00',dec='+20:00:00')
'''
TEST ENVOI DIRECT:
#data = 0x01000000:06#
data = b'01000000:06#'
##data = b'01000000:GD#'
#data = 0x010000003a474423
#data = b'010000003a474423'
#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)
print("data rec = ", data_received)
'''
# Send some commands to the Telescope
#pos = tele_client.get_position()
#dec = tele_client.get("DEC")
#ra = tele_client.get("RA")
'''
tele_client.get("NONE")
tele_client.set("NONE", 1)
tele_client.do("NONE")
'''
# 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()
'#'
>>> tele_client.mysock.sendto(b'\x00\x00\x00\x01\x00\x00\x00\x00\x3A\x47\x44\x23\x00', (HOST, PORT))
RECEIVED (ALL BYTES): b'\x00\x00\x00\x01\x00\x00\x00\x00+90.000000#\x00'
>>> a=b'\x52'
>>> a
b'R'
>>> a.decode()
'R'
>>> tele_client.mysock.sendto(b'\x00\x00\x00\x01\x00\x00\x00\x00\x3A\x47\x52\x23\x00', (HOST, PORT))
RECEIVED (ALL BYTES): b'\x00\x00\x00\x01\x00\x00\x00\x008.911844#\x00'
>>> tele_client.mysock.sendto(b'\x00\x00\x00\x01\x00\x00\x00\x00\x00\x06\x00\x00', (HOST, PORT))
RECEIVED (ALL BYTES): b'\x00\x00\x00\x01\x00\x00\x00\x00G#\x00'
'''
#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))
'''
# :GD#
###tele_client.mysock.sendto(b'\x00\x00\x00\x01\x00\x00\x00\x00\x3A\x47\x44\x23\x00', (HOST, PORT))
# :GR#
###tele_client.mysock.sendto(b'\x00\x00\x00\x01\x00\x00\x00\x00\x3A\x47\x52\x23\x00', (HOST, PORT))
# ACK 06 OK !!! :
tele_client.mysock.sendto(b'\x00\x00\x00\x01\x00\x00\x00\x00\x00\x06\x00\x00', (HOST, PORT))
RECEIVED (ALL BYTES): b'\x00\x00\x00\x01\x00\x00\x00\x00G#\x00'
tele_client.mysock.sendto(b'00010000\x00\x06\x00\x00', (HOST, PORT))
RECEIVED (ALL BYTES): b'00010000G#\x00'
'''
'''
# wrong: b'00010000\\x00\\x06\\x00\x00'
# ok:
\x05\x00\x00\
#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()
'''
# Execution
main()