Newer
Older
Olivier Kaufmann
committed
from abc import ABC, abstractmethod
from OhmPi.logging_setup import create_default_logger
Olivier Kaufmann
committed
class ControllerAbstract(ABC):
def __init__(self, **kwargs):
self.bus = None
class MuxAbstract(ABC):
pass
class TxAbstract(ABC):
def __init__(self, **kwargs):
Olivier Kaufmann
committed
self.board_name = kwargs.pop('board_name', 'unknown TX hardware')
polarity = kwargs.pop('polarity', 1)
inj_time = kwargs.pop('inj_time', 1.)
Olivier Kaufmann
committed
self.exec_logger = kwargs.pop('exec_logger', create_default_logger('exec_tx'))
self.soh_logger = kwargs.pop('soh_logger', create_default_logger('soh_tx'))
self._polarity = None
self._inj_time = None
Olivier Kaufmann
committed
self._dps_state = 'off'
Olivier Kaufmann
committed
self._adc_gain = 1.
self.polarity = polarity
self.inj_time = inj_time
Olivier Kaufmann
committed
self.exec_logger.debug(f'{self.board_name} TX initialization')
@property
def adc_gain(self):
return self._adc_gain
@adc_gain.setter
def adc_gain(self, value):
self._adc_gain = value
self.exec_logger.debug(f'Setting TX ADC gain to {value}')
@abstractmethod
def adc_gain_auto(self):
pass
Olivier Kaufmann
committed
@property
Olivier Kaufmann
committed
@abstractmethod
Olivier Kaufmann
committed
def current(self):
# add actions to read the DPS current and return it
return None
@current.setter
Olivier Kaufmann
committed
@abstractmethod
Olivier Kaufmann
committed
def current(self, value, **kwargs):
# add actions to set the DPS current
pass
Olivier Kaufmann
committed
@abstractmethod
Olivier Kaufmann
committed
def current_pulse(self, **kwargs):
pass
Olivier Kaufmann
committed
@abstractmethod
Olivier Kaufmann
committed
def inject(self, state='on'):
assert state in ['on', 'off']
@property
def inj_time(self):
return self._inj_time
@inj_time.setter
def inj_time(self, value):
assert isinstance(value, float)
self._inj_time = value
@property
def polarity(self):
return self._polarity
@polarity.setter
def polarity(self, value):
Olivier Kaufmann
committed
assert value in [-1,0,1]
self._polarity = value
# add actions to set the polarity (switch relays)
def turn_off(self):
Olivier Kaufmann
committed
self.exec_logger.debug(f'Switching DPS off')
self._dps_state = 'off'
Olivier Kaufmann
committed
self.exec_logger.debug(f'Switching DPS on')
self._dps_state = 'on'
Olivier Kaufmann
committed
@abstractmethod
def voltage(self):
# add actions to read the DPS voltage and return it
return None
@voltage.setter
Olivier Kaufmann
committed
@abstractmethod
def voltage(self, value, **kwargs):
# add actions to set the DPS voltage
pass
Olivier Kaufmann
committed
@property
@abstractmethod
def tx_bat(self):
pass
@abstractmethod
Olivier Kaufmann
committed
def voltage_pulse(self, voltage, length, polarity):
""" Generates a square voltage pulse
Parameters
----------
voltage: float, optional
Voltage to apply in volts, tx_v_def is applied if omitted.
length: float, optional
Length of the pulse in seconds
polarity: 1,0,-1
Polarity of the pulse
"""
pass
class RxAbstract(ABC):
Olivier Kaufmann
committed
def __init__(self, **kwargs):
self.exec_logger = kwargs.pop('exec_logger', create_default_logger('exec'))
self.soh_logger = kwargs.pop('soh_logger', create_default_logger('soh'))
Olivier Kaufmann
committed
self.board_name = kwargs.pop('board_name', 'unknown RX hardware')
self.exec_logger.debug(f'{self.board_name} RX initialization')
self._adc_gain = 1.
Olivier Kaufmann
committed
Olivier Kaufmann
committed
@property
def adc_gain(self):
return self._adc_gain
@adc_gain.setter
def adc_gain(self, value):
self._adc_gain = value
self.exec_logger.debug(f'Setting RX ADC gain to {value}')
@abstractmethod
def adc_gain_auto(self):
pass
@property
@abstractmethod
def voltage(self):
""" Gets the voltage VMN in Volts
"""
pass