Index: dialin/dg/dialysate_flow_sensor.py =================================================================== diff -u -r5eb006b08eb1d7b641b22fff20072ab7b685cfec -r3df1d92c0e920c12505c961b238d155d46efc407 --- dialin/dg/dialysate_flow_sensor.py (.../dialysate_flow_sensor.py) (revision 5eb006b08eb1d7b641b22fff20072ab7b685cfec) +++ dialin/dg/dialysate_flow_sensor.py (.../dialysate_flow_sensor.py) (revision 3df1d92c0e920c12505c961b238d155d46efc407) @@ -40,67 +40,65 @@ self.can_interface = can_interface self.logger = logger - # The flow rate of the sensor mL/min - self.flow_rate = 0.0 + # The flow rate of the sensors are L/min - self.new_ro_flow = 0.0 - self.new_ro_flow_with_conc = 0.0 - self.new_dialysate_flow = 0.0 + self.measured_ro_flow_LPM = 0.0 + self.measured_dialysate_flow_LPM = 0.0 + self.measured_ro_flow_with_cp_LPM = 0.0 if self.can_interface is not None: channel_id = DenaliChannels.dg_sync_broadcast_ch_id - msg_id = MsgIds.MSG_ID_DG_DIALYSATE_FLOW_METER_DATA.value - self.can_interface.register_receiving_publication_function(channel_id, msg_id, - self._handler_flow_sensor_sync) - - self.can_interface.register_receiving_publication_function(channel_id, MsgIds.MSG_ID_DG_FLOW_SENSORS_DATA.value, + self.can_interface.register_receiving_publication_function(channel_id, + MsgIds.MSG_ID_DG_FLOW_SENSORS_DATA.value, self._handler_flow_sensors_sync) - def get_flow_rate(self): + def get_measured_dialysate_flow_rate(self): """ - Gets a flow value from the sensor - - @param: flow sensor: (int) sensor index - @return: The dialysate flow rate mL/min of a flow sensor + Gets the measured flow value from DG's dialysate flow rate + @return: The dialysate flow rate L/min """ - return self.flow_rate - @publish(['flow_rate']) - def _handler_flow_sensor_sync(self, message): + return self.measured_dialysate_flow_LPM + + def get_measured_ro_flow(self): """ - Handles published flow sensor message. + Gets the measured flow value from DG's ro pump + @return: The RO flow rate L/min + """ + return self.measured_ro_flow_LPM - @param message: published flow sensor message - @return: none + def get_measured_ro_flow_with_cp(self): """ - flow = struct.unpack('f', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_1:MsgFieldPositions.END_POS_FIELD_1])) + Gets the measured flow value from DG's ro pump with concentrate pumps + @return: The RO flow rate with concentrate pumps flow rate L/min + """ + return self.measured_ro_flow_with_cp_LPM - self.flow_rate = flow[0] - + @publish(["measured_ro_flow_LPM", "measured_dialysate_flow_LPM", "measured_concentrate_ro_flow_LPM"]) def _handler_flow_sensors_sync(self, message): - self.new_ro_flow = struct.unpack('f', bytearray( + self.measured_ro_flow_LPM = struct.unpack('f', bytearray( message['message'][MsgFieldPositions.START_POS_FIELD_1:MsgFieldPositions.END_POS_FIELD_1]))[0] - self.new_ro_flow_with_conc = struct.unpack('f', bytearray( - message['message'][MsgFieldPositions.START_POS_FIELD_2:MsgFieldPositions.END_POS_FIELD_2]))[0] - self.new_dialysate_flow = struct.unpack('f', bytearray( + self.measured_dialysate_flow_LPM = struct.unpack('f', bytearray( message['message'][MsgFieldPositions.START_POS_FIELD_3:MsgFieldPositions.END_POS_FIELD_3]))[0] + self.measured_concentrate_ro_flow_LPM = struct.unpack('f', bytearray( + message['message'][MsgFieldPositions.START_POS_FIELD_2:MsgFieldPositions.END_POS_FIELD_2]))[0] - def cmd_flow_sensor_value_override(self, rate: float, reset: int = NO_RESET) -> int: + def cmd_measured_flow_sensor_value_override(self, rate: float, sensor_id: int, reset: int = NO_RESET) -> int: """ Constructs and sends the flow sensor value override command Constraints: Must be logged into DG. - @param rate: (float) the sensor flow rate to be set + @param rate: (float) the sensor flow rate to be set in L/min + @param sensor_id: (int) the sensor id to be overriden @param reset: (int) 1 to reset a previous override, 0 to override @return 1 if successful, zero otherwise """ - ml_per_liter: float = 1000.0 - reset_value = integer_to_bytearray(reset) - vlu = float_to_bytearray(rate / ml_per_liter) # DG expects the rate in mL/min - payload = reset_value + vlu + rst = integer_to_bytearray(reset) + sen = integer_to_bytearray(sensor_id) + flow = float_to_bytearray(rate) + payload = rst + sen + flow message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_dg_ch_id, message_id=MsgIds.MSG_ID_DIALYSATE_MEASURED_FLOW_OVERRIDE.value, @@ -136,8 +134,8 @@ mis = integer_to_bytearray(ms) payload = rst + mis - msg_id = MsgIds.MSG_ID_DIALYSATE_FLOW_SEND_INTERVAL_OVERRIDE.value - message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_dg_ch_id, message_id=msg_id, + message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_dg_ch_id, + message_id=MsgIds.MSG_ID_DIALYSATE_FLOW_SEND_INTERVAL_OVERRIDE.value, payload=payload) self.logger.debug("Overriding dialysate flow sensor broadcast interval")