client_gemini_run.py
5.18 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
#!/usr/bin/env python3
from src_socket.client.socket_client_telescope_gemini import SocketClientTelescopeGEMINI
import sys
#DEBUG = False
DEBUG = True
# 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
#HOST, PORT = "localhost", 11110
# Args given, connexion LOCAL
else:
#HOST, PORT = sys.argv[1:3]
#PORT = int(PORT)
#if sys.argv[1] == "local":
HOST, PORT = "localhost", 11110
#tele_client = SocketClient_UDP_TCP(HOST, PORT)
with SocketClientTelescopeGEMINI(HOST, PORT, DEBUG) as tele_client:
#tele_client.connect_to_server()
# Only useful for TCP (does nothing for UDP)
tele_client._connect_to_server()
print("RA is", tele_client.get_RA())
print("ack is", tele_client.get_ACK())
# Initialize telescope config (ack, date, time)
#tele_client.do("INIT")
tele_client.do_INIT()
'''
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")
'''
#radec = tele_client.get("RA-DEC")
radec = tele_client.get_RADEC()
print("RA-DEC is", radec)
#ack = tele_client.put_read("6")
ack = tele_client.get_ACK()
print("ACK is", ack)
# 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()
'''
#tele_client.do_GOTO(ra='22:00:00',dec='+30:00:00')
#tele_client.do_GOTO(ra='21:00:00',dec='+20:00:00')
#tele_client.do_MOVE_DIR('EAST','4', 'slew')
# Do EXPERT mode execution
while True:
#print("Available commands:", tele_client.available_commands())
tele_client.print_available_commands()
#data = input("\n(EXPERT MODE) REQUEST TO SERVER [ex: '6' (ACK), ':GD#' (Get Dec), ':GR#' (Get RA)'], (ENTER to quit): ").strip()
req = input("REQUEST TO SERVER (ENTER to quit): >>> ").strip()
# test d'arrêt
#if data=="": break
if not req: break
result = tele_client.execute(req)
'''
#data_to_send = bytes(data + "\n", "utf-8")`
tele_client.send_request(req)
#mysock.sendto("%s" % data, (HOST, PORT))
#print("Sent: {}".format(data))
# 2) RECEIVE REPLY data from server
data_received = tele_client.receive_data()
#reponse, adr = mysock.recvfrom(buf)
#print("Received: {}".format(data_received))
#print("Useful data received: {}".format(data_useful))
'''
###tele_client.do_PARK()
#tele_client.close()