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 | 1104 | #return (self._current_specific_thread is None) or not self._current_specific_thread.is_alive() |
1105 | 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 | 1110 | def kill_running_specific_cmd_if_exists(self, abort_sender): |
1109 | 1111 | if not self.is_running_specific_cmd(): | ... | ... |
src/core/pyros_django/agent/AgentDevice.py
... | ... | @@ -3,6 +3,7 @@ |
3 | 3 | |
4 | 4 | import sys |
5 | 5 | ##import utils.Logger as L |
6 | +import threading | |
6 | 7 | import time |
7 | 8 | |
8 | 9 | ##from .Agent import Agent |
... | ... | @@ -17,6 +18,11 @@ sys.path.append("../../..") |
17 | 18 | |
18 | 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 | 26 | _agent_device_status = None |
21 | 27 | |
22 | 28 | # FOR TEST ONLY |
... | ... | @@ -76,6 +82,8 @@ class AgentDevice(Agent): |
76 | 82 | def __init__(self, name:str, config_filename, RUN_IN_THREAD, device_controller, host, port): |
77 | 83 | if name is None: name = self.__class__.__name__ |
78 | 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 | 88 | # Initialize the device table status |
81 | 89 | # If table is empty, create a default 1st row |
... | ... | @@ -96,7 +104,7 @@ class AgentDevice(Agent): |
96 | 104 | #HOST, PORT = "localhost", 11110 |
97 | 105 | #self._device_ctrl = TelescopeControllerGEMINI(host, port, True) |
98 | 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 | 108 | self._log.print(f"init done for {name}") |
101 | 109 | |
102 | 110 | |
... | ... | @@ -108,6 +116,16 @@ class AgentDevice(Agent): |
108 | 116 | ##agent_alias = self.__class__.__name__ |
109 | 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 | 129 | # Device socket init |
112 | 130 | # (optional) Only useful for TCP (does nothing for UDP) |
113 | 131 | self._device_ctrl._connect_to_device() |
... | ... | @@ -117,6 +135,17 @@ class AgentDevice(Agent): |
117 | 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 | 150 | # @override |
122 | 151 | def load_config(self): | ... | ... |
src/core/pyros_django/agent/AgentDeviceTelescopeGemini.py
... | ... | @@ -3,7 +3,7 @@ |
3 | 3 | |
4 | 4 | import sys |
5 | 5 | ##import utils.Logger as L |
6 | -import threading | |
6 | +##import threading | |
7 | 7 | import time |
8 | 8 | |
9 | 9 | ##from .Agent import Agent |
... | ... | @@ -49,11 +49,13 @@ class AgentDeviceTelescopeGemini(AgentDevice): |
49 | 49 | |
50 | 50 | # @override |
51 | 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 | 54 | # START device SIMULATOR (in a thread) so that we can connect to it in place of the real device |
54 | 55 | self.HOST = "localhost" |
55 | 56 | thread_device_simulator = threading.Thread(target=self.device_simulator) |
56 | 57 | thread_device_simulator.start() |
58 | + ''' | |
57 | 59 | super().__init__(self.__class__.__name__, config_filename, RUN_IN_THREAD, device_controller=TelescopeControllerGEMINI, host=self.HOST, port=self.PORT) |
58 | 60 | |
59 | 61 | # Initialize the device table status |
... | ... | @@ -77,13 +79,12 @@ class AgentDeviceTelescopeGemini(AgentDevice): |
77 | 79 | |
78 | 80 | |
79 | 81 | def init(self): |
80 | - | |
81 | 82 | super().init() |
82 | - | |
83 | 83 | # Telescope (long) init |
84 | 84 | # TODO: |
85 | 85 | |
86 | 86 | def device_simulator(self): |
87 | + super().device_simulator() | |
87 | 88 | #HOST, PORT = "localhost", 11110 |
88 | 89 | #with get_SocketServer_UDP_TCP(HOST, PORT, "UDP") as myserver: |
89 | 90 | print(self.HOST, self.PORT) | ... | ... |