diff --git a/lewis_emulators/edwardstic/__init__.py b/lewis_emulators/edwardstic/__init__.py deleted file mode 100644 index af72fce4..00000000 --- a/lewis_emulators/edwardstic/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -from ..lewis_versions import LEWIS_LATEST -from .device import SimulatedEdwardsTIC - -framework_version = LEWIS_LATEST -__all__ = ['SimulatedEdwardsTIC', 'AlertStates', 'PriorityStates', 'PumpStates'] diff --git a/lewis_emulators/edwardstic/device.py b/lewis_emulators/edwardstic/device.py deleted file mode 100644 index 8c399df2..00000000 --- a/lewis_emulators/edwardstic/device.py +++ /dev/null @@ -1,305 +0,0 @@ -from collections import OrderedDict -from lewis.devices import StateMachineDevice -from enum import Enum - -from .states import DefaultState - - -class OnOffStates(Enum): - """ - Holds whether a device function is on or off - """ - - on = 4 - off = 0 - - -class PumpStates(object): - """ - The pump states - """ - - stopped = object() - starting_delay = object() - accelerating = object() - running = object() - stopping_short_delay = object() - stopping_normal_delay = object() - fault_braking = object() - braking = object() - - -class GaugeStates(object): - """ - Possible gauge states - """ - not_connected = object() - connected = object() - new_id = object() - change = object() - alert = object() - off = object() - striking = object() - initialising = object() - calibrating = object() - zeroing = object() - degassing = object() - on = object() - inhibited = object() - - -class PriorityStates(object): - """ - Priority values - """ - - OK = object() - Warning = object() - Alarm = object() - - -class GaugeUnits(object): - """ - Units the gauges can measure in - """ - - Pa = object() - V = object() - percent = object() - - -class SimulatedEdwardsTIC(StateMachineDevice): - - def _initialize_data(self): - """ - Initialize all of the device's attributes. - """ - - self._turbo_pump = PumpStates.stopped - self._turbo_priority = PriorityStates.OK - self._turbo_alert = 0 - self._turbo_in_standby = False - - self._gauge_state = GaugeStates.on - self._gauge_priority = PriorityStates.OK - self._gauge_alert = 0 - self._gauge_pressure = 0.0 - self._gauge_units = GaugeUnits.Pa - - self.is_connected = True - - def _get_state_handlers(self): - return { - 'default': DefaultState(), - } - - def _get_initial_state(self): - return 'default' - - def _get_transition_handlers(self): - return OrderedDict([ - ]) - - @property - def turbo_in_standby(self): - """ - Gets whether the turbo is in standby mode - - Returns: - _turbo_standby: Bool, True if the turbo is in standby mode - """ - - return self._turbo_in_standby - - @turbo_in_standby.setter - def turbo_in_standby(self, value): - """ - Sets the turbo standby mode - - Args: - value: Bool, True to set standby mode. False to unset standby mode - """ - - self._turbo_in_standby = value - - def turbo_set_standby(self, value): - """ - Sets / unsets turbo standby mode - - Args: - value, int: 1 to set standby mode, 0 to unset standby. - """ - - if value == 1: - self.log.info("Entering turbo standby mode") - self._turbo_in_standby = True - elif value == 0: - self.log.info("Leaving turbo standby mode") - self._turbo_in_standby = False - else: - raise ValueError("Invalid standby argument provided ({} not 0 or 1)".format(value)) - - @property - def turbo_pump(self): - """ - Gets the running state of the turbo pump - """ - - return self._turbo_pump - - def set_turbo_pump_state(self, state): - """ - Sets the state of the turbo pump. - This function doesn't exist on the real device and is only called through the back door. - - Args: - state: String, Matches an attribute of the PumpStates class - """ - pump_state = getattr(PumpStates, state) - - self._turbo_pump = pump_state - - def turbo_start_stop(self, value): - """ - Sets the turbo pump running/stopping - - Args: - value: int, 1 if starting the pump 0 to stop the pump - """ - - self.log.info("Starting or stopping turbo {}".format(value)) - - if value == 1: - self.log.info("Starting turbo") - self._turbo_pump = PumpStates.running - elif value == 0: - self.log.info("Stopping turbo") - self._turbo_pump = PumpStates.stopped - else: - raise ValueError("Invalid start/stop switch ({} not 0 or 1)".format(value)) - - @property - def turbo_priority(self): - """ - Gets the priority state of the turbo pump - """ - - self.log.info("Getting priority {}".format(self._turbo_priority)) - - return self._turbo_priority - - def set_turbo_priority(self, state): - """ - Sets the priority state of the turbo pump. - This function doesn't exist on the real device and is only called through the back door. - - Args: - state: object, an attribute of the PumpStates class - """ - - priority_state = getattr(PriorityStates, state) - - self._turbo_priority = priority_state - - @property - def turbo_alert(self): - """ - Gets the alert state of the turbo pump - """ - - return self._turbo_alert - - # This setter doesn't exist on the 'real' device - def set_turbo_alert(self, state): - """ - Sets the alert state of the turbo pump - - Args: - state: Int, the alert value - """ - - self._turbo_alert = state - - @property - def gauge_pressure(self): - """ - Gets the gauge pressure - """ - - return self._gauge_pressure - - @gauge_pressure.setter - def gauge_pressure(self, value): - """ - Sets the gauge pressure. - This function is not present on the real device and can only be accessed through the backdoor. - - Args: - value: float, The value to set the gauge pressure to. - """ - - self._gauge_pressure = value - - @property - def gauge_state(self): - """ - Gets the running state of the gauges - """ - - return self._gauge_state - - def set_gauge_state(self, state): - """ - Sets the state of the gauges - This function doesn't exist on the real device and is only called through the back door. - - Args: - state: String, Matches an attribute of the GaugeStates class - """ - gauge_state = getattr(GaugeStates, state) - - self._gauge_state = gauge_state - - @property - def gauge_alert(self): - return self._gauge_alert - - def set_gauge_alert(self, state): - """ - Sets the alert state of the gauges. - This is only accessed through the back door - - Args: - state: Int, the alert value - """ - - self._gauge_alert = state - - @property - def gauge_priority(self): - """ - Gets the priority state of the gauges - """ - - return self._gauge_priority - - def set_gauge_priority(self, state): - """ - Sets the priority state of the gauges. - This function doesn't exist on the real device and is only called through the back door. - - Args: - state: object, an attribute of the PumpStates class - """ - - priority_state = getattr(PriorityStates, state) - - self._gauge_priority = priority_state - - @property - def gauge_units(self): - """ - Getter for the gauge units - """ - - return self._gauge_units diff --git a/lewis_emulators/edwardstic/interfaces/__init__.py b/lewis_emulators/edwardstic/interfaces/__init__.py deleted file mode 100644 index 7f37fd5b..00000000 --- a/lewis_emulators/edwardstic/interfaces/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from .stream_interface import EdwardsTICStreamInterface - -__all__ = ['EdwardsTICStreamInterface'] diff --git a/lewis_emulators/edwardstic/interfaces/stream_interface.py b/lewis_emulators/edwardstic/interfaces/stream_interface.py deleted file mode 100644 index c7d09948..00000000 --- a/lewis_emulators/edwardstic/interfaces/stream_interface.py +++ /dev/null @@ -1,191 +0,0 @@ -from lewis.adapters.stream import StreamInterface -from lewis.utils.command_builder import CmdBuilder -from lewis.core.logging import has_log -from lewis.utils.replies import conditional_reply -from ..device import PumpStates, GaugeStates, GaugeUnits, PriorityStates - - -PUMPSTATES_MAP = { - 0: PumpStates.stopped, - 1: PumpStates.starting_delay, - 5: PumpStates.accelerating, - 4: PumpStates.running, - 2: PumpStates.stopping_short_delay, - 3: PumpStates.stopping_normal_delay, - 6: PumpStates.fault_braking, - 7: PumpStates.braking, -} - -GAUGESTATES_MAP = { - 0: GaugeStates.not_connected, - 1: GaugeStates.connected, - 2: GaugeStates.new_id, - 3: GaugeStates.change, - 4: GaugeStates.alert, - 5: GaugeStates.off, - 6: GaugeStates.striking, - 7: GaugeStates.initialising, - 8: GaugeStates.calibrating, - 9: GaugeStates.zeroing, - 10: GaugeStates.degassing, - 11: GaugeStates.on, - 12: GaugeStates.inhibited -} - -GAUGEUNITS_MAP = { - GaugeUnits.Pa: 59, - GaugeUnits.V: 66, - GaugeUnits.percent: 81 -} - -PRIORITYSTATES_MAP = { - PriorityStates.OK: 0, - PriorityStates.Warning: 1, - PriorityStates.Alarm: 3 - } - - -def reverse_dict_lookup(dictionary, value_to_find): - """ - Looks up the key for the supplied value in dictionary dict. - - Args: - dictionary: dictionary, the dictionary to do the reverse lookup - value_to_find: the value to find in the dictionary - - Raises: - KeyError if value does not exist in the dictionary - """ - - for key, value in dictionary.items(): - if value == value_to_find: - return key - else: - raise KeyError("Could not find {} in map".format(value_to_find)) - - -@has_log -class EdwardsTICStreamInterface(StreamInterface): - - # Commands that we expect via serial during normal operation - commands = { - CmdBuilder("turbo_start_stop").escape("!C904 ").int().eos().build(), - CmdBuilder("get_turbo_state").escape("?V904").eos().build(), - CmdBuilder("turbo_get_speed").escape("?V905").eos().build(), - CmdBuilder("turbo_get_sft").escape("?S905").eos().build(), - CmdBuilder("turbo_get_power").escape("?V906").eos().build(), - CmdBuilder("turbo_get_norm").escape("?V907").eos().build(), - CmdBuilder("turbo_set_standby").escape("!C908 ").int().eos().build(), - CmdBuilder("turbo_get_standby").escape("?V908").eos().build(), - CmdBuilder("turbo_get_cycle").escape("?V909").eos().build(), - CmdBuilder("backing_get_status").escape("?V910").eos().build(), - CmdBuilder("backing_start_stop").escape("!C910 ").int().eos().build(), - CmdBuilder("backing_get_speed").escape("?V911").eos().build(), - CmdBuilder("backing_get_power").escape("?V912").eos().build(), - CmdBuilder("get_gauge").escape("?V91").arg("3|4|5").eos().build(), - } - - in_terminator = "\r" - out_terminator = "\r" - - ACK = "&ACK!" + out_terminator - - def handle_error(self, request, error): - """ - Prints an error message if a command is not recognised. - - Args: - request : Request. - error: The error that has occurred. - Returns: - None. - """ - - self.log.info("An error occurred at request {}: {}".format(request, error)) - - @conditional_reply("is_connected") - def turbo_set_standby(self, switch): - self._device.turbo_set_standby(switch) - - return "*C908 0" - - @conditional_reply("is_connected") - def turbo_get_standby(self): - return_string = "=V908 {stdby_state};0;0" - - standby_state = 4 if self._device.turbo_in_standby else 0 - - self.log.info(return_string.format(stdby_state=standby_state)) - - return return_string.format(stdby_state=standby_state) - - @conditional_reply("is_connected") - def turbo_start_stop(self, switch): - self.log.info("turbo start stop command received") - self._device.turbo_start_stop(switch) - - return "*C904 0" - - @conditional_reply("is_connected") - def get_turbo_state(self): - state_string = "=V904 {turbo_state};{alert};{priority}" - - return state_string.format(turbo_state=reverse_dict_lookup(PUMPSTATES_MAP, self._device.turbo_pump), - alert=self._device.turbo_alert, - priority=PRIORITYSTATES_MAP[self._device.turbo_priority]) - - @conditional_reply("is_connected") - def get_turbo_status(self): - output_string = "*C904 {state};{alert};{priority}" - - state = self._device.turbo_state - alert = self._device.turbo_alert - priority = self._device.turbo_priority - - return output_string.format(state=state, alert=alert, priority=priority) - - @conditional_reply("is_connected") - def turbo_get_speed(self): - return "=V905 1;0;0" - - @conditional_reply("is_connected") - def turbo_get_sft(self): - return "=S905 1;0" - - @conditional_reply("is_connected") - def turbo_get_power(self): - return "=V906 1;0;0" - - @conditional_reply("is_connected") - def turbo_get_norm(self): - return "=V907 4;0;0" - - @conditional_reply("is_connected") - def turbo_get_cycle(self): - return "=V909 1;0;0;0" - - @conditional_reply("is_connected") - def backing_get_status(self): - return "=V910 1;0;0" - - @conditional_reply("is_connected") - def backing_start_stop(self, switch): - return "*C910 0" - - @conditional_reply("is_connected") - def backing_get_speed(self): - return "=V911 1;0;0" - - @conditional_reply("is_connected") - def backing_get_power(self): - return "=V912 1;0;0" - - @conditional_reply("is_connected") - def get_gauge(self, gauge_id): - state_string = "=V91{gauge_id} {pressure};{units};{gauge_state};{alert};{priority}" - - return state_string.format(gauge_id=gauge_id, pressure=self._device.gauge_pressure, - units=GAUGEUNITS_MAP[self._device.gauge_units], - gauge_state=reverse_dict_lookup(GAUGESTATES_MAP, self._device.gauge_state), - alert=self._device.gauge_alert, - priority=PRIORITYSTATES_MAP[self._device.gauge_priority]) diff --git a/lewis_emulators/edwardstic/states.py b/lewis_emulators/edwardstic/states.py deleted file mode 100644 index 35137c5e..00000000 --- a/lewis_emulators/edwardstic/states.py +++ /dev/null @@ -1,13 +0,0 @@ -from lewis.core.logging import has_log -from lewis.core.statemachine import State - - -@has_log -class DefaultState(State): - """ - Device is in default state. - """ - NAME = 'Default' - - def in_state(self, dt): - pass