Commit d52240d4f69221a1d6187b55dd3044bb43c13f88
1 parent
7a7e30cc
Exists in
dev
nouvelle classe DeviceCommand (dans DeviceController)
Showing
6 changed files
with
108 additions
and
48 deletions
Show diff stats
src/core/pyros_django/agent/AgentDevice.py
... | ... | @@ -190,7 +190,7 @@ class AgentDevice(Agent): |
190 | 190 | # Save current device status to DB |
191 | 191 | #AgentDeviceTelescopeStatus.objects.create(radec=myradec) |
192 | 192 | #if not self.is_running_specific_cmd(): |
193 | - self.save_device_status() | |
193 | + self._save_device_status() | |
194 | 194 | |
195 | 195 | self.print("Status saved in DB") |
196 | 196 | |
... | ... | @@ -198,7 +198,7 @@ class AgentDevice(Agent): |
198 | 198 | self.print("ROUTINE PROCESS END") |
199 | 199 | |
200 | 200 | |
201 | - def save_device_status(self): | |
201 | + def _save_device_status(self): | |
202 | 202 | self._agent_device_status.status = self.get_device_status() |
203 | 203 | self._agent_device_status.save() |
204 | 204 | |
... | ... | @@ -241,12 +241,13 @@ class AgentDevice(Agent): |
241 | 241 | ================================================================= |
242 | 242 | """ |
243 | 243 | |
244 | - # @Overwrite superclass (Agent) method | |
244 | + # @override superclass (Agent) method | |
245 | 245 | def cmd_step(self, step:int): |
246 | 246 | cmd = self._current_specific_cmd |
247 | 247 | print("cmd name is", cmd.name) |
248 | - res = self._device_ctrl.execute_cmd(cmd.name_and_args) | |
249 | - cmd.set_result(str(res)) | |
248 | + #res = self._device_ctrl.execute_cmd(cmd.name_and_args) | |
249 | + res = self._device_ctrl.execute_cmd(cmd.full_name) | |
250 | + ##cmd.set_result(str(res)) | |
250 | 251 | print("result is", str(res)) |
251 | 252 | if res.ok: print("OK") |
252 | 253 | #cmd.set_as_processed() | ... | ... |
src/core/pyros_django/agent/AgentDeviceSBIG.py
... | ... | @@ -67,8 +67,8 @@ class AgentDeviceSBIG(AgentDevice): |
67 | 67 | super().__init__( |
68 | 68 | config_filename, |
69 | 69 | RUN_IN_THREAD, |
70 | - device_controller=DeviceControllerSBIG, host=self.HOST, port=self.PORT, | |
71 | - device_simulator=DeviceSimulatorSBIG) | |
70 | + device_controller=DeviceControllerSBIG, host=self.HOST, port=self.PORT) | |
71 | + #device_simulator=DeviceSimulatorSBIG) | |
72 | 72 | |
73 | 73 | # Initialize the device table status |
74 | 74 | # If table is empty, create a default 1st row | ... | ... |
src/core/pyros_django/common/models.py
... | ... | @@ -423,7 +423,7 @@ class Command(models.Model): |
423 | 423 | "CMD_KILLED", # cde ignorée (je suis idle… et j’ai ignoré cette commande, et je passe à la cde suivante) |
424 | 424 | "CMD_OUTOFDATE" # cde périmée |
425 | 425 | ) |
426 | - GENERIC_COMMANDS = [ | |
426 | + _GENERAL_COMMANDS = [ | |
427 | 427 | #"do_eval", "set_state:idle", "set_state:active", |
428 | 428 | "do_eval", |
429 | 429 | "set_state", |
... | ... | @@ -688,7 +688,7 @@ class Command(models.Model): |
688 | 688 | ##name = self.name.split(' ')[0] |
689 | 689 | ##cmd_name, _ = self.tokenize() |
690 | 690 | #return cmd_name in self.GENERIC_COMMANDS |
691 | - return self.name in self.GENERIC_COMMANDS | |
691 | + return self.name in self._GENERAL_COMMANDS | |
692 | 692 | #"CMD_OUTOFDATE" # cde périmée |
693 | 693 | |
694 | 694 | def is_read(self): | ... | ... |
src/device_controller/README.md
... | ... | @@ -2,9 +2,9 @@ |
2 | 2 | ************************ |
3 | 3 | ## DEVICES & CHANNELS |
4 | 4 | ************************ |
5 | -VERSION: 0.30.0 | |
5 | +VERSION: 0.32 | |
6 | 6 | |
7 | -Date: 19/09/2019 | |
7 | +Date: 30/09/2019 | |
8 | 8 | |
9 | 9 | By: epallier@irap.omp.eu |
10 | 10 | |
... | ... | @@ -34,7 +34,7 @@ Là, il faut arrêter avec CTRL-C (car je ne sais pas encore comment arrêter le |
34 | 34 | ******************************************************************************************** |
35 | 35 | # 2) RUN |
36 | 36 | |
37 | -Pour lancer le client sur le telescope Gemini de Alain Klotz: | |
37 | +Pour lancer le client sur le telescope Gemini de Guitalens (AK) : | |
38 | 38 | |
39 | 39 | $ cd devices_controller_concrete/device_controller_Gemini/ |
40 | 40 | $ ./client_telescope_gemini_controller_run.py |
... | ... | @@ -72,10 +72,12 @@ Pour lancer le même client seulement sur le "simulateur" de telescope (localhos |
72 | 72 | $ cd devices_controller_concrete/device_controller_Gemini/ |
73 | 73 | $ ./client_telescope_gemini_controller_run.py local |
74 | 74 | |
75 | -Dans un autre terminal, lancer le simulateur: | |
76 | - | |
75 | +Ceci n'est plus nécessaire depuis le 30/9/19 car le simulateur est lancé automatiquement par le client : | |
76 | +((( | |
77 | + Dans un autre terminal, lancer le simulateur: | |
77 | 78 | $ ./server_telescope_gemini_simulator_run.py |
78 | 79 | (CTRL-C to stop it) |
80 | +))) | |
79 | 81 | |
80 | 82 | |
81 | 83 | ******************************************************************************************** | ... | ... |
src/device_controller/abstract_component/base.py
... | ... | @@ -74,6 +74,51 @@ def generic_cmd(func): |
74 | 74 | return wrapper_generic_cmd |
75 | 75 | |
76 | 76 | |
77 | +class DeviceCommand: | |
78 | + | |
79 | + full_name = None | |
80 | + name = None | |
81 | + type = None | |
82 | + args = None | |
83 | + | |
84 | + def __init__(self, cmd_full_name:str, cmd_type:str=None, cmd_args:str=None): | |
85 | + self.full_name = cmd_full_name | |
86 | + self.name = cmd_full_name | |
87 | + self.type = cmd_type | |
88 | + self.args = cmd_args | |
89 | + if self.is_generic(): | |
90 | + cmd_type,cmd_name,cmd_args = self.get_full_name_parts() | |
91 | + self.name = cmd_name | |
92 | + if cmd_type: self.type = cmd_type | |
93 | + if cmd_args: self.args = cmd_args | |
94 | + | |
95 | + def __str__(self): | |
96 | + return (f"Commmand '{self.full_name}'") | |
97 | + | |
98 | + def is_generic(self): | |
99 | + return self.name.startswith('do_') or self.name.startswith('get_') or self.name.startswith('set_') | |
100 | + | |
101 | + @property | |
102 | + def name_and_args(self): | |
103 | + cmd_name_and_args = self.full_name | |
104 | + if '.' in cmd_name_and_args: | |
105 | + cmd_name_and_args = cmd_name_and_args.split('.')[1] | |
106 | + return cmd_name_and_args | |
107 | + | |
108 | + def get_full_name_parts(self): | |
109 | + cmd_name = self.full_name | |
110 | + cmd_type = None | |
111 | + cmd_args = None | |
112 | + if '.' in cmd_name: | |
113 | + cmd_type, cmd_name = cmd_name.split('.') | |
114 | + if ' ' in cmd_name: | |
115 | + cmd_name, *cmd_args = cmd_name.split(' ') | |
116 | + return cmd_type, cmd_name, cmd_args | |
117 | + | |
118 | + | |
119 | + | |
120 | + | |
121 | + | |
77 | 122 | |
78 | 123 | class GenericResult: |
79 | 124 | ''' Usage: |
... | ... | @@ -299,10 +344,11 @@ class DeviceControllerAbstract(): |
299 | 344 | self._device_simulator.stop() |
300 | 345 | |
301 | 346 | |
347 | + ''' | |
302 | 348 | def is_generic_cmd(self, raw_input_cmd:str) -> bool: |
303 | 349 | print("raw_input_cmd is", raw_input_cmd) |
304 | 350 | # Using Google documentation format (https://www.sphinx-doc.org/en/master/usage/extensions/example_google.html#example-google) |
305 | - """ Is this a generic command ? | |
351 | + #"" Is this a generic command ? | |
306 | 352 | |
307 | 353 | Args: |
308 | 354 | raw_input_cmd: a command in string format (like 'set_state active' or 'get_ra' or 'set_ra 20:00:00' or 'set_radec 20:00:00 90:00:00" or 'do_park'...) |
... | ... | @@ -310,10 +356,10 @@ class DeviceControllerAbstract(): |
310 | 356 | Returns: |
311 | 357 | either False or (cmd, [args]) with cmd like "get_ra" and [args] like ['20:00:00', '90:00:00'] |
312 | 358 | |
313 | - """ | |
359 | + #"" | |
314 | 360 | #return cmd.startswith('get_') or cmd.startswith('set_') or cmd.startswith('do_') |
315 | 361 | #cmds = ['get ', 'get_', 'set ', 'set_', 'do ', 'do_'] |
316 | - ''' | |
362 | + #'' | |
317 | 363 | seps = (" ", "_") |
318 | 364 | #cmds = list(x+y for x in cmd for y in sep) |
319 | 365 | for cmd in cmds: |
... | ... | @@ -327,16 +373,16 @@ class DeviceControllerAbstract(): |
327 | 373 | # return cmd like "get_ra", [and values] |
328 | 374 | return generic_cmd.replace(' ','_'), values |
329 | 375 | return False, False |
330 | - ''' | |
376 | + #'' | |
331 | 377 | ##cmds = ("get","set","do") |
332 | 378 | |
333 | - ''' | |
379 | + #'' | |
334 | 380 | # ex: "set radec" => "set_radec" |
335 | 381 | raw_input_cmd = raw_input_cmd.strip() |
336 | 382 | cmd_splitted = raw_input_cmd.split(' ') |
337 | 383 | if len(cmd_splitted) == 1: return False,False |
338 | 384 | generic_cmd = cmd_splitted[0] + '_' + cmd_splitted[1] |
339 | - ''' | |
385 | + #'' | |
340 | 386 | # Ex: "set_radec 15 30", "do_init", "get_radec", "set_state active", "do_goto_radec 15 45"... |
341 | 387 | tokens = raw_input_cmd.split(' ') |
342 | 388 | generic_cmd = tokens[0] |
... | ... | @@ -349,36 +395,41 @@ class DeviceControllerAbstract(): |
349 | 395 | args = tokens[1:] if len(tokens)>1 else None |
350 | 396 | # ex: return "set_radec", ["20:00:00", "90:00:00"] |
351 | 397 | return generic_cmd, args |
398 | + ''' | |
352 | 399 | |
353 | - | |
400 | + #def execute_cmd(self, cmd:DeviceCommand)->GenericResult: | |
354 | 401 | def execute_cmd(self, raw_input_cmd:str)->GenericResult: |
355 | 402 | ''' |
356 | 403 | :param raw_input_cmd: |
357 | 404 | ''' |
358 | - generic_cmd, args = self.is_generic_cmd(raw_input_cmd) | |
405 | + | |
406 | + #generic_cmd, args = self.is_generic_cmd(raw_input_cmd) | |
407 | + cmd = DeviceCommand(raw_input_cmd) | |
359 | 408 | |
360 | 409 | # GENERIC command |
361 | - if generic_cmd is not False: | |
410 | + #if generic_cmd is not False: | |
411 | + if cmd.is_generic(): | |
362 | 412 | print("GENERIC COMMAND") |
363 | - return self.execute_generic_cmd(generic_cmd, args) | |
413 | + #return self.execute_generic_cmd(generic_cmd, args) | |
414 | + return self.execute_generic_cmd(cmd.name, cmd.args) | |
364 | 415 | |
365 | 416 | # NATIVE command |
366 | - else: | |
367 | - ''' | |
368 | - if cmd.startswith('get_'): | |
369 | - #generic_cmd,_ = request[4:].split('(') | |
370 | - generic_cmd = cmd[4:] | |
371 | - if (generic_cmd not in self._cmd_getset.keys()) and (generic_cmd not in self._cmd_do.keys()): | |
372 | - #eval(request) | |
373 | - return self.get_radec() | |
374 | - print("cmd is", generic_cmd) | |
375 | - return self._get(generic_cmd) | |
376 | - return | |
377 | - ''' | |
378 | - # NATIVE command | |
379 | - print("NATIVE COMMAND") | |
380 | - res_native = self.execute_native_cmd(raw_input_cmd) | |
381 | - return GenericResult(res_native) | |
417 | + ''' | |
418 | + if cmd.startswith('get_'): | |
419 | + #generic_cmd,_ = request[4:].split('(') | |
420 | + generic_cmd = cmd[4:] | |
421 | + if (generic_cmd not in self._cmd_getset.keys()) and (generic_cmd not in self._cmd_do.keys()): | |
422 | + #eval(request) | |
423 | + return self.get_radec() | |
424 | + print("cmd is", generic_cmd) | |
425 | + return self._get(generic_cmd) | |
426 | + return | |
427 | + ''' | |
428 | + # NATIVE command | |
429 | + print("NATIVE COMMAND") | |
430 | + #res_native = self.execute_native_cmd(raw_input_cmd) | |
431 | + res_native = self.execute_native_cmd(cmd.name_and_args) | |
432 | + return GenericResult(res_native) | |
382 | 433 | |
383 | 434 | |
384 | 435 | #def execute_native_cmd(self, request:str, awaited_res_if_ok=None)->GenericResult: |
... | ... | @@ -429,11 +480,12 @@ class DeviceControllerAbstract(): |
429 | 480 | def print_available_commands(self): |
430 | 481 | print("\nAvailable commands are:") |
431 | 482 | print("- GET commands:") |
432 | - print (list(cmd.replace('_',' ') for cmd in self._cmd.keys() if cmd.startswith('get_'))) | |
483 | + #print (list(cmd.replace('_',' ') for cmd in self._cmd.keys() if cmd.startswith('get_'))) | |
484 | + print (list(cmd for cmd in self._cmd.keys() if cmd.startswith('get_'))) | |
433 | 485 | print("- SET commands:") |
434 | - print (list(cmd.replace('_',' ') for cmd in self._cmd.keys() if cmd.startswith('set_'))) | |
486 | + print (list(cmd for cmd in self._cmd.keys() if cmd.startswith('set_'))) | |
435 | 487 | print("- DO commands:") |
436 | - print (list(cmd.replace('_',' ') for cmd in self._cmd.keys() if cmd.startswith('do_'))) | |
488 | + print (list(cmd for cmd in self._cmd.keys() if cmd.startswith('do_'))) | |
437 | 489 | |
438 | 490 | |
439 | 491 | def available_commands(self): |
... | ... | @@ -457,6 +509,7 @@ class DeviceControllerAbstract(): |
457 | 509 | TELESCOPE COMMANDS (abstract methods) |
458 | 510 | ''' |
459 | 511 | |
512 | + #def execute_generic_cmd(self, generic_cmd:DeviceCommand)->str: | |
460 | 513 | def execute_generic_cmd(self, generic_cmd:str, values_to_set:str=None)->str: |
461 | 514 | ''' Execute a generic command |
462 | 515 | |
... | ... | @@ -465,7 +518,7 @@ class DeviceControllerAbstract(): |
465 | 518 | ''' |
466 | 519 | |
467 | 520 | #log_d("\n\nGENERIC Command to send is "+generic_cmd) |
468 | - print("\n\nGENERIC Command to send is "+generic_cmd) | |
521 | + print("\n\nGENERIC Command to send is ", generic_cmd) | |
469 | 522 | # Check if generic_param exists |
470 | 523 | #if generic_cmd not in self._cmd.keys(): raise UnknownCommandException() |
471 | 524 | # if this generic command has no corresponding native command, raise NotImplementedError |
... | ... | @@ -493,9 +546,7 @@ class DeviceControllerAbstract(): |
493 | 546 | return res |
494 | 547 | |
495 | 548 | # NATIVE COMMAND (ex: native_cmd == "GR") |
496 | - else: | |
497 | - native_cmd = self.formated_cmd(native_cmd,values_to_set) | |
498 | - | |
549 | + native_cmd = self.formated_cmd(native_cmd, values_to_set) | |
499 | 550 | awaited_res_if_ok = None |
500 | 551 | if len(native_cmd_infos) > 1: awaited_res_if_ok = native_cmd_infos[1] |
501 | 552 | #native_res = self.execute_native_cmd(self.formated_cmd(native_cmd,value), awaited_res_ok) | ... | ... |
src/device_controller/concrete_component/gemini/client_telescope_gemini_controller_run.py
... | ... | @@ -14,7 +14,12 @@ ou (2) |
14 | 14 | #from gemini.telescope_controller_gemini import TelescopeControllerGemini |
15 | 15 | ou (3) |
16 | 16 | ''' |
17 | -from gemini_telescope_controller import DeviceControllerTelescopeGemini | |
17 | + | |
18 | + | |
19 | +sys.path.append("../../..") | |
20 | +from device_controller.abstract_component.base import DeviceCommand | |
21 | +#from gemini_telescope_controller import DeviceControllerTelescopeGemini | |
22 | +from device_controller.concrete_component.gemini.gemini_telescope_controller import DeviceControllerTelescopeGemini | |
18 | 23 | |
19 | 24 | #DEBUG = False |
20 | 25 | DEBUG = True |
... | ... | @@ -102,6 +107,7 @@ def main(): |
102 | 107 | cmd = input("REQUEST TO SERVER (ENTER to quit): >>> ").strip() |
103 | 108 | if not cmd: break |
104 | 109 | |
110 | + cmd = DeviceCommand(cmd) | |
105 | 111 | #res = tele_ctrl.execute_cmd(cmd.replace(' ', '_')) |
106 | 112 | res = tele_ctrl.execute_cmd(cmd) |
107 | 113 | print("result is", str(res)) | ... | ... |