Commit ce74dbbb336f8caeb53c923bb3cbca1c4063957d

Authored by Etienne Pallier
1 parent 09e6cfd0
Exists in dev

LOGGER unique : première phase de nettoyage et harmonisation du projet

- Toutes les classes utilisent self.print() et self.printd()
- Suppression des paramètres DEBUG passés à toutes les classes
(car il est obtenu via l'environnement, plus simple)
src/core/pyros_django/agent/Agent.py
... ... @@ -397,7 +397,8 @@ class Agent:
397 397 _log = None
398 398  
399 399 #def __init__(self, name:str="Agent", config_filename:str=None, RUN_IN_THREAD=True):
400   - def __init__(self, config_filename:str=None, RUN_IN_THREAD=True, DEBUG_MODE=False):
  400 + #def __init__(self, config_filename:str=None, RUN_IN_THREAD=True, DEBUG_MODE=False):
  401 + def __init__(self, config_filename:str=None, RUN_IN_THREAD=True):
401 402 #self.name = name
402 403 self.name = self.__class__.__name__
403 404 printd("*** ENVIRONMENT VARIABLE PYROS_DEBUG is:", os.environ.get('PYROS_DEBUG'), '***')
... ... @@ -1587,7 +1588,8 @@ def extract_parameters():
1587 1588 def build_agent(Agent_type:Agent, RUN_IN_THREAD=True):
1588 1589 DEBUG_MODE, WITH_SIM, TEST_MODE, VERBOSE_MODE, configfile = extract_parameters()
1589 1590 #agent = Agent("GenericAgent", configfile, RUN_IN_THREAD=True)
1590   - agent = Agent_type(configfile, RUN_IN_THREAD, DEBUG_MODE=DEBUG_MODE)
  1591 + #agent = Agent_type(configfile, RUN_IN_THREAD, DEBUG_MODE=DEBUG_MODE)
  1592 + agent = Agent_type(configfile, RUN_IN_THREAD)
1591 1593 #agent = Agent_type(name, configfile, RUN_IN_THREAD)
1592 1594 agent._set_with_simulator(WITH_SIM)
1593 1595 agent._set_test_mode(TEST_MODE)
... ...
src/core/pyros_django/agent/AgentDevice.py
... ... @@ -14,7 +14,11 @@ from common.models import AgentDeviceStatus, Command, get_or_create_unique_row_f
14 14  
15 15  
16 16 sys.path.append("../../..")
17   -from device_controller.abstract_component.device_controller import DeviceController, DeviceCommand, DCCNotFoundException, UnimplementedGenericCmdException, UnknownNativeCmdException
  17 +from device_controller.abstract_component.device_controller import (
  18 + DeviceController,
  19 + DeviceCommand,
  20 + DCCNotFoundException, UnimplementedGenericCmdException, UnknownNativeCmdException
  21 +)
18 22  
19 23 ##log = L.setupLogger("AgentXTaskLogger", "AgentX")
20 24  
... ... @@ -85,14 +89,13 @@ class AgentDevice(Agent):
85 89 =================================================================
86 90 """
87 91  
88   - # @override
89   - #def __init__(self, name:str=None, config_filename=None, RUN_IN_THREAD=True, device_controller, host, port):
90   - #def __init__(self, name:str, config_filename, RUN_IN_THREAD, device_controller, host, port, device_simulator):
91 92 ##def __init__(self, config_filename, RUN_IN_THREAD, device_controller:DeviceController, host, port, device_simulator):
92   - def __init__(self, config_filename, RUN_IN_THREAD, device_controller:DeviceController, host, port, DEBUG_MODE=False):
  93 + #def __init__(self, config_filename, RUN_IN_THREAD, device_controller:DeviceController, host, port, DEBUG_MODE=False):
  94 + def __init__(self, config_filename, RUN_IN_THREAD, device_controller:DeviceController, host, port):
93 95 ##if name is None: name = self.__class__.__name__
94 96 #super().__init__(name, config_filename, RUN_IN_THREAD)
95   - super().__init__(config_filename, RUN_IN_THREAD, DEBUG_MODE)
  97 + #super().__init__(config_filename, RUN_IN_THREAD, DEBUG_MODE)
  98 + super().__init__(config_filename, RUN_IN_THREAD)
96 99 self.HOST, self.PORT = host, port
97 100 self._device_ctrl = device_controller
98 101 ##self._device_sim = device_simulator
... ... @@ -140,7 +143,8 @@ class AgentDevice(Agent):
140 143  
141 144 # Create instance of a SPECIFIC device controller (device client)
142 145 # Ex: this can be the Gemini or the SBIG (...) DC
143   - self._device_ctrl = self._device_ctrl(self.HOST, self.PORT, DEBUG=self.DEBUG_MODE)
  146 + #self._device_ctrl = self._device_ctrl(self.HOST, self.PORT, DEBUG=self.DEBUG_MODE)
  147 + self._device_ctrl = self._device_ctrl(self.HOST, self.PORT)
144 148  
145 149 # Device socket init
146 150 # (optional) Only useful for TCP (does nothing for UDP)
... ...
src/core/pyros_django/agent/AgentDeviceGemini.py
... ... @@ -64,7 +64,8 @@ class AgentDeviceGemini(AgentDevice):
64 64 """
65 65  
66 66 # @override
67   - def __init__(self, config_filename=None, RUN_IN_THREAD=True, DEBUG_MODE=False):
  67 + #def __init__(self, config_filename=None, RUN_IN_THREAD=True, DEBUG_MODE=False):
  68 + def __init__(self, config_filename=None, RUN_IN_THREAD=True):
68 69 '''
69 70 if self.is_in_simulator_mode() and not self.WITH_SIMULATOR:
70 71 # START device SIMULATOR (in a thread) so that we can connect to it in place of the real device
... ... @@ -76,9 +77,10 @@ class AgentDeviceGemini(AgentDevice):
76 77 super().__init__(
77 78 config_filename,
78 79 RUN_IN_THREAD,
79   - device_controller=DC_Gemini, host=self.HOST, port=self.PORT,
80   - DEBUG_MODE=DEBUG_MODE)
81   - ###device_simulator=DeviceSimulatorTelescopeGemini)
  80 + device_controller=DC_Gemini, host=self.HOST, port=self.PORT
  81 + )
  82 + #DEBUG_MODE=DEBUG_MODE)
  83 + ###device_simulator=DeviceSimulatorTelescopeGemini)
82 84  
83 85 # Initialize the device table status
84 86 # If table is empty, create a default 1st row
... ...
src/core/pyros_django/agent/AgentDeviceSBIG.py
... ... @@ -63,8 +63,8 @@ class AgentDeviceSBIG(AgentDevice):
63 63 =================================================================
64 64 """
65 65  
66   - # @override
67   - def __init__(self, config_filename=None, RUN_IN_THREAD=True, DEBUG_MODE=False):
  66 + #def __init__(self, config_filename=None, RUN_IN_THREAD=True, DEBUG_MODE=False):
  67 + def __init__(self, config_filename=None, RUN_IN_THREAD=True):
68 68 '''
69 69 if self.is_in_simulator_mode() and not self.WITH_SIMULATOR:
70 70 # START device SIMULATOR (in a thread) so that we can connect to it in place of the real device
... ... @@ -76,9 +76,10 @@ class AgentDeviceSBIG(AgentDevice):
76 76 super().__init__(
77 77 config_filename,
78 78 RUN_IN_THREAD,
79   - device_controller=DC_SBIG, host=self.HOST, port=self.PORT,
80   - DEBUG_MODE=DEBUG_MODE)
81   - #device_simulator=DeviceSimulatorSBIG)
  79 + device_controller=DC_SBIG, host=self.HOST, port=self.PORT
  80 + )
  81 + #DEBUG_MODE=DEBUG_MODE)
  82 + #device_simulator=DeviceSimulatorSBIG)
82 83  
83 84 # Initialize the device table status
84 85 # If table is empty, create a default 1st row
... ...
src/device_controller/abstract_component/detector_sensor.py
... ... @@ -48,7 +48,8 @@ class DC_DetectorSensor(DeviceController):
48 48  
49 49 #TODO: remplacer PROTOCOL par "SOCKET-TCP", "SOCKET-UDP", "SERIAL", ou "USB"
50 50 #def __init__(self, device_host:str="localhost", device_port:int=11110, PROTOCOL:str="TCP", buffer_size=1024, DEBUG=False, device_sim=None):
51   - def __init__(self, device_host:str="localhost", device_port:int=11110, channel:str=None, buffer_size=None, protoc=None, gen2nat_cmds={}, device_sim=None, DEBUG=False):
  51 + #def __init__(self, device_host:str="localhost", device_port:int=11110, channel:str=None, buffer_size=None, protoc=None, gen2nat_cmds={}, device_sim=None, DEBUG=False):
  52 + def __init__(self, device_host:str="localhost", device_port:int=11110, channel:str=None, buffer_size=None, protoc=None, gen2nat_cmds={}, device_sim=None):
52 53 '''
53 54 :param device_host: server IP or hostname
54 55 :param device_port: server port
... ... @@ -58,7 +59,8 @@ class DC_DetectorSensor(DeviceController):
58 59 #self._my_gen2nat_cmds = { **self.GEN2NAT_CMDS, **gen2nat_cmds }
59 60 my_gen2nat_cmds = { **self.GEN2NAT_CMDS, **gen2nat_cmds }
60 61 #super().__init__(device_host, device_port, PROTOCOL, buffer_size, DEBUG, device_sim)
61   - super().__init__(device_host, device_port, channel, buffer_size, protoc=protoc, gen2nat_cmds=my_gen2nat_cmds, device_sim=device_sim, DEBUG=DEBUG)
  62 + #super().__init__(device_host, device_port, channel, buffer_size, protoc=protoc, gen2nat_cmds=my_gen2nat_cmds, device_sim=device_sim, DEBUG=DEBUG)
  63 + super().__init__(device_host, device_port, channel, buffer_size, protoc=protoc, gen2nat_cmds=my_gen2nat_cmds, device_sim=device_sim)
62 64  
63 65 # overwrite abstract _cmd dictionary with subclass native _cmd_native dictionary:
64 66 #self._cmd = {**self._cmd, **self._cmd_native}
... ...
src/device_controller/abstract_component/detector_shutter.py
... ... @@ -44,7 +44,7 @@ class DC_DetectorShutter(DeviceController):
44 44  
45 45 #TODO: remplacer PROTOCOL par "SOCKET-TCP", "SOCKET-UDP", "SERIAL", ou "USB"
46 46 #def __init__(self, device_host:str="localhost", device_port:int=11110, PROTOCOL:str="TCP", buffer_size=1024, DEBUG=False, device_sim=None):
47   - def __init__(self, device_host:str="localhost", device_port:int=11110, channel:str=None, buffer_size=None, protoc=None, gen2nat_cmds={}, device_sim=None, DEBUG=False):
  47 + def __init__(self, device_host:str="localhost", device_port:int=11110, channel:str=None, buffer_size=None, protoc=None, gen2nat_cmds={}, device_sim=None):
48 48 '''
49 49 :param device_host: server IP or hostname
50 50 :param device_port: server port
... ... @@ -54,7 +54,7 @@ class DC_DetectorShutter(DeviceController):
54 54 #self._my_gen2nat_cmds = { **self.GEN2NAT_CMDS, **gen2nat_cmds }
55 55 my_gen2nat_cmds = { **self.GEN2NAT_CMDS, **gen2nat_cmds }
56 56 #super().__init__(device_host, device_port, PROTOCOL, buffer_size, DEBUG, device_sim)
57   - super().__init__(device_host, device_port, channel, buffer_size, protoc=protoc, gen2nat_cmds=my_gen2nat_cmds, device_sim=device_sim, DEBUG=DEBUG)
  57 + super().__init__(device_host, device_port, channel, buffer_size, protoc=protoc, gen2nat_cmds=my_gen2nat_cmds, device_sim=device_sim)
58 58  
59 59 # overwrite abstract _cmd dictionary with subclass native _cmd_native dictionary:
60 60 #self._cmd = {**self._cmd, **self._cmd_native}
... ...
src/device_controller/abstract_component/device_controller.py
... ... @@ -447,7 +447,8 @@ class DeviceController():
447 447  
448 448  
449 449 ##def __init__(self, device_host:str="localhost", device_port:int=11110, PROTOCOL:str="TCP", buffer_size=1024, DEBUG=False):
450   - def __init__(self, device_host:str="localhost", device_port:int=11110, channel="TCP", buffer_size=1024, protoc=None, gen2nat_cmds={}, device_sim=None, DEBUG=False):
  450 + #def __init__(self, device_host:str="localhost", device_port:int=11110, channel="TCP", buffer_size=1024, protoc=None, gen2nat_cmds={}, device_sim=None, DEBUG=False):
  451 + def __init__(self, device_host:str="localhost", device_port:int=11110, channel="TCP", buffer_size=1024, protoc=None, gen2nat_cmds={}, device_sim=None):
451 452 '''
452 453 :param device_host: server IP or hostname
453 454 :param device_port: server port
... ... @@ -495,11 +496,12 @@ class DeviceController():
495 496 self._device_simulator = None
496 497 else:
497 498 if channel.startswith("SOCKET"):
498   - self._my_channel:ClientChannel = ClientChannelSocket(device_host, device_port, channel, buffer_size, DEBUG)
  499 + #self._my_channel:ClientChannel = ClientChannelSocket(device_host, device_port, channel, buffer_size, DEBUG)
  500 + self._my_channel:ClientChannel = ClientChannelSocket(device_host, device_port, channel, buffer_size)
499 501 elif channel == "SERIAL":
500   - self._my_channel:ClientChannel = ClientChannelSerial(device_host, device_port, buffer_size, DEBUG)
  502 + self._my_channel:ClientChannel = ClientChannelSerial(device_host, device_port, buffer_size)
501 503 elif channel == "USB":
502   - self._my_channel:ClientChannel = ClientChannelUSB(device_host, device_port, buffer_size, DEBUG)
  504 + self._my_channel:ClientChannel = ClientChannelUSB(device_host, device_port, buffer_size)
503 505 else: raise Exception("Unknown Channel", channel)
504 506 # If LOCALHOST, launch the device SIMULATOR
505 507 if device_host=="localhost":
... ...
src/device_controller/abstract_component/device_simulator.py
... ... @@ -15,7 +15,7 @@ class UnknownCommandException(Exception):
15 15 # Voir https://stackoverflow.com/questions/10085996/shutdown-socketserver-serve-forever-in-one-thread-python-application
16 16  
17 17  
18   -# Abstract class
  18 +# Abstract (static) class
19 19 class DeviceSimulator:
20 20 #with socketserver_type((HOST, PORT), MyUDPorTCPHandler_classic) as myserver:
21 21  
... ...
src/device_controller/abstract_component/filter_selector.py
... ... @@ -56,7 +56,7 @@ class DC_FilterSelector(DeviceController):
56 56  
57 57 #TODO: remplacer PROTOCOL par "SOCKET-TCP", "SOCKET-UDP", "SERIAL", ou "USB"
58 58 #def __init__(self, device_host:str="localhost", device_port:int=11110, PROTOCOL:str="TCP", buffer_size=1024, DEBUG=False, device_sim=None):
59   - def __init__(self, device_host:str="localhost", device_port:int=11110, channel:str=None, buffer_size=None, protoc=None, gen2nat_cmds={}, device_sim=None, DEBUG=False):
  59 + def __init__(self, device_host:str="localhost", device_port:int=11110, channel:str=None, buffer_size=None, protoc=None, gen2nat_cmds={}, device_sim=None):
60 60 '''
61 61 :param device_host: server IP or hostname
62 62 :param device_port: server port
... ... @@ -66,7 +66,7 @@ class DC_FilterSelector(DeviceController):
66 66 #self._my_gen2nat_cmds = { **self.GEN2NAT_CMDS, **gen2nat_cmds }
67 67 my_gen2nat_cmds = { **self.GEN2NAT_CMDS, **gen2nat_cmds }
68 68 #super().__init__(device_host, device_port, PROTOCOL, buffer_size, DEBUG, device_sim)
69   - super().__init__(device_host, device_port, channel, buffer_size, protoc=protoc, gen2nat_cmds=my_gen2nat_cmds, device_sim=device_sim, DEBUG=DEBUG)
  69 + super().__init__(device_host, device_port, channel, buffer_size, protoc=protoc, gen2nat_cmds=my_gen2nat_cmds, device_sim=device_sim)
70 70  
71 71 # overwrite abstract _cmd dictionary with subclass native _cmd_native dictionary:
72 72 #self._cmd = {**self._cmd, **self._cmd_native}
... ...
src/device_controller/abstract_component/mount.py
... ... @@ -126,7 +126,7 @@ class DC_Mount(DeviceController):
126 126  
127 127 #TODO: remplacer PROTOCOL par "SOCKET-TCP", "SOCKET-UDP", "SERIAL", ou "USB"
128 128 ##def __init__(self, device_host:str="localhost", device_port:int=11110, PROTOCOL:str="TCP", buffer_size=1024, DEBUG=False, device_sim=None):
129   - def __init__(self, device_host:str="localhost", device_port:int=11110, channel:str=None, buffer_size=None, protoc=None, gen2nat_cmds={}, device_sim=None, DEBUG=False):
  129 + def __init__(self, device_host:str="localhost", device_port:int=11110, channel:str=None, buffer_size=None, protoc=None, gen2nat_cmds={}, device_sim=None):
130 130 '''
131 131 :param device_host: server IP or hostname
132 132 :param device_port: server port
... ... @@ -144,7 +144,7 @@ class DC_Mount(DeviceController):
144 144 #printd("(mount 3) my cmds (after):", self._my_gen2nat_cmds)
145 145  
146 146 ##super().__init__(device_host, device_port, channel, buffer_size, DEBUG, device_sim)
147   - super().__init__(device_host, device_port, channel, buffer_size, protoc=protoc, gen2nat_cmds=my_gen2nat_cmds, device_sim=device_sim, DEBUG=DEBUG)
  147 + super().__init__(device_host, device_port, channel, buffer_size, protoc=protoc, gen2nat_cmds=my_gen2nat_cmds, device_sim=device_sim)
148 148 # overwrite abstract _cmd dictionary with subclass native _cmd_native dictionary:
149 149 #self._cmd = {**self._cmd, **self._cmd_native}
150 150 ##if gen2nat_qa: self._cmd_device_concrete = {**self._cmd_device_concrete, **gen2nat_qa}
... ...
src/device_controller/channels/client_channel.py
... ... @@ -13,42 +13,45 @@ import os
13 13 # None
14 14  
15 15 # Local application imports
  16 +from src.logpyros import LogPyros
16 17 from device_controller.logs import *
17 18  
18 19  
  20 +'''
19 21 def printd(*args, **kwargs):
20 22 if os.environ.get('PYROS_DEBUG', '0')=='1': print(*args, **kwargs)
21   -
  23 +'''
22 24  
23 25  
24 26 ##class SocketClientAbstract():
25 27 class ClientChannel():
26   -
  28 +
27 29 my_channel = None
28 30 buf = 1024
29   -
30   - def __init__(self, server_host:str="localhost", server_port:int=11110, PROTOCOL:str="SOCKET-TCP", buffer_size=1024, DEBUG=False):
  31 +
  32 + #def __init__(self, server_host:str="localhost", server_port:int=11110, PROTOCOL:str="SOCKET-TCP", buffer_size=1024, DEBUG=False):
  33 + def __init__(self, server_host:str="localhost", server_port:int=11110, PROTOCOL:str="SOCKET-TCP", buffer_size=1024):
31 34 '''
32 35 :param server_host: server IP or hostname
33 36 :param server_port: server port
34 37 :param PROTOCOL: "SOCKET-TCP" or "SOCKET-UDP" or "SERIAL" or "USB" (to be continued...)
35 38 '''
36   - self.DEBUG = DEBUG
37   -
  39 + self.DEBUG_MODE = os.environ.get('PYROS_DEBUG', '0') == '1'
38 40 self.HOST = server_host
39 41 self.PORT = server_port
40 42 self.PROTOCOL = PROTOCOL
41 43 self.buf = buffer_size
42   -
  44 +
  45 + self._log = LogPyros(self.__class__.__name__)
  46 +
43 47 # Logger configuration
44 48 #self.set_logger()
45 49 ##set_logger(DEBUG)
46   - printd("\n**************************")
  50 + self.printd("\n**************************")
47 51 ##log_d("Client CHANNEL instanciated")
48   - printd("Client CHANNEL instanciated")
49   -
50   -
51   -
  52 + self.printd("Client CHANNEL instanciated")
  53 +
  54 +
52 55 # So that we can use this with the "with" statement (context manager)
53 56 def __enter__(self):
54 57 return self
... ... @@ -57,6 +60,10 @@ class ClientChannel():
57 60 #printd("Client channel killed")
58 61 print("Client channel killed")
59 62  
  63 + # LOG methods
  64 + def print(self, *args, **kwargs): self._log.print(*args, **kwargs)
  65 + def printd(self, *args, **kwargs): self._log.printd(*args, **kwargs)
  66 +
60 67  
61 68 def send_data(self, data:str):
62 69 ##data_encapsulated = self.encapsulate_data_to_send(data)
... ...
src/device_controller/channels/client_channel_socket.py
... ... @@ -33,10 +33,10 @@ class ClientChannelSocket(ClientChannel):
33 33 MYSTAMP = '01'
34 34 MY_FULL_STAMP = MYSTAMP + STAMP_FILLER
35 35 '''
36   -
37   -
38   -
39   - def __init__(self, server_host:str="localhost", server_port:int=11110, PROTOCOL:str="SOCKET-TCP", buffer_size=1024, DEBUG=False):
  36 +
  37 +
  38 + #def __init__(self, server_host:str="localhost", server_port:int=11110, PROTOCOL:str="SOCKET-TCP", buffer_size=1024, DEBUG=False):
  39 + def __init__(self, server_host:str="localhost", server_port:int=11110, PROTOCOL:str="SOCKET-TCP", buffer_size=1024):
40 40 '''
41 41 :param server_host: server IP or hostname
42 42 :param server_port: server port
... ... @@ -44,7 +44,8 @@ class ClientChannelSocket(ClientChannel):
44 44 '''
45 45 myprotocol = socket.SOCK_DGRAM if PROTOCOL=="SOCKET-UDP" else socket.SOCK_STREAM
46 46 self.mysock = socket.socket(socket.AF_INET, myprotocol)
47   - super().__init__(server_host, server_port, PROTOCOL, buffer_size, DEBUG)
  47 + #super().__init__(server_host, server_port, PROTOCOL, buffer_size, DEBUG)
  48 + super().__init__(server_host, server_port, PROTOCOL, buffer_size)
48 49 # Logger configuration
49 50 #self.set_logger()
50 51 '''
... ... @@ -86,7 +87,7 @@ class ClientChannelSocket(ClientChannel):
86 87 #@override
87 88 def _connect_to_server(self):
88 89 if self.PROTOCOL=="SOCKET-TCP": self.mysock.connect((self.HOST, self.PORT))
89   - printd(f"Ready to send commands to HOST {self.HOST} on PORT {self.PORT} \n")
  90 + self.printd(f"Ready to send commands to HOST {self.HOST} on PORT {self.PORT} \n")
90 91  
91 92  
92 93 # Close socket
... ... @@ -112,7 +113,7 @@ class ClientChannelSocket(ClientChannel):
112 113 ##log_i(f"(channel sock) Sent {nb_bytes_sent} bytes")
113 114 ##log_i(f"(channel sock) Sent {nb_bytes_sent} bytes ; mesg sent is: ", data_to_send_bytes)
114 115 ##log_i("(channel sock) Sent ",nb_bytes_sent, "bytes ; mesg sent is: ", data_to_send_bytes)
115   - printd("(channel sock) Sent ",nb_bytes_sent, "bytes ; mesg sent is: ", data_to_send_bytes)
  116 + self.printd("(channel sock) Sent ",nb_bytes_sent, "bytes ; mesg sent is: ", data_to_send_bytes)
116 117  
117 118 #@override
118 119 def _receive_data(self)->str:
... ... @@ -122,9 +123,9 @@ class ClientChannelSocket(ClientChannel):
122 123 # so, replace it by ':' (b'\x3A')
123 124 if b'\xdf' in data_received_bytes:
124 125 data_received_bytes = data_received_bytes.replace(b'\xdf', b'\x3A')
125   - printd(f"(channel sock) RECEIVED (ALL BYTES...): {data_received_bytes}")
  126 + self.printd(f"(channel sock) RECEIVED (ALL BYTES...): {data_received_bytes}")
126 127 ##log_i(f"(channel sock) ({self}) RECEIVED (ALL BYTES...): {data_received_bytes}")
127   - printd(f"(channel sock) ({self}) RECEIVED (ALL BYTES...): {data_received_bytes}")
  128 + self.printd(f"(channel sock) ({self}) RECEIVED (ALL BYTES...): {data_received_bytes}")
128 129  
129 130 data_received = data_received_bytes.decode()
130 131 #log_d("data type is "+str(type(data_received)))
... ...
src/device_controller/channels/server_udp_or_tcp.py
... ... @@ -9,6 +9,7 @@ To be used as a minimalist telescope simulator to which a socket client (SocketC
9 9 """
10 10  
11 11 # Standard library imports
  12 +import os
12 13 import socketserver
13 14 import sys
14 15  
... ... @@ -17,13 +18,17 @@ import sys
17 18  
18 19 # Local application imports
19 20 # None
20   -from .client_channel import printd
21   -
  21 +#from .client_channel import printd
22 22 '''
23 23 sys.path.append('..')
24 24 from device_controller.abstract_component.device_simulator import getc, getp
25 25 '''
26 26  
  27 +
  28 +def printd(*args, **kwargs):
  29 + if os.environ.get('PYROS_DEBUG', '0')=='1': print(*args, **kwargs)
  30 +
  31 +
27 32 # Very BASIC implementation
28 33 def make_answer_for_request_CMD_TO_UPPER(request_bytes):
29 34 #raise NotImplementedError
... ...
src/device_controller/concrete_component/gemini/gemini_controller.py
... ... @@ -310,9 +310,11 @@ class DC_Gemini(DeviceController):
310 310 # Gemini is using UDP
311 311 #def __init__(self, device_host:str="localhost", device_port:int=11110, channel=socket, DEBUG=False):
312 312 #def __init__(self, device_host:str="localhost", device_port:int=11110, DEBUG=False):
313   - def __init__(self, device_host:str="localhost", device_port:int=11110, dcc_list=[], DEBUG=False):
  313 + #def __init__(self, device_host:str="localhost", device_port:int=11110, dcc_list=[], DEBUG=False):
  314 + def __init__(self, device_host:str="localhost", device_port:int=11110, dcc_list=[]):
314 315 ##super().__init__(device_host, device_port, "SOCKET-UDP", 1024, DEBUG)
315   - super().__init__(device_host, device_port, "SOCKET-UDP", MY_DEVICE_CHANNEL_BUFFER_SIZE, protoc=self.Protocol, gen2nat_cmds=self.GEN2NAT_CMDS, device_sim=DS_Gemini, DEBUG=DEBUG)
  316 + #super().__init__(device_host, device_port, "SOCKET-UDP", MY_DEVICE_CHANNEL_BUFFER_SIZE, protoc=self.Protocol, gen2nat_cmds=self.GEN2NAT_CMDS, device_sim=DS_Gemini, DEBUG=DEBUG)
  317 + super().__init__(device_host, device_port, "SOCKET-UDP", MY_DEVICE_CHANNEL_BUFFER_SIZE, protoc=self.Protocol, gen2nat_cmds=self.GEN2NAT_CMDS, device_sim=DS_Gemini)
316 318  
317 319 '''
318 320 Initialize my dcc(s), passing them the SAME parameters as I use :
... ... @@ -330,8 +332,8 @@ class DC_Gemini(DeviceController):
330 332 self.set_dc_components(
331 333 [
332 334 #DC_Mount(device_host, device_port, self._my_channel, 1024, protoc= self.Protocol, gen2nat_cmds= self.GEN2NAT_CMDS['DC_Mount'], device_sim=None, DEBUG=DEBUG),
333   - DC_Mount(device_host, device_port, self._my_channel, MY_DEVICE_CHANNEL_BUFFER_SIZE, protoc=self.Protocol, gen2nat_cmds=self.GEN2NAT_CMDS_MOUNT, device_sim=None, DEBUG=DEBUG),
334   - DC_MountBis(device_host, device_port, self._my_channel, MY_DEVICE_CHANNEL_BUFFER_SIZE, protoc=self.Protocol, gen2nat_cmds=self.GEN2NAT_CMDS_MOUNT, device_sim=None, DEBUG=DEBUG),
  335 + DC_Mount(device_host, device_port, self._my_channel, MY_DEVICE_CHANNEL_BUFFER_SIZE, protoc=self.Protocol, gen2nat_cmds=self.GEN2NAT_CMDS_MOUNT, device_sim=None),
  336 + DC_MountBis(device_host, device_port, self._my_channel, MY_DEVICE_CHANNEL_BUFFER_SIZE, protoc=self.Protocol, gen2nat_cmds=self.GEN2NAT_CMDS_MOUNT, device_sim=None),
335 337 ]
336 338 )
337 339  
... ...
src/device_controller/concrete_component/sbig/sbig_controller.py
... ... @@ -256,8 +256,8 @@ class DC_SBIG(DeviceController):
256 256 }
257 257  
258 258  
259   - def __init__(self, device_host:str="localhost", device_port:int=11110, DEBUG=False):
260   - super().__init__(device_host, device_port, "SOCKET-UDP", MY_DEVICE_CHANNEL_BUFFER_SIZE, protoc=self.Protocol, gen2nat_cmds=self.GEN2NAT_CMDS, device_sim=DS_SBIG, DEBUG=DEBUG)
  259 + def __init__(self, device_host:str="localhost", device_port:int=11110):
  260 + super().__init__(device_host, device_port, "SOCKET-UDP", MY_DEVICE_CHANNEL_BUFFER_SIZE, protoc=self.Protocol, gen2nat_cmds=self.GEN2NAT_CMDS, device_sim=DS_SBIG)
261 261  
262 262 printd('*****************************')
263 263 printd('*****************************')
... ... @@ -281,9 +281,10 @@ class DC_SBIG(DeviceController):
281 281 # @override superclass empty list
282 282 self.set_dc_components(
283 283 [
284   - DC_FilterSelector(device_host, device_port, self._my_channel, MY_DEVICE_CHANNEL_BUFFER_SIZE, protoc=self.Protocol, gen2nat_cmds=self.GEN2NAT_CMDS_FILTER, device_sim=None, DEBUG=DEBUG),
285   - DC_DetectorSensor(device_host, device_port, self._my_channel, MY_DEVICE_CHANNEL_BUFFER_SIZE, protoc=self.Protocol, gen2nat_cmds=self.GEN2NAT_CMDS_SENSOR, device_sim=None, DEBUG=DEBUG),
286   - DC_DetectorShutter(device_host, device_port, self._my_channel, MY_DEVICE_CHANNEL_BUFFER_SIZE, protoc=self.Protocol, gen2nat_cmds=self.GEN2NAT_CMDS_SHUTTER, device_sim=None, DEBUG=DEBUG),
  284 + #DC_FilterSelector(device_host, device_port, self._my_channel, MY_DEVICE_CHANNEL_BUFFER_SIZE, protoc=self.Protocol, gen2nat_cmds=self.GEN2NAT_CMDS_FILTER, device_sim=None, DEBUG=DEBUG),
  285 + DC_FilterSelector(device_host, device_port, self._my_channel, MY_DEVICE_CHANNEL_BUFFER_SIZE, protoc=self.Protocol, gen2nat_cmds=self.GEN2NAT_CMDS_FILTER, device_sim=None),
  286 + DC_DetectorSensor(device_host, device_port, self._my_channel, MY_DEVICE_CHANNEL_BUFFER_SIZE, protoc=self.Protocol, gen2nat_cmds=self.GEN2NAT_CMDS_SENSOR, device_sim=None),
  287 + DC_DetectorShutter(device_host, device_port, self._my_channel, MY_DEVICE_CHANNEL_BUFFER_SIZE, protoc=self.Protocol, gen2nat_cmds=self.GEN2NAT_CMDS_SHUTTER, device_sim=None),
287 288 ]
288 289 )
289 290  
... ...
src/logpyros.py
... ... @@ -319,7 +319,6 @@ class LogPyros:
319 319  
320 320 def log_msg_to_file(self, log_msg, path, file_name, night):
321 321  
322   - #if file_name == self._CHRONO_FILENAME: print("file_name,log_msg :", file_name,log_msg)
323 322 # 1) Create path if not exists
324 323 if not os.path.exists(path):
325 324 try:
... ... @@ -339,21 +338,10 @@ class LogPyros:
339 338 #ll = self._last_lines if file_name == self._CHRONO_FILENAME else self._last_lines_agent
340 339 ll.append(log_msg)
341 340 n = len(ll)
342   - #print("n is", n, "self.nbmax_last_lines is", self.nbmax_last_lines)
343 341 if n > self.nbmax_last_lines:
344 342 ll = ll[n-self.nbmax_last_lines:]
345 343 #print("ll is", len(ll))
346 344 #print("self._last_lines is", len(self._last_lines))
347   - #if file_name == self._CHRONO_FILENAME: print("ll last is", ll[-1])
348   - '''
349   - if file_name == "pyros2":
350   - self._last_lines.append(log_msg)
351   - n = len(self._last_lines)
352   - if n > self.nbmax_last_lines:
353   - self._last_lines = self._last_lines[n-self.nbmax_last_lines:]
354   - else:
355   - self._last_lines[-1] = log_msg
356   - '''
357 345 with open(file_prefix+'last'+'.log','w') as fic:
358 346 for line in ll:
359 347 fic.write(line+"\n")
... ... @@ -364,7 +352,6 @@ class LogPyros:
364 352 self._last_lines_agent = ll
365 353 '''
366 354 self._last_lines[filetype] = ll
367   - #if file_name == self._CHRONO_FILENAME: print("self._last_lines last is", self._last_lines[-1])
368 355  
369 356  
370 357 def file(self, *args, **kwargs):
... ...