001package jmri.jmrix.marklin;
002
003/**
004 * Constants to represent values seen in Marklin traffic.
005 * @see <a href="https://www.maerklin.de/fileadmin/media/produkte/CS2_can-protokoll_1-0.pdf">CS2 CAN Protocol 1.0</a>
006 * @see <a href="https://streaming.maerklin.de/public-media/cs2/cs2CAN-Protokoll-2_0.pdf">CS2 CAN Protocol 2.0</a>
007 * @author Kevin Dickerson Copyright (C) 2012
008 */
009public final class MarklinConstants {
010
011    // Utility class, only supplies static methods.
012    private MarklinConstants() {}
013
014    /* various bit masks */
015    // Priority 2+2bit
016    // Need to work these out correctly
017
018    /**
019     * Priority 1: Stop / go / short message
020     */
021    public static final int PRIO_1 = 0x00;
022
023    public static final int PRIO_2 = 0x01;  /* Priority 2: Feedback    */
024
025    public static final int PRIO_3 = 0x02;  /* Priority 3: Engine Stop    */
026
027    public static final int PRIO_4 = 0x03;  /* Priority 4: Engine / accessory command    */
028
029    // As of spec 2.0 - Commands
030
031    // System Commands
032    public static final int SYSCOMMANDNO = 1;
033    public static final int SYSCOMMANDSTART = 0x00;
034    public static final int SYSCOMMANDEND = 0x00;
035
036    // Management Commands
037    public static final int MANCOMMANDNO = 8;
038    public static final int MANCOMMANDSTART = 0x01;
039    public static final int MANCOMMANDEND = 0x0A;
040
041    // Accessory Commands
042    public static final int ACCCOMMANDNO = 2;
043    public static final int ACCCOMMANDSTART = 0x0B;
044    public static final int ACCCOMMANDEND = 0x0D;
045
046    // Software commands
047    public static final int SOFCOMMANDNO = 6;
048    public static final int SOFCOMMANDSTART = 0x18;
049    public static final int SOFCOMMANDEND = 0x1C;
050
051    // GUI Commands
052    public static final int GUICOMMANDNO = 3;
053    public static final int GUICOMMANDSTART = 0x20;
054    public static final int GUICOMMANDEND = 0x22;
055
056    // Automation Commnads
057    public static final int AUTCOMMANDSTART = 0x30;
058    public static final int AUTCOMMANDEND = 0xFF;
059
060    // Feedback Commands
061    public static final int FEECOMMANDSTART = 0x10;
062    public static final int FEECOMMANDEND = 0x12;
063
064    public static final int HASHBYTE1 = 0x47;
065    public static final int HASHBYTE2 = 0x11;
066
067    public static final int CMDSTOPSYS = 0x00;
068    public static final int CMDGOSYS = 0x01;
069    public static final int CMDHALTSYS = 0x02;
070
071    // Location within the UDP packet of the address bytes
072    public static final int CANADDRESSBYTE1 = 0x05;
073    public static final int CANADDRESSBYTE2 = 0x06;
074    public static final int CANADDRESSBYTE3 = 0x07;
075    public static final int CANADDRESSBYTE4 = 0x08;
076
077    public static final int PROTOCOL_UNKNOWN = 0x00;
078    public static final int PROTOCOL_DCC = 0x02;
079    public static final int PROTOCOL_SX = 0x04;
080    public static final int PROTOCOL_MM2 = 0x08;
081
082    // CAN ADDRESS Ranges, lower two bytes of the address, upper - 0x0000
083    // 0x03FF MM1, 2 locomotives and function decoder (20 & 40 kHz, 80 & 255 addresses)
084    public static final int MM1START = 0x0000;
085    public static final int MM1END = 0x03FF;
086
087    //Res. for MM1, 2 function decoder F1 - F4 (40 kHz, 80 & 255 addresses)
088    public static final int MM1FUNCTSTART = 0x1000;
089    public static final int MM1FUNCTEND = 0x13FF;
090
091    //Res. for MM1, 2 locomotive decoder (20 kHz, 80 & 256 addresses) for MM1
092    public static final int MM1LOCOSTART = 0x2000;
093    public static final int MM1LOCOEND = 0x23FF;
094
095    // SX1
096    public static final int SX1START = 0x0800;
097    public static final int SX1END = 0x0BFF;
098
099    // SX1 - accessories (extension)
100    public static final int SX1ACCSTART = 0x2800;
101    public static final int SX1ACCEND = 0x2BFF;
102
103    // MM1 2 accessories article decoder (40 kHz, 320 & 1024 addresses)
104    public static final int MM1ACCSTART = 0x3000;
105    public static final int MM1ACCEND = 0x33FF;
106
107    // DCC accessories article decoder (40 kHz, 320 & 1024 addresses)
108    public static final int DCCACCSTART = 0x3800;
109    public static final int DCCACCEND = 0x3FFF;
110
111    // MFX Decoders
112    public static final int MFXSTART = 0x4000;
113    public static final int MFXEND = 0x7FFF;
114
115    // Selectrix 2
116    public static final int SX2START = 0x8000;
117    public static final int SX2END = 0xBFFF;
118
119    // DCC locomotives
120    public static final int DCCSTART = 0xC000;
121    public static final int DCCEND = 0xFFFF;
122
123    /**
124     * These CAN bus ranges do not translate to track signals
125     * They are free for adressing equipment by 3rd parties,
126     * i.e. sending commands to accessory or providing firmware updates.
127     */
128    // Free for clubs and individuals
129    public static final int CLUBRANGESTART = 0x1800;
130    public static final int CLUBRANGEEND = 0x1BFF;
131    // Free for 3rd Party Vendors - Probably the range used by CdB products
132    public static final int VENDORRANGESTART = 0x1C00;
133    public static final int VENDORRANGEEND = 0x1FFF;
134
135
136
137
138    public static final int LOCOEMERGENCYSTOP = 0x03;
139    public static final int LOCOSPEED = 0x04;
140    public static final int LOCODIRECTION = 0x05;
141    public static final int LOCOFUNCTION = 0x06;
142
143    public static final int STEPSHORT28 = 0x00;
144    public static final int STEPSHORT14 = 0x01;
145    public static final int STEPSHORT128 = 0x02;
146    public static final int STEPLONG28 = 0x03;
147    public static final int STEPLONG128 = 0x04;
148
149    public static final int S88EVENT = 0x11;
150    public static final int MCAN_BROADCAST = 0x00000000;
151    public static final int MCAN_UNINITIALIZED = 0xFFFFFFFF;
152}