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 OPS_MODE_CSRESULT = 0x27;
175    public static final int CS_VERSION = 0x21;
176    public static final int CS_STATUS = 0x24;
177
178    /* the following sets the Command station Power up mode, it's
179     used as the first two bytes of the command */
180    public static final int CS_SET_POWERMODE = 0x22;
181
182    /* the third byte of the Power up mode is set for either Auto or Manual
183     startup */
184    public static final int CS_POWERMODE_AUTO = 0x04;
185    public static final int CS_POWERMODE_MANUAL = 0x00;
186
187
188    /* Emergency Stop */
189    public static final int ALL_ESTOP = 0x80;
190
191    /* this is for a single locomotive.  With version 3 of expressnet, this is
192     followed with a two byte address.  For version 2, this should be followed
193     by a 1 byte address */
194    public static final int EMERGENCY_STOP_XNETV1V2 = 0x91;
195    public static final int EMERGENCY_STOP = 0x92;
196
197    /* Program mode read requests */
198    public static final int PROG_READ_REQUEST = 0x22;
199
200    /* programming modes to be used with PROG_READ_REQUEST */
201    public static final int PROG_READ_MODE_REGISTER = 0x11;
202    public static final int PROG_READ_MODE_CV = 0x15;
203    public static final int PROG_READ_MODE_PAGED = 0x14;
204    public static final int PROG_READ_MODE_CV_V36 = 0x18; // version 3.6 read
205
206    /* Program mode write requests */
207    public static final int PROG_WRITE_REQUEST = 0x23;
208
209    /* programming modes to be used with PROG_WRITE_REQUEST */
210    public static final int PROG_WRITE_MODE_REGISTER = 0x12;
211    public static final int PROG_WRITE_MODE_CV = 0x16;
212    public static final int PROG_WRITE_MODE_PAGED = 0x17;
213    public static final int PROG_WRITE_MODE_CV_V36 = 0x1c; // version 3.6 write
214
215    /* Accessory Decoder Info Request */
216    public static final int ACC_INFO_REQ = 0x42;
217
218    /* Accessory Decoder Operation Request */
219    public static final int ACC_OPER_REQ = 0x52;
220
221    /* Locomotive Information Request */
222    public static final int LOCO_INFO_REQ_V1 = 0xA1; /* for version 1 of XNet
223     Follow imediatly with address*/
224
225    public static final int LOCO_INFO_REQ_V2 = 0xA2; /* for version 1 or 2 of
226     XNet.
227     folow with address and
228     Mode Selection bytes */
229    /* V3 Status requests */
230
231    public static final int LOCO_STATUS_REQ = 0xE3;
232
233    /* Status request subcodes for V3 */
234    public static final int LOCO_INFO_REQ_V3 = 0x00; /* for XNet V3, follow
235     with 2 byte address */
236
237    public static final int LOCO_INFO_REQ_FUNC = 0x07; /* momentary/constatant
238     function status request */
239
240    public static final int LOCO_INFO_REQ_FUNC_HI_ON = 0x09; /* ON/OFF
241     function status request
242     for Functions 13-28*/
243
244    public static final int LOCO_INFO_REQ_FUNC_HI_MOM = 0x08; /* momentary/constatant
245     function status request
246     for Functions 13-28*/
247
248    public static final int LOCO_STACK_SEARCH_FWD = 0x05; /* search forward in
249     the command station stack for this unit */
250
251    public static final int LOCO_STACK_SEARCH_BKWD = 0x06; /* search backward in
252     the command station stack for this unit */
253
254    public static final int LOCO_STACK_DELETE = 0x44; /* Delete a unit from
255     the command station stack */
256
257    /* Locomotive Operations for XNet  (see XNet docs for more info */
258    public static final int LOCO_OPER_REQ_V1 = 0xB3;  /* for XNet V1 */
259
260    public static final int LOCO_OPER_REQ_V2 = 0xB4;  /* for XNet V2 */
261
262    /* Locomotive Operations for XNet V3 */
263    public static final int LOCO_OPER_REQ = 0xE4;
264
265    /* XNet V3 operations subcommands */
266    public static final int LOCO_SPEED_14 = 0x10; /* speed and direction 14
267     speed steps */
268
269    public static final int LOCO_SPEED_27 = 0x11; /* speed and direction 27
270     speed steps */
271
272    public static final int LOCO_SPEED_28 = 0x12; /* speed and direction 28
273     speed steps */
274
275    public static final int LOCO_SPEED_128 = 0x13; /* speed and direction 128
276     speed steps */
277
278    public static final int LOCO_SET_FUNC_GROUP1 = 0x20; /* set functions F0-F4*/
279
280    public static final int LOCO_SET_FUNC_GROUP2 = 0x21; /* set functions F5-F8*/
281
282    public static final int LOCO_SET_FUNC_GROUP3 = 0x22; /* set functions F9-F12*/
283
284    public static final int LOCO_SET_FUNC_GROUP4 = 0x23; /* set functions F13-F20*/
285
286    public static final int LOCO_SET_FUNC_GROUP5 = 0x28; /* set functions F21-F28*/
287
288    public static final int LOCO_SET_FUNC_GROUP6 = 0x29; /* set functions F29-36*/
289
290    public static final int LOCO_SET_FUNC_GROUP7 = 0x2A; /* set functions F37-44*/
291
292    public static final int LOCO_SET_FUNC_GROUP8 = 0x2B; /* set functions F45-52*/
293
294    public static final int LOCO_SET_FUNC_GROUP9 = 0x50; /* set functions F53-60*/
295
296    public static final int LOCO_SET_FUNC_GROUP10 = 0x51; /* set functions F61-68*/
297
298    /* these set momentary status for functions with 0xE4 as the opcode*/
299    public static final int LOCO_SET_FUNC_GROUP1_MOMENTARY = 0x24; /* set functions F0-F4*/
300
301    public static final int LOCO_SET_FUNC_GROUP2_MOMENTARY = 0x25; /* set functions F5-F8*/
302
303    public static final int LOCO_SET_FUNC_GROUP3_MOMENTARY = 0x26; /* set functions F9-F12*/
304
305    public static final int LOCO_SET_FUNC_GROUP4_MOMENTARY = 0x27; /* set functions F13-F20*/
306
307    public static final int LOCO_SET_FUNC_GROUP5_MOMENTARY = 0x2C; /* set functions F21-F28*/
308
309    public static final int LOCO_SET_FUNC_GROUP6_MOMENTARY = 0x2D; /* set functions F29-36*/
310
311    public static final int LOCO_SET_FUNC_GROUP7_MOMENTARY = 0x2E; /* set functions F37-44*/
312
313    public static final int LOCO_SET_FUNC_GROUP8_MOMENTARY = 0x52; /* set functions F45-52*/
314
315    public static final int LOCO_SET_FUNC_GROUP9_MOMENTARY = 0x53; /* set functions F53-60*/
316
317    public static final int LOCO_SET_FUNC_GROUP10_MOMENTARY = 0x54; /* set functions F61-68*/
318
319    /* add a unit to a multi-unit set opcode requires addition of the
320     direction relative to the lead unit as the least significant bit
321     This is followed by the 2 byte unit address of the unit, and the 1
322     byte consist address */
323    public static final int LOCO_ADD_MULTI_UNIT_REQ = 0x40;
324
325    /* remove a unit from a multi-unit set This is followed by the 2
326     byte unit address of the unit, and the 1 byte consist address */
327    public static final int LOCO_REM_MULTI_UNIT_REQ = 0x42;
328
329    /* find out if a unit is part of a specifc multi-unit set These are
330     followed by the 1 byte consist address, and the 2 byte consist
331     address (Forward and Backward refer to search direction) */
332    public static final int LOCO_IN_MULTI_UNIT_SEARCH_REQ = 0xE4; //This is the opcode
333
334    /* These are byte 2 of the message */
335    public static final int LOCO_IN_MULTI_UNIT_REQ_FORWARD = 0x01;
336    public static final int LOCO_IN_MULTI_UNIT_REQ_BACKWARD = 0x02;
337
338    /* double headers for XNet V1 and V2 */
339    public static final int LOCO_DOUBLEHEAD_V1 = 0xC3;
340    /*subcommands for establishing/Disolving DH in V1 and V2 */
341    public static final int LOCO_ESTABLISH_DH_V1 = 0x05;
342    public static final int LOCO_DISOLVE_DH_V1 = 0x04;
343
344    /* double headers for XNet V3.  In V3, there is only one command.
345     The third and 4th bytes are the locomotive address of the lead unit,
346     the locomotive to add to the consist is the 5th and 6th byte.  To
347     Disolve the double header, use 00 for both bytes of the second address */
348    public static final int LOCO_DOUBLEHEAD = 0xE5;
349    public static final int LOCO_DOUBLEHEAD_BYTE2 = 0x43;
350
351    /* Operations mode programming */
352    public static final int OPS_MODE_PROG_REQ = 0xE6;
353
354    /* Read requests (second byte for above) */
355    public static final int OPS_MODE_PROG_READ_REQ = 0x30;
356
357    /* Write requests (second byte for above) */
358    public static final int OPS_MODE_PROG_WRITE_REQ = 0x30;
359
360    /* Address inquiry Multi Unit Request
361     this is used to find the next Multi Unit address known to the
362     command station.  FWD and BKWD refer to search direction */
363    public static final int CS_MULTI_UNIT_REQ = 0xE2;  // This is the OpCode
364    /* These are byte 2 of the message */
365    public static final int CS_MULTI_UNIT_REQ_FWD = 0x03;
366    public static final int CS_MULTI_UNIT_REQ_BKWD = 0x04;
367
368    /* The following are for information requests from the LI100/LI100F/LI101*/
369
370    /* LI10x responses for general messages */
371    public static final int LI_MESSAGE_RESPONSE_HEADER = 0x01;
372    /* First, we have an error for timeouts between the PC and the LI10x */
373    public static final int LI_MESSAGE_RESPONSE_PC_DATA_ERROR = 0x01;
374    /* Second, we have an error for timeouts between the LI10x and the C.S.*/
375    public static final int LI_MESSAGE_RESPONSE_CS_DATA_ERROR = 0x02;
376    /* Next is an unknown communications error */
377    public static final int LI_MESSAGE_RESPONSE_UNKNOWN_DATA_ERROR = 0x03;
378    /* Now, we have a response indicating what was sent was OK */
379    public static final int LI_MESSAGE_RESPONSE_SEND_SUCCESS = 0x04;
380    /* and a message indicating the LI10x doesn't have a timeslot on the
381     XpressNet (possibly too many devices connected) */
382    public static final int LI_MESSAGE_RESPONSE_TIMESLOT_ERROR = 0x05;
383    /* Last, there is an error for an LI10x buffer overflow */
384    public static final int LI_MESSAGE_RESPONSE_BUFFER_OVERFLOW = 0x06;
385
386    /* LI100/LI100F/LI101 information (version) request */
387    public static final int LI_VERSION_REQUEST = 0xF0;
388    /* The response to the above */
389    public static final int LI_VERSION_RESPONSE = 0x02;
390
391    /* request to the LI101 */
392    public static final int LI101_REQUEST = 0xF2;
393    /* The following are the two possible values for the second byte of a
394     request to the LI101 */
395    public static final int LI101_REQUEST_ADDRESS = 0x01;
396    public static final int LI101_REQUEST_BAUD = 0x02;
397
398    /* The following are error messages sent by the LIUSB (version 3.6) */
399    public static final int LIUSB_TIMESLOT_RESTORED = 0x07;
400    public static final int LIUSB_REQUEST_SENT_WHILE_NO_TIMESLOT = 0x08;
401    public static final int LIUSB_BAD_DATA_IN_REQUEST = 0x09;
402    public static final int LIUSB_RETRANSMIT_REQUEST = 0x0A;
403
404    /* Information response from the Command Station - V3.8 or above */
405    public static final int CS_ADVANCED_INFO_RESPONSE = 0x64; // opcode
406    /* specific responses for the above */
407    public static final int POM_RESULTS = 0x24;
408    public static final int MODEL_TIME = 0x25;
409
410}