From ce74dbbb336f8caeb53c923bb3cbca1c4063957d Mon Sep 17 00:00:00 2001 From: Etienne Pallier Date: Mon, 9 Dec 2019 17:36:47 +0100 Subject: [PATCH] LOGGER unique : première phase de nettoyage et harmonisation du projet --- src/core/pyros_django/agent/Agent.py | 6 ++++-- src/core/pyros_django/agent/AgentDevice.py | 18 +++++++++++------- src/core/pyros_django/agent/AgentDeviceGemini.py | 10 ++++++---- src/core/pyros_django/agent/AgentDeviceSBIG.py | 11 ++++++----- src/device_controller/abstract_component/detector_sensor.py | 6 ++++-- src/device_controller/abstract_component/detector_shutter.py | 4 ++-- src/device_controller/abstract_component/device_controller.py | 10 ++++++---- src/device_controller/abstract_component/device_simulator.py | 2 +- src/device_controller/abstract_component/filter_selector.py | 4 ++-- src/device_controller/abstract_component/mount.py | 4 ++-- src/device_controller/channels/client_channel.py | 31 +++++++++++++++++++------------ src/device_controller/channels/client_channel_socket.py | 19 ++++++++++--------- src/device_controller/channels/server_udp_or_tcp.py | 9 +++++++-- src/device_controller/concrete_component/gemini/gemini_controller.py | 10 ++++++---- src/device_controller/concrete_component/sbig/sbig_controller.py | 11 ++++++----- src/logpyros.py | 13 ------------- 16 files changed, 92 insertions(+), 76 deletions(-) diff --git a/src/core/pyros_django/agent/Agent.py b/src/core/pyros_django/agent/Agent.py index 9874bc3..b8c93e0 100755 --- a/src/core/pyros_django/agent/Agent.py +++ b/src/core/pyros_django/agent/Agent.py @@ -397,7 +397,8 @@ class Agent: _log = None #def __init__(self, name:str="Agent", config_filename:str=None, RUN_IN_THREAD=True): - def __init__(self, config_filename:str=None, RUN_IN_THREAD=True, DEBUG_MODE=False): + #def __init__(self, config_filename:str=None, RUN_IN_THREAD=True, DEBUG_MODE=False): + def __init__(self, config_filename:str=None, RUN_IN_THREAD=True): #self.name = name self.name = self.__class__.__name__ printd("*** ENVIRONMENT VARIABLE PYROS_DEBUG is:", os.environ.get('PYROS_DEBUG'), '***') @@ -1587,7 +1588,8 @@ def extract_parameters(): def build_agent(Agent_type:Agent, RUN_IN_THREAD=True): DEBUG_MODE, WITH_SIM, TEST_MODE, VERBOSE_MODE, configfile = extract_parameters() #agent = Agent("GenericAgent", configfile, RUN_IN_THREAD=True) - agent = Agent_type(configfile, RUN_IN_THREAD, DEBUG_MODE=DEBUG_MODE) + #agent = Agent_type(configfile, RUN_IN_THREAD, DEBUG_MODE=DEBUG_MODE) + agent = Agent_type(configfile, RUN_IN_THREAD) #agent = Agent_type(name, configfile, RUN_IN_THREAD) agent._set_with_simulator(WITH_SIM) agent._set_test_mode(TEST_MODE) diff --git a/src/core/pyros_django/agent/AgentDevice.py b/src/core/pyros_django/agent/AgentDevice.py index 1237c11..3c9943c 100755 --- a/src/core/pyros_django/agent/AgentDevice.py +++ b/src/core/pyros_django/agent/AgentDevice.py @@ -14,7 +14,11 @@ from common.models import AgentDeviceStatus, Command, get_or_create_unique_row_f sys.path.append("../../..") -from device_controller.abstract_component.device_controller import DeviceController, DeviceCommand, DCCNotFoundException, UnimplementedGenericCmdException, UnknownNativeCmdException +from device_controller.abstract_component.device_controller import ( + DeviceController, + DeviceCommand, + DCCNotFoundException, UnimplementedGenericCmdException, UnknownNativeCmdException +) ##log = L.setupLogger("AgentXTaskLogger", "AgentX") @@ -85,14 +89,13 @@ class AgentDevice(Agent): ================================================================= """ - # @override - #def __init__(self, name:str=None, config_filename=None, RUN_IN_THREAD=True, device_controller, host, port): - #def __init__(self, name:str, config_filename, RUN_IN_THREAD, device_controller, host, port, device_simulator): ##def __init__(self, config_filename, RUN_IN_THREAD, device_controller:DeviceController, host, port, device_simulator): - def __init__(self, config_filename, RUN_IN_THREAD, device_controller:DeviceController, host, port, DEBUG_MODE=False): + #def __init__(self, config_filename, RUN_IN_THREAD, device_controller:DeviceController, host, port, DEBUG_MODE=False): + def __init__(self, config_filename, RUN_IN_THREAD, device_controller:DeviceController, host, port): ##if name is None: name = self.__class__.__name__ #super().__init__(name, config_filename, RUN_IN_THREAD) - super().__init__(config_filename, RUN_IN_THREAD, DEBUG_MODE) + #super().__init__(config_filename, RUN_IN_THREAD, DEBUG_MODE) + super().__init__(config_filename, RUN_IN_THREAD) self.HOST, self.PORT = host, port self._device_ctrl = device_controller ##self._device_sim = device_simulator @@ -140,7 +143,8 @@ class AgentDevice(Agent): # Create instance of a SPECIFIC device controller (device client) # Ex: this can be the Gemini or the SBIG (...) DC - self._device_ctrl = self._device_ctrl(self.HOST, self.PORT, DEBUG=self.DEBUG_MODE) + #self._device_ctrl = self._device_ctrl(self.HOST, self.PORT, DEBUG=self.DEBUG_MODE) + self._device_ctrl = self._device_ctrl(self.HOST, self.PORT) # Device socket init # (optional) Only useful for TCP (does nothing for UDP) diff --git a/src/core/pyros_django/agent/AgentDeviceGemini.py b/src/core/pyros_django/agent/AgentDeviceGemini.py index 3e7c8e1..a6cc4dd 100755 --- a/src/core/pyros_django/agent/AgentDeviceGemini.py +++ b/src/core/pyros_django/agent/AgentDeviceGemini.py @@ -64,7 +64,8 @@ class AgentDeviceGemini(AgentDevice): """ # @override - def __init__(self, config_filename=None, RUN_IN_THREAD=True, DEBUG_MODE=False): + #def __init__(self, config_filename=None, RUN_IN_THREAD=True, DEBUG_MODE=False): + def __init__(self, config_filename=None, RUN_IN_THREAD=True): ''' if self.is_in_simulator_mode() and not self.WITH_SIMULATOR: # 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): super().__init__( config_filename, RUN_IN_THREAD, - device_controller=DC_Gemini, host=self.HOST, port=self.PORT, - DEBUG_MODE=DEBUG_MODE) - ###device_simulator=DeviceSimulatorTelescopeGemini) + device_controller=DC_Gemini, host=self.HOST, port=self.PORT + ) + #DEBUG_MODE=DEBUG_MODE) + ###device_simulator=DeviceSimulatorTelescopeGemini) # Initialize the device table status # If table is empty, create a default 1st row diff --git a/src/core/pyros_django/agent/AgentDeviceSBIG.py b/src/core/pyros_django/agent/AgentDeviceSBIG.py index 96af50f..6ab603d 100755 --- a/src/core/pyros_django/agent/AgentDeviceSBIG.py +++ b/src/core/pyros_django/agent/AgentDeviceSBIG.py @@ -63,8 +63,8 @@ class AgentDeviceSBIG(AgentDevice): ================================================================= """ - # @override - def __init__(self, config_filename=None, RUN_IN_THREAD=True, DEBUG_MODE=False): + #def __init__(self, config_filename=None, RUN_IN_THREAD=True, DEBUG_MODE=False): + def __init__(self, config_filename=None, RUN_IN_THREAD=True): ''' if self.is_in_simulator_mode() and not self.WITH_SIMULATOR: # 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): super().__init__( config_filename, RUN_IN_THREAD, - device_controller=DC_SBIG, host=self.HOST, port=self.PORT, - DEBUG_MODE=DEBUG_MODE) - #device_simulator=DeviceSimulatorSBIG) + device_controller=DC_SBIG, host=self.HOST, port=self.PORT + ) + #DEBUG_MODE=DEBUG_MODE) + #device_simulator=DeviceSimulatorSBIG) # Initialize the device table status # If table is empty, create a default 1st row diff --git a/src/device_controller/abstract_component/detector_sensor.py b/src/device_controller/abstract_component/detector_sensor.py index dfa33e9..465d014 100755 --- a/src/device_controller/abstract_component/detector_sensor.py +++ b/src/device_controller/abstract_component/detector_sensor.py @@ -48,7 +48,8 @@ class DC_DetectorSensor(DeviceController): #TODO: remplacer PROTOCOL par "SOCKET-TCP", "SOCKET-UDP", "SERIAL", ou "USB" #def __init__(self, device_host:str="localhost", device_port:int=11110, PROTOCOL:str="TCP", buffer_size=1024, DEBUG=False, device_sim=None): - 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): + #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): + def __init__(self, device_host:str="localhost", device_port:int=11110, channel:str=None, buffer_size=None, protoc=None, gen2nat_cmds={}, device_sim=None): ''' :param device_host: server IP or hostname :param device_port: server port @@ -58,7 +59,8 @@ class DC_DetectorSensor(DeviceController): #self._my_gen2nat_cmds = { **self.GEN2NAT_CMDS, **gen2nat_cmds } my_gen2nat_cmds = { **self.GEN2NAT_CMDS, **gen2nat_cmds } #super().__init__(device_host, device_port, PROTOCOL, buffer_size, DEBUG, device_sim) - super().__init__(device_host, device_port, channel, buffer_size, protoc=protoc, gen2nat_cmds=my_gen2nat_cmds, device_sim=device_sim, DEBUG=DEBUG) + #super().__init__(device_host, device_port, channel, buffer_size, protoc=protoc, gen2nat_cmds=my_gen2nat_cmds, device_sim=device_sim, DEBUG=DEBUG) + super().__init__(device_host, device_port, channel, buffer_size, protoc=protoc, gen2nat_cmds=my_gen2nat_cmds, device_sim=device_sim) # overwrite abstract _cmd dictionary with subclass native _cmd_native dictionary: #self._cmd = {**self._cmd, **self._cmd_native} diff --git a/src/device_controller/abstract_component/detector_shutter.py b/src/device_controller/abstract_component/detector_shutter.py index 1ef00c1..40add44 100755 --- a/src/device_controller/abstract_component/detector_shutter.py +++ b/src/device_controller/abstract_component/detector_shutter.py @@ -44,7 +44,7 @@ class DC_DetectorShutter(DeviceController): #TODO: remplacer PROTOCOL par "SOCKET-TCP", "SOCKET-UDP", "SERIAL", ou "USB" #def __init__(self, device_host:str="localhost", device_port:int=11110, PROTOCOL:str="TCP", buffer_size=1024, DEBUG=False, device_sim=None): - 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): + def __init__(self, device_host:str="localhost", device_port:int=11110, channel:str=None, buffer_size=None, protoc=None, gen2nat_cmds={}, device_sim=None): ''' :param device_host: server IP or hostname :param device_port: server port @@ -54,7 +54,7 @@ class DC_DetectorShutter(DeviceController): #self._my_gen2nat_cmds = { **self.GEN2NAT_CMDS, **gen2nat_cmds } my_gen2nat_cmds = { **self.GEN2NAT_CMDS, **gen2nat_cmds } #super().__init__(device_host, device_port, PROTOCOL, buffer_size, DEBUG, device_sim) - super().__init__(device_host, device_port, channel, buffer_size, protoc=protoc, gen2nat_cmds=my_gen2nat_cmds, device_sim=device_sim, DEBUG=DEBUG) + super().__init__(device_host, device_port, channel, buffer_size, protoc=protoc, gen2nat_cmds=my_gen2nat_cmds, device_sim=device_sim) # overwrite abstract _cmd dictionary with subclass native _cmd_native dictionary: #self._cmd = {**self._cmd, **self._cmd_native} diff --git a/src/device_controller/abstract_component/device_controller.py b/src/device_controller/abstract_component/device_controller.py index 6ee6037..de5479d 100755 --- a/src/device_controller/abstract_component/device_controller.py +++ b/src/device_controller/abstract_component/device_controller.py @@ -447,7 +447,8 @@ class DeviceController(): ##def __init__(self, device_host:str="localhost", device_port:int=11110, PROTOCOL:str="TCP", buffer_size=1024, DEBUG=False): - 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): + #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): + def __init__(self, device_host:str="localhost", device_port:int=11110, channel="TCP", buffer_size=1024, protoc=None, gen2nat_cmds={}, device_sim=None): ''' :param device_host: server IP or hostname :param device_port: server port @@ -495,11 +496,12 @@ class DeviceController(): self._device_simulator = None else: if channel.startswith("SOCKET"): - self._my_channel:ClientChannel = ClientChannelSocket(device_host, device_port, channel, buffer_size, DEBUG) + #self._my_channel:ClientChannel = ClientChannelSocket(device_host, device_port, channel, buffer_size, DEBUG) + self._my_channel:ClientChannel = ClientChannelSocket(device_host, device_port, channel, buffer_size) elif channel == "SERIAL": - self._my_channel:ClientChannel = ClientChannelSerial(device_host, device_port, buffer_size, DEBUG) + self._my_channel:ClientChannel = ClientChannelSerial(device_host, device_port, buffer_size) elif channel == "USB": - self._my_channel:ClientChannel = ClientChannelUSB(device_host, device_port, buffer_size, DEBUG) + self._my_channel:ClientChannel = ClientChannelUSB(device_host, device_port, buffer_size) else: raise Exception("Unknown Channel", channel) # If LOCALHOST, launch the device SIMULATOR if device_host=="localhost": diff --git a/src/device_controller/abstract_component/device_simulator.py b/src/device_controller/abstract_component/device_simulator.py index 6897318..6cb8ae7 100755 --- a/src/device_controller/abstract_component/device_simulator.py +++ b/src/device_controller/abstract_component/device_simulator.py @@ -15,7 +15,7 @@ class UnknownCommandException(Exception): # Voir https://stackoverflow.com/questions/10085996/shutdown-socketserver-serve-forever-in-one-thread-python-application -# Abstract class +# Abstract (static) class class DeviceSimulator: #with socketserver_type((HOST, PORT), MyUDPorTCPHandler_classic) as myserver: diff --git a/src/device_controller/abstract_component/filter_selector.py b/src/device_controller/abstract_component/filter_selector.py index d88f1c8..2f65b39 100755 --- a/src/device_controller/abstract_component/filter_selector.py +++ b/src/device_controller/abstract_component/filter_selector.py @@ -56,7 +56,7 @@ class DC_FilterSelector(DeviceController): #TODO: remplacer PROTOCOL par "SOCKET-TCP", "SOCKET-UDP", "SERIAL", ou "USB" #def __init__(self, device_host:str="localhost", device_port:int=11110, PROTOCOL:str="TCP", buffer_size=1024, DEBUG=False, device_sim=None): - 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): + def __init__(self, device_host:str="localhost", device_port:int=11110, channel:str=None, buffer_size=None, protoc=None, gen2nat_cmds={}, device_sim=None): ''' :param device_host: server IP or hostname :param device_port: server port @@ -66,7 +66,7 @@ class DC_FilterSelector(DeviceController): #self._my_gen2nat_cmds = { **self.GEN2NAT_CMDS, **gen2nat_cmds } my_gen2nat_cmds = { **self.GEN2NAT_CMDS, **gen2nat_cmds } #super().__init__(device_host, device_port, PROTOCOL, buffer_size, DEBUG, device_sim) - super().__init__(device_host, device_port, channel, buffer_size, protoc=protoc, gen2nat_cmds=my_gen2nat_cmds, device_sim=device_sim, DEBUG=DEBUG) + super().__init__(device_host, device_port, channel, buffer_size, protoc=protoc, gen2nat_cmds=my_gen2nat_cmds, device_sim=device_sim) # overwrite abstract _cmd dictionary with subclass native _cmd_native dictionary: #self._cmd = {**self._cmd, **self._cmd_native} diff --git a/src/device_controller/abstract_component/mount.py b/src/device_controller/abstract_component/mount.py index ab34ebf..dc99106 100755 --- a/src/device_controller/abstract_component/mount.py +++ b/src/device_controller/abstract_component/mount.py @@ -126,7 +126,7 @@ class DC_Mount(DeviceController): #TODO: remplacer PROTOCOL par "SOCKET-TCP", "SOCKET-UDP", "SERIAL", ou "USB" ##def __init__(self, device_host:str="localhost", device_port:int=11110, PROTOCOL:str="TCP", buffer_size=1024, DEBUG=False, device_sim=None): - 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): + def __init__(self, device_host:str="localhost", device_port:int=11110, channel:str=None, buffer_size=None, protoc=None, gen2nat_cmds={}, device_sim=None): ''' :param device_host: server IP or hostname :param device_port: server port @@ -144,7 +144,7 @@ class DC_Mount(DeviceController): #printd("(mount 3) my cmds (after):", self._my_gen2nat_cmds) ##super().__init__(device_host, device_port, channel, buffer_size, DEBUG, device_sim) - super().__init__(device_host, device_port, channel, buffer_size, protoc=protoc, gen2nat_cmds=my_gen2nat_cmds, device_sim=device_sim, DEBUG=DEBUG) + super().__init__(device_host, device_port, channel, buffer_size, protoc=protoc, gen2nat_cmds=my_gen2nat_cmds, device_sim=device_sim) # overwrite abstract _cmd dictionary with subclass native _cmd_native dictionary: #self._cmd = {**self._cmd, **self._cmd_native} ##if gen2nat_qa: self._cmd_device_concrete = {**self._cmd_device_concrete, **gen2nat_qa} diff --git a/src/device_controller/channels/client_channel.py b/src/device_controller/channels/client_channel.py index 9531485..9245cc8 100755 --- a/src/device_controller/channels/client_channel.py +++ b/src/device_controller/channels/client_channel.py @@ -13,42 +13,45 @@ import os # None # Local application imports +from src.logpyros import LogPyros from device_controller.logs import * +''' def printd(*args, **kwargs): if os.environ.get('PYROS_DEBUG', '0')=='1': print(*args, **kwargs) - +''' ##class SocketClientAbstract(): class ClientChannel(): - + my_channel = None buf = 1024 - - def __init__(self, server_host:str="localhost", server_port:int=11110, PROTOCOL:str="SOCKET-TCP", buffer_size=1024, DEBUG=False): + + #def __init__(self, server_host:str="localhost", server_port:int=11110, PROTOCOL:str="SOCKET-TCP", buffer_size=1024, DEBUG=False): + def __init__(self, server_host:str="localhost", server_port:int=11110, PROTOCOL:str="SOCKET-TCP", buffer_size=1024): ''' :param server_host: server IP or hostname :param server_port: server port :param PROTOCOL: "SOCKET-TCP" or "SOCKET-UDP" or "SERIAL" or "USB" (to be continued...) ''' - self.DEBUG = DEBUG - + self.DEBUG_MODE = os.environ.get('PYROS_DEBUG', '0') == '1' self.HOST = server_host self.PORT = server_port self.PROTOCOL = PROTOCOL self.buf = buffer_size - + + self._log = LogPyros(self.__class__.__name__) + # Logger configuration #self.set_logger() ##set_logger(DEBUG) - printd("\n**************************") + self.printd("\n**************************") ##log_d("Client CHANNEL instanciated") - printd("Client CHANNEL instanciated") - - - + self.printd("Client CHANNEL instanciated") + + # So that we can use this with the "with" statement (context manager) def __enter__(self): return self @@ -57,6 +60,10 @@ class ClientChannel(): #printd("Client channel killed") print("Client channel killed") + # LOG methods + def print(self, *args, **kwargs): self._log.print(*args, **kwargs) + def printd(self, *args, **kwargs): self._log.printd(*args, **kwargs) + def send_data(self, data:str): ##data_encapsulated = self.encapsulate_data_to_send(data) diff --git a/src/device_controller/channels/client_channel_socket.py b/src/device_controller/channels/client_channel_socket.py index ba75c67..8035a19 100755 --- a/src/device_controller/channels/client_channel_socket.py +++ b/src/device_controller/channels/client_channel_socket.py @@ -33,10 +33,10 @@ class ClientChannelSocket(ClientChannel): MYSTAMP = '01' MY_FULL_STAMP = MYSTAMP + STAMP_FILLER ''' - - - - def __init__(self, server_host:str="localhost", server_port:int=11110, PROTOCOL:str="SOCKET-TCP", buffer_size=1024, DEBUG=False): + + + #def __init__(self, server_host:str="localhost", server_port:int=11110, PROTOCOL:str="SOCKET-TCP", buffer_size=1024, DEBUG=False): + def __init__(self, server_host:str="localhost", server_port:int=11110, PROTOCOL:str="SOCKET-TCP", buffer_size=1024): ''' :param server_host: server IP or hostname :param server_port: server port @@ -44,7 +44,8 @@ class ClientChannelSocket(ClientChannel): ''' myprotocol = socket.SOCK_DGRAM if PROTOCOL=="SOCKET-UDP" else socket.SOCK_STREAM self.mysock = socket.socket(socket.AF_INET, myprotocol) - super().__init__(server_host, server_port, PROTOCOL, buffer_size, DEBUG) + #super().__init__(server_host, server_port, PROTOCOL, buffer_size, DEBUG) + super().__init__(server_host, server_port, PROTOCOL, buffer_size) # Logger configuration #self.set_logger() ''' @@ -86,7 +87,7 @@ class ClientChannelSocket(ClientChannel): #@override def _connect_to_server(self): if self.PROTOCOL=="SOCKET-TCP": self.mysock.connect((self.HOST, self.PORT)) - printd(f"Ready to send commands to HOST {self.HOST} on PORT {self.PORT} \n") + self.printd(f"Ready to send commands to HOST {self.HOST} on PORT {self.PORT} \n") # Close socket @@ -112,7 +113,7 @@ class ClientChannelSocket(ClientChannel): ##log_i(f"(channel sock) Sent {nb_bytes_sent} bytes") ##log_i(f"(channel sock) Sent {nb_bytes_sent} bytes ; mesg sent is: ", data_to_send_bytes) ##log_i("(channel sock) Sent ",nb_bytes_sent, "bytes ; mesg sent is: ", data_to_send_bytes) - printd("(channel sock) Sent ",nb_bytes_sent, "bytes ; mesg sent is: ", data_to_send_bytes) + self.printd("(channel sock) Sent ",nb_bytes_sent, "bytes ; mesg sent is: ", data_to_send_bytes) #@override def _receive_data(self)->str: @@ -122,9 +123,9 @@ class ClientChannelSocket(ClientChannel): # so, replace it by ':' (b'\x3A') if b'\xdf' in data_received_bytes: data_received_bytes = data_received_bytes.replace(b'\xdf', b'\x3A') - printd(f"(channel sock) RECEIVED (ALL BYTES...): {data_received_bytes}") + self.printd(f"(channel sock) RECEIVED (ALL BYTES...): {data_received_bytes}") ##log_i(f"(channel sock) ({self}) RECEIVED (ALL BYTES...): {data_received_bytes}") - printd(f"(channel sock) ({self}) RECEIVED (ALL BYTES...): {data_received_bytes}") + self.printd(f"(channel sock) ({self}) RECEIVED (ALL BYTES...): {data_received_bytes}") data_received = data_received_bytes.decode() #log_d("data type is "+str(type(data_received))) diff --git a/src/device_controller/channels/server_udp_or_tcp.py b/src/device_controller/channels/server_udp_or_tcp.py index 9f35c5b..3ad57c8 100755 --- a/src/device_controller/channels/server_udp_or_tcp.py +++ b/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 """ # Standard library imports +import os import socketserver import sys @@ -17,13 +18,17 @@ import sys # Local application imports # None -from .client_channel import printd - +#from .client_channel import printd ''' sys.path.append('..') from device_controller.abstract_component.device_simulator import getc, getp ''' + +def printd(*args, **kwargs): + if os.environ.get('PYROS_DEBUG', '0')=='1': print(*args, **kwargs) + + # Very BASIC implementation def make_answer_for_request_CMD_TO_UPPER(request_bytes): #raise NotImplementedError diff --git a/src/device_controller/concrete_component/gemini/gemini_controller.py b/src/device_controller/concrete_component/gemini/gemini_controller.py index 3b14d11..66753bd 100755 --- a/src/device_controller/concrete_component/gemini/gemini_controller.py +++ b/src/device_controller/concrete_component/gemini/gemini_controller.py @@ -310,9 +310,11 @@ class DC_Gemini(DeviceController): # Gemini is using UDP #def __init__(self, device_host:str="localhost", device_port:int=11110, channel=socket, DEBUG=False): #def __init__(self, device_host:str="localhost", device_port:int=11110, DEBUG=False): - def __init__(self, device_host:str="localhost", device_port:int=11110, dcc_list=[], DEBUG=False): + #def __init__(self, device_host:str="localhost", device_port:int=11110, dcc_list=[], DEBUG=False): + def __init__(self, device_host:str="localhost", device_port:int=11110, dcc_list=[]): ##super().__init__(device_host, device_port, "SOCKET-UDP", 1024, DEBUG) - 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) + #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) + 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) ''' Initialize my dcc(s), passing them the SAME parameters as I use : @@ -330,8 +332,8 @@ class DC_Gemini(DeviceController): self.set_dc_components( [ #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), - 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), - 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), + 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), + 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), ] ) diff --git a/src/device_controller/concrete_component/sbig/sbig_controller.py b/src/device_controller/concrete_component/sbig/sbig_controller.py index da9bcd6..5b525d5 100755 --- a/src/device_controller/concrete_component/sbig/sbig_controller.py +++ b/src/device_controller/concrete_component/sbig/sbig_controller.py @@ -256,8 +256,8 @@ class DC_SBIG(DeviceController): } - def __init__(self, device_host:str="localhost", device_port:int=11110, DEBUG=False): - 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) + def __init__(self, device_host:str="localhost", device_port:int=11110): + 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) printd('*****************************') printd('*****************************') @@ -281,9 +281,10 @@ class DC_SBIG(DeviceController): # @override superclass empty list self.set_dc_components( [ - 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), - 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), - 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), + #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), + 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), + 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), + 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), ] ) diff --git a/src/logpyros.py b/src/logpyros.py index 1d5abf2..db41526 100644 --- a/src/logpyros.py +++ b/src/logpyros.py @@ -319,7 +319,6 @@ class LogPyros: def log_msg_to_file(self, log_msg, path, file_name, night): - #if file_name == self._CHRONO_FILENAME: print("file_name,log_msg :", file_name,log_msg) # 1) Create path if not exists if not os.path.exists(path): try: @@ -339,21 +338,10 @@ class LogPyros: #ll = self._last_lines if file_name == self._CHRONO_FILENAME else self._last_lines_agent ll.append(log_msg) n = len(ll) - #print("n is", n, "self.nbmax_last_lines is", self.nbmax_last_lines) if n > self.nbmax_last_lines: ll = ll[n-self.nbmax_last_lines:] #print("ll is", len(ll)) #print("self._last_lines is", len(self._last_lines)) - #if file_name == self._CHRONO_FILENAME: print("ll last is", ll[-1]) - ''' - if file_name == "pyros2": - self._last_lines.append(log_msg) - n = len(self._last_lines) - if n > self.nbmax_last_lines: - self._last_lines = self._last_lines[n-self.nbmax_last_lines:] - else: - self._last_lines[-1] = log_msg - ''' with open(file_prefix+'last'+'.log','w') as fic: for line in ll: fic.write(line+"\n") @@ -364,7 +352,6 @@ class LogPyros: self._last_lines_agent = ll ''' self._last_lines[filetype] = ll - #if file_name == self._CHRONO_FILENAME: print("self._last_lines last is", self._last_lines[-1]) def file(self, *args, **kwargs): -- libgit2 0.21.2