001package jmri.jmrix.loconet;
002
003import org.slf4j.Logger;
004import org.slf4j.LoggerFactory;
005
006/**
007 * A specialization of the LocoNet Throttle for Intellibox-II foibles.
008 *
009 * @author Bob Jacobsen Copyright (C) 2014
010 */
011public class Ib2Throttle extends LocoNetThrottle {
012
013    /**
014     * Constructor.
015     *
016     * @param memo system connection.
017     * @param slot The LocoNetSlot this throttle will talk on.
018     */
019    public Ib2Throttle(LocoNetSystemConnectionMemo memo, LocoNetSlot slot) {
020        super(memo, slot);
021        log.debug("Ib2Throttle created");
022    }
023
024    @Override
025    protected void sendFunctionGroup3() {
026        // Special LocoNet message for Uhlenbrock Intellibox-II implementation
027        // Intellibox-I uses another implementation for these functions
028        // Functions F9 to F12
029        log.debug("IB1 sendFunctionGroup3");
030        int new_IB2_F9_F12 = ((getFunction(12) ? LnConstants.RE_IB2_F12_MASK : 0)
031                | (getFunction(11) ? LnConstants.RE_IB2_F11_MASK : 0)
032                | (getFunction(10) ? LnConstants.RE_IB2_F10_MASK : 0)
033                | (getFunction(9) ? LnConstants.RE_IB2_F9_MASK : 0));
034        LocoNetMessage msg = new LocoNetMessage(4);
035        msg.setOpCode(LnConstants.RE_OPC_IB2_F9_F12);
036        msg.setElement(1, slot.getSlot());
037        msg.setElement(2, new_IB2_F9_F12);
038        network.sendLocoNetMessage(msg);
039    }
040
041    @Override
042    protected void sendFunctionGroup4() {
043        // Special LocoNet message for Uhlenbrock (IB-I and IB-II) implementation
044        // Functions F13 to F19
045        log.debug("IB1 sendFunctionGroup4");
046        int new_IB2_F13_F19 = ((getFunction(19) ? LnConstants.RE_IB2_F19_MASK : 0)
047                | (getFunction(18) ? LnConstants.RE_IB2_F18_MASK : 0)
048                | (getFunction(17) ? LnConstants.RE_IB2_F17_MASK : 0)
049                | (getFunction(16) ? LnConstants.RE_IB2_F16_MASK : 0)
050                | (getFunction(15) ? LnConstants.RE_IB2_F15_MASK : 0)
051                | (getFunction(14) ? LnConstants.RE_IB2_F14_MASK : 0)
052                | (getFunction(13) ? LnConstants.RE_IB2_F13_MASK : 0));
053        LocoNetMessage msg = new LocoNetMessage(6);
054        msg.setOpCode(LnConstants.OPC_EXP_SLOT_MOVE_RE_OPC_IB2_SPECIAL);
055        msg.setElement(1, LnConstants.RE_IB2_SPECIAL_FUNCS_TOKEN);
056        msg.setElement(2, slot.getSlot());
057        msg.setElement(3, LnConstants.RE_IB2_SPECIAL_F13_F19_TOKEN);
058        msg.setElement(4, new_IB2_F13_F19);
059        network.sendLocoNetMessage(msg);
060
061        // Function F20 (and F28)
062        // F12 is also controlled from this message though IB-II uses RE_OPC_IB2_F9_F12 OPS code for F12 - needed to avoid overridding F12 value
063        int new_IB2_F20_F28 = ((getFunction(12) ? LnConstants.RE_IB2_SPECIAL_F12_MASK : 0)
064                | (getFunction(20) ? LnConstants.RE_IB2_SPECIAL_F20_MASK : 0)
065                | (getFunction(28) ? LnConstants.RE_IB2_SPECIAL_F28_MASK : 0));
066        LocoNetMessage msg2 = new LocoNetMessage(6);
067        msg2.setOpCode(LnConstants.OPC_EXP_SLOT_MOVE_RE_OPC_IB2_SPECIAL);
068        msg2.setElement(1, LnConstants.RE_IB2_SPECIAL_FUNCS_TOKEN);
069        msg2.setElement(2, slot.getSlot());
070        msg2.setElement(3, LnConstants.RE_IB2_SPECIAL_F20_F28_TOKEN);
071        msg2.setElement(4, new_IB2_F20_F28);
072        network.sendLocoNetMessage(msg2);
073    }
074
075    @Override
076    protected void sendFunctionGroup5() {
077        // Functions F21 to F27
078        log.debug("IB1 sendFunctionGroup5");
079        int new_IB2_F21_F27 = ((getFunction(27) ? LnConstants.RE_IB2_F27_MASK : 0)
080                | (getFunction(26) ? LnConstants.RE_IB2_F26_MASK : 0)
081                | (getFunction(25) ? LnConstants.RE_IB2_F25_MASK : 0)
082                | (getFunction(24) ? LnConstants.RE_IB2_F24_MASK : 0)
083                | (getFunction(23) ? LnConstants.RE_IB2_F23_MASK : 0)
084                | (getFunction(22) ? LnConstants.RE_IB2_F22_MASK : 0)
085                | (getFunction(21) ? LnConstants.RE_IB2_F21_MASK : 0));
086        LocoNetMessage msg = new LocoNetMessage(6);
087        msg.setOpCode(LnConstants.OPC_EXP_SLOT_MOVE_RE_OPC_IB2_SPECIAL);
088        msg.setElement(1, LnConstants.RE_IB2_SPECIAL_FUNCS_TOKEN);
089        msg.setElement(2, slot.getSlot());
090        msg.setElement(3, LnConstants.RE_IB2_SPECIAL_F21_F27_TOKEN);
091        msg.setElement(4, new_IB2_F21_F27);
092        network.sendLocoNetMessage(msg);
093
094        // Function F28 (and F20)
095        // F12 is also controlled from this message though IB-II uses RE_OPC_IB2_F9_F12 OPS code for F12 - needed to avoid overridding F12 value
096        int new_IB2_F20_F28 = ((getFunction(12) ? LnConstants.RE_IB2_SPECIAL_F12_MASK : 0)
097                | (getFunction(20) ? LnConstants.RE_IB2_SPECIAL_F20_MASK : 0)
098                | (getFunction(28) ? LnConstants.RE_IB2_SPECIAL_F28_MASK : 0));
099        LocoNetMessage msg2 = new LocoNetMessage(6);
100        msg2.setOpCode(LnConstants.OPC_EXP_SLOT_MOVE_RE_OPC_IB2_SPECIAL);
101        msg2.setElement(1, LnConstants.RE_IB2_SPECIAL_FUNCS_TOKEN);
102        msg2.setElement(2, slot.getSlot());
103        msg2.setElement(3, LnConstants.RE_IB2_SPECIAL_F20_F28_TOKEN);
104        msg2.setElement(4, new_IB2_F20_F28);
105        network.sendLocoNetMessage(msg2);
106    }
107
108    // initialize logging
109    private final static Logger log = LoggerFactory.getLogger(Ib2Throttle.class);
110
111}