|
|
|
|
using log4net;
|
|
|
|
|
using Service.Execute.Api;
|
|
|
|
|
using Service.Execute.Enum;
|
|
|
|
|
using Service.Execute.Model;
|
|
|
|
|
using Service.Execute.StaticTools;
|
|
|
|
|
using Service.Execute.SwapException;
|
|
|
|
|
using Swapping.Business.Tech;
|
|
|
|
|
|
|
|
|
|
namespace Service.Execute.Step;
|
|
|
|
|
|
|
|
|
|
public class CarCtrlState : IState
|
|
|
|
|
{
|
|
|
|
|
private readonly ILog _log = LogManager.GetLogger(typeof(CarCtrlState));
|
|
|
|
|
|
|
|
|
|
public StateResult Handle(SwappingStateMachine machine)
|
|
|
|
|
{
|
|
|
|
|
//解锁车辆
|
|
|
|
|
InvokeStatus unLockCar = UnLockCar(machine);
|
|
|
|
|
if (unLockCar != InvokeStatus.Done)
|
|
|
|
|
{
|
|
|
|
|
return SwappingStateMachine.ReturnWithInvokeErr(unLockCar, ExceptionReason.None);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//下发选包
|
|
|
|
|
InvokeStatus distributeSelectPack = DistributeSelectPack(machine);
|
|
|
|
|
|
|
|
|
|
if (distributeSelectPack != InvokeStatus.Done)
|
|
|
|
|
{
|
|
|
|
|
return SwappingStateMachine.ReturnWithInvokeErr(distributeSelectPack, ExceptionReason.None);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new StateResult()
|
|
|
|
|
{
|
|
|
|
|
SwappingState = SwappingState.DoSwapping
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 车辆解锁
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public InvokeStatus UnLockCar(SwappingStateMachine machine)
|
|
|
|
|
{
|
|
|
|
|
return Invoker.Invoke("UnLockCar", 500, 100, machine.IsCanceled,
|
|
|
|
|
() => machine.VelUnlockFlag, () =>
|
|
|
|
|
{
|
|
|
|
|
Task<bool> result = TBoxApi.UnLockCar();
|
|
|
|
|
bool unLock = result.Result;
|
|
|
|
|
if (unLock)
|
|
|
|
|
{
|
|
|
|
|
//查询车辆锁止状态
|
|
|
|
|
Task<TboxCarInfoModel> carInfo = TBoxApi.GetCarInfo();
|
|
|
|
|
if (carInfo.Result.HeartBeatMsg.LockStatus == 1)
|
|
|
|
|
{
|
|
|
|
|
machine.VelUnlockFlag = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, () =>
|
|
|
|
|
{
|
|
|
|
|
machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.ErrUnLockCar.GetLed());
|
|
|
|
|
SoundTool.PlayOneSound((int)InfoEnum.SwapInfo.ErrUnLockCar);
|
|
|
|
|
}, false, () => { machine.ExceptionReason = ExceptionReason.UnLockCarError; }
|
|
|
|
|
, 10, InvokeStatus.None);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 下发选包
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public InvokeStatus DistributeSelectPack(SwappingStateMachine machine)
|
|
|
|
|
{
|
|
|
|
|
return Invoker.Invoke("DistributeSelectPack", 500, 10, machine.IsCanceled,
|
|
|
|
|
() => machine.DistributeSelectPackFlag, () =>
|
|
|
|
|
{
|
|
|
|
|
var swapOrderBatteryInfo = machine.SwapOrderBatteryInfo;
|
|
|
|
|
machine.DistributeSelectPackFlag =
|
|
|
|
|
PlcApi.DistributeSelectPack(swapOrderBatteryInfo.InBinInfo.No, swapOrderBatteryInfo.UpBinInfo.No);
|
|
|
|
|
}, () => { machine.LedTool?.WriteProgramContent(InfoEnum.SwapInfo.ErrDistributeSelectPack.GetLed()); });
|
|
|
|
|
}
|
|
|
|
|
}
|