Index: leahi_dialin/dd/modules/heaters.py =================================================================== diff -u -r829d25cb941953c353279777e82a083d204f99ff -rbeb046149da1b7cf85dbdadb500467490f350fb8 --- leahi_dialin/dd/modules/heaters.py (.../heaters.py) (revision 829d25cb941953c353279777e82a083d204f99ff) +++ leahi_dialin/dd/modules/heaters.py (.../heaters.py) (revision beb046149da1b7cf85dbdadb500467490f350fb8) @@ -20,34 +20,13 @@ from .constants import NO_RESET from leahi_dialin.common.msg_defs import MsgIds, MsgFieldPositions +from leahi_dialin.common.dd_defs import HeatersStartStop, HeatersState, HeatersNames, HeatersAttributesEnum from leahi_dialin.protocols.CAN import DenaliMessage, DenaliChannels from leahi_dialin.utils.base import AbstractSubSystem, publish, DialinEnum from leahi_dialin.utils.checks import check_broadcast_interval_override_ms from leahi_dialin.utils.conversions import integer_to_bytearray, float_to_bytearray -@unique -class HeatersStartStop(DialinEnum): - STOP = 0 - START = 1 - - -@unique -class HeatersState(DialinEnum): - HEATER_EXEC_STATE_OFF = 0 - HEATER_EXEC_STATE_RAMP_TO_TARGET = 1 - HEATER_EXEC_STATE_CONTROL_TO_TARGET = 2 - HEATER_EXEC_STATE_CONTROL_TO_DISINFECT_TARGET = 3 - NUM_OF_HEATERS_STATE = 4 - - -@unique -class HeatersNames(DialinEnum): - D5_HEAT = 0 - D45_HEAT = 1 - NUM_OF_DD_HEATERS = 2 - - class DDHeaters(AbstractSubSystem): """ @@ -65,17 +44,23 @@ self.can_interface = can_interface self.logger = logger - self.d5_heat_duty_cycle = 0.0 - self.d45_heat_duty_cycle = 0.0 - self.d5_heat_target_temperature = 0.0 - self.d45_heat_target_temperature = 0.0 - self.d5_heat_state = 0 - self.d45_heat_state = 0 - self.d5_duty_cycle_count = 0.0 - self.d5_pwm_period = 0.0 - self.d5_adjusted_target_temp = 0.0 - self.d5_target_temp_td = 0.0 self.dd_heaters_timestamp = 0.0 + self.dd_heaters = { + HeatersNames.D5_HEAT.name: { + HeatersAttributesEnum.HEAT_DUTY_CYCLE.name: 0.0, + HeatersAttributesEnum.HEAT_TARGET_TEMP.name: 0.0, + HeatersAttributesEnum.HEAT_STATE.name: 0, + HeatersAttributesEnum.DUTY_CYCLE_COUNT.name: 0.0, + HeatersAttributesEnum.PWM_PERIOD.name: 0.0, + HeatersAttributesEnum.ADJUSTED_TARGET_TEMP.name: 0.0, + HeatersAttributesEnum.TARGET_TEMP_TD.name: 0.0 + }, + HeatersNames.D45_HEAT.name: { + HeatersAttributesEnum.HEAT_DUTY_CYCLE.name: 0.0, + HeatersAttributesEnum.HEAT_TARGET_TEMP.name: 0.0, + HeatersAttributesEnum.HEAT_STATE.name: 0 + } + } #Temp Heater Debugging published fields self.dbg1 = 0.0 @@ -94,39 +79,34 @@ msg_id = MsgIds.MSG_ID_DD_HEATERS_DATA.value self.can_interface.register_receiving_publication_function(channel_id, msg_id, self._handler_heaters_sync) - @publish(["dd_heaters_timestamp", - "d5_heat_duty_cycle","d45_heat_duty_cycle", - "d5_heat_target_temperature","d45_heat_target_temperature", - "d5_heat_state","d45_heat_state", - "d5_duty_cycle_count","d5_pwm_period", - "d5_adjusted_target_temp","d5_target_temp_td"]) + @publish(["dd_heaters_timestamp", "dd_heaters"]) def _handler_heaters_sync(self, message, timestamp=0.0): """ Handles published DD heaters message @param message: published DD heaters data message @returns none """ - self.d5_heat_duty_cycle = struct.unpack('f', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_1:MsgFieldPositions.END_POS_FIELD_1]))[0] - self.d45_heat_duty_cycle = struct.unpack('f', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_2:MsgFieldPositions.END_POS_FIELD_2]))[0] - self.d5_heat_target_temperature = struct.unpack('f', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_3:MsgFieldPositions.END_POS_FIELD_3]))[0] - self.d45_heat_target_temperature = struct.unpack('f', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_4:MsgFieldPositions.END_POS_FIELD_4]))[0] - self.d5_heat_state = struct.unpack('i', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_5:MsgFieldPositions.END_POS_FIELD_5]))[0] - self.d45_heat_state = struct.unpack('i', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_6:MsgFieldPositions.END_POS_FIELD_6]))[0] - self.d5_duty_cycle_count = struct.unpack('f', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_7:MsgFieldPositions.END_POS_FIELD_7]))[0] - self.d5_pwm_period = struct.unpack('f', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_8:MsgFieldPositions.END_POS_FIELD_8]))[0] - self.d5_adjusted_target_temp = struct.unpack('f', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_9:MsgFieldPositions.END_POS_FIELD_9]))[0] - self.d5_target_temp_td = struct.unpack('f', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_10:MsgFieldPositions.END_POS_FIELD_10]))[0] + self.dd_heaters[HeatersNames.D5_HEAT.name][HeatersAttributesEnum.HEAT_DUTY_CYCLE.name] = ( + struct.unpack('f', bytearray(message['message'][MsgFieldPositions.START_POS_FIELD_1:MsgFieldPositions.END_POS_FIELD_1])))[0] + self.dd_heaters[HeatersNames.D45_HEAT.name][HeatersAttributesEnum.HEAT_DUTY_CYCLE.name] = ( + struct.unpack('f', bytearray(message['message'][MsgFieldPositions.START_POS_FIELD_2:MsgFieldPositions.END_POS_FIELD_2])))[0] + self.dd_heaters[HeatersNames.D5_HEAT.name][HeatersAttributesEnum.HEAT_TARGET_TEMP.name] = ( + struct.unpack('f', bytearray(message['message'][MsgFieldPositions.START_POS_FIELD_3:MsgFieldPositions.END_POS_FIELD_3])))[0] + self.dd_heaters[HeatersNames.D45_HEAT.name][HeatersAttributesEnum.HEAT_TARGET_TEMP.name] = ( + struct.unpack('f', bytearray(message['message'][MsgFieldPositions.START_POS_FIELD_4:MsgFieldPositions.END_POS_FIELD_4])))[0] + self.dd_heaters[HeatersNames.D5_HEAT.name][HeatersAttributesEnum.HEAT_STATE.name] = ( + struct.unpack('i', bytearray(message['message'][MsgFieldPositions.START_POS_FIELD_5:MsgFieldPositions.END_POS_FIELD_5])))[0] + self.dd_heaters[HeatersNames.D45_HEAT.name][HeatersAttributesEnum.HEAT_STATE.name] = ( + struct.unpack('i', bytearray(message['message'][MsgFieldPositions.START_POS_FIELD_6:MsgFieldPositions.END_POS_FIELD_6])))[0] + self.dd_heaters[HeatersNames.D5_HEAT.name][HeatersAttributesEnum.DUTY_CYCLE_COUNT.name] = ( + struct.unpack('f', bytearray(message['message'][MsgFieldPositions.START_POS_FIELD_7:MsgFieldPositions.END_POS_FIELD_7])))[0] + self.dd_heaters[HeatersNames.D5_HEAT.name][HeatersAttributesEnum.PWM_PERIOD.name] = ( + struct.unpack('f', bytearray(message['message'][MsgFieldPositions.START_POS_FIELD_8:MsgFieldPositions.END_POS_FIELD_8])))[0] + self.dd_heaters[HeatersNames.D5_HEAT.name][HeatersAttributesEnum.ADJUSTED_TARGET_TEMP.name] = ( + struct.unpack('f', bytearray(message['message'][MsgFieldPositions.START_POS_FIELD_9:MsgFieldPositions.END_POS_FIELD_9])))[0] + self.dd_heaters[HeatersNames.D5_HEAT.name][HeatersAttributesEnum.TARGET_TEMP_TD.name] = ( + struct.unpack('f', bytearray(message['message'][MsgFieldPositions.START_POS_FIELD_10:MsgFieldPositions.END_POS_FIELD_10])))[0] self.dbg1 = struct.unpack('f', bytearray( message['message'][MsgFieldPositions.START_POS_FIELD_11:MsgFieldPositions.END_POS_FIELD_11]))[0]