An error occurred while loading the file. Please try again.
-
Olivier Kaufmann authored034baa3d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
from abc import ABC, abstractmethod
from OhmPi.logging_setup import create_stdout_logger
import time
class ControllerAbstract(ABC):
def __init__(self, **kwargs):
self.bus = None
class MuxAbstract(ABC):
def __init__(self, **kwargs):
pass
class TxAbstract(ABC):
def __init__(self, **kwargs):
self.board_name = kwargs.pop('board_name', 'unknown TX hardware')
polarity = kwargs.pop('polarity', 1)
if polarity is None:
polarity = 0
self._polarity = polarity
inj_time = kwargs.pop('inj_time', 1.)
self.exec_logger = kwargs.pop('exec_logger', None)
if self.exec_logger is None:
self.exec_logger = create_stdout_logger('exec_tx')
self.soh_logger = kwargs.pop('soh_logger', None)
if self.soh_logger is None:
self.soh_logger = create_stdout_logger('soh_tx')
#self._polarity = polarity
self._inj_time = None
self._dps_state = 'off'
self._adc_gain = 1.
self.inj_time = inj_time
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
@property
@abstractmethod
def current(self):
# add actions to read the TX current and return it
return None
@current.setter
@abstractmethod
def current(self, value, **kwargs):
# add actions to set the DPS current
pass
@abstractmethod
def current_pulse(self, **kwargs):
pass
@abstractmethod
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):
assert value in [-1,0,1]
self._polarity = value
# add actions to set the polarity (switch relays)
def turn_off(self):
self.exec_logger.debug(f'Switching DPS off')
self._dps_state = 'off'
def turn_on(self):
self.exec_logger.debug(f'Switching DPS on')
self._dps_state = 'on'
@property
@abstractmethod
def voltage(self):
# add actions to read the DPS voltage and return it
return None
@voltage.setter
@abstractmethod
def voltage(self, value, **kwargs):
# add actions to set the DPS voltage
pass
@property
@abstractmethod
def tx_bat(self):
pass
def voltage_pulse(self, voltage=0., length=None, polarity=None):
""" 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
"""
if length is None:
length = self.inj_time
if polarity is None:
polarity = self.polarity
self.polarity = polarity
self.voltage = voltage
self.exec_logger.debug(f'Voltage pulse of {polarity * voltage:.3f} V for {length:.3f} s')
self.inject(state='on')
time.sleep(length)
# self.tx_sync.clear()
self.inject(state='off')
class RxAbstract(ABC):
def __init__(self, **kwargs):
self.exec_logger = kwargs.pop('exec_logger', None)
if self.exec_logger is None:
self.exec_logger = create_stdout_logger('exec_tx')
self.soh_logger = kwargs.pop('soh_logger', None)
self.board_name = kwargs.pop('board_name', 'unknown RX hardware')
self.exec_logger.debug(f'{self.board_name} RX initialization')
self._adc_gain = 1.
@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