Exemplo n.º 1
0
        /// <summary>
        /// Put the data from this slot into the loc state.
        /// </summary>
        public void UpdateLocFromSlot(Slot slot, ILocState l)
        {
            var spd = slot.Speed;

            l.SpeedInSteps.Actual = (spd == 1) ? 0 : spd;
            var dirf = slot.DirF;

            l.Direction.Actual = dirf.IsSet(DirFunc.Direction) ? LocDirection.Reverse : LocDirection.Forward;
            l.F0.Actual        = dirf.IsSet(DirFunc.F0);
            l.SetFunctionActualState(LocFunction.F1, dirf.IsSet(DirFunc.F1));
            l.SetFunctionActualState(LocFunction.F2, dirf.IsSet(DirFunc.F2));
            l.SetFunctionActualState(LocFunction.F3, dirf.IsSet(DirFunc.F3));
            l.SetFunctionActualState(LocFunction.F4, dirf.IsSet(DirFunc.F4));
            var snd = slot.Sound;

            l.SetFunctionActualState(LocFunction.F5, snd.IsSet(Sound.Snd1));
            l.SetFunctionActualState(LocFunction.F6, snd.IsSet(Sound.Snd2));
            l.SetFunctionActualState(LocFunction.F7, snd.IsSet(Sound.Snd3));
            l.SetFunctionActualState(LocFunction.F8, snd.IsSet(Sound.Snd4));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Send the speed and direction of the given loc towards the railway.
        /// </summary>
        protected override void OnSendLocSpeedAndDirection(ILocState loc)
        {
            Log.Trace("OnSendLocSpeedAndDirection: {0}", loc);
            try
            {
                var forward = (loc.Direction.Requested == LocDirection.Forward);
                var f1      = loc.GetFunctionRequestedState(LocFunction.F1);
                var f2      = loc.GetFunctionRequestedState(LocFunction.F2);
                var f3      = loc.GetFunctionRequestedState(LocFunction.F3);
                var f4      = loc.GetFunctionRequestedState(LocFunction.F4);
                client.LocCommand(loc.Address.ValueAsInt, loc.SpeedInSteps.Requested, forward, loc.F0.Requested, f1, f2, f3, f4);
                loc.Direction.Actual = loc.Direction.Requested;
                loc.Speed.Actual     = loc.Speed.Requested;
                loc.F0.Actual        = loc.F0.Requested;
                loc.SetFunctionActualState(LocFunction.F1, f1);
                loc.SetFunctionActualState(LocFunction.F2, f2);
                loc.SetFunctionActualState(LocFunction.F3, f3);
                loc.SetFunctionActualState(LocFunction.F4, f4);

                var f5 = loc.GetFunctionRequestedState(LocFunction.F5);
                var f6 = loc.GetFunctionRequestedState(LocFunction.F6);
                var f7 = loc.GetFunctionRequestedState(LocFunction.F7);
                var f8 = loc.GetFunctionRequestedState(LocFunction.F8);
                client.LocFunctions(loc.Address.ValueAsInt, f1, f2, f3, f4, f5, f6, f7, f8);
                loc.SetFunctionActualState(LocFunction.F1, f1);
                loc.SetFunctionActualState(LocFunction.F2, f2);
                loc.SetFunctionActualState(LocFunction.F3, f3);
                loc.SetFunctionActualState(LocFunction.F4, f4);
                loc.SetFunctionActualState(LocFunction.F5, f5);
                loc.SetFunctionActualState(LocFunction.F6, f6);
                loc.SetFunctionActualState(LocFunction.F7, f7);
                loc.SetFunctionActualState(LocFunction.F8, f8);

                var f9  = loc.GetFunctionRequestedState(LocFunction.F9);
                var f10 = loc.GetFunctionRequestedState(LocFunction.F10);
                var f11 = loc.GetFunctionRequestedState(LocFunction.F11);
                var f12 = loc.GetFunctionRequestedState(LocFunction.F12);
                var f13 = loc.GetFunctionRequestedState(LocFunction.F13);
                var f14 = loc.GetFunctionRequestedState(LocFunction.F14);
                var f15 = loc.GetFunctionRequestedState(LocFunction.F15);
                var f16 = loc.GetFunctionRequestedState(LocFunction.F16);
                client.LocFunctions2(loc.Address.ValueAsInt, f9, f10, f11, f12, f13, f14, f15, f16);
                loc.SetFunctionActualState(LocFunction.F9, f9);
                loc.SetFunctionActualState(LocFunction.F10, f10);
                loc.SetFunctionActualState(LocFunction.F11, f11);
                loc.SetFunctionActualState(LocFunction.F12, f12);
                loc.SetFunctionActualState(LocFunction.F13, f13);
                loc.SetFunctionActualState(LocFunction.F14, f14);
                loc.SetFunctionActualState(LocFunction.F15, f15);
                loc.SetFunctionActualState(LocFunction.F16, f16);
            }
            catch (Exception ex)
            {
                Log.Warn("Loc command failed: " + ex);
            }
        }