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 | 295 | #cmds = {} |
296 | 296 | |
297 | 297 | def __init__(self, cmds:dict={}): |
298 | - self.GEN2NAT_CMDS = cmds | |
299 | 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 | 304 | def __str__(self)->str: return str(self.GEN2NAT_CMDS) |
302 | 305 | |
... | ... | @@ -392,6 +395,9 @@ class Gen2NatCmds: |
392 | 395 | return 'G'+ cmd[1] |
393 | 396 | def get_simulated_answer_for_native_cmd(self, cmd:str)->str: |
394 | 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 | 401 | if cmd in val: |
396 | 402 | # No native cmd defined |
397 | 403 | if cmd != val[0]: return None |
... | ... | @@ -413,6 +419,11 @@ class Gen2NatCmds: |
413 | 419 | return True |
414 | 420 | # nothing set |
415 | 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 | 428 | #TODO: chercher dans les DCC !! (recursive) |
418 | 429 | def is_valid_native_cmd(self, cmd:str)->bool: |
... | ... | @@ -429,8 +440,8 @@ class Gen2NatCmds: |
429 | 440 | ##return cmd in self.GEN2NAT_CMDS.values() |
430 | 441 | # More elaborated version |
431 | 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 | 445 | # no notive cmd found |
435 | 446 | return False |
436 | 447 | def print_available_cmds(self): |
... | ... | @@ -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 | 1270 | #def exec_generic_cmd(self, generic_cmd:DeviceCmd)->str: |
1250 | 1271 | ##def exec_generic_cmd(self, generic_cmd:str, values_to_set:str=None, dcc_type:str=None)->str: |
1251 | 1272 | def exec_generic_cmd(self, generic_cmd:str, values_to_set:str=None)->str: |
... | ... | @@ -1279,7 +1300,9 @@ class DeviceController(): |
1279 | 1300 | return dcc.exec_generic_cmd(generic_cmd, values_to_set) |
1280 | 1301 | ''' |
1281 | 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 | 1306 | if not native_cmd: raise UnimplementedGenericCmdException(generic_cmd) |
1284 | 1307 | |
1285 | 1308 | # 2) MACRO-COMMAND or NORMAL NATIVE COMMAND ? |
... | ... | @@ -1314,8 +1337,14 @@ class DeviceController(): |
1314 | 1337 | # 2.b) NORMAL NATIVE COMMAND (ex: native_cmd == "GR") |
1315 | 1338 | ##native_cmd = self.formated_cmd(native_cmd, values_to_set) |
1316 | 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 | 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 | 1348 | #native_res = self.exec_native_cmd(self.formated_cmd(native_cmd,value), awaited_res_ok) |
1320 | 1349 | ##native_res = self.exec_native_cmd(native_cmd) |
1321 | 1350 | try: | ... | ... |
src/device_controller/abstract_component/mount.py
... | ... | @@ -94,9 +94,8 @@ class DC_Mount(DeviceController): |
94 | 94 | Cmd('set_ra'), |
95 | 95 | Cmd('get_dec'), |
96 | 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 | 100 | Cmd('get_longitude'), |
102 | 101 | Cmd('set_longitude'), |
... | ... | @@ -124,9 +123,11 @@ class DC_Mount(DeviceController): |
124 | 123 | Cmd('do_warm_start'), |
125 | 124 | Cmd('do_prec_refr'), |
126 | 125 | ] |
126 | + ''' | |
127 | 127 | my_cmds2 = Gen2NatCmds() |
128 | 128 | my_cmds2.add_cmds(GEN2NAT_CMDS_obj) |
129 | 129 | ''' |
130 | + ''' | |
130 | 131 | print("******************************") |
131 | 132 | print("(MOUNT) Mes commandes") |
132 | 133 | my_cmds2.print_mes_commandes() |
... | ... | @@ -176,7 +177,8 @@ class DC_Mount(DeviceController): |
176 | 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 | 182 | GEN2NAT_CMDS = GEN2NAT_CMDS_dict |
181 | 183 | |
182 | 184 | #TODO: remplacer PROTOCOL par "SOCKET-TCP", "SOCKET-UDP", "SERIAL", ou "USB" |
... | ... | @@ -195,7 +197,7 @@ class DC_Mount(DeviceController): |
195 | 197 | #printd("(mount 2) given cmds (before):", gen2nat_cmds) |
196 | 198 | ##self._my_gen2nat_cmds = { **self.GEN2NAT_CMDS, **gen2nat_cmds } |
197 | 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 | 202 | ##super().__init__(device_host, device_port, channel, buffer_size, DEBUG, device_sim) |
201 | 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 | 574 | 'do_stop': ['Q'], |
575 | 575 | } |
576 | 576 | |
577 | + GEN2NAT_CMDS_MOUNT = Gen2NatCmds(GEN2NAT_CMDS_MOUNT_obj).get_as_dict() | |
577 | 578 | GEN2NAT_CMDS_MOUNT = GEN2NAT_CMDS_MOUNT_dict |
578 | 579 | |
579 | 580 | GEN2NAT_CMDS_dict = { |
... | ... | @@ -592,8 +593,8 @@ class DC_Gemini(DeviceController): |
592 | 593 | GEN2NAT_CMDS_MOUNT_obj |
593 | 594 | ] |
594 | 595 | ''' |
595 | - GEN2NAT_CMDS = my_cmds.get_as_dict() | |
596 | 596 | GEN2NAT_CMDS = GEN2NAT_CMDS_dict |
597 | + GEN2NAT_CMDS = my_cmds.get_as_dict() | |
597 | 598 | |
598 | 599 | # Utilisation, affichage |
599 | 600 | #mes_commandes.add_cmd(get_ack) | ... | ... |