Index: leahi_dialin/dd/modules/valves.py =================================================================== diff -u -r9a915d188a0e77cc68e9d5a91de66bacbd1da96f -rf9dd375900151a5daafe3b687187187645d5f1ab --- leahi_dialin/dd/modules/valves.py (.../valves.py) (revision 9a915d188a0e77cc68e9d5a91de66bacbd1da96f) +++ leahi_dialin/dd/modules/valves.py (.../valves.py) (revision f9dd375900151a5daafe3b687187187645d5f1ab) @@ -255,36 +255,36 @@ # Extract each valve state from U16 valves states using bit-masking self.valve_state_VHO["state"] = self._binary_to_valve_state(vst[0] & 1) self.valve_state_VTD["state"] = self._binary_to_valve_state(vst[0] & 2) - self.valve_state_VHB["state"] = self._binary_to_valve_state(vst[0] & 8) - self.valve_state_VRP["state"] = self._binary_to_valve_state(vst[0] & 16) - self.valve_state_VDR["state"] = self._binary_to_valve_state(vst[0] & 32) - self.valve_state_VDB2["state"] = self._binary_to_valve_state(vst[0] & 64) - self.valve_state_VP1["state"] = self._binary_to_valve_state(vst[0] & 128) - self.valve_state_VPT["state"] = self._binary_to_valve_state(vst[0] & 256) - self.valve_state_VDB1["state"] = self._binary_to_valve_state(vst[0] & 512) - self.valve_state_VDI["state"] = self._binary_to_valve_state(vst[0] & 1024) - self.valve_state_VDO["state"] = self._binary_to_valve_state(vst[0] & 2048) - self.valve_state_VP2["state"] = self._binary_to_valve_state(vst[0] & 4096) - self.valve_state_VHI["state"] = self._binary_to_valve_state(vst[0] & 8192) - self.valve_state_VWI["state"] = self._binary_to_valve_state(vst[0] & 16384) - self.valve_state_rsvrd1["state"] = self._binary_to_valve_state(vst[0] & 32768) - self.valve_state_rsvrd2["state"] = self._binary_to_valve_state(vst[0] & 65536) + self.valve_state_VHB["state"] = self._binary_to_valve_state(vst[0] & 4) + self.valve_state_VRP["state"] = self._binary_to_valve_state(vst[0] & 8) + self.valve_state_VDR["state"] = self._binary_to_valve_state(vst[0] & 16) + self.valve_state_VDB2["state"] = self._binary_to_valve_state(vst[0] & 32) + self.valve_state_VP1["state"] = self._binary_to_valve_state(vst[0] & 64) + self.valve_state_VPT["state"] = self._binary_to_valve_state(vst[0] & 128) + self.valve_state_VDB1["state"] = self._binary_to_valve_state(vst[0] & 256) + self.valve_state_VDI["state"] = self._binary_to_valve_state(vst[0] & 512) + self.valve_state_VDO["state"] = self._binary_to_valve_state(vst[0] & 1024) + self.valve_state_VP2["state"] = self._binary_to_valve_state(vst[0] & 2048) + self.valve_state_VHI["state"] = self._binary_to_valve_state(vst[0] & 4096) + self.valve_state_VWI["state"] = self._binary_to_valve_state(vst[0] & 8192) + self.valve_state_rsvrd1["state"] = self._binary_to_valve_state(vst[0] & 16384) + self.valve_state_rsvrd2["state"] = self._binary_to_valve_state(vst[0] & 32768) bcv = struct.unpack('B', bytearray(message['message'][self.START_POS_BCV_VALVES_STATES:self.END_POS_BCV_VALVES_STATES])) self.valve_state_BCV1["state"] = self._binary_to_valve_state(bcv[0] & 1) self.valve_state_BCV2["state"] = self._binary_to_valve_state(bcv[0] & 2) - self.valve_state_BCV3["state"] = self._binary_to_valve_state(bcv[0] & 8) - self.valve_state_BCV7["state"] = self._binary_to_valve_state(bcv[0] & 16) - self.valve_state_BCV5["state"] = self._binary_to_valve_state(bcv[0] & 32) - self.valve_state_BCV6["state"] = self._binary_to_valve_state(bcv[0] & 64) - self.valve_state_BCV4["state"] = self._binary_to_valve_state(bcv[0] & 128) - self.valve_state_BCV8["state"] = self._binary_to_valve_state(bcv[0] & 256) + self.valve_state_BCV3["state"] = self._binary_to_valve_state(bcv[0] & 4) + self.valve_state_BCV7["state"] = self._binary_to_valve_state(bcv[0] & 8) + self.valve_state_BCV5["state"] = self._binary_to_valve_state(bcv[0] & 16) + self.valve_state_BCV6["state"] = self._binary_to_valve_state(bcv[0] & 32) + self.valve_state_BCV4["state"] = self._binary_to_valve_state(bcv[0] & 64) + self.valve_state_BCV8["state"] = self._binary_to_valve_state(bcv[0] & 128) ufi = struct.unpack('B', bytearray(message['message'][self.START_POS_UFI_VALVES_STATES:self.END_POS_UFI_VALVES_STATES])) self.valve_state_UFI1["state"] = self._binary_to_valve_state(ufi[0] & 1) self.valve_state_UFI2["state"] = self._binary_to_valve_state(ufi[0] & 2) - self.valve_state_UFI3["state"] = self._binary_to_valve_state(ufi[0] & 8) - self.valve_state_UFI4["state"] = self._binary_to_valve_state(ufi[0] & 16) + self.valve_state_UFI3["state"] = self._binary_to_valve_state(ufi[0] & 4) + self.valve_state_UFI4["state"] = self._binary_to_valve_state(ufi[0] & 8) start = self.END_POS_UFI_VALVES_STATES end = start + 1 @@ -366,6 +366,61 @@ self.logger.debug("Timeout!!!!") return False + def cmd_bc_valves_override(self, bcv1: bool, bcv2: bool, bcv3: bool, bcv4: bool, bcv5: bool, bcv6: bool, bcv7: bool, bcv8: bool) -> int: + """ + Constructs and sends the balancing chamber valve states override command. + Constraints: + Must be logged into DD. + Given valve ID must be one of the valve IDs listed below. + + @param bcv1: bool - valve state for BCV1 (true=open, false=closed) + @param bcv2: bool - valve state for BCV2 (true=open, false=closed) + @param bcv3: bool - valve state for BCV3 (true=open, false=closed) + @param bcv4: bool - valve state for BCV4 (true=open, false=closed) + @param bcv5: bool - valve state for BCV5 (true=open, false=closed) + @param bcv6: bool - valve state for BCV6 (true=open, false=closed) + @param bcv7: bool - valve state for BCV7 (true=open, false=closed) + @param bcv8: bool - valve state for BCV8 (true=open, false=closed) + @return: 1 if successful, zero otherwise + """ + + valve = 0 + if bcv1: + valve = valve | 0x1 + if bcv2: + valve = valve | 0x2 + if bcv3: + valve = valve | 0x4 + if bcv7: + valve = valve | 0x8 + if bcv5: + valve = valve | 0x10 + if bcv6: + valve = valve | 0x20 + if bcv4: + valve = valve | 0x40 + if bcv8: + valve = valve | 0x80 + + payload = integer_to_bytearray(valve) + + message = DenaliMessage.build_message(channel_id=DenaliChannels.dialin_to_dd_ch_id, + message_id=MsgIds.MSG_ID_DD_BC_VALVE_STATES_OVERRIDE_REQUEST.value, + payload=payload) + + self.logger.debug("Override balancing chamber valve states") + + # Send message + received_message = self.can_interface.send(message) + + # If there is content... + if received_message is not None: + # response payload is OK or not OK + return received_message['message'][DenaliMessage.PAYLOAD_START_INDEX] + else: + self.logger.debug("Timeout!!!!") + return False + def cmd_valve_broadcast_interval_override(self, ms: int, reset: int = NO_RESET) -> int: """ Constructs and sends the valve state override command.