001package jmri.jmrix.loconet;
002
003
004/**
005 * Extends representation of a single slot for the Uhlenbrock IB command station.
006 * <p>
007 * Does specific Uhlenbrock Intellibox message handling.
008 * <p>
009 * Some of the message formats used in this class are Copyright Digitrax, Inc.
010 * and used with permission as part of the JMRI project. That permission does
011 * not extend to uses in other software products. If you wish to use this code,
012 * algorithm or these message formats outside of JMRI, please contact Digitrax
013 * Inc for separate permission.
014 *
015 * @author Alain Le Marchand Copyright (C) 2014
016 */
017public class UhlenbrockSlot extends LocoNetSlot {
018
019    public UhlenbrockSlot(int i) {
020        super(i);
021    }
022
023    public UhlenbrockSlot(LocoNetMessage l) throws LocoNetException {
024        super(l);
025    }
026
027    /**
028     * Load functions 9 through 12 from LocoNet Uhlenbrock Intellibox-II
029     * implementation to be used only for message with Op code
030     * RE_OPC_IB2_F9_F12.
031     * @param m a LocoNet message which contains an iB2 "function control" message.
032     */
033    public void iB2functionMessage(LocoNetMessage m) {
034        // parse for F9-12 functions
035        int funcs = m.getElement(2);
036        localF9 = (funcs & LnConstants.RE_IB2_F9_MASK) != 0;
037        localF10 = (funcs & LnConstants.RE_IB2_F10_MASK) != 0;
038        localF11 = (funcs & LnConstants.RE_IB2_F11_MASK) != 0;
039        localF12 = (funcs & LnConstants.RE_IB2_F12_MASK) != 0;
040        notifySlotListeners();
041    }
042
043    /**
044     * Load functions 9 through 28 from LocoNet Uhlenbrock Intellibox-I and -II
045     * implementation to be used only for message with Op code
046     * RE_OPC_IB2_SPECIAL.
047     * @param m a LocoNet message which contains an iB "function control" message.
048     */
049    public void iBfunctionMessage(LocoNetMessage m) {
050        // parse for which set of functions
051        int token = m.getElement(3);
052        int funcs = m.getElement(4);
053        if (token == LnConstants.RE_IB1_SPECIAL_F5_F11_TOKEN) {
054            // F9-12
055            localF9 = (funcs & LnConstants.RE_IB1_F9_MASK) != 0;
056            localF10 = (funcs & LnConstants.RE_IB1_F10_MASK) != 0;
057            localF11 = (funcs & LnConstants.RE_IB1_F11_MASK) != 0;
058            notifySlotListeners();
059        } else if (token == LnConstants.RE_IB2_SPECIAL_F13_F19_TOKEN) {
060            // check F13-19
061            localF13 = (funcs & LnConstants.RE_IB2_F13_MASK) != 0;
062            localF14 = (funcs & LnConstants.RE_IB2_F14_MASK) != 0;
063            localF15 = (funcs & LnConstants.RE_IB2_F15_MASK) != 0;
064            localF16 = (funcs & LnConstants.RE_IB2_F16_MASK) != 0;
065            localF17 = (funcs & LnConstants.RE_IB2_F17_MASK) != 0;
066            localF18 = (funcs & LnConstants.RE_IB2_F18_MASK) != 0;
067            localF19 = (funcs & LnConstants.RE_IB2_F19_MASK) != 0;
068            notifySlotListeners();
069        } else if (token == LnConstants.RE_IB2_SPECIAL_F21_F27_TOKEN) {
070            // check F21-27
071            localF21 = (funcs & LnConstants.RE_IB2_F21_MASK) != 0;
072            localF22 = (funcs & LnConstants.RE_IB2_F22_MASK) != 0;
073            localF23 = (funcs & LnConstants.RE_IB2_F23_MASK) != 0;
074            localF24 = (funcs & LnConstants.RE_IB2_F24_MASK) != 0;
075            localF25 = (funcs & LnConstants.RE_IB2_F25_MASK) != 0;
076            localF26 = (funcs & LnConstants.RE_IB2_F26_MASK) != 0;
077            localF27 = (funcs & LnConstants.RE_IB2_F27_MASK) != 0;
078            notifySlotListeners();
079        } else if (token == LnConstants.RE_IB2_SPECIAL_F20_F28_TOKEN) {
080            // check F12, F20 and  F28
081            localF12 = (funcs & LnConstants.RE_IB2_SPECIAL_F12_MASK) != 0;
082            localF20 = (funcs & LnConstants.RE_IB2_SPECIAL_F20_MASK) != 0;
083            localF28 = (funcs & LnConstants.RE_IB2_SPECIAL_F28_MASK) != 0;
084            notifySlotListeners();
085        }
086    }
087
088}