public void Step() { if (DeviceMgr.IsInAction()) //communication action is going on { return; } if (currRx.i_State == RUN_STATE.STOPPING) //user choose to stop { DeviceMgr.Reset(); act_mgr.Reset(); bPaused = false; bRunning = false; currRx.i_State = RUN_STATE.IDLE; } if (bPaused || !bRunning || act_mgr.IsBusy) { return; } Debug.WriteLine("Step:" + stm.ToString()); if (stm == ACTION_STATE.INIT_FOR_START)//search the next valid channel { currRx.i_State = RUN_STATE.SEARCHING; StatusChanged(this, "search"); stm = act_mgr.Do(ACTION_REQUEST.INIT_NAV_RANGE, stm); return; } if (stm == ACTION_STATE.INIT_FOR_SEARCH) //prepare the capture with 1:1 mode { currRx.i_State = RUN_STATE.SEARCHING; StatusChanged(this, "search"); stm = act_mgr.Do(ACTION_REQUEST.INITKI_FOR_SEARCH, stm); return; } if (stm == ACTION_STATE.INIT_FOR_RS_KTTP) //capture once //set to KTTP mode and delay 1s { currRx.i_State = RUN_STATE.SEARCHING; StatusChanged(this, "search"); stm = act_mgr.Do(ACTION_REQUEST.SET_FOR_RS_KTTP, stm); return; } if (stm == ACTION_STATE.INIT_FOR_RS_KTTN) { currRx.i_State = RUN_STATE.SEARCHING; StatusChanged(this, "search"); double val = act_mgr.dStableReading; if (val < -999) { currRx.i_State = RUN_STATE.STOPPING; StatusChanged(this, "stopping"); return; } currRx.var.vRs = val; stm = act_mgr.Do(ACTION_REQUEST.SET_FOR_RS_KTTN, stm); return; } if (stm == ACTION_STATE.COMPLETE_ISRC) //capture once //set to KTTP mode { currRx.i_State = RUN_STATE.SEARCHING; StatusChanged(this, "search"); double val = act_mgr.dStableReading; if (val < -999) { currRx.i_State = RUN_STATE.STOPPING; StatusChanged(this, "stopping"); return; } currRx.var.vRs = Math.Abs(currRx.var.vRs - val) / 2.0; currRx.var.iSrc = currRx.var.vRs / currRx.var.rRs; currRx.var.iSrc = currRx.var.iSrc * RX_VAR.INIT_LOOP / (double)currRx.var.iK; double stdcurr = RunWnd.syscfg.GetStdCurrent(currRx.iIx, currRx.bSqrt); if (currRx.var.iSrc < 0 || (Math.Abs(stdcurr - currRx.var.iSrc) > stdcurr * 0.5)) { if (retry == 0) { retry++; stm = ACTION_STATE.INIT_FOR_SEARCH; DeviceMgr.SysLog(String.Format("Incorrect current {0} vs std:{1}, bSqrt is {2}, iIx is {3}", currRx.var.iSrc.ToString(), stdcurr.ToString(), currRx.bSqrt.ToString(), currRx.iIx.ToString())); } else { currRx.i_State = RUN_STATE.STOPPING; StatusChanged(this, "stopping"); return; } } else { stm = act_mgr.Do(ACTION_REQUEST.SET_FOR_TRACKP, stm); } return; } #region no use /* * if (stm == ACTION_STATE.INIT_FOR_RX_KTTP) //capture once //set to KTTP mode * { * currRx.i_State = RUN_STATE.SEARCHING; * StatusChanged(this, "search"); * double val = act_mgr.dStableReading; * if (val < -999) * { * currRx.i_State = RUN_STATE.STOPPING; * StatusChanged(this, "stopping"); * return; * } * * currRx.var.vRs = Math.Abs(currRx.var.vRs - val) / 2.0; * currRx.var.iSrc = currRx.var.vRs / currRx.var.rRs; * stm = act_mgr.Do(ACTION_REQUEST.SET_FOR_RX_KTTP, stm); * return; * } * if (stm == ACTION_STATE.INIT_FOR_RX_KTTN) * { * currRx.i_State = RUN_STATE.SEARCHING; * StatusChanged(this, "search"); * double val = act_mgr.dStableReading; * if (val < -999) * { * currRx.i_State = RUN_STATE.STOPPING; * StatusChanged(this, "stopping"); * return; * } * currRx.var.vRx = val; * stm = act_mgr.Do(ACTION_REQUEST.SET_FOR_RX_KTTN, stm); * return; * } * if (stm == ACTION_STATE.INIT_K_ADJUST) //adjust K * { * double val = act_mgr.dStableReading; * if (val < -999) * { * currRx.i_State = RUN_STATE.STOPPING; * StatusChanged(this, "stopping"); * return; * } * * currRx.var.vRx = Math.Abs(currRx.var.vRx - val)/ 2; * currRx.var.rRx = currRx.var.vRx / currRx.var.iSrc; * * currRx.var.iK = currRx.var.calc_capture_nextk(); * DeviceMgr.Action("turnk", Convert.ToUInt32(currRx.var.iK)); * stm = ACTION_STATE.INIT_FOR_TRACKP; * } */ #endregion if (stm == ACTION_STATE.INIT_FOR_TRACKP) //capture once //set to KTTP mode { currRx.i_State = RUN_STATE.TRACKING; StatusChanged(this, "tracking"); stm = act_mgr.Do(ACTION_REQUEST.SET_FOR_TRACKP, stm); return; } if (stm == ACTION_STATE.INIT_FOR_TRACKN) { currRx.i_State = RUN_STATE.TRACKING; StatusChanged(this, "tracking"); double val = act_mgr.dStableReading; if (val < -999) { currRx.i_State = RUN_STATE.STOPPING; StatusChanged(this, "stopping"); return; } currRx.var.vCrossP = val; stm = act_mgr.Do(ACTION_REQUEST.SET_FOR_TRACKN, stm); return; } if (stm == ACTION_STATE.UPDATE_K_TRACK) { currRx.i_State = RUN_STATE.TRACKING; StatusChanged(this, "tracking"); double val = act_mgr.dStableReading; if (val < -999) { currRx.i_State = RUN_STATE.STOPPING; StatusChanged(this, "stopping"); return; } currRx.var.vCrossN = val; stm = act_mgr.Do(ACTION_REQUEST.SET_NEXT_K, stm); if (stm == ACTION_STATE.SHOW_NEW_VALUE) { currRx.var.log_start(currRx.iRRange); } return; } if (stm == ACTION_STATE.SHOW_NEW_VALUE) { if (data_mgr.AddNewValue(ref currRx.var.rRx)) { StatusChanged(this, "newvalue"); } if (data_mgr.iMeasCnt == RunWnd.syscfg.iMeasTimes) { stm = ACTION_STATE.COMPLETE; } else { stm = ACTION_STATE.INIT_FOR_TRACKP; } return; } if (stm == ACTION_STATE.COMPLETE) //update the display and try the next channel { currRx.i_State = RUN_STATE.IDLE; bRunning = false; StatusChanged(this, "complete"); act_mgr.Do(ACTION_REQUEST.INIT_NAV_RANGE, stm); DeviceMgr.Reset(); while (DeviceMgr.IsInAction()) { ; } stm = ACTION_STATE.IDLE; } }
//Blit action debug info in the planning UI public virtual void BlitDebugUI() { GUILayout.Label(_state.ToString()); }