Commit 6d4817bfb085fa0b86b5919229ad27ea49b77261
1 parent
1e46d3f8
Exists in
dev
Démarrage du simulateur généralisé au niveau de AgentDevice
AgentDeviceTelescopeGemini hérite de ce comportement via AgentDevice et se contente de définir son simulateur Reste à savoir stopper le simulateur !!!
Showing
3 changed files
with
37 additions
and
5 deletions
Show diff stats
src/core/pyros_django/agent/Agent.py
@@ -1104,6 +1104,8 @@ class Agent: | @@ -1104,6 +1104,8 @@ class Agent: | ||
1104 | #return (self._current_specific_thread is None) or not self._current_specific_thread.is_alive() | 1104 | #return (self._current_specific_thread is None) or not self._current_specific_thread.is_alive() |
1105 | return self._current_specific_thread and self._current_specific_thread.is_alive() | 1105 | return self._current_specific_thread and self._current_specific_thread.is_alive() |
1106 | 1106 | ||
1107 | + def is_in_simulator_mode(self): | ||
1108 | + return self.SIMULATOR_MODE | ||
1107 | 1109 | ||
1108 | def kill_running_specific_cmd_if_exists(self, abort_sender): | 1110 | def kill_running_specific_cmd_if_exists(self, abort_sender): |
1109 | if not self.is_running_specific_cmd(): | 1111 | if not self.is_running_specific_cmd(): |
src/core/pyros_django/agent/AgentDevice.py
@@ -3,6 +3,7 @@ | @@ -3,6 +3,7 @@ | ||
3 | 3 | ||
4 | import sys | 4 | import sys |
5 | ##import utils.Logger as L | 5 | ##import utils.Logger as L |
6 | +import threading | ||
6 | import time | 7 | import time |
7 | 8 | ||
8 | ##from .Agent import Agent | 9 | ##from .Agent import Agent |
@@ -17,6 +18,11 @@ sys.path.append("../../..") | @@ -17,6 +18,11 @@ sys.path.append("../../..") | ||
17 | 18 | ||
18 | class AgentDevice(Agent): | 19 | class AgentDevice(Agent): |
19 | 20 | ||
21 | + # Default host and port of the device controller | ||
22 | + _device_ctrl = None | ||
23 | + HOST, PORT = None, None | ||
24 | + _thread_device_simulator = None | ||
25 | + | ||
20 | _agent_device_status = None | 26 | _agent_device_status = None |
21 | 27 | ||
22 | # FOR TEST ONLY | 28 | # FOR TEST ONLY |
@@ -76,6 +82,8 @@ class AgentDevice(Agent): | @@ -76,6 +82,8 @@ class AgentDevice(Agent): | ||
76 | def __init__(self, name:str, config_filename, RUN_IN_THREAD, device_controller, host, port): | 82 | def __init__(self, name:str, config_filename, RUN_IN_THREAD, device_controller, host, port): |
77 | if name is None: name = self.__class__.__name__ | 83 | if name is None: name = self.__class__.__name__ |
78 | super().__init__(name, config_filename, RUN_IN_THREAD) | 84 | super().__init__(name, config_filename, RUN_IN_THREAD) |
85 | + self.HOST, self.PORT = host, port | ||
86 | + self._device_ctrl = device_controller | ||
79 | 87 | ||
80 | # Initialize the device table status | 88 | # Initialize the device table status |
81 | # If table is empty, create a default 1st row | 89 | # If table is empty, create a default 1st row |
@@ -96,7 +104,7 @@ class AgentDevice(Agent): | @@ -96,7 +104,7 @@ class AgentDevice(Agent): | ||
96 | #HOST, PORT = "localhost", 11110 | 104 | #HOST, PORT = "localhost", 11110 |
97 | #self._device_ctrl = TelescopeControllerGEMINI(host, port, True) | 105 | #self._device_ctrl = TelescopeControllerGEMINI(host, port, True) |
98 | ##self._device_ctrl = device_controller(HOST, PORT, True) | 106 | ##self._device_ctrl = device_controller(HOST, PORT, True) |
99 | - self._device_ctrl = device_controller(host, port, True) | 107 | + ##self._device_ctrl = device_controller(host, port, True) |
100 | self._log.print(f"init done for {name}") | 108 | self._log.print(f"init done for {name}") |
101 | 109 | ||
102 | 110 | ||
@@ -108,6 +116,16 @@ class AgentDevice(Agent): | @@ -108,6 +116,16 @@ class AgentDevice(Agent): | ||
108 | ##agent_alias = self.__class__.__name__ | 116 | ##agent_alias = self.__class__.__name__ |
109 | ##self.set_mode_from_config(agent_alias) | 117 | ##self.set_mode_from_config(agent_alias) |
110 | 118 | ||
119 | + # Start device simulator (device server) if in simulator mode | ||
120 | + if self.is_in_simulator_mode() and not self.SIMULATOR_WITH_REAL_DEVICE: | ||
121 | + # START device SIMULATOR (in a thread) so that we can connect to it in place of the real device | ||
122 | + self.HOST = "localhost" | ||
123 | + self._thread_device_simulator = threading.Thread(target=self.device_simulator) | ||
124 | + self._thread_device_simulator.start() | ||
125 | + | ||
126 | + # Create instance of device controller (device client) | ||
127 | + self._device_ctrl = self._device_ctrl(self.HOST, self.PORT, True) | ||
128 | + | ||
111 | # Device socket init | 129 | # Device socket init |
112 | # (optional) Only useful for TCP (does nothing for UDP) | 130 | # (optional) Only useful for TCP (does nothing for UDP) |
113 | self._device_ctrl._connect_to_device() | 131 | self._device_ctrl._connect_to_device() |
@@ -117,6 +135,17 @@ class AgentDevice(Agent): | @@ -117,6 +135,17 @@ class AgentDevice(Agent): | ||
117 | # TODO: | 135 | # TODO: |
118 | 136 | ||
119 | 137 | ||
138 | + def device_simulator(self): | ||
139 | + #HOST, PORT = "localhost", 11110 | ||
140 | + #with get_SocketServer_UDP_TCP(HOST, PORT, "UDP") as myserver: | ||
141 | + print("Starting device simulator on (host, port): ", self.HOST, self.PORT) | ||
142 | + ''' | ||
143 | + with get_SocketServer_UDP_TCP(self.HOST, self.PORT, "UDP") as myserver: | ||
144 | + myserver.serve_forever() | ||
145 | + myserver = get_SocketServer_UDP_TCP(self.HOST, self.PORT, "UDP") | ||
146 | + myserver.serve_forever() | ||
147 | + ''' | ||
148 | + | ||
120 | ''' | 149 | ''' |
121 | # @override | 150 | # @override |
122 | def load_config(self): | 151 | def load_config(self): |
src/core/pyros_django/agent/AgentDeviceTelescopeGemini.py
@@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
3 | 3 | ||
4 | import sys | 4 | import sys |
5 | ##import utils.Logger as L | 5 | ##import utils.Logger as L |
6 | -import threading | 6 | +##import threading |
7 | import time | 7 | import time |
8 | 8 | ||
9 | ##from .Agent import Agent | 9 | ##from .Agent import Agent |
@@ -49,11 +49,13 @@ class AgentDeviceTelescopeGemini(AgentDevice): | @@ -49,11 +49,13 @@ class AgentDeviceTelescopeGemini(AgentDevice): | ||
49 | 49 | ||
50 | # @override | 50 | # @override |
51 | def __init__(self, config_filename=None, RUN_IN_THREAD=True): | 51 | def __init__(self, config_filename=None, RUN_IN_THREAD=True): |
52 | - if not self.SIMULATOR_WITH_REAL_DEVICE: | 52 | + ''' |
53 | + if self.is_in_simulator_mode() and not self.SIMULATOR_WITH_REAL_DEVICE: | ||
53 | # START device SIMULATOR (in a thread) so that we can connect to it in place of the real device | 54 | # START device SIMULATOR (in a thread) so that we can connect to it in place of the real device |
54 | self.HOST = "localhost" | 55 | self.HOST = "localhost" |
55 | thread_device_simulator = threading.Thread(target=self.device_simulator) | 56 | thread_device_simulator = threading.Thread(target=self.device_simulator) |
56 | thread_device_simulator.start() | 57 | thread_device_simulator.start() |
58 | + ''' | ||
57 | super().__init__(self.__class__.__name__, config_filename, RUN_IN_THREAD, device_controller=TelescopeControllerGEMINI, host=self.HOST, port=self.PORT) | 59 | super().__init__(self.__class__.__name__, config_filename, RUN_IN_THREAD, device_controller=TelescopeControllerGEMINI, host=self.HOST, port=self.PORT) |
58 | 60 | ||
59 | # Initialize the device table status | 61 | # Initialize the device table status |
@@ -77,13 +79,12 @@ class AgentDeviceTelescopeGemini(AgentDevice): | @@ -77,13 +79,12 @@ class AgentDeviceTelescopeGemini(AgentDevice): | ||
77 | 79 | ||
78 | 80 | ||
79 | def init(self): | 81 | def init(self): |
80 | - | ||
81 | super().init() | 82 | super().init() |
82 | - | ||
83 | # Telescope (long) init | 83 | # Telescope (long) init |
84 | # TODO: | 84 | # TODO: |
85 | 85 | ||
86 | def device_simulator(self): | 86 | def device_simulator(self): |
87 | + super().device_simulator() | ||
87 | #HOST, PORT = "localhost", 11110 | 88 | #HOST, PORT = "localhost", 11110 |
88 | #with get_SocketServer_UDP_TCP(HOST, PORT, "UDP") as myserver: | 89 | #with get_SocketServer_UDP_TCP(HOST, PORT, "UDP") as myserver: |
89 | print(self.HOST, self.PORT) | 90 | print(self.HOST, self.PORT) |