Commit 1d7f99210d42714ab926f2cc242f3fd152c85276
1 parent
52df9a16
Exists in
dev
transition (7) vers new class Commande (Cmd)
Showing
3 changed files
with
43 additions
and
11 deletions
Show diff stats
src/device_controller/abstract_component/device_controller.py
@@ -295,8 +295,11 @@ class Gen2NatCmds: | @@ -295,8 +295,11 @@ class Gen2NatCmds: | ||
295 | #cmds = {} | 295 | #cmds = {} |
296 | 296 | ||
297 | def __init__(self, cmds:dict={}): | 297 | def __init__(self, cmds:dict={}): |
298 | - self.GEN2NAT_CMDS = cmds | ||
299 | #self.cmds = {} | 298 | #self.cmds = {} |
299 | + self.GEN2NAT_CMDS = cmds | ||
300 | + if isinstance(cmds, list): | ||
301 | + self.GEN2NAT_CMDS = {} | ||
302 | + self.add_cmds(cmds) | ||
300 | 303 | ||
301 | def __str__(self)->str: return str(self.GEN2NAT_CMDS) | 304 | def __str__(self)->str: return str(self.GEN2NAT_CMDS) |
302 | 305 | ||
@@ -392,6 +395,9 @@ class Gen2NatCmds: | @@ -392,6 +395,9 @@ class Gen2NatCmds: | ||
392 | return 'G'+ cmd[1] | 395 | return 'G'+ cmd[1] |
393 | def get_simulated_answer_for_native_cmd(self, cmd:str)->str: | 396 | def get_simulated_answer_for_native_cmd(self, cmd:str)->str: |
394 | for val in self.GEN2NAT_CMDS.values(): | 397 | for val in self.GEN2NAT_CMDS.values(): |
398 | + if isinstance(val, Cmd): | ||
399 | + if val.native_name == cmd: return val.final_simul_response | ||
400 | + continue | ||
395 | if cmd in val: | 401 | if cmd in val: |
396 | # No native cmd defined | 402 | # No native cmd defined |
397 | if cmd != val[0]: return None | 403 | if cmd != val[0]: return None |
@@ -413,6 +419,11 @@ class Gen2NatCmds: | @@ -413,6 +419,11 @@ class Gen2NatCmds: | ||
413 | return True | 419 | return True |
414 | # nothing set | 420 | # nothing set |
415 | return False | 421 | return False |
422 | + | ||
423 | + def cmd_native_name_is(self, native_cmd_infos:Cmd, cmd:str): | ||
424 | + if isinstance(native_cmd_infos, Cmd): | ||
425 | + return cmd == native_cmd_infos.native_name | ||
426 | + return cmd in native_cmd_infos and cmd == native_cmd_infos[0] | ||
416 | ''' | 427 | ''' |
417 | #TODO: chercher dans les DCC !! (recursive) | 428 | #TODO: chercher dans les DCC !! (recursive) |
418 | def is_valid_native_cmd(self, cmd:str)->bool: | 429 | def is_valid_native_cmd(self, cmd:str)->bool: |
@@ -429,8 +440,8 @@ class Gen2NatCmds: | @@ -429,8 +440,8 @@ class Gen2NatCmds: | ||
429 | ##return cmd in self.GEN2NAT_CMDS.values() | 440 | ##return cmd in self.GEN2NAT_CMDS.values() |
430 | # More elaborated version | 441 | # More elaborated version |
431 | for native_cmd_infos in self.GEN2NAT_CMDS.values(): | 442 | for native_cmd_infos in self.GEN2NAT_CMDS.values(): |
432 | - if cmd in native_cmd_infos: | ||
433 | - if cmd == native_cmd_infos[0]: return True | 443 | + #if cmd in native_cmd_infos and cmd == native_cmd_infos[0]: return True |
444 | + if self.cmd_native_name_is(native_cmd_infos, cmd): return True | ||
434 | # no notive cmd found | 445 | # no notive cmd found |
435 | return False | 446 | return False |
436 | def print_available_cmds(self): | 447 | def print_available_cmds(self): |
@@ -1246,6 +1257,16 @@ class DeviceController(): | @@ -1246,6 +1257,16 @@ class DeviceController(): | ||
1246 | 1257 | ||
1247 | 1258 | ||
1248 | 1259 | ||
1260 | + def cmd_get_native_name(self, native_cmd_infos:Cmd): | ||
1261 | + #if isinstance(native_cmd_infos, Cmd): return [native_cmd_infos.native_name, native_cmd_infos.final_simul_response] | ||
1262 | + if isinstance(native_cmd_infos, Cmd): return native_cmd_infos.native_name | ||
1263 | + return native_cmd_infos[0] | ||
1264 | + | ||
1265 | + def cmd_get_simul_response(self, native_cmd_infos:Cmd): | ||
1266 | + if isinstance(native_cmd_infos, Cmd): | ||
1267 | + return native_cmd_infos.final_simul_response if native_cmd_infos.final_simul_response!='simulator response' else None | ||
1268 | + return native_cmd_infos[1] if len(native_cmd_infos)>1 else None | ||
1269 | + | ||
1249 | #def exec_generic_cmd(self, generic_cmd:DeviceCmd)->str: | 1270 | #def exec_generic_cmd(self, generic_cmd:DeviceCmd)->str: |
1250 | ##def exec_generic_cmd(self, generic_cmd:str, values_to_set:str=None, dcc_type:str=None)->str: | 1271 | ##def exec_generic_cmd(self, generic_cmd:str, values_to_set:str=None, dcc_type:str=None)->str: |
1251 | def exec_generic_cmd(self, generic_cmd:str, values_to_set:str=None)->str: | 1272 | def exec_generic_cmd(self, generic_cmd:str, values_to_set:str=None)->str: |
@@ -1279,7 +1300,9 @@ class DeviceController(): | @@ -1279,7 +1300,9 @@ class DeviceController(): | ||
1279 | return dcc.exec_generic_cmd(generic_cmd, values_to_set) | 1300 | return dcc.exec_generic_cmd(generic_cmd, values_to_set) |
1280 | ''' | 1301 | ''' |
1281 | # Get corresponding native command: | 1302 | # Get corresponding native command: |
1282 | - native_cmd = native_cmd_infos[0] | 1303 | + #native_cmd = native_cmd_infos[0] |
1304 | + native_cmd = self.cmd_get_native_name(native_cmd_infos) | ||
1305 | + print("***** generic, native_cmd", generic_cmd, native_cmd) | ||
1283 | if not native_cmd: raise UnimplementedGenericCmdException(generic_cmd) | 1306 | if not native_cmd: raise UnimplementedGenericCmdException(generic_cmd) |
1284 | 1307 | ||
1285 | # 2) MACRO-COMMAND or NORMAL NATIVE COMMAND ? | 1308 | # 2) MACRO-COMMAND or NORMAL NATIVE COMMAND ? |
@@ -1314,8 +1337,14 @@ class DeviceController(): | @@ -1314,8 +1337,14 @@ class DeviceController(): | ||
1314 | # 2.b) NORMAL NATIVE COMMAND (ex: native_cmd == "GR") | 1337 | # 2.b) NORMAL NATIVE COMMAND (ex: native_cmd == "GR") |
1315 | ##native_cmd = self.formated_cmd(native_cmd, values_to_set) | 1338 | ##native_cmd = self.formated_cmd(native_cmd, values_to_set) |
1316 | native_cmd = dcc.formated_cmd(native_cmd, values_to_set) | 1339 | native_cmd = dcc.formated_cmd(native_cmd, values_to_set) |
1340 | + awaited_res_if_ok = self.cmd_get_simul_response(native_cmd_infos) | ||
1341 | + ''' | ||
1317 | awaited_res_if_ok = None | 1342 | awaited_res_if_ok = None |
1318 | - if len(native_cmd_infos) > 1: awaited_res_if_ok = native_cmd_infos[1] | 1343 | + if isinstance(native_cmd_infos, Cmd) and native_cmd_infos.final_simul_response!='simulator response': |
1344 | + awaited_res_if_ok = native_cmd_infos.final_simul_response | ||
1345 | + elif len(native_cmd_infos) > 1: | ||
1346 | + awaited_res_if_ok = native_cmd_infos[1] | ||
1347 | + ''' | ||
1319 | #native_res = self.exec_native_cmd(self.formated_cmd(native_cmd,value), awaited_res_ok) | 1348 | #native_res = self.exec_native_cmd(self.formated_cmd(native_cmd,value), awaited_res_ok) |
1320 | ##native_res = self.exec_native_cmd(native_cmd) | 1349 | ##native_res = self.exec_native_cmd(native_cmd) |
1321 | try: | 1350 | try: |
src/device_controller/abstract_component/mount.py
@@ -94,9 +94,8 @@ class DC_Mount(DeviceController): | @@ -94,9 +94,8 @@ class DC_Mount(DeviceController): | ||
94 | Cmd('set_ra'), | 94 | Cmd('set_ra'), |
95 | Cmd('get_dec'), | 95 | Cmd('get_dec'), |
96 | Cmd('set_dec'), | 96 | Cmd('set_dec'), |
97 | - #'get_radec': [get_radec], | ||
98 | - Cmd('get_radec'), | ||
99 | - Cmd('set_radec'), | 97 | + Cmd('get_radec', 'get_radec'), |
98 | + Cmd('set_radec', 'set_radec'), | ||
100 | 99 | ||
101 | Cmd('get_longitude'), | 100 | Cmd('get_longitude'), |
102 | Cmd('set_longitude'), | 101 | Cmd('set_longitude'), |
@@ -124,9 +123,11 @@ class DC_Mount(DeviceController): | @@ -124,9 +123,11 @@ class DC_Mount(DeviceController): | ||
124 | Cmd('do_warm_start'), | 123 | Cmd('do_warm_start'), |
125 | Cmd('do_prec_refr'), | 124 | Cmd('do_prec_refr'), |
126 | ] | 125 | ] |
126 | + ''' | ||
127 | my_cmds2 = Gen2NatCmds() | 127 | my_cmds2 = Gen2NatCmds() |
128 | my_cmds2.add_cmds(GEN2NAT_CMDS_obj) | 128 | my_cmds2.add_cmds(GEN2NAT_CMDS_obj) |
129 | ''' | 129 | ''' |
130 | + ''' | ||
130 | print("******************************") | 131 | print("******************************") |
131 | print("(MOUNT) Mes commandes") | 132 | print("(MOUNT) Mes commandes") |
132 | my_cmds2.print_mes_commandes() | 133 | my_cmds2.print_mes_commandes() |
@@ -176,7 +177,8 @@ class DC_Mount(DeviceController): | @@ -176,7 +177,8 @@ class DC_Mount(DeviceController): | ||
176 | 'do_prec_refr': [], | 177 | 'do_prec_refr': [], |
177 | } | 178 | } |
178 | 179 | ||
179 | - GEN2NAT_CMDS = my_cmds2.get_as_dict() | 180 | + #GEN2NAT_CMDS = my_cmds2.get_as_dict() |
181 | + GEN2NAT_CMDS = Gen2NatCmds(GEN2NAT_CMDS_obj).get_as_dict() | ||
180 | GEN2NAT_CMDS = GEN2NAT_CMDS_dict | 182 | GEN2NAT_CMDS = GEN2NAT_CMDS_dict |
181 | 183 | ||
182 | #TODO: remplacer PROTOCOL par "SOCKET-TCP", "SOCKET-UDP", "SERIAL", ou "USB" | 184 | #TODO: remplacer PROTOCOL par "SOCKET-TCP", "SOCKET-UDP", "SERIAL", ou "USB" |
@@ -195,7 +197,7 @@ class DC_Mount(DeviceController): | @@ -195,7 +197,7 @@ class DC_Mount(DeviceController): | ||
195 | #printd("(mount 2) given cmds (before):", gen2nat_cmds) | 197 | #printd("(mount 2) given cmds (before):", gen2nat_cmds) |
196 | ##self._my_gen2nat_cmds = { **self.GEN2NAT_CMDS, **gen2nat_cmds } | 198 | ##self._my_gen2nat_cmds = { **self.GEN2NAT_CMDS, **gen2nat_cmds } |
197 | my_gen2nat_cmds = { **self.GEN2NAT_CMDS, **gen2nat_cmds } | 199 | my_gen2nat_cmds = { **self.GEN2NAT_CMDS, **gen2nat_cmds } |
198 | - #printd("(mount 3) my cmds (after):", self._my_gen2nat_cmds) | 200 | + #print("(mount 3) my cmds (after):", my_gen2nat_cmds) |
199 | 201 | ||
200 | ##super().__init__(device_host, device_port, channel, buffer_size, DEBUG, device_sim) | 202 | ##super().__init__(device_host, device_port, channel, buffer_size, DEBUG, device_sim) |
201 | super().__init__(device_host, device_port, channel, buffer_size, protoc=protoc, gen2nat_cmds=my_gen2nat_cmds, device_sim=device_sim) | 203 | super().__init__(device_host, device_port, channel, buffer_size, protoc=protoc, gen2nat_cmds=my_gen2nat_cmds, device_sim=device_sim) |
src/device_controller/concrete_component/gemini/gemini_controller.py
@@ -574,6 +574,7 @@ class DC_Gemini(DeviceController): | @@ -574,6 +574,7 @@ class DC_Gemini(DeviceController): | ||
574 | 'do_stop': ['Q'], | 574 | 'do_stop': ['Q'], |
575 | } | 575 | } |
576 | 576 | ||
577 | + GEN2NAT_CMDS_MOUNT = Gen2NatCmds(GEN2NAT_CMDS_MOUNT_obj).get_as_dict() | ||
577 | GEN2NAT_CMDS_MOUNT = GEN2NAT_CMDS_MOUNT_dict | 578 | GEN2NAT_CMDS_MOUNT = GEN2NAT_CMDS_MOUNT_dict |
578 | 579 | ||
579 | GEN2NAT_CMDS_dict = { | 580 | GEN2NAT_CMDS_dict = { |
@@ -592,8 +593,8 @@ class DC_Gemini(DeviceController): | @@ -592,8 +593,8 @@ class DC_Gemini(DeviceController): | ||
592 | GEN2NAT_CMDS_MOUNT_obj | 593 | GEN2NAT_CMDS_MOUNT_obj |
593 | ] | 594 | ] |
594 | ''' | 595 | ''' |
595 | - GEN2NAT_CMDS = my_cmds.get_as_dict() | ||
596 | GEN2NAT_CMDS = GEN2NAT_CMDS_dict | 596 | GEN2NAT_CMDS = GEN2NAT_CMDS_dict |
597 | + GEN2NAT_CMDS = my_cmds.get_as_dict() | ||
597 | 598 | ||
598 | # Utilisation, affichage | 599 | # Utilisation, affichage |
599 | #mes_commandes.add_cmd(get_ack) | 600 | #mes_commandes.add_cmd(get_ack) |