diff --git a/src/devices_controller/devices_controller_abstract_component/device_controller_abstract.py b/src/devices_controller/devices_controller_abstract_component/device_controller_abstract.py index 2f00ab7..ab07458 100755 --- a/src/devices_controller/devices_controller_abstract_component/device_controller_abstract.py +++ b/src/devices_controller/devices_controller_abstract_component/device_controller_abstract.py @@ -249,7 +249,8 @@ class DeviceControllerAbstract(): def uncap_received_data(self, data_received:str): return self.my_channel.uncap_received_data(data_received) ''' - + + def get_utc_date(self): return celme.Date("now").iso(0) #return celme.Date("now").ymdhms() @@ -257,13 +258,19 @@ class DeviceControllerAbstract(): def close(self): self.my_channel.close() - - def is_generic_cmd(self, raw_input_cmd:str): - ''' is this a generic command ? - - :param raw_input_cmd: like 'get ra' or 'set ra 20:00:00' or 'set radec 20:00:00 90:00:00" or 'do park' or 'do_park'... - :return either False or (cmd, [values]) with cmd like "get_ra" (using underscore '_' instead of space ' ') - ''' + + + def is_generic_cmd(self, raw_input_cmd:str) -> bool: + # Using Google documentation format (https://www.sphinx-doc.org/en/master/usage/extensions/example_google.html#example-google) + """ Is this a generic command ? + + Args: + raw_input_cmd: a command in raw string format (like 'get ra' or 'set ra 20:00:00' or 'set radec 20:00:00 90:00:00" or 'do park' or 'do_park'...) + + Returns: + either False or (cmd, [values]) with cmd like "get_ra" (using underscore '_' instead of space ' '). + + """ #return cmd.startswith('get_') or cmd.startswith('set_') or cmd.startswith('do_') #cmds = ['get ', 'get_', 'set ', 'set_', 'do ', 'do_'] ''' @@ -295,8 +302,8 @@ class DeviceControllerAbstract(): 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 - - + + def execute_cmd(self, raw_input_cmd:str)->GenericResult: # GENERIC command generic_cmd, values = self.is_generic_cmd(raw_input_cmd) @@ -319,9 +326,19 @@ class DeviceControllerAbstract(): #print("NATIVE COMMAND") res_native = self.execute_native_cmd(raw_input_cmd) return GenericResult(res_native) - + + #def execute_native_cmd(self, request:str, awaited_res_if_ok=None)->GenericResult: - def execute_native_cmd(self, native_cmd:str)->str: + def execute_native_cmd(self, native_cmd:str) -> str: + """ Execute a native command + + Args: + native_cmd: a native command + + Returns: + the command result + + """ print("NATIVE Command to send is "+ repr(native_cmd)) #self.send_request(native_cmd) self.send_native_cmd(native_cmd) @@ -331,25 +348,31 @@ class DeviceControllerAbstract(): ok = True if not awaited_res_if_ok else (native_res == awaited_res_if_ok) return GenericResult(native_res, ok) ''' - + + ''' def execute_native_cmd_OLD(self, request:str)->str: self.send_request(request) native_res = self.receive_data() return native_res ''' - def execute_unformated_native_cmd(self, request:str)->str: + + + def execute_unformated_native_cmd(self, request:str) -> str: request = self.formated_cmd(request) #return self.execute_native_cmd_OLD(request) return self.execute_native_cmd(request) + def send_native_cmd(self, native_cmd:str)->str: return self.send_data(native_cmd) + + #@deprecated def send_request(self, request:str)->str: return self.send_native_cmd(request) - + def print_available_commands(self): print("\nAvailable commands are:") print("- GET commands:") @@ -358,14 +381,17 @@ class DeviceControllerAbstract(): print (list(cmd.replace('_',' ') for cmd in self._cmd.keys() if cmd.startswith('set_'))) print("- DO commands:") print (list(cmd.replace('_',' ') for cmd in self._cmd.keys() if cmd.startswith('do_'))) - + + def available_commands(self): return list(self._cmd.keys()) - + + # @abstract def formated_cmd(self, cmd:str, value:str=None)->str: return cmd - + + #def run_func(self, func, arg=None): def run_func(self, func, *args): #print("args", args) @@ -380,7 +406,7 @@ class DeviceControllerAbstract(): def execute_generic_cmd(self, generic_cmd:str, values_to_set:str=None)->str: ''' Execute a generic command - + :param generic_cmd: str like "get_ra" or "set_ra" or "do_park"... :param value: only for a "set_" cmd ''' -- libgit2 0.21.2