/// <summary>
        /// Execute this action on the given loc.
        /// </summary>
        protected override void Execute(ILocState loc, IActionContext context)
        {
            IStateProperty <bool> property;

            switch (Entity.Function)
            {
            case LocFunction.Light:
                property = loc.F0;
                break;

            default:
                if (!loc.TryGetFunctionState(Entity.Function, out property))
                {
                    return;
                }
                break;
            }

            switch (Entity.Command)
            {
            case LocFunctionCommand.On:
                property.Requested = true;
                break;

            case LocFunctionCommand.Off:
                property.Requested = false;
                break;

            case LocFunctionCommand.Toggle:
                property.Requested = !property.Requested;
                break;
            }
        }
示例#2
0
        /// <summary>
        /// SetFunctionActualState set the actual state of a function in the given loc.
        /// </summary>
        public static void SetFunctionActualState(this ILocState loc, LocFunction function, bool value)
        {
            IStateProperty <bool> state;

            if (loc.TryGetFunctionState(function, out state))
            {
                state.Actual = value;
            }
        }
示例#3
0
        /// <summary>
        /// GetFunctionActualState returns the actual state of a function in the given loc.
        /// If no such function exists, false is returned.
        /// </summary>
        public static bool GetFunctionActualState(this ILocState loc, LocFunction function)
        {
            IStateProperty <bool> state;

            if (loc.TryGetFunctionState(function, out state))
            {
                return(state.Actual);
            }
            return(false);
        }
        /// <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);
            Loc l;

            if (!connection.TryGetLoc(loc, true, out l))
            {
                return;
            }

            var direction = (loc.Direction.Requested == LocDirection.Forward);

            l.SetDirection(direction);
            loc.Direction.Actual = loc.Direction.Requested;
            if (!loc.F0.IsConsistent)
            {
                l.SetFunction(0, loc.F0.Requested);
            }
            foreach (var lf in loc.Functions)
            {
                IStateProperty <bool> state;
                if (loc.TryGetFunctionState(lf, out state))
                {
                    if (!state.IsConsistent)
                    {
                        l.SetFunction((int)lf, state.Requested);
                    }
                }
            }

            l.SetSpeed((int)((127.0 / 100.0) * loc.Speed.Requested));
            loc.Speed.Actual = loc.Speed.Requested;
            loc.F0.Actual    = loc.F0.Requested;
            foreach (var lf in loc.Functions)
            {
                IStateProperty <bool> state;
                if (loc.TryGetFunctionState(lf, out state))
                {
                    state.Actual = state.Requested;
                }
            }
        }