client_gemini_run.py 5.18 KB
#!/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()