Exemple #1
0
 void ChangeState(UpdateStateDelegate newState)
 {
     if (newState != UpdateState)
     {
         RespawnNavAgent();
         UpdateState = newState;
     }
 }
Exemple #2
0
        public CpuModel(ICpuModelOutput output)
        {
            _output = output;
            Reset();

            _updateStateDelegate   = new UpdateStateDelegate(UpdateState);
            _commandHasRunDelegate = new UpdateStateDelegate(CommandHasRunAsync);
        }
Exemple #3
0
 private void StateChanged(object sender, EyeTrackingStateChangedEventArgs eyeTrackingStateChangedEventArgs)
 {
     // Forward state change to UI thread
     if (InvokeRequired)
     {
         var updateStateDelegate = new UpdateStateDelegate(UpdateState);
         Invoke(updateStateDelegate, new object[] { eyeTrackingStateChangedEventArgs });
     }
     else
     {
         UpdateState(eyeTrackingStateChangedEventArgs);
     }
 }
Exemple #4
0
    private void Update()
    {
        if (CurrentState != NextState)
        {
            UpdateStateDelegate = null;
            FinishStateDelegate?.Invoke();
            FinishStateDelegate = null;

            CurrentState = NextState;

            StartEvents();

            StartStateDelegate?.Invoke();
            StartStateDelegate = null;
            OnStartState?.Invoke(CurrentState);

            return;
        }

        UpdateStateDelegate?.Invoke();
    }
Exemple #5
0
        /// <summary>
        /// 注册一个状态,不适用的方法可以传递Null
        /// </summary>
        public void RegistState(T state, EnterStateDelegate onEnter = null, ExitStateDelegate onExit = null, UpdateStateDelegate onUpdate = null, CheckSwitchStateEnableDelegate checkSwitchEnable = null)
        {
            StateController <T> sc = new StateController <T>(state);

            sc.onEnter           = onEnter;
            sc.onExit            = onExit;
            sc.onUpdate          = onUpdate;
            sc.checkSwitchEnable = checkSwitchEnable;

            if (null == CurState)
            {
                //设置为第一个状态
                CurState = state;
            }

            _stateDic[state] = sc;
        }
Exemple #6
0
        public bool registerUpdateStateDelegate(
            UpdateStateDelegate aUpdateStateDelegate)
        {
            bool lresult = false;

            do
            {
                if (mSession == null)
                {
                    break;
                }

                try
                {
                    object lUnknown;

                    mSession.getIConnectionPointContainer(
                        typeof(IConnectionPointContainer).GUID,
                        out lUnknown);

                    if (lUnknown == null)
                    {
                        break;
                    }

                    var lConnectionPointContainer = lUnknown as IConnectionPointContainer;

                    if (lConnectionPointContainer == null)
                    {
                        break;
                    }

                    IConnectionPoint lConnectionPoint = null;

                    lConnectionPointContainer.FindConnectionPoint(
                        typeof(CaptureManagerLibrary.ISessionCallback).GUID,
                        out lConnectionPoint);

                    if (lConnectionPoint == null)
                    {
                        break;
                    }

                    int lId = 0;

                    lConnectionPoint.Advise(
                        new SessionCallback(aUpdateStateDelegate),
                        out lId);

                    mStateDelegate[aUpdateStateDelegate] = lId;

                    lresult = true;
                }
                catch (Exception exc)
                {
                    LogManager.getInstance().write(exc.Message);
                }
            } while (false);

            return(lresult);
        }
Exemple #7
0
 public SessionCallback(
     UpdateStateDelegate aUpdateStateDelegate)
 {
     mUpdateStateDelegate = aUpdateStateDelegate;
 }
Exemple #8
0
        public bool FwUpdate(UpdateStateDelegate handler, string fileName, bool programWrite = true, bool programVerify = true, bool programStart = true, string password = "******")
        {
            try
            {
                handler?.Invoke(UpdateState.ReadHex);
                byte[] buffer = new byte[MaximumBufferSize];
                if (!LoadProgramFile(fileName, buffer, out uint updateBufferUsed))
                {
                    return(false);
                }

                handler?.Invoke(UpdateState.Connect);
                if (!Connect(password, out bool oneWireMode))
                {
                    return(false);
                }

                _failureAddress = 0;
                _oneWire        = oneWireMode;

                bool supportsCrc = DetectSupport(CommandProgramCheckCRC);
                ResetCrc();
                bool supportsVerify = DetectSupport(CommandProgramVerify);

                string deviceRevision = ReadRevisionInfo();
                if (string.IsNullOrEmpty(deviceRevision))
                {
                    return(false);
                }

                if (string.Compare(deviceRevision, ValidBootloader, StringComparison.OrdinalIgnoreCase) != 0)
                {
                    return(false);
                }

                string deviceSignature = ReadSignatureInfo();
                if (string.IsNullOrEmpty(deviceSignature))
                {
                    return(false);
                }

                string deviceName = GetDeviceName(deviceSignature);
                if (string.IsNullOrEmpty(deviceName))
                {
                    return(false);
                }

                long deviceFlashSize = ReadFlashSizeInfo();
                if (deviceFlashSize < 0)
                {
                    return(false);
                }

                if (deviceFlashSize > buffer.Length)
                {
                    return(false);
                }

                if (deviceFlashSize < updateBufferUsed)
                {
                    return(false);
                }

                long deviceWriteBuffer = ReadBufferSizeInfo();
                if (deviceWriteBuffer < MinimumWriteBuffer)
                {
                    return(false);
                }

                if (supportsCrc)
                {
                    if (!CheckCrc())
                    {
                        return(false);
                    }
                }

                if (programWrite)
                {
                    handler?.Invoke(UpdateState.Update);
                    if (!WriteFirmware(buffer, (int)updateBufferUsed, (int)deviceWriteBuffer))
                    {
                        return(false);
                    }
                }

                if (programVerify && supportsVerify)
                {
                    handler?.Invoke(UpdateState.Verify);
                    if (!VerifyFirmware(buffer, (int)updateBufferUsed))
                    {
                        return(false);
                    }
                }

                if (supportsCrc)
                {
                    if (!CheckCrc())
                    {
                        return(false);
                    }
                }

                if (programStart)
                {
                    handler?.Invoke(UpdateState.StartFw);
                    if (!StartFirmware())
                    {
                        return(false);
                    }
                }

                Thread.Sleep(500);

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }