001package jmri.jmrix.powerline.insteon2412s;
002
003/**
004 * Constants and functions specific to the Insteon 2412S interface
005 *
006 * @author Bob Jacobsen Copyright (C) 2008, 2009
007 * @author Ken Cameron Copyright (C) 2010
008 */
009public class Constants {
010
011    public static final int HEAD_STX = 0x02;
012
013    public static final int POLL_REQ_STD = 0x50;
014    public static final int POLL_REQ_EXT = 0x51;
015    public static final int POLL_REQ_X10 = 0x52;
016    public static final int POLL_REQ_BUTTON = 0x54;
017    public static final int POLL_REQ_BUTTON_RESET = 0x55;
018    public static final int FUNCTION_REQ_STD = 0x62;
019    public static final int FUNCTION_REQ_X10 = 0x63;
020
021    public static final int CMD_LIGHT_ON_RAMP = 0x11;
022    public static final int CMD_LIGHT_ON_FAST = 0x12;
023    public static final int CMD_LIGHT_OFF_RAMP = 0x13;
024    public static final int CMD_LIGHT_OFF_FAST = 0x14;
025    public static final int CMD_LIGHT_CHG = 0x21;
026
027    public static final int BUTTON_TAP = 0x02;
028    public static final int BUTTON_HELD = 0x03;
029    public static final int BUTTON_REL = 0x04;
030    public static final int BUTTON_BITS_ID = 0xF0;
031    public static final int BUTTON_BITS_OP = 0x0F;
032
033    public static final int REPLY_ACK = 0x06;
034    public static final int REPLY_NAK = 0x15;
035
036    // flag values
037    public static final int FLAG_BIT_STDEXT = 0x10;
038    public static final int FLAG_STD = 0x00;
039    public static final int FLAG_EXT = 0x10;
040    public static final int FLAG_TYPE_P2P = 0x00;
041    public static final int FLAG_TYPE_ACK = 0x20;
042    public static final int FLAG_TYPE_NAK = 0xA0;
043    public static final int FLAG_TYPE_GBCAST = 0xC0;
044    public static final int FLAG_TYPE_GBCLEANUP = 0x40;
045    public static final int FLAG_TYPE_GBCLEANACK = 0x60;
046    public static final int FLAG_TYPE_GBCLEANNAK = 0xE0;
047
048    public static final int FLAG_BIT_X10_CMDUNIT = 0x80;
049    public static final int FLAG_X10_RECV_CMD = 0x80;
050    public static final int FLAG_X10_RECV_UNIT = 0x00;
051
052    public static final int FLAG_MASK_HOPSLEFT = 0x0C;
053    public static final int FLAG_SHIFT_HOPSLEFT = 2;
054    public static final int FLAG_MASK_MAXHOPS = 0x03;
055    public static final int FLAG_MAXHOPS_DEFAULT = 0x01;
056    public static final int FLAG_MASK_MSGTYPE = 0xE0;
057
058    /**
059     * Pretty-print a header code
060     * @param b header value
061     * @return  formated translation of header value
062     */
063    public static String formatHeaderByte(int b) {
064        return "Dim: " + ((b >> 3) & 0x1F)
065                + ((b & 0x02) != 0 ? " function" : " address ")
066                + ((b & 0x01) != 0 ? " extended" : " ");
067    }
068
069}