001package jmri.jmrix.lenz;
002
003/**
004 * Constants to represent values seen in XpressNet traffic.
005 * <p>
006 * Variable prefix abreviation keys: ACC_ is for accessory messages BC_ is for
007 * broadcast messages CS_ is for command station messages PROG_ is for
008 * programming related messages LOCO_ is for locomotive related commands
009 * OPS_MODE_ is for operations mode programming commands LI_ is for commands that
010 * are for messages to and from the computer interface LI101_ is for commands
011 * specific to the LI101.
012 * <p>
013 * A few variables don't have a prefix. The name should be self explanitory, but
014 * a prefix may be added later.
015 *
016 * @author Paul Bender Copyright (C) 2003-2009
017 */
018public final class XNetConstants {
019
020    private XNetConstants(){
021        // final class of static methods.
022    }
023
024    /* Commands send from the command station to the computer*/
025
026    /* Generic Information Messages */
027    public static final int CS_INFO = 0x61;
028
029    /* byte 2 commands for Information messages */
030
031    /* broadcast messages */
032    public static final int BC_NORMAL_OPERATIONS = 0x01; /* broadcast -normal
033     operations resumed */
034
035    public static final int BC_EVERYTHING_OFF = 0x00; /* broadcast emergency
036     off (short circuit) */
037
038    public static final int BC_SERVICE_MODE_ENTRY = 0x02;/* enter service mode */
039
040    /* program mode messages */
041    public static final int PROG_SHORT_CIRCUIT = 0x12; /* program mode short */
042
043    public static final int PROG_BYTE_NOT_FOUND = 0x13; /* requested data
044     byte not found */
045
046    public static final int PROG_CS_BUSY = 0x1f; /* command station busy */
047
048    public static final int PROG_CS_READY = 0x11; /* command station ready */
049
050    /* standard responses */
051    public static final int CS_TRANSFER_ERROR = 0x80; /* transfer error */
052
053    public static final int CS_BUSY = 0x81; /* command station busy */
054
055    public static final int CS_NOT_SUPPORTED = 0x82; /* command not supported */
056
057    /* double header errors. These are for Xnet V1 and V2 */
058    public static final int CS_DH_ERROR_NON_OP = 0x83; /* unit not operated by
059     controler */
060
061    public static final int CS_DH_ERROR_IN_USE = 0x84; /* one unit in DH
062     controled by another device */
063
064    public static final int CS_DH_ERROR_ALREADY_DH = 0x85; /* One locomotive in
065     Double header is already
066     in a Double Header */
067
068    public static final int CS_DH_ERROR_NONZERO_SPD = 0x86; /* One or both units
069     has a non-zero
070     speed setting */
071
072    /* Service mode and Informational responses from the command station */
073    public static final int CS_SERVICE_MODE_RESPONSE = 0x63;
074
075    /* service mode sub commands for byte 2 */
076    public static final int CS_SERVICE_DIRECT_RESPONSE = 0x14;  /* direct mode
077     response */
078
079    public static final int CS_SERVICE_REG_PAGE_RESPONSE = 0x10; /* Register and
080     paged mode response */
081
082    public static final int CS_SOFTWARE_VERSION = 0x21; /*software version
083     is included with
084     the 0x63 group.*/
085
086    /* informational request response */
087    public static final int CS_REQUEST_RESPONSE = 0x62;
088    /* information request response sub messages for byte 2 */
089    /* CS_SOFTWARE_VERSION (0x21) is a valid byte 2 command for 0x62 */
090    public static final int CS_STATUS_RESPONSE = 0x22; /* command station status */
091
092    /* Different Command Station Type values */
093    public static final int CS_TYPE_LZ100 = 0x00;  // Lenz LZ100/LZV100
094    public static final int CS_TYPE_LH200 = 0x01;  // Lenz LH200
095    public static final int CS_TYPE_COMPACT = 0x02; // Lenz Compact/Atlas Commander
096    public static final int CS_TYPE_LOKMAUSII = 0x04; // Roco LokMaus II
097    public static final int CS_TYPE_LDH35 = 0x07;   // LDH
098    public static final int CS_TYPE_MULTIMAUS = 0x10; // Roco multiMAUS
099    public static final int CS_TYPE_Z21 = 0x12; // Roco z21
100
101    /* Emergency Stop */
102    public static final int BC_EMERGENCY_STOP = 0x81;
103    /* byte 2 commands for Emergecy Stop messages */
104    public static final int BC_EVERYTHING_STOP = 0x00;   /* broadcast of
105     emergency stop */
106
107    /* Feedback - this is basically a bitmask.  The second nibble Indicates
108     how many address byte/data byte pairs follow the command */
109    public static final int BC_FEEDBACK = 0x40;
110
111    /* Accessory information response
112     * NOTE: This is identical to the feedback {@link BC_FEEDBACK} when
113     * there is only one address byte/data byte pair
114     */
115    public static final int ACC_INFO_RESPONSE = 0x42;
116
117    /* Locomotive Information for V1 & V2 */
118    public static final int LOCO_AVAILABLE_V1 = 0x83; /* for XNet V1 */
119
120    public static final int LOCO_NOT_AVAILABLE_V1 = 0xA3; /* for XNet V1 */
121
122    public static final int LOCO_AVAILABLE_V2 = 0x84; /* for XNet V2 */
123
124    public static final int LOCO_NOT_AVAILABLE_V2 = 0xA4; /* for XNet V2 */
125
126    /* Locomotive Information for V3
127     NOTE: for version 3.6, 0xE4 and 0xE3 are used to send information
128     about functions 13-28 */
129    public static final int LOCO_INFO_NORMAL_UNIT = 0xE4;
130    public static final int LOCO_INFO_MUED_UNIT = 0xE5;
131    public static final int LOCO_INFO_MU_ADDRESS = 0xE2;
132    public static final int LOCO_INFO_DH_UNIT = 0xE6;
133    public static final int LOCO_INFO_RESPONSE = 0xE3;
134
135    /* response types for LOCO_INFO_RESPONSE (byte two commands */
136    public static final int LOCO_NOT_AVAILABLE = 0x40;
137    public static final int LOCO_FUNCTION_STATUS = 0x50;
138    public static final int LOCO_FUNCTION_STATUS_HIGH = 0x52; // for F13-F28
139    public static final int LOCO_FUNCTION_STATUS_HIGH_MOM = 0x51; // for F13-F28
140
141    /* responses for stack/database searches */
142    public static final int LOCO_SEARCH_RESPONSE_N = 0x30; /*Normal Loco */
143
144    public static final int LOCO_SEARCH_RESPONSE_DH = 0x31; /* in DH */
145
146    public static final int LOCO_SEARCH_RESPONSE_MU_BASE = 0x32; /*MU base address */
147
148    public static final int LOCO_SEARCH_RESPONSE_MU = 0x33; /* MUED Loco */
149
150    public static final int LOCO_SEARCH_NO_RESULT = 0x34; /* No address found */
151
152    /* Double Header Info for XNet V1 and V2 */
153    public static final int LOCO_DH_INFO_V1 = 0xC5; /* Byte 1 for XNET V1 */
154
155    public static final int LOCO_DH_INFO_V2 = 0xC6; /* Byte 1 for XNET V2 */
156
157    /* byte 2 DH information for either V1 or V2 */
158    public static final int LOCO_DH_AVAILABLE = 0x04;
159    public static final int LOCO_DH_NOT_AVAILABLE = 0x05;
160
161    /* XpressNet MU or DH Error Message */
162    public static final int LOCO_MU_DH_ERROR = 0xE1;
163
164    /* Commands send from the computer to the command station */
165
166    /* Generic command station requests - used for*/
167    public static final int CS_REQUEST = 0x21;
168
169    /* sub operations for generic request  this is the second byte of
170     the message */
171    public static final int EMERGENCY_OFF = 0x80;
172    public static final int RESUME_OPS = 0x81;
173    public static final int SERVICE_MODE_CSRESULT = 0x10;
174    public static final int CS_VERSION = 0x21;
175    public static final int CS_STATUS = 0x24;
176
177    /* the following sets the Command station Power up mode, it's
178     used as the first two bytes of the command */
179    public static final int CS_SET_POWERMODE = 0x22;
180
181    /* the third byte of the Power up mode is set for either Auto or Manual
182     startup */
183    public static final int CS_POWERMODE_AUTO = 0x04;
184    public static final int CS_POWERMODE_MANUAL = 0x00;
185
186
187    /* Emergency Stop */
188    public static final int ALL_ESTOP = 0x80;
189
190    /* this is for a single locomotive.  With version 3 of expressnet, this is
191     followed with a two byte address.  For version 2, this should be followed
192     by a 1 byte address */
193    public static final int EMERGENCY_STOP_XNETV1V2 = 0x91;
194    public static final int EMERGENCY_STOP = 0x92;
195
196    /* Program mode read requests */
197    public static final int PROG_READ_REQUEST = 0x22;
198
199    /* programming modes to be used with PROG_READ_REQUEST */
200    public static final int PROG_READ_MODE_REGISTER = 0x11;
201    public static final int PROG_READ_MODE_CV = 0x15;
202    public static final int PROG_READ_MODE_PAGED = 0x14;
203    public static final int PROG_READ_MODE_CV_V36 = 0x18; // version 3.6 read
204
205    /* Program mode read requests */
206    public static final int PROG_WRITE_REQUEST = 0x23;
207
208    /* programming modes to be used with PROG_WRITE_REQUEST */
209    public static final int PROG_WRITE_MODE_REGISTER = 0x12;
210    public static final int PROG_WRITE_MODE_CV = 0x16;
211    public static final int PROG_WRITE_MODE_PAGED = 0x17;
212    public static final int PROG_WRITE_MODE_CV_V36 = 0x1c; // version 3.6 write
213
214    /* Accessory Decoder Info Request */
215    public static final int ACC_INFO_REQ = 0x42;
216
217    /* Accessory Decoder Operation Request */
218    public static final int ACC_OPER_REQ = 0x52;
219
220    /* Locomotive Information Request */
221    public static final int LOCO_INFO_REQ_V1 = 0xA1; /* for version 1 of XNet
222     Follow imediatly with address*/
223
224    public static final int LOCO_INFO_REQ_V2 = 0xA2; /* for version 1 or 2 of
225     XNet.
226     folow with address and
227     Mode Selection bytes */
228    /* V3 Status requests */
229
230    public static final int LOCO_STATUS_REQ = 0xE3;
231
232    /* Status request subcodes for V3 */
233    public static final int LOCO_INFO_REQ_V3 = 0x00; /* for XNet V3, follow
234     with 2 byte address */
235
236    public static final int LOCO_INFO_REQ_FUNC = 0x07; /* momentary/constatant
237     function status request */
238
239    public static final int LOCO_INFO_REQ_FUNC_HI_ON = 0x09; /* ON/OFF
240     function status request
241     for Functions 13-28*/
242
243    public static final int LOCO_INFO_REQ_FUNC_HI_MOM = 0x08; /* momentary/constatant
244     function status request
245     for Functions 13-28*/
246
247    public static final int LOCO_STACK_SEARCH_FWD = 0x05; /* search forward in
248     the command station stack for this unit */
249
250    public static final int LOCO_STACK_SEARCH_BKWD = 0x06; /* search backward in
251     the command station stack for this unit */
252
253    public static final int LOCO_STACK_DELETE = 0x44; /* Delete a unit from
254     the command station stack */
255
256    /* Locomotive Operations for XNet  (see XNet docs for more info */
257    public static final int LOCO_OPER_REQ_V1 = 0xB3;  /* for XNet V1 */
258
259    public static final int LOCO_OPER_REQ_V2 = 0xB4;  /* for XNet V2 */
260
261    /* Locomotive Operations for XNet V3 */
262    public static final int LOCO_OPER_REQ = 0xE4;
263
264    /* XNet V3 operations subcommands */
265    public static final int LOCO_SPEED_14 = 0x10; /* speed and direction 14
266     speed steps */
267
268    public static final int LOCO_SPEED_27 = 0x11; /* speed and direction 27
269     speed steps */
270
271    public static final int LOCO_SPEED_28 = 0x12; /* speed and direction 28
272     speed steps */
273
274    public static final int LOCO_SPEED_128 = 0x13; /* speed and direction 128
275     speed steps */
276
277    public static final int LOCO_SET_FUNC_GROUP1 = 0x20; /* set functions F0-F4*/
278
279    public static final int LOCO_SET_FUNC_GROUP2 = 0x21; /* set functions F5-F8*/
280
281    public static final int LOCO_SET_FUNC_GROUP3 = 0x22; /* set functions F9-F12*/
282
283    public static final int LOCO_SET_FUNC_GROUP4 = 0x23; /* set functions F13-F20*/
284
285    public static final int LOCO_SET_FUNC_GROUP5 = 0x28; /* set functions F21-F28*/
286
287    public static final int LOCO_SET_FUNC_GROUP6 = 0x29; /* set functions F29-36*/
288
289    public static final int LOCO_SET_FUNC_GROUP7 = 0x2A; /* set functions F37-44*/
290
291    public static final int LOCO_SET_FUNC_GROUP8 = 0x2B; /* set functions F45-52*/
292
293    public static final int LOCO_SET_FUNC_GROUP9 = 0x50; /* set functions F53-60*/
294
295    public static final int LOCO_SET_FUNC_GROUP10= 0x51; /* set functions F61-68*/
296
297    /* these set momentary status for functions with 0xE4 as the opcode*/
298    public static final int LOCO_SET_FUNC_GROUP1_MOMENTARY = 0x24; /* set functions F0-F4*/
299
300    public static final int LOCO_SET_FUNC_GROUP2_MOMENTARY = 0x25; /* set functions F5-F8*/
301
302    public static final int LOCO_SET_FUNC_GROUP3_MOMENTARY = 0x26; /* set functions F9-F12*/
303
304    public static final int LOCO_SET_FUNC_GROUP4_MOMENTARY = 0x27; /* set functions F13-F20*/
305
306    public static final int LOCO_SET_FUNC_GROUP5_MOMENTARY = 0x2C; /* set functions F21-F28*/
307
308    public static final int LOCO_SET_FUNC_GROUP6_MOMENTARY = 0x2D; /* set functions F29-36*/
309
310    public static final int LOCO_SET_FUNC_GROUP7_MOMENTARY = 0x2E; /* set functions F37-44*/
311
312    public static final int LOCO_SET_FUNC_GROUP8_MOMENTARY = 0x52; /* set functions F45-52*/
313
314    public static final int LOCO_SET_FUNC_GROUP9_MOMENTARY = 0x53; /* set functions F53-60*/
315
316    public static final int LOCO_SET_FUNC_GROUP10_MOMENTARY= 0x54; /* set functions F61-68*/
317
318    /* add a unit to a multi-unit set opcode requires addition of the
319     direction relative to the lead unit as the least significant bit
320     This is followed by the 2 byte unit address of the unit, and the 1
321     byte consist address */
322    public static final int LOCO_ADD_MULTI_UNIT_REQ = 0x40;
323
324    /* remove a unit from a multi-unit set This is followed by the 2
325     byte unit address of the unit, and the 1 byte consist address */
326    public static final int LOCO_REM_MULTI_UNIT_REQ = 0x42;
327
328    /* find out if a unit is part of a specifc multi-unit set These are
329     followed by the 1 byte consist address, and the 2 byte consist
330     address (Forward and Backward refer to search direction) */
331    public static final int LOCO_IN_MULTI_UNIT_SEARCH_REQ = 0xE4; //This is the opcode
332
333    /* These are byte 2 of the message */
334    public static final int LOCO_IN_MULTI_UNIT_REQ_FORWARD = 0x01;
335    public static final int LOCO_IN_MULTI_UNIT_REQ_BACKWARD = 0x02;
336
337    /* double headers for XNet V1 and V2 */
338    public static final int LOCO_DOUBLEHEAD_V1 = 0xC3;
339    /*subcommands for establishing/Disolving DH in V1 and V2 */
340    public static final int LOCO_ESTABLISH_DH_V1 = 0x05;
341    public static final int LOCO_DISOLVE_DH_V1 = 0x04;
342
343    /* double headers for XNet V3.  In V3, there is only one command.
344     The third and 4th bytes are the locomotive address of the lead unit,
345     the locomotive to add to the consist is the 5th and 6th byte.  To
346     Disolve the double header, use 00 for both bytes of the second address */
347    public static final int LOCO_DOUBLEHEAD = 0xE5;
348    public static final int LOCO_DOUBLEHEAD_BYTE2 = 0x43;
349
350    /* Operations mode programming */
351    public static final int OPS_MODE_PROG_REQ = 0xE6;
352
353    /* Write requests (second byte for above) */
354    public static final int OPS_MODE_PROG_WRITE_REQ = 0x30;
355
356    /* Address inquiry Multi Unit Request
357     this is used to find the next Multi Unit address known to the
358     command station.  FWD and BKWD refer to search direction */
359    public static final int CS_MULTI_UNIT_REQ = 0xE2;  // This is the OpCode
360/* These are byte 2 of the message */
361    public static final int CS_MULTI_UNIT_REQ_FWD = 0x03;
362    public static final int CS_MULTI_UNIT_REQ_BKWD = 0x04;
363
364    /* The following are for information requests from the LI100/LI100F/LI101*/
365
366    /* LI10x responses for general messages */
367    public static final int LI_MESSAGE_RESPONSE_HEADER = 0x01;
368    /* First, we have an error for timeouts between the PC and the LI10x */
369    public static final int LI_MESSAGE_RESPONSE_PC_DATA_ERROR = 0x01;
370    /* Second, we have an error for timeouts between the LI10x and the C.S.*/
371    public static final int LI_MESSAGE_RESPONSE_CS_DATA_ERROR = 0x02;
372    /* Next is an unknown communications error */
373    public static final int LI_MESSAGE_RESPONSE_UNKNOWN_DATA_ERROR = 0x03;
374    /* Now, we have a response indicating what was sent was OK */
375    public static final int LI_MESSAGE_RESPONSE_SEND_SUCCESS = 0x04;
376    /* and a message indicating the LI10x doesn't have a timeslot on the
377     XpressNet (possibly too many devices connected) */
378    public static final int LI_MESSAGE_RESPONSE_TIMESLOT_ERROR = 0x05;
379    /* Last, there is an error for an LI10x buffer overflow */
380    public static final int LI_MESSAGE_RESPONSE_BUFFER_OVERFLOW = 0x06;
381
382    /* LI100/LI100F/LI101 information (version) request */
383    public static final int LI_VERSION_REQUEST = 0xF0;
384    /* The response to the above */
385    public static final int LI_VERSION_RESPONSE = 0x02;
386
387    /* request to the LI101 */
388    public static final int LI101_REQUEST = 0xF2;
389    /* The following are the two possible values for the second byte of a
390     request to the LI101 */
391    public static final int LI101_REQUEST_ADDRESS = 0x01;
392    public static final int LI101_REQUEST_BAUD = 0x02;
393
394    /* The following are error messages sent by the LIUSB (version 3.6) */
395    public static final int LIUSB_TIMESLOT_RESTORED = 0x07;
396    public static final int LIUSB_REQUEST_SENT_WHILE_NO_TIMESLOT = 0x08;
397    public static final int LIUSB_BAD_DATA_IN_REQUEST = 0x09;
398    public static final int LIUSB_RETRANSMIT_REQUEST = 0x0A;
399
400}