70 lines
2.0 KiB
Python
70 lines
2.0 KiB
Python
from ScEpTIC.emulator.energy import energy_utils
|
|
from ScEpTIC.exceptions import ConfigurationException
|
|
from ScEpTIC.emulator.energy.voltage_source import VoltageSource
|
|
|
|
|
|
class EnergySourceModel(VoltageSource):
|
|
"""
|
|
Model of an energy source
|
|
"""
|
|
|
|
# Used for integer conversion
|
|
TIME_MULTIPLIER = energy_utils.str_to_int('1G')
|
|
|
|
def __init__(self):
|
|
# On power failure during energy simulation -> recharge accordingly to energy source
|
|
self.power_off_full_recharge = False
|
|
|
|
# Power off full recharge voltage
|
|
self.full_recharge_voltage = 0.0
|
|
|
|
# Sampling time (default 1ms)
|
|
self.trace_sampling_time = 0.001
|
|
|
|
# Elapsed time
|
|
self.elapsed_time = 0.0
|
|
self.sampled_time = 0.0
|
|
|
|
def load_resistance_unset(self):
|
|
return False
|
|
|
|
def get_current_sample_remaining_time(self):
|
|
"""
|
|
:return: the remaining time of the current trace sample
|
|
"""
|
|
raise NotImplementedError(f"{self.__class__.__name__} must implement get_current_sample_remaining_time()")
|
|
|
|
|
|
def get_voltage(self):
|
|
"""
|
|
:return: energy source current voltage
|
|
"""
|
|
raise NotImplementedError(f"{self.__class__.__name__} must implement get_voltage()")
|
|
|
|
|
|
def get_voltage_intervals(self, t):
|
|
"""
|
|
Returns voltage intervals of the energy source
|
|
:param t: elapsed time
|
|
:return: a list of (voltage, energy, elapsed_time)
|
|
"""
|
|
raise NotImplementedError(f"{self.__class__.__name__} must implement get_voltage_intervals()")
|
|
|
|
def _time_to_int(self, t):
|
|
"""
|
|
Converts time from float (s) to int (ns)
|
|
:param t: time (float)
|
|
:return: time (int)
|
|
"""
|
|
return int(self.TIME_MULTIPLIER * t)
|
|
|
|
def _int_to_time(self, t):
|
|
"""
|
|
Converts time from int (ns) to float (s)
|
|
:param t: time (int)
|
|
:return: time (float)
|
|
"""
|
|
return float(t / self.TIME_MULTIPLIER)
|
|
|
|
|