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