001package jmri.jmrix.sprog;
002
003/**
004 * Constants to represent values seen in SPROG traffic.
005 *
006 * @author Andrew Crosland Copyright (C) 2006 from LnConstants.java
007 */
008
009public final class SprogConstants {
010
011    // prevent new instance, Class supplies static constants.
012    private SprogConstants(){}
013
014    /* SPROG mode */
015    public static final int SPROG = 0;
016    public static final int SPROG_CS = 1;
017
018    // Current SPROG state
019    public enum SprogState {
020
021        NORMAL, SIIBOOTMODE, V4BOOTMODE
022    }
023
024    public enum SprogMode {
025
026        SERVICE, OPS
027    }
028
029    /* The following parameters may be overridden by scripts if the user desires */
030    /**
031     * Threshold to warn of long delays between DCC packets to the rails.
032     * 
033     * Worst case DCC packet transmission time is ~10 ms, which equates to 100
034     * packets/s. Wait for a somewhat arbitrary time before reporting a possible
035     * issue with the system performance. A delay of 50 ms equates to 20 packets/s
036     * if sustained.
037     * 
038     * Slower systems such as Raspberry Pi with flash based file systems are
039     * more likely to exhibit longer delays between packets.
040     */
041    public static int PACKET_DELAY_WARN_THRESHOLD = 50;
042
043    /**
044     * Timeout for command station to wait for reply from hardware.
045     * 
046     * Slower systems such as Raspberry Pi with flash based file systems are more
047     * likely to exhibit longer delays.
048     */
049    public static int CS_REPLY_TIMEOUT = 2500;
050
051    /**
052     * Number of consecutive reply timeouts before the command station
053     * shuts down track power.
054     * <p>
055     * A single timeout can occur when the JVM is temporarily busy (e.g.
056     * garbage collection or Swing rendering). Requiring multiple consecutive
057     * timeouts before taking the drastic step of removing power avoids
058     * false-positive shutdowns on slower systems.
059     */
060    public static int CS_MAX_TIMEOUT_COUNT = 3;
061
062    /**
063     * Timeout for traffic controller to wait for reply from hardware.
064     * 
065     * Most replies are received from SPROG hardware with a few seconds, but
066     * paged mode programming operations can take considerably longer when
067     * reading a high value from a CV. Therefore we set a very long timeout,
068     * which should longer than the programmer timeout.
069     */
070    public static int TC_PROG_REPLY_TIMEOUT = 70*1000;
071    public static int TC_OPS_REPLY_TIMEOUT = 200;
072    public static int TC_BOOT_REPLY_TIMEOUT = 200;
073    
074    /* The following should be altered only if you know what you are doing */
075    /* How many times to repeat an accessory or function packet in the S queue */
076    public static final int S_REPEATS = 1;
077
078    /* How many times to repeat an ops mode programming packet */
079    public static final int OPS_REPEATS = 3;
080
081    /* Longest packet possible */
082    public static final int MAX_PACKET_LENGTH = 6;
083
084    /* Slot status */
085    public static final int SLOT_FREE = 0;
086    public static final int SLOT_IN_USE = 1;
087
088    /*
089     * Maximum number of slots for soft command station 
090     * 
091     * More slots allows more throttles to be opened but the refresh rate for
092     * each throttle will reduce.
093     * 
094     */
095    /* Default */
096    public static final int DEFAULT_MAX_SLOTS = 16;
097
098    /* Minimum number of slots */
099    public static final int MIN_SLOTS = 8;
100    
101    /* Maimum number of slots */
102    public static final int SLOTS_LIMIT = 64;
103    
104    /* Number of function buttons on a throttle */
105    public static int MAX_FUNCTIONS = 32; 
106    
107    /* various bit masks */
108    public static final int F8 = 0x100; /* Function 8 bit */
109
110    public static final int F7 = 0x80; /* Function 7 bit */
111
112    public static final int F6 = 0x40; /* Function 6 bit */
113
114    public static final int F5 = 0x20; /* Function 5 bit */
115
116    public static final int F4 = 0x10; /* Function 4 bit   */
117
118    public static final int F3 = 0x08; /* Function 3 bit   */
119
120    public static final int F2 = 0x04; /* Function 2 bit   */
121
122    public static final int F1 = 0x02; /* Function 1 bit   */
123
124    public static final int F0 = 0x01; /* Function 0 bit   */
125
126    /* Mode word bit masks */
127    public static final int UNLOCK_BIT = 0x0001;      /* Unlock bootloader */
128
129    public static final int CALC_BIT = 0x0008;        /* Add error byte */
130
131    public static final int POWER_BIT = 0x0010;       /* Track power */
132
133    public static final int ZTC_BIT = 0x0020;         /* Old ZTC bit timing */
134
135    public static final int BLUE_BIT = 0x0040;        /* Use direct byte for Blueline */
136
137    public static final int STEP_MASK = 0x0E00;       /* Mask for speed step bits */
138
139    public static final int STEP14_BIT = 0x0200;
140    public static final int STEP28_BIT = 0x0400;
141    public static final int STEP128_BIT = 0x0800;
142    public static final int LONG_ADD = 0x1000;
143
144    public static final int DEFAULT_I = 996;            /* milliAmps */
145
146    public static final int MAX_ACC_DECODER_JMRI_ADDR = 2044; // copied from DCCppConstants
147
148}