Exemplo n.º 1
0
        public override void Start()
        {
            var allAIThingPaths     = config.AIThings.AllAIThingPaths;
            var autoArmAIThingPaths = config.AIThings.AutoArmAIThingPaths;

            allAIThingStates = new Dictionary <string, Status>();
            allAIFinishFlags = new Dictionary <string, bool>();

            foreach (var aiThingPath in allAIThingPaths)
            {
                allAIThingStates.Add(aiThingPath, Status.Idle);
                allAIFinishFlags.Add(aiThingPath, false);
            }

            AllAIStatePrevious = AllAIStatus.AllIdle;
            _allAIStateNow     = AllAIStatus.AllIdle;

            //订阅每个aiThing的StateChanged和AITaskFinished事件
            foreach (var aiThingPath in allAIThingPaths)
            {
                MyHub.EventHub.Subscribe(new EventFilter(aiThingPath, "StateChanged"), stateChangedhandler);
                MyHub.EventHub.Subscribe(new EventFilter(aiThingPath, "AITaskFinished"), aiTaskFinishedhandler);
            }

            //第一次无需判断(默认认为程序启动时所有AIThing都是idle状态)
            //直接arm所有需要自动arm的AIThing
            StartArmTask();
        }
Exemplo n.º 2
0
        //当所有卡状态都变为一致时,AllAIState为该状态,否则AllAIState为Chaos
        //当所有卡状态都变为Idle时,arm所有需要自动arm的AIThing
        private void attemptToChangeAllAIState()
        {
            var tempState = allAIThingStates.Values.FirstOrDefault();

            foreach (var state in allAIThingStates.Values)
            {
                if (state != tempState)
                {
                    if (!(AllAIStateNow == AllAIStatus.Chaos))
                    {
                        AllAIStatePrevious = AllAIStateNow;
                        AllAIStateNow      = AllAIStatus.Chaos;
                    }
                    return;
                }
            }
            //循环完还没return说明所有卡状态一致
            AllAIStatePrevious = AllAIStateNow;
            //tempState是AllAIStatus的子集,可以强制转换
            AllAIStateNow = (AllAIStatus)tempState;
            //当所有卡状态都变为Idle时,arm所有需要自动arm的AIThing
            if (AllAIStateNow == AllAIStatus.AllIdle)
            {
                Thread.Sleep(config.DelaySecondAfterFinish * 1000);
                StartArmTask();
            }
        }