Index: leahi_dialin/fp/proxies/dd_proxy.py =================================================================== diff -u -r68422d08c4141999a13496343264483a32314d37 -r89bc63999a581c9bf99c68f20ad05b30b6dcf0cb --- leahi_dialin/fp/proxies/dd_proxy.py (.../dd_proxy.py) (revision 68422d08c4141999a13496343264483a32314d37) +++ leahi_dialin/fp/proxies/dd_proxy.py (.../dd_proxy.py) (revision 89bc63999a581c9bf99c68f20ad05b30b6dcf0cb) @@ -13,28 +13,30 @@ # @date (original) 02-Apr-2020 # ############################################################################ -import struct + from logging import Logger -from leahi_dialin.common.msg_defs import MsgIds, MsgFieldPositions +from leahi_dialin.common.msg_defs import MsgIds +from leahi_dialin.common.fp_defs import FPOpModes from leahi_dialin.protocols.CAN import DenaliMessage, DenaliCanMessenger, DenaliChannels -from leahi_dialin.utils.base import AbstractSubSystem, publish -from leahi_dialin.utils.conversions import integer_to_bytearray, byte_to_bytearray, float_to_bytearray +from leahi_dialin.utils.base import AbstractSubSystem +from leahi_dialin.utils.conversions import integer_to_bytearray, float_to_bytearray class DDProxy(AbstractSubSystem): """ Filtration Purification (FP) Dialin API sub-class for DD proxy ( injection ) related commands. """ - def __init__(self, can_interface: DenaliCanMessenger, logger: Logger): + def __init__(self, can_interface: DenaliCanMessenger, logger: Logger, fp): """ ROProxy constructor @param can_interface: the Denali CAN interface object """ super().__init__() + self._fp = fp self.can_interface = can_interface self.logger = logger @@ -60,3 +62,24 @@ self.logger.debug("Sending DD start stop request to FP.") self.can_interface.send(message, 0) + + def cmd_send_dd_mode_change_request(self, op_mode: int) -> int: + """ + Constructs and sends a set operation mode request command via internal CAN bus. + Constraints: + Must be logged into FP. + Transition from current to requested op mode must be legal. + NOTE: for POST the FP device shall be in Standby Mode + + @param op_mode: ID of operation mode to transition to + + @return: 1 if successful, zero otherwise + """ + + target_opmode = op_mode + if op_mode in [FPOpModes.MODE_PRE_GENP, FPOpModes.MODE_DPGP]: + target_opmode = FPOpModes.MODE_DPGP if self._fp.fp_defeaturized else FPOpModes.MODE_PRE_GENP + elif op_mode in [FPOpModes.MODE_GENP, FPOpModes.MODE_DEGP]: + target_opmode = FPOpModes.MODE_DEGP if self._fp.fp_defeaturized else FPOpModes.MODE_GENP + + return self._fp.cmd_fp_set_operation_mode(target_opmode)