Пример #1
0
        // speed < 0 => emergency-stop
        // speed = 0 => brake
        // speed = 1...28 => normal speed
        public static DCCCommand LocoSpeed28(LocomotiveAddress address, int speed, bool forward)
        {
            // 01DCSSSS
            // CV29bit1=1 => 28 steps, C is intermediate speed bit, least significant bit
            // FL is controlled by LocoFunctionGroup1, bit C
            /*
            SSSSC  Speed parameter
            -----|---------------
             0  00000   0 - Stop-brake
             1  00001   0 - Stop-brake Direction bit may be ignored for directional sensitive functions. (Optional)
             2  00010   <0 - Emergency-Stop
             3  00011   <0 - Emergency-Stop, Direction bit may be ignored for directional sensitive functions. (Optional)
             4  00100   1
             5  00101   2
             6  00110   3
             7  00111   4
            ............
            30  11110   27
            31  11111   28
            */

            int ssssc = 0;
            if (speed < 0)
                ssssc = 2; // 2 or 3
            else if (speed == 0)
                ssssc = 0; // 0 or 1
            else if (speed > 0 && speed <= 28)
                ssssc = speed + 3;
            else if (speed > 28)
                ssssc = 31;

            ArrayList list = new ArrayList();
            foreach (byte b in address.GetBytes())
                list.Add(b);

            byte c = (byte)((ssssc & 0x01) << 4);	 // 000C0000
            byte ssss = (byte)((ssssc & 0x1E) >> 1); // 0000SSSS
            list.Add((byte)(
                (ssss | c) | // 000CSSSS
                (forward ? DCC.SpeedForward : DCC.SpeedReverse) // 01DCSSSS
                ));

            return new DCCCommand(DCCCommandPriority.Normal, DCCCommandType.Speed, list);
        }
Пример #2
0
        // speed < 0 => emergency-stop
        // speed = 0 => brake
        // speed = 1...126 => normal speed
        public static DCCCommand LocoSpeed128(LocomotiveAddress address, int speed, bool forward)
        {
            // through NMRA.AdvancedOperation => 00100000
            // 001CCCCC DSSSSSSS;
            // CCCCC = 11111 => 128 speed steps
            // FL is controlled by LocoFunctionGroup1, bit C
            /*
            SSSSSSS| Speed parameter
            -------|---------------
             0  0000000 0 - Stop-brake
             1  0000001 <0 - Emergency-Stop
             2  0000010 1
             3  0000011 2
             4  0000100 3
             5  0000101 4
            ............
               126  1111110 125
               127  1111111 126
            */

            int sssssss = 0;
            if (speed < 0)
                sssssss = 1;
            else if (speed == 0)
                sssssss = 0;
            else if (speed >= 1 && speed <= 126)
                sssssss = speed + 1;
            else if (speed > 126)
                sssssss = 127;

            ArrayList list = new ArrayList();
            foreach (byte b in address.GetBytes())
                list.Add(b);
            list.Add((byte)(DCC.AdvancedOperation | 0x1F)); // 00111111
            list.Add((byte)(
                (sssssss & 0x7F) | // 0SSSSSSS
                (forward ? 0x80 : 0x00) // DSSSSSSS
                ));

            return new DCCCommand(DCCCommandPriority.Normal, DCCCommandType.Speed, list);
        }
Пример #3
0
        // speed < 0 => emergency-stop
        // speed = 0 => brake
        // speed = 1...14 => normal speed
        public static DCCCommand LocoSpeed14(LocomotiveAddress address, int speed, bool forward, bool light)
        {
            // 01DCSSSS
            // CV29 bit1=0 => 14 steps (older compartible), C is used for headlight
            /*
            SSSS    Speed parameter
            ----|---------------
             0  0000    0 - Brake
             1  0001    <0 - Emergency-Stop
             2  0010    1
             3  0011    2
            0100    3
            0101    4
            0110    5
            0111    6
            1000    7
            1001    8
            1010    9
            1011    10
            1100    11
            13  1101    12
            14  1110    13
            15  1111    14
            */

            int ssss = 0;
            if (speed < 0)
                ssss = 1;
            else if (speed == 0)
                ssss = 0;
            else if (speed > 0 && speed <= 14)
                ssss = speed + 1;
            else if (speed > 14)
                ssss = 15; // always max speed

            ArrayList list = new ArrayList();
            foreach (byte b in address.GetBytes())
                list.Add(b);
            list.Add((byte)(
                (ssss & 0x0F) | // 0000SSSS
                (light ? 0x10 : 0x00) | // 000[F0]SSSS
                (forward ? DCC.SpeedForward : DCC.SpeedReverse) // 01DCSSSS
                ));

            return new DCCCommand(DCCCommandPriority.Normal, DCCCommandType.Speed, list);
        }
Пример #4
0
        public static DCCCommand LocoFunctionGroup4(LocomotiveAddress address, bool F13, bool F14, bool F15, bool F16, bool F17, bool F18, bool F19, bool F20)
        {
            // 11011110 FFFFFFFF
            // FFFFFFFF => F20, F19, F18, F17, F16, F15, F14, F13

            ArrayList list = new ArrayList();
            foreach (byte b in address.GetBytes())
                list.Add(b);
            list.Add((byte)(
                DCC.Reserved | 0x1E | // 11000000 | 00011110
                (F13 ? 0x01 : 0) |
                (F14 ? 0x02 : 0) |
                (F15 ? 0x04 : 0) |
                (F16 ? 0x08 : 0) |
                (F17 ? 0x10 : 0) |
                (F18 ? 0x20 : 0) |
                (F19 ? 0x40 : 0) |
                (F20 ? 0x80 : 0)
                ));

            return new DCCCommand(DCCCommandPriority.Normal, DCCCommandType.Function, list);
        }
Пример #5
0
        public static DCCCommand LocoFunctionGroup5(LocomotiveAddress address, bool F21, bool F22, bool F23, bool F24, bool F25, bool F26, bool F27, bool F28)
        {
            // 11011111 FFFFFFFF
            // FFFFFFFF => F28, F27, F26, F25, F24, F23, F22, F21

            ArrayList list = new ArrayList();
            foreach (byte b in address.GetBytes())
                list.Add(b);
            list.Add((byte)(
                DCC.Reserved | 0x1F | // 11000000 | 00011111
                (F21 ? 0x01 : 0) |
                (F22 ? 0x02 : 0) |
                (F23 ? 0x04 : 0) |
                (F24 ? 0x08 : 0) |
                (F25 ? 0x10 : 0) |
                (F26 ? 0x20 : 0) |
                (F27 ? 0x40 : 0) |
                (F28 ? 0x80 : 0)
                ));

            return new DCCCommand(DCCCommandPriority.Normal, DCCCommandType.Function, list);
        }
Пример #6
0
        public static DCCCommand LocoFunctionGroup3(LocomotiveAddress address, bool F9, bool F10, bool F11, bool F12)
        {
            // 101SFFFF
            // S=0 FFFF => F12, F11, F10, F9

            ArrayList list = new ArrayList();
            foreach (byte b in address.GetBytes())
                list.Add(b);
            list.Add((byte)(
                DCC.FunctionGroup2 | // 10100000
                (F9 ? 0x01 : 0) |
                (F10 ? 0x02 : 0) |
                (F11 ? 0x04 : 0) |
                (F12 ? 0x08 : 0)
                ));

            return new DCCCommand(DCCCommandPriority.Normal, DCCCommandType.Function, list);
        }
Пример #7
0
        public static DCCCommand LocoFunctionGroup2(LocomotiveAddress address, bool F5, bool F6, bool F7, bool F8)
        {
            // 101SFFFF
            // S=1 FFFF => F8, F7, F6, F5

            ArrayList list = new ArrayList();
            foreach (byte b in address.GetBytes())
                list.Add(b);
            list.Add((byte)(
                DCC.FunctionGroup2 | 0x10 | // 10110000
                (F5 ? 0x01 : 0) |
                (F6 ? 0x02 : 0) |
                (F7 ? 0x04 : 0) |
                (F8 ? 0x08 : 0)
                ));

            return new DCCCommand(DCCCommandPriority.Normal, DCCCommandType.Function, list);
        }
Пример #8
0
        public static DCCCommand LocoFunctionGroup1(LocomotiveAddress address, bool F0, bool F1, bool F2, bool F3, bool F4)
        {
            // 100CFFFF
            // CFFFF => F0, F4, F3, F2, F1
            // CV29 bit1=1 => C controls F0 (flight), 28/128 speed steps
            // CV29 bit1=0 => C not used here; flight is controlled by (C in speed14 )
            //If CV29 bit1 has a value of one (1), then bit 4(F0) controls function FL, otherwise bit 4 has no meaning!!!

            ArrayList list = new ArrayList();
            foreach (byte b in address.GetBytes())
                list.Add(b);
            list.Add((byte)(
                DCC.FunctionGroup1 | // 10000000
                (F1 ? 0x01 : 0) |
                (F2 ? 0x02 : 0) |
                (F3 ? 0x04 : 0) |
                (F4 ? 0x08 : 0) |
                (F0 ? 0x10 : 0) // if speed format != speed14
                ));

            return new DCCCommand(DCCCommandPriority.Normal, DCCCommandType.Function, list);
        }
Пример #9
0
        public static DCCCommand LocoConsist(LocomotiveAddress address, byte consistAddress, bool forward)
        {
            // 0001CCCC 0AAAAAAA

            // When Consist Control is in effect, the decoder will ignore any speed or direction instructions addressed to its
            // normal locomotive address (unless this address is the same as its consist address). Speed and direction instructions
            // now apply to the consist address only.
            // Functions controlled by instruction 100 and 101 will continue to respond to the decoders baseline address and also respond
            // to the consist address if the appropriate bits in CVs #21,22 have been activated.
            // By default all forms of Bi-directional communication are not activated in response to commands sent to the consist
            // address until specifically activated by a Decoder Control instruction. Operations mode acknowledgement and Data
            // Transmission applies to the appropriate commands at the respective decoder addresses.
            // A value of У1Ф in bit 7 of the second byte is reserved for future use.
            // CCCC contains a consist setup instruction, and the AAAAAAA in the second byte is a seven bit consist address.
            // If the address is "0000000" then the consist is deactivated. If the address is non-zero, then the consist is activated.
            // If the consist is deactivated (by setting the consist to С0000000Т), the Bi-Directional communications settings are set as specified in CVs 26-28.

            // When operations-mode acknowledgement is enabled, all consist commands must be acknowledged via operations mode acknowledgement. The format for CCCC shall be:
            // CCCC=0010 (0x02)
            // Set the consist address as specified in the second byte, and activate the consist. The consist
            // address is stored in bits 0-6 of CV #19, and bit 7 of CV #19 is set to a value of 0. The direction
            // of this unit in the consist is the normal direction. If the consist address is 0000000 the consist is deactivated.
            // CCCC=0011 (0x03)
            // Set the consist address as specified in the second byte and activate the consist. The consist
            // address is stored in bits 0-6 of CV #19, and bit 7 of CV#19 is set to a value of 1. The direction
            // of this unit in the consist is opposite its normal direction. If the consist address is 0000000 the consist is deactivated.

            // All other values of CCCC are reserved for future use.

            if (consistAddress > 127 || consistAddress < 0)
                return null;

            ArrayList list = new ArrayList();
            foreach (byte b in address.GetBytes())
                list.Add(b);
            list.Add((byte)(
                DCC.ConsistControl | // 00010000
                (forward ? 0x02 : 0x03)
                ));
            list.Add((byte)(consistAddress & 0x7F));

            return new DCCCommand(DCCCommandPriority.Normal, DCCCommandType.None, list);
        }
Пример #10
0
 private void SetAddresses()
 {
     addresses[0] = new LocomotiveAddress(7, false);
     addresses[1] = new LocomotiveAddress(3, false);
 }