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 final static int SPROG = 0;
016    public final static 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     * Timeout for traffic controller to wait for reply from hardware.
053     * 
054     * Most replies are received from SPROG hardware with a few seconds, but
055     * paged mode programming operations can take considerably longer when
056     * reading a high value from a CV. Therefore we set a very long timeout,
057     * which should longer than the programmer timeout.
058     */
059    public static int TC_PROG_REPLY_TIMEOUT = 70*1000;
060    public static int TC_OPS_REPLY_TIMEOUT = 200;
061    public static int TC_BOOT_REPLY_TIMEOUT = 200;
062    
063    /* The following should be altered only if you know what you are doing */
064    /* How many times to repeat an accessory or function packet in the S queue */
065    public final static int S_REPEATS = 1;
066
067    /* How many times to repeat an ops mode programming packet */
068    public final static int OPS_REPEATS = 3;
069
070    /* Longest packet possible */
071    public final static int MAX_PACKET_LENGTH = 6;
072
073    /* Slot status */
074    public final static int SLOT_FREE = 0;
075    public final static int SLOT_IN_USE = 1;
076
077    /*
078     * Maximum number of slots for soft command station 
079     * 
080     * More slots allows more throttles to be opened but the refresh rate for
081     * each throttle will reduce.
082     * 
083     */
084    /* Default */
085    public final static int DEFAULT_MAX_SLOTS = 16;
086
087    /* Minimum number of slots */
088    public final static int MIN_SLOTS = 8;
089    
090    /* Maimum number of slots */
091    public final static int SLOTS_LIMIT = 64;
092    
093    /* Number of function buttons on a throttle */
094    public static int MAX_FUNCTIONS = 32; 
095    
096    /* various bit masks */
097    public final static int F8 = 0x100; /* Function 8 bit */
098
099    public final static int F7 = 0x80; /* Function 7 bit */
100
101    public final static int F6 = 0x40; /* Function 6 bit */
102
103    public final static int F5 = 0x20; /* Function 5 bit */
104
105    public final static int F4 = 0x10; /* Function 4 bit   */
106
107    public final static int F3 = 0x08; /* Function 3 bit   */
108
109    public final static int F2 = 0x04; /* Function 2 bit   */
110
111    public final static int F1 = 0x02; /* Function 1 bit   */
112
113    public final static int F0 = 0x01; /* Function 0 bit   */
114
115    /* Mode word bit masks */
116    public final static int UNLOCK_BIT = 0x0001;      /* Unlock bootloader */
117
118    public final static int CALC_BIT = 0x0008;        /* Add error byte */
119
120    public final static int POWER_BIT = 0x0010;       /* Track power */
121
122    public final static int ZTC_BIT = 0x0020;         /* Old ZTC bit timing */
123
124    public final static int BLUE_BIT = 0x0040;        /* Use direct byte for Blueline */
125
126    public final static int STEP_MASK = 0x0E00;       /* Mask for speed step bits */
127
128    public final static int STEP14_BIT = 0x0200;
129    public final static int STEP28_BIT = 0x0400;
130    public final static int STEP128_BIT = 0x0800;
131    public final static int LONG_ADD = 0x1000;
132
133    public final static int DEFAULT_I = 996;            /* milliAmps */
134
135    public final static int MAX_ACC_DECODER_JMRI_ADDR = 2044; // copied from DCCppConstants
136
137}