using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using COMM;
using AR;
using Project.StateMachine;

namespace Project
{
    public partial class fMain
    {

        public Boolean _SM_RUN_CHARGE_CHECK(bool isFirst, TimeSpan stepTime)
        {
            //충전상태체크를 확인합니다
            //10초안에 충전 플래그가 활성화되지 않으면 QC상태로 이동한다
            if (PUB.AGV.system1.Battery_charging == false || VAR.BOOL[eVarBool.FLAG_CHARGEONA] == false)
            {
                if (PUB.AGV.error.Charger_pos_error)
                {
                    PUB.Speak(Lang.충전기위치오류로작업을취소합니다, true);
                    PUB.sm.ClearRunStep();
                    PUB.sm.SetNewRunStep(ERunStep.CHARGEOFF);
                    PUB.sm.SetNewStep(eSMStep.RUN);
                }
                else if (PUB.AGV.error.Charger_run_error)
                {
                    PUB.Speak(Lang.충전기위치오류로작업을취소합니다, true);
                    PUB.sm.ClearRunStep();
                    PUB.sm.SetNewRunStep(ERunStep.CHARGEOFF);
                    PUB.sm.SetNewStep(eSMStep.RUN);
                }
                else
                {
                    var tsCmd = DateTime.Now - LastCommandTime;
                    if (tsCmd.TotalSeconds >= 30)
                    {
                        PUB.log.AddE( Lang.충전기작동확인이오버되어홈으로이동조치합니다);
                        PUB.AGV.AGVCharge(PUB.setting.ChargerID, false);
                        PUB.sm.ClearRunStep();
                        PUB.sm.SetNewRunStep(ERunStep.CHARGEOFF);
                        PUB.sm.SetNewStep(eSMStep.RUN);
                    }
                    else
                    {
                        PUB.Result.result_message = string.Format("충전기 활성화 수신 확인 중({0:N1}/{1})", tsCmd.TotalSeconds, 30);
                        PUB.Result.result_progressmax = 15;
                        PUB.Result.result_progressvalue = tsCmd.TotalSeconds;
                    }
                }
                
                return false;
            }
            else return true;
        }
    }
}
