From f6e5fcb2a6c30e248bacb81c37c4ce5d004eea8a Mon Sep 17 00:00:00 2001 From: Etienne Pallier Date: Tue, 2 Oct 2018 11:56:19 +0200 Subject: [PATCH] abstract commands dictionary is now the default one and is ovewritable with native dictionary --- sockets_tele/README.txt | 6 ++++++ sockets_tele/client_gemini_run.py | 8 +++++--- sockets_tele/src_socket/client/socket_client_telescope_abstract.py | 77 ++++++++++++++++++++++++++++++++++++++++++++++------------------------------- sockets_tele/src_socket/client/socket_client_telescope_gemini.py | 129 +++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------ 4 files changed, 102 insertions(+), 118 deletions(-) diff --git a/sockets_tele/README.txt b/sockets_tele/README.txt index 93570b8..1b16676 100644 --- a/sockets_tele/README.txt +++ b/sockets_tele/README.txt @@ -63,6 +63,12 @@ Pour lancer le client sur le "simulateur" de telescope (localhost, port 11110): ******************************************************************************************** 4) DONE + 2/10/18: + - abstract commands dictionary is now the default one and is ovewritable with native dictionary + - native telescope class is now less than 300 lines (majority of code is in the abstract class so that it is easy to make a new concrete telescope class): + => ne contient quasiment QUE le dictionnaire des commandes natives + - cleanup + 1/10/18: - interpreteur de cde generique et native : set ra 20:00:00 ou :GR# - execute_cmd(): diff --git a/sockets_tele/client_gemini_run.py b/sockets_tele/client_gemini_run.py index 10089eb..e3a5fdc 100755 --- a/sockets_tele/client_gemini_run.py +++ b/sockets_tele/client_gemini_run.py @@ -2,6 +2,7 @@ from src_socket.client.socket_client_telescope_gemini import SocketClientTelescopeGEMINI +import pprint import sys #DEBUG = False @@ -57,7 +58,6 @@ class GenericResult: 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 @@ -70,8 +70,6 @@ def main(): #tele_client = SocketClient_UDP_TCP(HOST, PORT) with SocketClientTelescopeGEMINI(HOST, PORT, DEBUG) as tele_client: - print("res is", tele_client.run_func('formated_cmd','GD')) - # (optional) Only useful for TCP (does nothing for UDP) tele_client._connect_to_server() @@ -121,6 +119,10 @@ def main(): 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) diff --git a/sockets_tele/src_socket/client/socket_client_telescope_abstract.py b/sockets_tele/src_socket/client/socket_client_telescope_abstract.py index 5c25149..e093953 100755 --- a/sockets_tele/src_socket/client/socket_client_telescope_abstract.py +++ b/sockets_tele/src_socket/client/socket_client_telescope_abstract.py @@ -110,29 +110,45 @@ class UnknownCommandException(Exception): class SocketClientTelescopeAbstract(SocketClientAbstract): # @abstract (to be overriden) - _cmd = {} - """ - _cmd_getset = { - 'ack': [], - 'ra': [], - 'dec': [], - #'RADEC': [], - 'timezone': [], - #'TIMEZONE_IS_UTC': [], - 'DATE': [], - 'TIME': [], - 'LONGITUDE': [], - 'LATITUDE': [], - 'VELOCITY': [], - } - _cmd_do = { - #'INIT': [], - 'PARK': [], - 'MOVE': [], - 'WARM_START': [], - 'PREC_REFR': [], + _cmd_native = {} + _cmd = { + # GET-SET commands: + 'get_ack': [], + + 'get_ra': [], + 'set_ra': [], + 'get_dec': [], + 'set_dec': [], + 'get_radec': ['get_radec'], + 'set_radec': ['set_radec'], + + 'get_timezone': [], + 'set_timezone': [], + + 'get_date': [], + 'set_date': [], + + 'get_time': [], + 'set_time': [], + + 'get_longitude': [], + 'set_longitude': [], + 'get_latitude': [], + 'set_latitude': [], + + 'get_velocity': [], + 'set_velocity': [], + + # DO commands: + 'do_init': ['do_init'], + 'do_park': [], + 'do_goto': [], + 'do_move_dir': [], + 'do_warm_start': [], + 'do_prec_refr': [], } - """ + + def __init__(self, server_host:str="localhost", server_port:int=11110, PROTOCOL:str="TCP", buffer_size=1024, DEBUG=False): ''' @@ -141,6 +157,8 @@ class SocketClientTelescopeAbstract(SocketClientAbstract): :param PROTOCOL: "UDP" or "TCP" ''' super().__init__(server_host, server_port, PROTOCOL, buffer_size, DEBUG) + # overwrite abstract _cmd dictionary with subclass native _cmd_native dictionary: + self._cmd = {**self._cmd, **self._cmd_native} @@ -187,11 +205,9 @@ class SocketClientTelescopeAbstract(SocketClientAbstract): # ex: "set_radec" generic_cmd = cmd_splitted[0] + '_' + cmd_splitted[1] # Check this generic command exists - if (generic_cmd not in self._cmd.keys()) and (): - return False,False + if (generic_cmd not in self._cmd.keys()): return False,False # Is there value(s) passed ? - if len(cmd_splitted) > 2: - values_to_set = cmd_splitted[2:] + if len(cmd_splitted) > 2: values_to_set = cmd_splitted[2:] # ex: return "set_radec", ["20:00:00", "90:00:00"] return generic_cmd, values_to_set @@ -244,11 +260,11 @@ class SocketClientTelescopeAbstract(SocketClientAbstract): def print_available_commands(self): print("\nAvailable commands are:") print("- GET commands:") - print (list(cmd for cmd in self._cmd.keys() if cmd.startswith('get_'))) + print (list(cmd.replace('_',' ') for cmd in self._cmd.keys() if cmd.startswith('get_'))) print("- SET commands:") - print (list(cmd for cmd in self._cmd.keys() if cmd.startswith('set_'))) + print (list(cmd.replace('_',' ') for cmd in self._cmd.keys() if cmd.startswith('set_'))) print("- DO commands:") - print (list(cmd for cmd in self._cmd.keys() if cmd.startswith('do_'))) + print (list(cmd.replace('_',' ') for cmd in self._cmd.keys() if cmd.startswith('do_'))) def available_commands(self): return list(self._cmd.keys()) @@ -418,8 +434,7 @@ class SocketClientTelescopeAbstract(SocketClientAbstract): # @abstract #def get_radec(self): return self._get("RADEC") def get_radec(self)->tuple: return (self.get_ra(), self.get_dec()) - - def set_RADEC(self, radec): return self._set("RADEC", radec) + def set_radec(self, ra, dec)->tuple: return (self.set_ra(ra), self.set_dec(dec)) #def set_TIMEZONE_IS_UTC(self): return self._set('TIMEZONE_IS_UTC') def get_timezone(self): return self.execute_generic_cmd('get_timezone') diff --git a/sockets_tele/src_socket/client/socket_client_telescope_gemini.py b/sockets_tele/src_socket/client/socket_client_telescope_gemini.py index 4a3bce4..06c48c4 100755 --- a/sockets_tele/src_socket/client/socket_client_telescope_gemini.py +++ b/sockets_tele/src_socket/client/socket_client_telescope_gemini.py @@ -1,11 +1,9 @@ #!/usr/bin/env python3 """Socket Client GEMINI Telescope implementation - To be used as a concrete class to system control a GEMINI telescope """ - # Standard library imports #import socket #import logging @@ -20,7 +18,6 @@ sys.path.append('../..') #from src.client.socket_client_telescope_abstract import Position, UnknownCommandException, TimeoutException, SocketClientTelescopeAbstract from src_socket.client.socket_client_telescope_abstract import * - # Default timeouts TIMEOUT_SEND = 10 TIMEOUT_RECEIVE = 10 @@ -55,95 +52,78 @@ class SocketClientTelescopeGEMINI(SocketClientTelescopeAbstract): #data = " ".join(sys.argv[1:]) #data_to_send = bytes(data + "\n", "utf-8") - ''' Commands dictionary + NEW foramt is: + 'generic-command-name': ['native-command-name', 'awaited_result_if_ok', 'other-awaited-results if not ok...], + + Old format was: 'CMD-NAME': ['cmd-get', 'awaited_res_ok_for_get', 'cmd-set', 'awaited_res_ok_for_set', 'comment'], ''' - - # @override - _cmd = { + # @overwrite + _cmd_native = { # GET @ SET commands 'get_ack': [COMMAND6, 'G', 'B','b','S'], # 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. - 'get_ra': ['GR'], - 'set_ra': ['Sr'], - - 'get_dec': ['GD'], - - 'get_timezone': ['GG'], - 'set_timezone': ['SG', '1'], - - - # DO commands - 'do_move': [':MS#', '0', '1Object below horizon.#', '2No object selected.#', '3Manual Control.#', '4Position unreachable.#', '5Not aligned.#', '6Outside Limits.#' ], - 'do_stop': [':Q#'], - 'do_init': ['do_init'], - } - - """ - # @override - _cmd_getset = { - - 'ack': [COMMAND6, 'G'], - # RA-DEC (p109-110) #:Sr:.# or :Sr::# #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 #:Sd{+-}
{*°}# or :Sd{+- }
{*°:}: #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" - 'ra': ['GR', None, 'Sr', None, 'commentaire'], - 'dec': ['GD', None, 'Sd'], #'RADEC': [('GR','GD'), ''], + #'ra': ['GR', None, 'Sr', None, 'commentaire'], + 'get_ra': ['GR'], + 'set_ra': ['Sr'], + 'get_dec': ['GD'], + 'set_dec': ['Sd'], + # get_radec and set_radec are already defined in abstract class + + 'get_timezone': ['GG'], + 'set_timezone': ['SG', '1'], # ALT-AZ (p?) - "ALT": ['GA'], - "AZ": ['GZ'], + "get_alt": ['GA'], + "get_az": ['GZ'], #"ALT-AZ": [('GA','GZ'), ''], # LONG-LAT - "LONGITUDE": ['Gg', None, 'Sg'], - "LATITUDE": ['Gt', None, 'St'], + "get_long": ['Gg'], + "set_long": ['Sg'], + "get_lat": ['Gt'], + "set_lat": ['St'], #"LONGLAT": [('Gg','Gt'), ''], - "hour-angle": ['GH'], + "get_hangle": ['GH'], - "max-vel": ['Gv'], + 'get_vel': ['Gv'], + #"get_maxvel": ['Gv'], - 'timezone': ['GG', None, 'SG', '1'], - 'DATE': ['GC', None, 'SC'], - 'TIME': ['GL', None, 'SL'], - - 'VELOCITY': ['Gv'], - - + 'get_date': ['GC'], + 'set_date': ['SC'], + 'get_time': ['GL'], + 'set_time': ['SL'], + # DO commands + # defined in abstract class: + #'do_init': ['do_init'], + 'do_park': ['hP'], + 'do_warm_start': ['bW'], + 'do_prec_refr': ['p3'], + 'do_move': ['MS', '0', '1Object below horizon.', '2No object selected.', '3Manual Control.', '4Position unreachable.', '5Not aligned.', '6Outside Limits.' ], + 'do_movenorth': ['Mn'], + 'do_movesouth': ['Ms'], + 'do_movewest': ['Mw'], + 'do_moveeast': ['Me'], + 'do_stop': ['Q'], } - ''' Commands dictionary - 'CMD-NAME': ['cmd-do', 'comment'], - ''' - # @override - _cmd_do = { - #'INIT': [], - 'PARK': ['hP'], - 'WARM_START': ['bW'], - 'PREC_REFR': ['p3'], - 'MOVE': ['MS'], - 'MOVE_NORTH': ['Mn'], - 'MOVE_SOUTH': ['Ms'], - 'MOVE_WEST': ['Mw'], - 'MOVE_EAST': ['Me'], - 'STOP': ['Q'], - } - """ - # @override + # @overwrite # GEMINI is using UDP def __init__(self, server_host:str="localhost", server_port:int=11110, DEBUG=False): super().__init__(server_host, server_port, "UDP", 1024, DEBUG) - # @override + # @overwrite def formated_cmd(self, cmd:str, values_to_set:str=None)->str: if values_to_set != None: for value_to_set in values_to_set: @@ -158,7 +138,7 @@ class SocketClientTelescopeGEMINI(SocketClientTelescopeAbstract): return getattr(self, func)(arg) - # @override + # @overwrite def _encapsulate_data_to_send(self, command:str): r''' Encapsulate useful data to be ready for sending @@ -207,7 +187,7 @@ class SocketClientTelescopeGEMINI(SocketClientTelescopeAbstract): #return bytes(data + "\n", "utf-8") ####return bytes(self.MYSTAMP + self.STAMP_FILLER + data + "\n", "utf-8") - # @override + # @overwrite def _uncap_received_data(self, data_received_bytes:bytes)->str: r""" Extract useful data from received raw data @@ -256,25 +236,6 @@ class SocketClientTelescopeGEMINI(SocketClientTelescopeAbstract): if not native_cmd: raise UnknownCommandException(speed_rate) return self.execute_unformated_native_cmd(native_cmd) - ''' - def do_MOVE_NORTH(self): return self.execute_native_cmd_OLD(':Mn#') - def do_MOVE_SOUTH(self): return self.execute_native_cmd_OLD(':Ms#') - def do_MOVE_WEST(self): return self.execute_native_cmd_OLD(':Mw#') - def do_MOVE_EAST(self): return self.execute_native_cmd_OLD(':Me#') - ''' - - ''' - TELESCOPE COMMANDS implementation - ''' - - ''' - The 3 main generic commands : get(), set(), do() - ''' - ''' 1) GET methods ''' - ''' 2) SET methods ''' - ''' 3) DO methods ''' - ''' SPECIFIC methods ''' - if __name__ == "__main__": @@ -315,4 +276,4 @@ if __name__ == "__main__": #print("Useful data received: {}".format(data_useful)) print('\n') - #tele_client.close() + #tele_client.close() \ No newline at end of file -- libgit2 0.21.2