plc_controller_abstract.py 2.48 KB
#!/usr/bin/env python3

"""Socket Client Telescope (abstract) implementation

To be used as a base class (interface) for any concrete socket client telescope class
"""


# Standard library imports
#from enum import Enum
import functools
import logging
import socket
import sys
import time

# Third party imports

# from sockets_tele/
sys.path.append("..")
# from src_socket/client/
sys.path.append("../../..")
import src.utils.celme as celme


# Local application imports
#sys.path.append('../..')
#from src.client.socket_client_abstract import UnknownCommandException, SocketClientAbstract
from src_device.client.device_controller_abstract import *




# Execute also "set" and "do" commands
GET_ONLY=False
# Execute only "get" commands
#GET_ONLY=True

# Default timeouts
TIMEOUT_SEND = 10
TIMEOUT_RECEIVE = 10


'''
class c(Enum):

    # GET, SET
    DEC = 'DEC'
    RA = 'RA'
    RA_DEC = 'RA_DEC'
    
    # DO
    PARK = 'PARK'
    WARM_START = 'WARM_START'
'''





class PLCControllerAbstract(DeviceControllerAbstract):
    
    # @abstract (to be overriden)
    _cmd_native = {}
    _cmd = {
        # GET-SET commands:
        'get_ack': [],
        
        'get_timezone': [],
        'set_timezone': [],
        
        'get_date': [],
        'set_date': [],
        
        'get_time': [],
        'set_time': [],
        
        # DO commands:
    }


    
    def __init__(self, server_host:str="localhost", server_port:int=11110, PROTOCOL:str="TCP", buffer_size=1024, DEBUG=False):
        '''
        :param server_host: server IP or hostname
        :param server_port: server port
        :param PROTOCOL: "UDP" or "TCP"
        '''
        super().__init__(server_host, server_port, PROTOCOL, buffer_size, DEBUG)
        # overwrite abstract _cmd dictionary with subclass native _cmd_native dictionary:
        self._cmd = {**self._cmd, **self._cmd_native}

                

    
   

    '''
    ****************************
    ****************************
    GENERIC PLC COMMANDS (abstract methods)
    ****************************
    ****************************
    '''



    '''
    ****************************
     GENERIC GET & SET commands 
    **************************** 
    '''
    
    # @abstract
    @generic_cmd
    def get_ack(self): pass
    #return self.execute_generic_cmd("get_ack")



    '''
    ****************************
     GENERIC DO commands 
    **************************** 
    '''


        

# TODO: empecher de creer une instance de cette classe abstraite
# Avec ABC ?